Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Paywalls V2] Updated outdated image component properties #4649

Merged
merged 3 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,15 @@ struct ImageComponentView: View {
// WIP: Fix this later when accessibility info is available
.accessibilityHidden(true)
// WIP: Need to replace this gradient with the better one
.overlay(
LinearGradient(
gradient: Gradient(colors: style.gradientColors),
startPoint: .top,
endPoint: .bottom
.applyIfLet(style.colorOverlay, apply: { view, colorOverlay in
view.overlay(
Color.clear
.backgroundStyle(
.color(colorOverlay),
uiConfigProvider: viewModel.uiConfigProvider
)
)
)
})
// WIP: this needs more shapes and borders
// WIP: this might also need dropshadow
.shape(border: nil,
Expand Down Expand Up @@ -187,9 +189,10 @@ struct ImageComponentView_Previews: PreviewProvider {
)
),
fitMode: .fill,
gradientColors: [
"#ffffff00", "#ffffff00", "#ffffffff"
]
colorOverlay: .init(light: .linear(0, [
.init(color: "#ffffff", percent: 0),
.init(color: "#ffffff00", percent: 40)
]))
)
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class ImageComponentViewModel {
private var introOfferEligibilityContext: IntroOfferEligibilityContext

private let localizationProvider: LocalizationProvider
private let uiConfigProvider: UIConfigProvider
let uiConfigProvider: UIConfigProvider
private let component: PaywallComponent.ImageComponent

private let imageInfo: PaywallComponent.ThemeImageUrls
Expand Down Expand Up @@ -71,7 +71,11 @@ class ImageComponentViewModel {
size: partial?.size ?? self.component.size,
fitMode: partial?.fitMode ?? self.component.fitMode,
maskShape: partial?.maskShape ?? self.component.maskShape,
gradientColors: partial?.gradientColors ?? self.component.gradientColors
colorOverlay: partial?.colorOverlay ?? self.component.colorOverlay,
padding: partial?.padding ?? self.component.padding,
margin: partial?.margin ?? self.component.margin,
border: partial?.border ?? self.component.border,
shadow: partial?.shadow ?? self.component.shadow
)

apply(style)
Expand All @@ -97,7 +101,11 @@ struct LocalizedImagePartial: PresentedPartial {
overrideSourceLid: otherPartial?.overrideSourceLid ?? basePartial?.overrideSourceLid,
fitMode: otherPartial?.fitMode ?? basePartial?.fitMode,
maskShape: otherPartial?.maskShape ?? basePartial?.maskShape,
gradientColors: otherPartial?.gradientColors ?? basePartial?.gradientColors
colorOverlay: otherPartial?.colorOverlay ?? basePartial?.colorOverlay,
padding: otherPartial?.padding ?? basePartial?.padding,
margin: otherPartial?.margin ?? basePartial?.margin,
border: otherPartial?.border ?? basePartial?.border,
shadow: otherPartial?.shadow ?? basePartial?.shadow
)
)
}
Expand Down Expand Up @@ -134,7 +142,11 @@ struct ImageComponentStyle {
let darkLowResUrl: URL?
let size: PaywallComponent.Size
let shape: ShapeModifier.Shape?
let gradientColors: [Color]
let colorOverlay: PaywallComponent.ColorScheme?
let padding: PaywallComponent.Padding?
let margin: PaywallComponent.Padding?
let border: PaywallComponent.Border?
let shadow: PaywallComponent.Shadow?
let contentMode: ContentMode

init(
Expand All @@ -143,7 +155,11 @@ struct ImageComponentStyle {
size: PaywallComponent.Size,
fitMode: PaywallComponent.FitMode,
maskShape: PaywallComponent.MaskShape? = nil,
gradientColors: [PaywallComponent.ColorHex]? = nil
colorOverlay: PaywallComponent.ColorScheme? = nil,
padding: PaywallComponent.Padding? = nil,
margin: PaywallComponent.Padding? = nil,
border: PaywallComponent.Border? = nil,
shadow: PaywallComponent.Shadow? = nil
) {
self.visible = visible
self.widthLight = source.light.width
Expand All @@ -156,7 +172,11 @@ struct ImageComponentStyle {
self.darkLowResUrl = source.dark?.heicLowRes
self.size = size
self.shape = maskShape?.shape
self.gradientColors = gradientColors?.compactMap { $0.toColor(fallback: Color.clear) } ?? []
self.colorOverlay = colorOverlay
self.padding = padding
self.margin = margin
self.border = border
self.shadow = shadow
self.contentMode = fitMode.contentMode
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ private enum Template1Preview {
)
),
fitMode: .fit,
gradientColors: ["#ffffff00", "#ffffff00", "#ffffffff"]
colorOverlay: .init(light: .linear(0, [
.init(color: "#ffffff", percent: 0),
.init(color: "#ffffff00", percent: 40)
]))
)

static let title = PaywallComponent.TextComponent(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ private enum Template5Preview {
)
),
fitMode: .fill,
maxHeight: 200,
gradientColors: ["#ffffff00", "#ffffff00", "#ffffffff"]
colorOverlay: .init(light: .linear(0, [
.init(color: "#ffffff", percent: 0),
.init(color: "#ffffff00", percent: 40)
]))
)

static let title = PaywallComponent.TextComponent(
Expand Down
39 changes: 31 additions & 8 deletions Sources/Paywalls/Components/PaywallImageComponent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@ public extension PaywallComponent {
public let source: ThemeImageUrls
public let size: Size
public let overrideSourceLid: LocalizationKey?
public let maskShape: MaskShape?
public let gradientColors: [ColorHex]?
public let fitMode: FitMode
public let maskShape: MaskShape?
public let colorOverlay: ColorScheme?
public let padding: Padding?
public let margin: Padding?
public let border: Border?
public let shadow: Shadow?

public let overrides: ComponentOverrides<PartialImageComponent>?

Expand All @@ -29,9 +33,12 @@ public extension PaywallComponent {
size: Size = .init(width: .fill, height: .fit),
overrideSourceLid: LocalizationKey? = nil,
fitMode: FitMode = .fit,
maxHeight: CGFloat? = nil,
maskShape: MaskShape? = nil,
gradientColors: [ColorHex]? = [],
colorOverlay: ColorScheme? = nil,
padding: Padding? = nil,
margin: Padding? = nil,
border: Border? = nil,
shadow: Shadow? = nil,
overrides: ComponentOverrides<PartialImageComponent>? = nil
) {
self.type = .image
Expand All @@ -40,7 +47,11 @@ public extension PaywallComponent {
self.overrideSourceLid = overrideSourceLid
self.fitMode = fitMode
self.maskShape = maskShape
self.gradientColors = gradientColors
self.colorOverlay = colorOverlay
self.padding = padding
self.margin = margin
self.border = border
self.shadow = shadow
self.overrides = overrides
}

Expand All @@ -53,8 +64,12 @@ public extension PaywallComponent {
public let size: Size?
public let overrideSourceLid: LocalizationKey?
public let maskShape: MaskShape?
public let gradientColors: [ColorHex]?
public let fitMode: FitMode?
public let colorOverlay: ColorScheme?
public let padding: Padding?
public let margin: Padding?
public let border: Border?
public let shadow: Shadow?

public init(
visible: Bool? = true,
Expand All @@ -63,15 +78,23 @@ public extension PaywallComponent {
overrideSourceLid: LocalizationKey? = nil,
fitMode: FitMode? = nil,
maskShape: MaskShape? = nil,
gradientColors: [ColorHex]? = nil
colorOverlay: ColorScheme? = nil,
padding: Padding? = nil,
margin: Padding? = nil,
border: Border? = nil,
shadow: Shadow? = nil
) {
self.visible = visible
self.source = source
self.size = size
self.overrideSourceLid = overrideSourceLid
self.fitMode = fitMode
self.maskShape = maskShape
self.gradientColors = gradientColors
self.colorOverlay = colorOverlay
self.padding = padding
self.margin = margin
self.border = border
self.shadow = shadow
}

}
Expand Down