@billdog.io/react-native 1.0.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (309) hide show
  1. package/BillDogReactNative.podspec +30 -0
  2. package/LICENSE +21 -0
  3. package/README.md +330 -0
  4. package/android/build.gradle +99 -0
  5. package/android/src/main/AndroidManifest.xml +1 -0
  6. package/android/src/main/kotlin/io/billdog/reactnative/BillDogABTestModule.kt +317 -0
  7. package/android/src/main/kotlin/io/billdog/reactnative/BillDogAnalyticsModule.kt +389 -0
  8. package/android/src/main/kotlin/io/billdog/reactnative/BillDogModule.kt +817 -0
  9. package/android/src/main/kotlin/io/billdog/reactnative/BillDogPaywallViewManager.kt +383 -0
  10. package/android/src/main/kotlin/io/billdog/reactnative/BillDogSurveyModule.kt +427 -0
  11. package/android/src/main/kotlin/io/billdog/reactnative/BillDogVirtualCurrencyModule.kt +407 -0
  12. package/android/src/main/kotlin/io/billdog/virtualcurrency/BillDogVirtualCurrencyPackage.kt +44 -0
  13. package/dist/AdvancedPaywallCache.d.ts +70 -0
  14. package/dist/AdvancedPaywallCache.js +344 -0
  15. package/dist/BillDog.d.ts +255 -0
  16. package/dist/BillDog.js +918 -0
  17. package/dist/BillDogConfiguration.d.ts +145 -0
  18. package/dist/BillDogConfiguration.js +229 -0
  19. package/dist/ComponentRenderer.d.ts +17 -0
  20. package/dist/ComponentRenderer.js +886 -0
  21. package/dist/LayoutEngine.d.ts +101 -0
  22. package/dist/LayoutEngine.js +394 -0
  23. package/dist/LocalizationResolver.d.ts +99 -0
  24. package/dist/LocalizationResolver.js +266 -0
  25. package/dist/NativePaywallView.d.ts +36 -0
  26. package/dist/NativePaywallView.js +59 -0
  27. package/dist/PaywallCache.d.ts +74 -0
  28. package/dist/PaywallCache.js +293 -0
  29. package/dist/PaywallStateManager.d.ts +62 -0
  30. package/dist/PaywallStateManager.js +147 -0
  31. package/dist/PaywallView.d.ts +42 -0
  32. package/dist/PaywallView.js +275 -0
  33. package/dist/ProductVariableProvider.d.ts +60 -0
  34. package/dist/ProductVariableProvider.js +239 -0
  35. package/dist/VariableResolver.d.ts +120 -0
  36. package/dist/VariableResolver.js +379 -0
  37. package/dist/WebViewPaywall.d.ts +75 -0
  38. package/dist/WebViewPaywall.js +360 -0
  39. package/dist/animations/presets.d.ts +49 -0
  40. package/dist/animations/presets.js +367 -0
  41. package/dist/components/AccoladeCpsComponent.d.ts +13 -0
  42. package/dist/components/AccoladeCpsComponent.js +248 -0
  43. package/dist/components/AccordionComponent.d.ts +10 -0
  44. package/dist/components/AccordionComponent.js +187 -0
  45. package/dist/components/AnimatedWrapper.d.ts +35 -0
  46. package/dist/components/AnimatedWrapper.js +277 -0
  47. package/dist/components/CarouselComponent.d.ts +23 -0
  48. package/dist/components/CarouselComponent.js +484 -0
  49. package/dist/components/ChartCurveComponent.d.ts +13 -0
  50. package/dist/components/ChartCurveComponent.js +333 -0
  51. package/dist/components/CheckboxComponent.d.ts +9 -0
  52. package/dist/components/CheckboxComponent.js +172 -0
  53. package/dist/components/ConfettiComponent.d.ts +9 -0
  54. package/dist/components/ConfettiComponent.js +172 -0
  55. package/dist/components/CountdownComponent.d.ts +16 -0
  56. package/dist/components/CountdownComponent.js +414 -0
  57. package/dist/components/DelayedXComponent.d.ts +12 -0
  58. package/dist/components/DelayedXComponent.js +240 -0
  59. package/dist/components/DrawerModalComponent.d.ts +20 -0
  60. package/dist/components/DrawerModalComponent.js +286 -0
  61. package/dist/components/GradientView.d.ts +38 -0
  62. package/dist/components/GradientView.js +126 -0
  63. package/dist/components/HapticFeedbackComponent.d.ts +16 -0
  64. package/dist/components/HapticFeedbackComponent.js +64 -0
  65. package/dist/components/HorizontalProductsComponent.d.ts +17 -0
  66. package/dist/components/HorizontalProductsComponent.js +284 -0
  67. package/dist/components/MultiChoiceGridComponent.d.ts +13 -0
  68. package/dist/components/MultiChoiceGridComponent.js +234 -0
  69. package/dist/components/NPSScaleComponent.d.ts +16 -0
  70. package/dist/components/NPSScaleComponent.js +260 -0
  71. package/dist/components/NavigationComponent.d.ts +26 -0
  72. package/dist/components/NavigationComponent.js +302 -0
  73. package/dist/components/OAuthButtonComponent.d.ts +20 -0
  74. package/dist/components/OAuthButtonComponent.js +237 -0
  75. package/dist/components/ProgressLoaderComponent.d.ts +13 -0
  76. package/dist/components/ProgressLoaderComponent.js +308 -0
  77. package/dist/components/ProgressStepperComponent.d.ts +18 -0
  78. package/dist/components/ProgressStepperComponent.js +228 -0
  79. package/dist/components/SegmentedPickerComponent.d.ts +10 -0
  80. package/dist/components/SegmentedPickerComponent.js +221 -0
  81. package/dist/components/ShareButtonsComponent.d.ts +21 -0
  82. package/dist/components/ShareButtonsComponent.js +265 -0
  83. package/dist/components/ShareCodeComponent.d.ts +16 -0
  84. package/dist/components/ShareCodeComponent.js +274 -0
  85. package/dist/components/SingleChoiceGridComponent.d.ts +13 -0
  86. package/dist/components/SingleChoiceGridComponent.js +210 -0
  87. package/dist/components/SliderComponent.d.ts +9 -0
  88. package/dist/components/SliderComponent.js +263 -0
  89. package/dist/components/StarRatingInputComponent.d.ts +20 -0
  90. package/dist/components/StarRatingInputComponent.js +198 -0
  91. package/dist/components/StickerCompositeComponent.d.ts +13 -0
  92. package/dist/components/StickerCompositeComponent.js +136 -0
  93. package/dist/components/TabsComponent.d.ts +19 -0
  94. package/dist/components/TabsComponent.js +431 -0
  95. package/dist/components/TextInputComponent.d.ts +18 -0
  96. package/dist/components/TextInputComponent.js +227 -0
  97. package/dist/components/TimelineComponent.d.ts +19 -0
  98. package/dist/components/TimelineComponent.js +104 -0
  99. package/dist/components/ToggleComponent.d.ts +14 -0
  100. package/dist/components/ToggleComponent.js +132 -0
  101. package/dist/components/VerticalProductsComponent.d.ts +17 -0
  102. package/dist/components/VerticalProductsComponent.js +311 -0
  103. package/dist/dynamicValues.d.ts +36 -0
  104. package/dist/dynamicValues.js +142 -0
  105. package/dist/filters/dateFilters.d.ts +50 -0
  106. package/dist/filters/dateFilters.js +390 -0
  107. package/dist/filters/index.d.ts +18 -0
  108. package/dist/filters/index.js +253 -0
  109. package/dist/hooks/useOfferings.d.ts +76 -0
  110. package/dist/hooks/useOfferings.js +99 -0
  111. package/dist/hooks/usePaywall.d.ts +27 -0
  112. package/dist/hooks/usePaywall.js +114 -0
  113. package/dist/hooks/usePlacement.d.ts +34 -0
  114. package/dist/hooks/usePlacement.js +89 -0
  115. package/dist/hooks/useSubscription.d.ts +40 -0
  116. package/dist/hooks/useSubscription.js +97 -0
  117. package/dist/index.d.ts +98 -0
  118. package/dist/index.js +198 -0
  119. package/dist/models/BillDogError.d.ts +40 -0
  120. package/dist/models/BillDogError.js +11 -0
  121. package/dist/models/CacheFetchPolicy.d.ts +8 -0
  122. package/dist/models/CacheFetchPolicy.js +4 -0
  123. package/dist/models/CustomProduct.d.ts +32 -0
  124. package/dist/models/CustomProduct.js +15 -0
  125. package/dist/models/CustomerInfo.d.ts +17 -0
  126. package/dist/models/CustomerInfo.js +11 -0
  127. package/dist/models/Delegate.d.ts +20 -0
  128. package/dist/models/Delegate.js +11 -0
  129. package/dist/models/EntitlementInfo.d.ts +19 -0
  130. package/dist/models/EntitlementInfo.js +2 -0
  131. package/dist/models/Placement.d.ts +54 -0
  132. package/dist/models/Placement.js +15 -0
  133. package/dist/models/PurchaseParams.d.ts +39 -0
  134. package/dist/models/PurchaseParams.js +60 -0
  135. package/dist/models/PurchaseResult.d.ts +30 -0
  136. package/dist/models/PurchaseResult.js +15 -0
  137. package/dist/models/RestoreResult.d.ts +30 -0
  138. package/dist/models/RestoreResult.js +22 -0
  139. package/dist/models/RestoredItem.d.ts +26 -0
  140. package/dist/models/RestoredItem.js +13 -0
  141. package/dist/modules/ABTest.d.ts +65 -0
  142. package/dist/modules/ABTest.js +113 -0
  143. package/dist/modules/Analytics.d.ts +91 -0
  144. package/dist/modules/Analytics.js +182 -0
  145. package/dist/modules/Survey.d.ts +65 -0
  146. package/dist/modules/Survey.js +82 -0
  147. package/dist/modules/VirtualCurrency.d.ts +63 -0
  148. package/dist/modules/VirtualCurrency.js +147 -0
  149. package/dist/murmur.d.ts +23 -0
  150. package/dist/murmur.js +104 -0
  151. package/dist/notifications/LiveActivitiesManager.d.ts +47 -0
  152. package/dist/notifications/LiveActivitiesManager.js +106 -0
  153. package/dist/notifications/NotificationScheduler.d.ts +55 -0
  154. package/dist/notifications/NotificationScheduler.js +199 -0
  155. package/dist/notifications/PurchaseNotificationHandler.d.ts +24 -0
  156. package/dist/notifications/PurchaseNotificationHandler.js +55 -0
  157. package/dist/notifications/useDeviceToken.d.ts +36 -0
  158. package/dist/notifications/useDeviceToken.js +97 -0
  159. package/dist/notifications/useLiveActivity.d.ts +39 -0
  160. package/dist/notifications/useLiveActivity.js +104 -0
  161. package/dist/review/ReviewAnalytics.d.ts +34 -0
  162. package/dist/review/ReviewAnalytics.js +73 -0
  163. package/dist/review/ReviewManager.d.ts +83 -0
  164. package/dist/review/ReviewManager.js +339 -0
  165. package/dist/review/ReviewTimingManager.d.ts +82 -0
  166. package/dist/review/ReviewTimingManager.js +224 -0
  167. package/dist/survey-core/types.d.ts +215 -0
  168. package/dist/survey-core/types.js +8 -0
  169. package/dist/types.d.ts +438 -0
  170. package/dist/types.js +158 -0
  171. package/dist/utils/ApiClient.d.ts +65 -0
  172. package/dist/utils/ApiClient.js +132 -0
  173. package/dist/utils/CSSConverter.d.ts +49 -0
  174. package/dist/utils/CSSConverter.js +470 -0
  175. package/dist/utils/animations.d.ts +41 -0
  176. package/dist/utils/animations.js +194 -0
  177. package/dist/utils/calendarIntegration.d.ts +36 -0
  178. package/dist/utils/calendarIntegration.js +89 -0
  179. package/dist/utils/configurationResolver.d.ts +23 -0
  180. package/dist/utils/configurationResolver.js +78 -0
  181. package/dist/utils/deviceDetection.d.ts +38 -0
  182. package/dist/utils/deviceDetection.js +59 -0
  183. package/dist/utils/hapticFeedback.d.ts +17 -0
  184. package/dist/utils/hapticFeedback.js +53 -0
  185. package/dist/utils/iconMapper.d.ts +26 -0
  186. package/dist/utils/iconMapper.js +113 -0
  187. package/dist/utils/notificationPermissions.d.ts +13 -0
  188. package/dist/utils/notificationPermissions.js +51 -0
  189. package/dist/utils/priceFormatting.d.ts +19 -0
  190. package/dist/utils/priceFormatting.js +99 -0
  191. package/dist/utils/shareSheet.d.ts +17 -0
  192. package/dist/utils/shareSheet.js +42 -0
  193. package/dist/utils/subscriptionUpgrade.d.ts +84 -0
  194. package/dist/utils/subscriptionUpgrade.js +100 -0
  195. package/dist/valueUtils.d.ts +48 -0
  196. package/dist/valueUtils.js +129 -0
  197. package/dist/xFlowTags.d.ts +18 -0
  198. package/dist/xFlowTags.js +385 -0
  199. package/ios/BillDogABTest.m +50 -0
  200. package/ios/BillDogABTest.swift +188 -0
  201. package/ios/BillDogAnalytics.m +105 -0
  202. package/ios/BillDogAnalytics.swift +324 -0
  203. package/ios/BillDogBridge.m +222 -0
  204. package/ios/BillDogBridge.swift +715 -0
  205. package/ios/BillDogLiveActivities.m +41 -0
  206. package/ios/BillDogLiveActivities.swift +104 -0
  207. package/ios/BillDogPaywallViewManager.m +39 -0
  208. package/ios/BillDogPaywallViewManager.swift +361 -0
  209. package/ios/BillDogSurvey.m +34 -0
  210. package/ios/BillDogSurvey.swift +257 -0
  211. package/ios/BillDogVirtualCurrencyBridge.m +63 -0
  212. package/ios/BillDogVirtualCurrencyBridge.swift +511 -0
  213. package/junit.xml +25 -0
  214. package/package.json +61 -0
  215. package/react-native.config.js +13 -0
  216. package/src/AdvancedPaywallCache.ts +433 -0
  217. package/src/BillDog.ts +983 -0
  218. package/src/BillDogConfiguration.ts +318 -0
  219. package/src/ComponentRenderer.tsx +1325 -0
  220. package/src/LayoutEngine.ts +459 -0
  221. package/src/LocalizationResolver.ts +311 -0
  222. package/src/NativePaywallView.tsx +132 -0
  223. package/src/PaywallCache.ts +358 -0
  224. package/src/PaywallStateManager.ts +154 -0
  225. package/src/PaywallView.tsx +328 -0
  226. package/src/ProductVariableProvider.ts +282 -0
  227. package/src/VariableResolver.ts +516 -0
  228. package/src/WebViewPaywall.tsx +454 -0
  229. package/src/animations/presets.ts +421 -0
  230. package/src/components/AccoladeCpsComponent.tsx +259 -0
  231. package/src/components/AccordionComponent.tsx +213 -0
  232. package/src/components/AnimatedWrapper.tsx +316 -0
  233. package/src/components/CarouselComponent.tsx +615 -0
  234. package/src/components/ChartCurveComponent.tsx +452 -0
  235. package/src/components/CheckboxComponent.tsx +185 -0
  236. package/src/components/ConfettiComponent.tsx +178 -0
  237. package/src/components/CountdownComponent.tsx +454 -0
  238. package/src/components/DelayedXComponent.tsx +266 -0
  239. package/src/components/DrawerModalComponent.tsx +324 -0
  240. package/src/components/GradientView.tsx +129 -0
  241. package/src/components/HapticFeedbackComponent.tsx +39 -0
  242. package/src/components/HorizontalProductsComponent.tsx +329 -0
  243. package/src/components/MultiChoiceGridComponent.tsx +265 -0
  244. package/src/components/NPSScaleComponent.tsx +294 -0
  245. package/src/components/NavigationComponent.tsx +329 -0
  246. package/src/components/OAuthButtonComponent.tsx +266 -0
  247. package/src/components/ProgressLoaderComponent.tsx +366 -0
  248. package/src/components/ProgressStepperComponent.tsx +250 -0
  249. package/src/components/SegmentedPickerComponent.tsx +245 -0
  250. package/src/components/ShareButtonsComponent.tsx +299 -0
  251. package/src/components/ShareCodeComponent.tsx +303 -0
  252. package/src/components/SingleChoiceGridComponent.tsx +229 -0
  253. package/src/components/SliderComponent.tsx +280 -0
  254. package/src/components/StarRatingInputComponent.tsx +223 -0
  255. package/src/components/StickerCompositeComponent.tsx +168 -0
  256. package/src/components/TabsComponent.tsx +496 -0
  257. package/src/components/TextInputComponent.tsx +258 -0
  258. package/src/components/TimelineComponent.tsx +129 -0
  259. package/src/components/ToggleComponent.tsx +142 -0
  260. package/src/components/VerticalProductsComponent.tsx +357 -0
  261. package/src/dynamicValues.ts +180 -0
  262. package/src/filters/dateFilters.ts +411 -0
  263. package/src/filters/index.ts +281 -0
  264. package/src/hooks/useOfferings.ts +192 -0
  265. package/src/hooks/usePaywall.ts +154 -0
  266. package/src/hooks/usePlacement.ts +143 -0
  267. package/src/hooks/useSubscription.ts +154 -0
  268. package/src/index.ts +245 -0
  269. package/src/models/BillDogError.ts +24 -0
  270. package/src/models/CacheFetchPolicy.ts +13 -0
  271. package/src/models/CustomProduct.ts +33 -0
  272. package/src/models/CustomerInfo.ts +26 -0
  273. package/src/models/Delegate.ts +22 -0
  274. package/src/models/EntitlementInfo.ts +27 -0
  275. package/src/models/Placement.ts +50 -0
  276. package/src/models/PurchaseParams.ts +81 -0
  277. package/src/models/PurchaseResult.ts +32 -0
  278. package/src/models/RestoreResult.ts +27 -0
  279. package/src/models/RestoredItem.ts +25 -0
  280. package/src/modules/ABTest.ts +131 -0
  281. package/src/modules/Analytics.ts +227 -0
  282. package/src/modules/Survey.ts +126 -0
  283. package/src/modules/VirtualCurrency.ts +223 -0
  284. package/src/murmur.ts +102 -0
  285. package/src/notifications/LiveActivitiesManager.ts +140 -0
  286. package/src/notifications/NotificationScheduler.ts +292 -0
  287. package/src/notifications/PurchaseNotificationHandler.ts +67 -0
  288. package/src/notifications/useDeviceToken.ts +116 -0
  289. package/src/notifications/useLiveActivity.ts +125 -0
  290. package/src/review/ReviewAnalytics.ts +89 -0
  291. package/src/review/ReviewManager.ts +355 -0
  292. package/src/review/ReviewTimingManager.ts +265 -0
  293. package/src/survey-core/types.ts +244 -0
  294. package/src/types/ambient.d.ts +9 -0
  295. package/src/types.ts +680 -0
  296. package/src/utils/ApiClient.ts +163 -0
  297. package/src/utils/CSSConverter.ts +552 -0
  298. package/src/utils/animations.ts +232 -0
  299. package/src/utils/calendarIntegration.ts +113 -0
  300. package/src/utils/configurationResolver.ts +106 -0
  301. package/src/utils/deviceDetection.ts +83 -0
  302. package/src/utils/hapticFeedback.ts +55 -0
  303. package/src/utils/iconMapper.ts +102 -0
  304. package/src/utils/notificationPermissions.ts +48 -0
  305. package/src/utils/priceFormatting.ts +119 -0
  306. package/src/utils/shareSheet.ts +55 -0
  307. package/src/utils/subscriptionUpgrade.ts +183 -0
  308. package/src/valueUtils.ts +108 -0
  309. package/src/xFlowTags.ts +463 -0
@@ -0,0 +1,178 @@
1
+ import React, { useEffect, useRef, useState, useCallback } from 'react';
2
+ import { View, StyleSheet, Animated, Dimensions } from 'react-native';
3
+ import { PaywallComponent } from '../types';
4
+
5
+ interface ConfettiComponentProps {
6
+ component: PaywallComponent;
7
+ stateManager?: any;
8
+ isPreviewMode?: boolean;
9
+ }
10
+
11
+ interface ConfettiPiece {
12
+ id: number;
13
+ x: Animated.Value;
14
+ y: Animated.Value;
15
+ rotation: Animated.Value;
16
+ color: string;
17
+ size: number;
18
+ shape: 'square' | 'circle';
19
+ }
20
+
21
+ // Color presets for confetti
22
+ const COLOR_PRESETS: Record<string, string[]> = {
23
+ celebration: ['#FF6B6B', '#4ECDC4', '#45B7D1', '#96CEB4', '#FFEAA7', '#DDA0DD', '#98D8C8'],
24
+ rainbow: ['#FF0000', '#FF7F00', '#FFFF00', '#00FF00', '#0000FF', '#4B0082', '#9400D3'],
25
+ metallic: ['#FFD700', '#C0C0C0', '#DAA520', '#B8860B', '#E8E8E8'],
26
+ pastel: ['#FFB3BA', '#BAFFC9', '#BAE1FF', '#FFFFBA', '#FFDFBA'],
27
+ brand: ['#6366F1', '#8B5CF6', '#A855F7', '#D946EF'],
28
+ };
29
+
30
+ export const ConfettiComponent: React.FC<ConfettiComponentProps> = ({
31
+ component,
32
+ stateManager,
33
+ isPreviewMode = false,
34
+ }) => {
35
+ const props = component.properties as any;
36
+ const pieceCount = props.pieceCount ?? 150;
37
+ const trigger = props.trigger ?? 'onLoad';
38
+ const duration = props.duration ?? 3000;
39
+ const recycle = props.recycle ?? false;
40
+ const shape = props.shape ?? 'mix';
41
+ const gravity = props.gravity ?? 1;
42
+ const colorPreset = props.colorPreset ?? 'celebration';
43
+ const customColors = props.customColors;
44
+
45
+ const [pieces, setPieces] = useState<ConfettiPiece[]>([]);
46
+ const recycleTimerRef = useRef<NodeJS.Timeout | null>(null);
47
+ const { width, height } = Dimensions.get('window');
48
+
49
+ // Get colors based on preset or custom
50
+ const getColors = useCallback((): string[] => {
51
+ if (colorPreset === 'custom' && customColors) {
52
+ return customColors.split(',').map((c: string) => c.trim()).filter((c: string) => c.startsWith('#'));
53
+ }
54
+ return COLOR_PRESETS[colorPreset] || COLOR_PRESETS.celebration;
55
+ }, [colorPreset, customColors]);
56
+
57
+ const createPieces = useCallback((): ConfettiPiece[] => {
58
+ const colors = getColors();
59
+ return Array.from({ length: pieceCount }, (_, i) => ({
60
+ id: i,
61
+ x: new Animated.Value(Math.random() * width),
62
+ y: new Animated.Value(-50 - Math.random() * 100),
63
+ rotation: new Animated.Value(0),
64
+ color: colors[Math.floor(Math.random() * colors.length)],
65
+ size: 8 + Math.random() * 8,
66
+ shape: shape === 'mix'
67
+ ? (Math.random() > 0.5 ? 'square' : 'circle')
68
+ : shape as 'square' | 'circle',
69
+ }));
70
+ }, [pieceCount, width, shape, getColors]);
71
+
72
+ const fireConfetti = useCallback(() => {
73
+ const newPieces = createPieces();
74
+ setPieces(newPieces);
75
+
76
+ newPieces.forEach((piece) => {
77
+ const fallDuration = (duration / gravity) * (0.8 + Math.random() * 0.4);
78
+ const drift = (Math.random() - 0.5) * 200;
79
+
80
+ Animated.parallel([
81
+ Animated.timing(piece.y, {
82
+ toValue: height + 50,
83
+ duration: fallDuration,
84
+ useNativeDriver: true,
85
+ }),
86
+ Animated.timing(piece.x, {
87
+ toValue: (piece.x as any)._value + drift,
88
+ duration: fallDuration,
89
+ useNativeDriver: true,
90
+ }),
91
+ Animated.timing(piece.rotation, {
92
+ toValue: 360 * (2 + Math.random() * 3),
93
+ duration: fallDuration,
94
+ useNativeDriver: true,
95
+ }),
96
+ ]).start();
97
+ });
98
+
99
+ if (recycle) {
100
+ recycleTimerRef.current = setTimeout(fireConfetti, duration);
101
+ }
102
+ }, [createPieces, duration, gravity, height, recycle]);
103
+
104
+ // Subscribe to manual trigger state changes
105
+ useEffect(() => {
106
+ if (!stateManager || trigger !== 'manual') return;
107
+
108
+ const stateKey = `element:${component.id}.fire`;
109
+
110
+ const unsubscribe = stateManager.subscribe(stateKey, (value: boolean) => {
111
+ if (value === true) {
112
+ fireConfetti();
113
+ // Reset the state after firing
114
+ setTimeout(() => {
115
+ stateManager.setState(stateKey, false);
116
+ }, 50);
117
+ }
118
+ });
119
+
120
+ return () => {
121
+ unsubscribe?.();
122
+ };
123
+ }, [stateManager, trigger, component.id, fireConfetti]);
124
+
125
+ useEffect(() => {
126
+ if (trigger === 'onLoad') {
127
+ const timer = setTimeout(fireConfetti, 100);
128
+ return () => clearTimeout(timer);
129
+ }
130
+ }, [trigger, fireConfetti]);
131
+
132
+ useEffect(() => {
133
+ return () => {
134
+ if (recycleTimerRef.current) {
135
+ clearTimeout(recycleTimerRef.current);
136
+ }
137
+ };
138
+ }, []);
139
+
140
+ return (
141
+ <View style={styles.container} pointerEvents="none">
142
+ {pieces.map((piece) => (
143
+ <Animated.View
144
+ key={piece.id}
145
+ style={[
146
+ styles.piece,
147
+ {
148
+ width: piece.size,
149
+ height: piece.size,
150
+ backgroundColor: piece.color,
151
+ borderRadius: piece.shape === 'circle' ? piece.size / 2 : 0,
152
+ transform: [
153
+ { translateX: piece.x },
154
+ { translateY: piece.y },
155
+ {
156
+ rotate: piece.rotation.interpolate({
157
+ inputRange: [0, 360],
158
+ outputRange: ['0deg', '360deg'],
159
+ }),
160
+ },
161
+ ],
162
+ },
163
+ ]}
164
+ />
165
+ ))}
166
+ </View>
167
+ );
168
+ };
169
+
170
+ const styles = StyleSheet.create({
171
+ container: {
172
+ ...StyleSheet.absoluteFillObject,
173
+ overflow: 'hidden',
174
+ },
175
+ piece: {
176
+ position: 'absolute',
177
+ },
178
+ });
@@ -0,0 +1,454 @@
1
+ /**
2
+ * Countdown Component - Native React Native implementation
3
+ * Supports variant (boxed/text/digital/flip), styling, and state manager integration
4
+ */
5
+
6
+ import React, { useEffect, useState, useMemo, useCallback } from 'react';
7
+ import { View, Text, StyleSheet, ViewStyle, TextStyle } from 'react-native';
8
+ import { PaywallComponent, PaywallConfiguration } from '../types';
9
+
10
+ interface CountdownComponentProps {
11
+ component: PaywallComponent;
12
+ configuration: PaywallConfiguration;
13
+ style?: ViewStyle;
14
+ onComplete?: () => void;
15
+ onStateChange?: (key: string, value: any) => void;
16
+ }
17
+
18
+ interface TimeRemaining {
19
+ days: number;
20
+ hours: number;
21
+ minutes: number;
22
+ seconds: number;
23
+ totalSeconds: number;
24
+ isExpired: boolean;
25
+ }
26
+
27
+ export const CountdownComponent: React.FC<CountdownComponentProps> = ({
28
+ component,
29
+ configuration,
30
+ style,
31
+ onComplete,
32
+ onStateChange,
33
+ }) => {
34
+ const properties = component.properties || {};
35
+
36
+ // MARK: - Parse Properties
37
+ const endTimeStr = (properties.endTime as string) || '';
38
+ const durationSeconds = (properties.duration as number) || 0;
39
+ const format = (properties.format as string) || 'digital';
40
+
41
+ // Determine variant from explicit value or map from format
42
+ const variant = useMemo(() => {
43
+ if (properties.variant) return properties.variant as string;
44
+ switch (format) {
45
+ case 'digital':
46
+ case 'digital_full':
47
+ case 'compact':
48
+ return 'boxed';
49
+ case 'short':
50
+ case 'long':
51
+ return 'text';
52
+ default:
53
+ return 'boxed';
54
+ }
55
+ }, [properties.variant, format]);
56
+
57
+ const showDays = properties.showDays !== false;
58
+ const showHours = properties.showHours !== false;
59
+ const showMinutes = properties.showMinutes !== false;
60
+ const showSeconds = properties.showSeconds !== false;
61
+ const showLabels = properties.showLabels === true;
62
+ const separator = (properties.separator as string) || ':';
63
+ const labelStyle = (properties.labelStyle as string) || 'short';
64
+
65
+ // MARK: - Styling Properties
66
+ const fontSize = (properties.fontSize as number) || 32;
67
+ const textColor = (properties.textColor as string) || undefined; // Fixed: use textColor not color
68
+ const backgroundColor = (properties.backgroundColor as string) || '#F3F4F6';
69
+ const separatorColor = (properties.separatorColor as string) || textColor;
70
+ const hasExplicitSeparatorColor = !!properties.separatorColor;
71
+ const unitColor = (properties.unitColor as string) || '#9CA3AF';
72
+ const fontWeight = (properties.fontWeight as string) || 'bold';
73
+ const fontFamily = (properties.fontFamily as string) || 'monospace';
74
+ const padding = (properties.padding as number) || 12;
75
+ const gap = (properties.gap as number) || 8;
76
+ const borderRadius = (properties.borderRadius as number) || 8;
77
+ const expiredText = (properties.expiredText as string) || '00:00:00';
78
+
79
+ // MARK: - Calculate Target Time
80
+ const targetTime = useMemo(() => {
81
+ const trimmedEndTime = endTimeStr.trim();
82
+
83
+ if (trimmedEndTime) {
84
+ // Handle relative time (+7d, +1h, +30m, +60s)
85
+ if (trimmedEndTime.startsWith('+')) {
86
+ const valueStr = trimmedEndTime.slice(1, -1);
87
+ const unit = trimmedEndTime.slice(-1);
88
+ const value = parseInt(valueStr, 10) || 0;
89
+
90
+ let multiplier = 1000; // default seconds
91
+ switch (unit) {
92
+ case 'd': multiplier = 86400000; break;
93
+ case 'h': multiplier = 3600000; break;
94
+ case 'm': multiplier = 60000; break;
95
+ case 's': multiplier = 1000; break;
96
+ }
97
+ return Date.now() + (value * multiplier);
98
+ }
99
+
100
+ // Handle ISO date string
101
+ const parsed = Date.parse(trimmedEndTime);
102
+ if (!isNaN(parsed)) {
103
+ return parsed;
104
+ }
105
+ }
106
+
107
+ // Use duration if specified
108
+ if (durationSeconds > 0) {
109
+ return Date.now() + (durationSeconds * 1000);
110
+ }
111
+
112
+ // Default 1 hour
113
+ return Date.now() + 3600000;
114
+ }, [endTimeStr, durationSeconds]);
115
+
116
+ // State for remaining time
117
+ const [timeRemaining, setTimeRemaining] = useState<TimeRemaining>(() =>
118
+ calculateTimeRemaining(targetTime)
119
+ );
120
+
121
+ // Calculate time remaining
122
+ function calculateTimeRemaining(target: number): TimeRemaining {
123
+ const now = Date.now();
124
+ const diff = Math.max(0, target - now);
125
+ const totalSeconds = Math.floor(diff / 1000);
126
+
127
+ return {
128
+ days: Math.floor(totalSeconds / 86400),
129
+ hours: Math.floor((totalSeconds % 86400) / 3600),
130
+ minutes: Math.floor((totalSeconds % 3600) / 60),
131
+ seconds: totalSeconds % 60,
132
+ totalSeconds,
133
+ isExpired: diff <= 0,
134
+ };
135
+ }
136
+
137
+ // Timer effect
138
+ useEffect(() => {
139
+ const interval = setInterval(() => {
140
+ const remaining = calculateTimeRemaining(targetTime);
141
+ setTimeRemaining(remaining);
142
+
143
+ // Publish state changes
144
+ onStateChange?.(`element:${component.id}.remainingSeconds`, remaining.totalSeconds);
145
+ onStateChange?.(`element:${component.id}.isExpired`, remaining.isExpired);
146
+
147
+ if (remaining.isExpired) {
148
+ clearInterval(interval);
149
+ onComplete?.();
150
+ }
151
+ }, 1000);
152
+
153
+ // Publish initial state
154
+ onStateChange?.(`element:${component.id}.remainingSeconds`, timeRemaining.totalSeconds);
155
+ onStateChange?.(`element:${component.id}.isExpired`, timeRemaining.isExpired);
156
+
157
+ return () => clearInterval(interval);
158
+ }, [targetTime, onComplete, onStateChange, component.id]);
159
+
160
+ // MARK: - Label Formatting
161
+ const getLabelForUnit = useCallback((unit: string): string => {
162
+ switch (labelStyle) {
163
+ case 'full':
164
+ switch (unit) {
165
+ case 'days': return 'Days';
166
+ case 'hours': return 'Hours';
167
+ case 'minutes': return 'Minutes';
168
+ case 'seconds': return 'Seconds';
169
+ default: return unit;
170
+ }
171
+ case 'none':
172
+ return '';
173
+ default: // 'short'
174
+ switch (unit) {
175
+ case 'days': return 'D';
176
+ case 'hours': return 'H';
177
+ case 'minutes': return 'M';
178
+ case 'seconds': return 'S';
179
+ default: return unit.charAt(0).toUpperCase();
180
+ }
181
+ }
182
+ }, [labelStyle]);
183
+
184
+ // Format the display string for digital variant
185
+ const formattedTime = useMemo(() => {
186
+ const { days, hours, minutes, seconds, totalSeconds, isExpired } = timeRemaining;
187
+
188
+ if (isExpired) return expiredText;
189
+
190
+ const pad = (n: number) => n.toString().padStart(2, '0');
191
+
192
+ switch (format) {
193
+ case 'digital_full':
194
+ return `${pad(days)}${separator}${pad(hours)}${separator}${pad(minutes)}${separator}${pad(seconds)}`;
195
+
196
+ case 'digital':
197
+ if (days > 0) {
198
+ return `${pad(days)}${separator}${pad(hours)}${separator}${pad(minutes)}${separator}${pad(seconds)}`;
199
+ }
200
+ return `${pad(hours)}${separator}${pad(minutes)}${separator}${pad(seconds)}`;
201
+
202
+ case 'short': {
203
+ const parts: string[] = [];
204
+ if (showDays && days > 0) parts.push(`${days}d`);
205
+ if (showHours) parts.push(`${hours}h`);
206
+ if (showMinutes) parts.push(`${minutes}m`);
207
+ if (showSeconds) parts.push(`${seconds}s`);
208
+ return parts.join(' ');
209
+ }
210
+
211
+ case 'long': {
212
+ const parts: string[] = [];
213
+ if (showDays && days > 0) parts.push(`${days} days`);
214
+ if (showHours) parts.push(`${hours} hours`);
215
+ if (showMinutes) parts.push(`${minutes} minutes`);
216
+ if (showSeconds) parts.push(`${seconds} seconds`);
217
+ return parts.join(', ');
218
+ }
219
+
220
+ case 'compact':
221
+ return `${days}:${pad(hours)}:${pad(minutes)}:${pad(seconds)}`;
222
+
223
+ case 'days_only':
224
+ return `${days}`;
225
+
226
+ case 'hours_only':
227
+ return `${days * 24 + hours}`;
228
+
229
+ case 'minutes_only':
230
+ return `${(days * 24 + hours) * 60 + minutes}`;
231
+
232
+ case 'seconds_only':
233
+ return `${totalSeconds}`;
234
+
235
+ default:
236
+ return `${pad(hours)}${separator}${pad(minutes)}${separator}${pad(seconds)}`;
237
+ }
238
+ }, [timeRemaining, format, separator, showDays, showHours, showMinutes, showSeconds, expiredText]);
239
+
240
+ // MARK: - Font Weight Helper
241
+ const getFontWeight = useCallback((): TextStyle['fontWeight'] => {
242
+ switch (fontWeight) {
243
+ case '100':
244
+ case 'thin': return '100';
245
+ case '200':
246
+ case 'extraLight': return '200';
247
+ case '300':
248
+ case 'light': return '300';
249
+ case '400':
250
+ case 'normal':
251
+ case 'regular': return '400';
252
+ case '500':
253
+ case 'medium': return '500';
254
+ case '600':
255
+ case 'semibold': return '600';
256
+ case '700':
257
+ case 'bold': return '700';
258
+ case '800':
259
+ case 'extraBold': return '800';
260
+ case '900':
261
+ case 'black': return '900';
262
+ default: return 'bold';
263
+ }
264
+ }, [fontWeight]);
265
+
266
+ // MARK: - Render Helpers
267
+
268
+ const renderTimeUnitBox = (value: number, label: string) => (
269
+ <View style={styles.unitContainer}>
270
+ <View style={[
271
+ styles.unitBox,
272
+ {
273
+ backgroundColor,
274
+ borderRadius,
275
+ paddingHorizontal: padding,
276
+ paddingVertical: padding * 0.67,
277
+ }
278
+ ]}>
279
+ <Text style={[
280
+ styles.unitValue,
281
+ {
282
+ fontSize,
283
+ fontWeight: getFontWeight(),
284
+ fontFamily,
285
+ ...(textColor && { color: textColor }),
286
+ }
287
+ ]}>
288
+ {value.toString().padStart(2, '0')}
289
+ </Text>
290
+ </View>
291
+ {showLabels && label && (
292
+ <Text style={[styles.unitLabel, { color: unitColor, fontSize: fontSize * 0.3 }]}>
293
+ {label}
294
+ </Text>
295
+ )}
296
+ </View>
297
+ );
298
+
299
+ const renderSeparator = () => (
300
+ <Text style={[
301
+ styles.separator,
302
+ {
303
+ fontSize,
304
+ fontWeight: getFontWeight(),
305
+ fontFamily,
306
+ color: separatorColor || textColor,
307
+ ...(!hasExplicitSeparatorColor && { opacity: 0.6 }),
308
+ }
309
+ ]}>
310
+ {separator}
311
+ </Text>
312
+ );
313
+
314
+ const renderTimeUnitText = (value: number, label: string) => (
315
+ <View style={styles.textUnit}>
316
+ <Text style={[
317
+ styles.textValue,
318
+ {
319
+ fontSize,
320
+ fontWeight: getFontWeight(),
321
+ fontFamily,
322
+ ...(textColor && { color: textColor }),
323
+ }
324
+ ]}>
325
+ {value}
326
+ </Text>
327
+ <Text style={[styles.textLabel, { color: unitColor, fontSize: fontSize * 0.5 }]}>
328
+ {' '}{label}
329
+ </Text>
330
+ </View>
331
+ );
332
+
333
+ // MARK: - Variant Renderers
334
+
335
+ const renderBoxedVariant = () => {
336
+ const { days, hours, minutes, seconds } = timeRemaining;
337
+
338
+ return (
339
+ <View style={[styles.boxedContainer, { gap }, style]}>
340
+ {showDays && days > 0 && (
341
+ <>
342
+ {renderTimeUnitBox(days, getLabelForUnit('days'))}
343
+ {renderSeparator()}
344
+ </>
345
+ )}
346
+ {showHours && (
347
+ <>
348
+ {renderTimeUnitBox(hours, getLabelForUnit('hours'))}
349
+ {renderSeparator()}
350
+ </>
351
+ )}
352
+ {showMinutes && (
353
+ <>
354
+ {renderTimeUnitBox(minutes, getLabelForUnit('minutes'))}
355
+ {showSeconds && renderSeparator()}
356
+ </>
357
+ )}
358
+ {showSeconds && renderTimeUnitBox(seconds, getLabelForUnit('seconds'))}
359
+ </View>
360
+ );
361
+ };
362
+
363
+ const renderTextVariant = () => {
364
+ const { days, hours, minutes, seconds } = timeRemaining;
365
+
366
+ return (
367
+ <View style={[styles.textContainer, { gap: gap * 2 }, style]}>
368
+ {showDays && days > 0 && renderTimeUnitText(days, getLabelForUnit('days'))}
369
+ {showHours && renderTimeUnitText(hours, getLabelForUnit('hours'))}
370
+ {showMinutes && renderTimeUnitText(minutes, getLabelForUnit('minutes'))}
371
+ {showSeconds && renderTimeUnitText(seconds, getLabelForUnit('seconds'))}
372
+ </View>
373
+ );
374
+ };
375
+
376
+ const renderDigitalVariant = () => (
377
+ <View style={[styles.container, style]}>
378
+ <Text style={[
379
+ styles.digitalText,
380
+ {
381
+ fontSize,
382
+ fontWeight: getFontWeight(),
383
+ fontFamily,
384
+ ...(textColor && { color: textColor }),
385
+ }
386
+ ]}>
387
+ {formattedTime}
388
+ </Text>
389
+ </View>
390
+ );
391
+
392
+ // MARK: - Main Render
393
+
394
+ switch (variant) {
395
+ case 'boxed':
396
+ return renderBoxedVariant();
397
+ case 'text':
398
+ return renderTextVariant();
399
+ case 'flip':
400
+ // Flip uses boxed layout (full flip animation would need more work)
401
+ return renderBoxedVariant();
402
+ default:
403
+ return renderDigitalVariant();
404
+ }
405
+ };
406
+
407
+ const styles = StyleSheet.create({
408
+ container: {
409
+ alignItems: 'center',
410
+ justifyContent: 'center',
411
+ },
412
+ boxedContainer: {
413
+ flexDirection: 'row',
414
+ alignItems: 'center',
415
+ justifyContent: 'center',
416
+ },
417
+ textContainer: {
418
+ flexDirection: 'row',
419
+ alignItems: 'center',
420
+ justifyContent: 'center',
421
+ },
422
+ unitContainer: {
423
+ alignItems: 'center',
424
+ },
425
+ unitBox: {
426
+ alignItems: 'center',
427
+ justifyContent: 'center',
428
+ },
429
+ unitValue: {
430
+ textAlign: 'center',
431
+ },
432
+ unitLabel: {
433
+ marginTop: 4,
434
+ textAlign: 'center',
435
+ },
436
+ separator: {
437
+ marginHorizontal: 2,
438
+ },
439
+ textUnit: {
440
+ flexDirection: 'row',
441
+ alignItems: 'flex-end',
442
+ },
443
+ textValue: {
444
+ textAlign: 'center',
445
+ },
446
+ textLabel: {
447
+ marginBottom: 2,
448
+ },
449
+ digitalText: {
450
+ textAlign: 'center',
451
+ },
452
+ });
453
+
454
+ export default CountdownComponent;