|
| 1 | +package com.revenuecat.paywallstester.paywalls |
| 2 | + |
| 3 | +import androidx.compose.ui.graphics.Color |
| 4 | +import androidx.compose.ui.graphics.toArgb |
| 5 | +import com.revenuecat.paywallstester.SampleData |
| 6 | +import com.revenuecat.purchases.InternalRevenueCatAPI |
| 7 | +import com.revenuecat.purchases.paywalls.components.ButtonComponent |
| 8 | +import com.revenuecat.purchases.paywalls.components.StackComponent |
| 9 | +import com.revenuecat.purchases.paywalls.components.TextComponent |
| 10 | +import com.revenuecat.purchases.paywalls.components.WebViewComponent |
| 11 | +import com.revenuecat.purchases.paywalls.components.common.Background |
| 12 | +import com.revenuecat.purchases.paywalls.components.common.ComponentsConfig |
| 13 | +import com.revenuecat.purchases.paywalls.components.common.LocaleId |
| 14 | +import com.revenuecat.purchases.paywalls.components.common.LocalizationData |
| 15 | +import com.revenuecat.purchases.paywalls.components.common.LocalizationKey |
| 16 | +import com.revenuecat.purchases.paywalls.components.common.PaywallComponentsConfig |
| 17 | +import com.revenuecat.purchases.paywalls.components.common.PaywallComponentsData |
| 18 | +import com.revenuecat.purchases.paywalls.components.properties.ColorInfo |
| 19 | +import com.revenuecat.purchases.paywalls.components.properties.ColorScheme |
| 20 | +import com.revenuecat.purchases.paywalls.components.properties.Dimension.Vertical |
| 21 | +import com.revenuecat.purchases.paywalls.components.properties.Dimension.ZLayer |
| 22 | +import com.revenuecat.purchases.paywalls.components.properties.FlexDistribution.END |
| 23 | +import com.revenuecat.purchases.paywalls.components.properties.FontWeight |
| 24 | +import com.revenuecat.purchases.paywalls.components.properties.HorizontalAlignment.LEADING |
| 25 | +import com.revenuecat.purchases.paywalls.components.properties.Padding |
| 26 | +import com.revenuecat.purchases.paywalls.components.properties.Shape |
| 27 | +import com.revenuecat.purchases.paywalls.components.properties.Size |
| 28 | +import com.revenuecat.purchases.paywalls.components.properties.SizeConstraint.Fill |
| 29 | +import com.revenuecat.purchases.paywalls.components.properties.SizeConstraint.Fixed |
| 30 | +import com.revenuecat.purchases.paywalls.components.properties.SizeConstraint.Fit |
| 31 | +import com.revenuecat.purchases.paywalls.components.properties.TwoDimensionalAlignment |
| 32 | +import java.net.URL |
| 33 | + |
| 34 | +private const val PLACEHOLDER_WEB_VIEW_URL = "https://example.com" |
| 35 | + |
| 36 | +@OptIn(InternalRevenueCatAPI::class) |
| 37 | +internal fun webViewSample(): SampleData.Components { |
| 38 | + val textColor = ColorScheme( |
| 39 | + light = ColorInfo.Hex(Color.Black.toArgb()), |
| 40 | + dark = ColorInfo.Hex(Color.White.toArgb()), |
| 41 | + ) |
| 42 | + val backgroundColor = ColorScheme( |
| 43 | + light = ColorInfo.Hex(Color.White.toArgb()), |
| 44 | + dark = ColorInfo.Hex(Color.Black.toArgb()), |
| 45 | + ) |
| 46 | + val accentColor = ColorScheme( |
| 47 | + light = ColorInfo.Hex(Color(red = 5, green = 124, blue = 91).toArgb()), |
| 48 | + ) |
| 49 | + |
| 50 | + return SampleData.Components( |
| 51 | + data = PaywallComponentsData( |
| 52 | + id = "sample_web_view_paywall_id", |
| 53 | + templateName = "template", |
| 54 | + assetBaseURL = URL("https://assets.pawwalls.com"), |
| 55 | + componentsConfig = ComponentsConfig( |
| 56 | + base = PaywallComponentsConfig( |
| 57 | + stack = StackComponent( |
| 58 | + components = listOf( |
| 59 | + TextComponent( |
| 60 | + text = LocalizationKey("title"), |
| 61 | + color = textColor, |
| 62 | + fontWeight = FontWeight.BOLD, |
| 63 | + fontSize = 24, |
| 64 | + horizontalAlignment = LEADING, |
| 65 | + size = Size(width = Fill, height = Fit), |
| 66 | + margin = Padding(top = 16.0, bottom = 8.0, leading = 16.0, trailing = 16.0), |
| 67 | + ), |
| 68 | + WebViewComponent( |
| 69 | + id = "sample_web_view", |
| 70 | + url = PLACEHOLDER_WEB_VIEW_URL, |
| 71 | + size = Size(width = Fill, height = Fixed(400u)), |
| 72 | + fallback = StackComponent( |
| 73 | + components = listOf( |
| 74 | + TextComponent( |
| 75 | + text = LocalizationKey("fallback"), |
| 76 | + color = textColor, |
| 77 | + horizontalAlignment = LEADING, |
| 78 | + size = Size(width = Fill, height = Fit), |
| 79 | + padding = Padding( |
| 80 | + top = 16.0, |
| 81 | + bottom = 16.0, |
| 82 | + leading = 16.0, |
| 83 | + trailing = 16.0, |
| 84 | + ), |
| 85 | + ), |
| 86 | + ), |
| 87 | + dimension = ZLayer(alignment = TwoDimensionalAlignment.CENTER), |
| 88 | + size = Size(width = Fill, height = Fixed(400u)), |
| 89 | + ), |
| 90 | + ), |
| 91 | + ButtonComponent( |
| 92 | + action = ButtonComponent.Action.RestorePurchases, |
| 93 | + stack = StackComponent( |
| 94 | + components = listOf( |
| 95 | + TextComponent( |
| 96 | + text = LocalizationKey("cta"), |
| 97 | + color = ColorScheme(light = ColorInfo.Hex(Color.White.toArgb())), |
| 98 | + fontWeight = FontWeight.BOLD, |
| 99 | + ), |
| 100 | + ), |
| 101 | + dimension = ZLayer(alignment = TwoDimensionalAlignment.CENTER), |
| 102 | + size = Size(width = Fit, height = Fit), |
| 103 | + backgroundColor = accentColor, |
| 104 | + padding = Padding( |
| 105 | + top = 8.0, |
| 106 | + bottom = 8.0, |
| 107 | + leading = 32.0, |
| 108 | + trailing = 32.0, |
| 109 | + ), |
| 110 | + margin = Padding(top = 16.0, bottom = 16.0, leading = 16.0, trailing = 16.0), |
| 111 | + shape = Shape.Pill, |
| 112 | + ), |
| 113 | + ), |
| 114 | + ), |
| 115 | + dimension = Vertical(alignment = LEADING, distribution = END), |
| 116 | + size = Size(width = Fill, height = Fill), |
| 117 | + backgroundColor = backgroundColor, |
| 118 | + ), |
| 119 | + background = Background.Color(backgroundColor), |
| 120 | + stickyFooter = null, |
| 121 | + ), |
| 122 | + ), |
| 123 | + componentsLocalizations = mapOf( |
| 124 | + LocaleId("en_US") to mapOf( |
| 125 | + LocalizationKey("title") to LocalizationData.Text("Web view placeholder"), |
| 126 | + LocalizationKey("fallback") to LocalizationData.Text("Could not load the web view."), |
| 127 | + LocalizationKey("cta") to LocalizationData.Text("Restore purchases"), |
| 128 | + ), |
| 129 | + ), |
| 130 | + defaultLocaleIdentifier = LocaleId("en_US"), |
| 131 | + ), |
| 132 | + ) |
| 133 | +} |
0 commit comments