Skip to content

Commit

Permalink
Update outdated image properties
Browse files Browse the repository at this point in the history
  • Loading branch information
joshdholtz committed Jan 13, 2025
1 parent b3e2f26 commit 162df23
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 29 deletions.
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
11 changes: 0 additions & 11 deletions Sources/Paywalls/Components/PaywallImageComponent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,6 @@ import Foundation

#if PAYWALL_COMPONENTS

//source: ImageScheme | None = None
//override_source_lid: LocalizationId | None = None
//color_overlay: ColorSchemes | None = None
//fit_mode: FitMode | None = None
//mask_shape: MaskShape | None = None
//size: Size | None = None
//padding: Spacing | None = None
//margin: Spacing | None = None
//border: Border | None = None
//shadow: Shadow | None = None

public extension PaywallComponent {

struct ImageComponent: PaywallComponentBase {
Expand Down

0 comments on commit 162df23

Please sign in to comment.