@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,213 @@
1
+ import React, { useState, useEffect } from 'react';
2
+ import {
3
+ View,
4
+ Text,
5
+ TouchableOpacity,
6
+ StyleSheet,
7
+ LayoutAnimation,
8
+ Platform,
9
+ UIManager,
10
+ } from 'react-native';
11
+ import { PaywallComponent } from '../types';
12
+
13
+ // Enable LayoutAnimation on Android
14
+ if (Platform.OS === 'android' && UIManager.setLayoutAnimationEnabledExperimental) {
15
+ UIManager.setLayoutAnimationEnabledExperimental(true);
16
+ }
17
+
18
+ interface AccordionComponentProps {
19
+ component: PaywallComponent;
20
+ renderChild: (child: PaywallComponent) => React.ReactNode;
21
+ stateManager?: any;
22
+ isPreviewMode?: boolean;
23
+ }
24
+
25
+ export const AccordionComponent: React.FC<AccordionComponentProps> = ({
26
+ component,
27
+ renderChild,
28
+ stateManager,
29
+ isPreviewMode = false,
30
+ }) => {
31
+ const props = component.properties as any;
32
+ const allowMultiple = props.allowMultiple ?? false;
33
+ const defaultExpanded = props.defaultExpandedIndex ?? -1;
34
+ const animated = props.animated !== false;
35
+ const gap = props.gap ?? 4;
36
+ const headerPadding = props.headerPadding ?? 12;
37
+ const contentPadding = props.contentPadding ?? 12;
38
+ const opacity = props.opacity ?? 1;
39
+ const headerBackground = props.headerBackground ?? '#f5f5f5';
40
+
41
+ const [expandedIndexes, setExpandedIndexes] = useState<number[]>(
42
+ defaultExpanded >= 0 ? [defaultExpanded] : []
43
+ );
44
+
45
+ // Get items from children only
46
+ const items: PaywallComponent[] = component.children || [];
47
+
48
+ // Register initial state
49
+ useEffect(() => {
50
+ if (stateManager) {
51
+ const currentIndex = expandedIndexes.length > 0 ? expandedIndexes[0] : -1;
52
+ stateManager.updateState(`element:${component.id}.currentIndex`, currentIndex);
53
+ stateManager.updateState(`element:${component.id}.expandedIndexes`, expandedIndexes);
54
+ stateManager.updateState(`element:${component.id}.totalItems`, items.length);
55
+ }
56
+ }, []);
57
+
58
+ // Subscribe to external state changes
59
+ useEffect(() => {
60
+ if (stateManager) {
61
+ const unsubscribe = stateManager.subscribeToState(
62
+ `element:${component.id}.currentIndex`,
63
+ (value: number) => {
64
+ const current = expandedIndexes.length > 0 ? expandedIndexes[0] : -1;
65
+ if (value !== current) {
66
+ if (animated) {
67
+ LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut);
68
+ }
69
+ setExpandedIndexes(value >= 0 ? [value] : []);
70
+ }
71
+ }
72
+ );
73
+
74
+ const unsubscribeMultiple = stateManager.subscribeToState(
75
+ `element:${component.id}.expandedIndexes`,
76
+ (value: number[]) => {
77
+ if (Array.isArray(value) && allowMultiple) {
78
+ if (animated) {
79
+ LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut);
80
+ }
81
+ setExpandedIndexes(value);
82
+ }
83
+ }
84
+ );
85
+
86
+ return () => {
87
+ unsubscribe?.();
88
+ unsubscribeMultiple?.();
89
+ };
90
+ }
91
+ }, [component.id, stateManager, allowMultiple]);
92
+
93
+ const toggleItem = (index: number) => {
94
+ if (animated) {
95
+ LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut);
96
+ }
97
+
98
+ let newExpandedIndexes: number[];
99
+ if (allowMultiple) {
100
+ newExpandedIndexes = expandedIndexes.includes(index)
101
+ ? expandedIndexes.filter(i => i !== index)
102
+ : [...expandedIndexes, index];
103
+ } else {
104
+ newExpandedIndexes = expandedIndexes.includes(index) ? [] : [index];
105
+ }
106
+
107
+ setExpandedIndexes(newExpandedIndexes);
108
+
109
+ if (stateManager) {
110
+ const currentIndex = newExpandedIndexes.length > 0 ? newExpandedIndexes[0] : -1;
111
+ stateManager.updateState(`element:${component.id}.currentIndex`, currentIndex);
112
+ stateManager.updateState(`element:${component.id}.expandedIndexes`, newExpandedIndexes);
113
+ }
114
+ };
115
+
116
+ return (
117
+ <View style={[styles.container, { opacity, gap }]}>
118
+ {items.map((item, index) => {
119
+ const isExpanded = expandedIndexes.includes(index);
120
+ const itemProps = item.properties as any;
121
+
122
+ const header = item.children?.find((c: PaywallComponent) =>
123
+ c.properties?.role === 'header' || c.type === 'accordion-header'
124
+ );
125
+ const contentChildren = item.children?.filter((c: PaywallComponent) =>
126
+ c.properties?.role !== 'header' && c.type !== 'accordion-header'
127
+ ) || [];
128
+
129
+ return (
130
+ <View key={item.id} style={styles.item}>
131
+ {/* Header */}
132
+ <TouchableOpacity
133
+ onPress={() => toggleItem(index)}
134
+ style={[
135
+ styles.header,
136
+ {
137
+ backgroundColor: itemProps?.headerBackground ?? headerBackground,
138
+ padding: headerPadding,
139
+ }
140
+ ]}
141
+ activeOpacity={0.7}
142
+ >
143
+ <View style={styles.headerContent}>
144
+ {header ? (
145
+ renderChild(header)
146
+ ) : (
147
+ <Text style={styles.headerText}>
148
+ {itemProps?.title ?? `Item ${index + 1}`}
149
+ </Text>
150
+ )}
151
+ </View>
152
+ <Text style={[
153
+ styles.chevron,
154
+ isExpanded && styles.chevronExpanded
155
+ ]}>
156
+
157
+ </Text>
158
+ </TouchableOpacity>
159
+
160
+ {/* Content */}
161
+ {isExpanded && (
162
+ <View style={[styles.content, { padding: contentPadding }]}>
163
+ {contentChildren.length > 0
164
+ ? contentChildren.map((child: PaywallComponent) => (
165
+ <View key={child.id}>
166
+ {renderChild(child)}
167
+ </View>
168
+ ))
169
+ : itemProps?.content && <Text>{itemProps.content}</Text>
170
+ }
171
+ </View>
172
+ )}
173
+ </View>
174
+ );
175
+ })}
176
+ </View>
177
+ );
178
+ };
179
+
180
+ const styles = StyleSheet.create({
181
+ container: {
182
+ width: '100%',
183
+ },
184
+ item: {
185
+ backgroundColor: '#f5f5f5',
186
+ borderRadius: 8,
187
+ overflow: 'hidden',
188
+ },
189
+ header: {
190
+ flexDirection: 'row',
191
+ alignItems: 'center',
192
+ justifyContent: 'space-between',
193
+ },
194
+ headerContent: {
195
+ flex: 1,
196
+ },
197
+ headerText: {
198
+ fontSize: 16,
199
+ fontWeight: '600',
200
+ },
201
+ chevron: {
202
+ fontSize: 12,
203
+ color: '#666',
204
+ marginLeft: 8,
205
+ },
206
+ chevronExpanded: {
207
+ transform: [{ rotate: '180deg' }],
208
+ },
209
+ content: {
210
+ borderTopWidth: 1,
211
+ borderTopColor: '#e0e0e0',
212
+ },
213
+ });
@@ -0,0 +1,316 @@
1
+ /**
2
+ * AnimatedWrapper - React Native animation component
3
+ * Wraps children with animations based on preset configurations
4
+ */
5
+
6
+ import React, { useEffect, useRef, useMemo } from 'react';
7
+ import {
8
+ Animated,
9
+ Easing,
10
+ ViewStyle,
11
+ EasingFunction,
12
+ } from 'react-native';
13
+ // Local copy of packages/core/src/animations/presets (see src/animations/presets.ts).
14
+ // Imported locally because ANIMATION_PRESETS is a runtime value and tsc rootDir
15
+ // cannot span files outside this package.
16
+ import { ANIMATION_PRESETS, EasingType, AnimationKeyframe } from '../animations/presets';
17
+
18
+ interface AnimatedWrapperProps {
19
+ preset?: string;
20
+ trigger?: 'enter' | 'loop' | 'tap';
21
+ duration?: number;
22
+ delay?: number;
23
+ easing?: EasingType;
24
+ iterations?: number;
25
+ children: React.ReactNode;
26
+ style?: ViewStyle;
27
+ onAnimationComplete?: () => void;
28
+ }
29
+
30
+ /**
31
+ * Map easing type to React Native Easing function
32
+ */
33
+ function getEasingFunction(easing: EasingType): EasingFunction {
34
+ switch (easing) {
35
+ case 'linear':
36
+ return Easing.linear;
37
+ case 'ease':
38
+ return Easing.ease;
39
+ case 'ease-in':
40
+ return Easing.in(Easing.ease);
41
+ case 'ease-out':
42
+ return Easing.out(Easing.ease);
43
+ case 'ease-in-out':
44
+ return Easing.inOut(Easing.ease);
45
+ case 'spring':
46
+ return Easing.elastic(1);
47
+ default:
48
+ return Easing.ease;
49
+ }
50
+ }
51
+
52
+ /**
53
+ * Calculate interpolated value at a specific progress point
54
+ */
55
+ function interpolateKeyframes(
56
+ keyframes: AnimationKeyframe[],
57
+ property: keyof AnimationKeyframe,
58
+ progress: number
59
+ ): number | undefined {
60
+ if (keyframes.length === 0) return undefined;
61
+
62
+ // Find surrounding keyframes
63
+ let prevFrame = keyframes[0];
64
+ let nextFrame = keyframes[keyframes.length - 1];
65
+
66
+ for (let i = 0; i < keyframes.length - 1; i++) {
67
+ if (keyframes[i].offset <= progress && keyframes[i + 1].offset >= progress) {
68
+ prevFrame = keyframes[i];
69
+ nextFrame = keyframes[i + 1];
70
+ break;
71
+ }
72
+ }
73
+
74
+ const prevValue = prevFrame[property];
75
+ const nextValue = nextFrame[property];
76
+
77
+ if (prevValue === undefined || nextValue === undefined) return undefined;
78
+ if (typeof prevValue !== 'number' || typeof nextValue !== 'number') return undefined;
79
+
80
+ // Linear interpolation between keyframes
81
+ const range = nextFrame.offset - prevFrame.offset;
82
+ if (range === 0) return prevValue;
83
+
84
+ const localProgress = (progress - prevFrame.offset) / range;
85
+ return prevValue + (nextValue - prevValue) * localProgress;
86
+ }
87
+
88
+ export const AnimatedWrapper: React.FC<AnimatedWrapperProps> = ({
89
+ preset,
90
+ trigger = 'enter',
91
+ duration: customDuration,
92
+ delay: customDelay,
93
+ easing: customEasing,
94
+ iterations: customIterations,
95
+ children,
96
+ style,
97
+ onAnimationComplete,
98
+ }) => {
99
+ const animatedValue = useRef(new Animated.Value(0)).current;
100
+
101
+ // Get preset configuration
102
+ const presetConfig = preset ? ANIMATION_PRESETS[preset] : undefined;
103
+
104
+ // Merge custom parameters with preset defaults
105
+ const animationParams = useMemo(() => {
106
+ if (!presetConfig) {
107
+ return { duration: 300, delay: 0, easing: 'ease-out' as EasingType, iterations: 1 };
108
+ }
109
+
110
+ return {
111
+ duration: customDuration ?? presetConfig.defaultDuration,
112
+ delay: customDelay ?? presetConfig.defaultDelay,
113
+ easing: customEasing ?? presetConfig.defaultEasing,
114
+ iterations: customIterations ?? presetConfig.defaultIterations,
115
+ };
116
+ }, [presetConfig, customDuration, customDelay, customEasing, customIterations]);
117
+
118
+ // Run animation on mount or when trigger changes
119
+ useEffect(() => {
120
+ if (!presetConfig) return;
121
+
122
+ const isLooping = animationParams.iterations === -1 || trigger === 'loop';
123
+
124
+ const runAnimation = () => {
125
+ animatedValue.setValue(0);
126
+
127
+ const animation = Animated.timing(animatedValue, {
128
+ toValue: 1,
129
+ duration: animationParams.duration,
130
+ delay: animationParams.delay,
131
+ easing: getEasingFunction(animationParams.easing),
132
+ useNativeDriver: true,
133
+ });
134
+
135
+ if (isLooping) {
136
+ Animated.loop(animation).start();
137
+ } else {
138
+ animation.start(({ finished }) => {
139
+ if (finished && onAnimationComplete) {
140
+ onAnimationComplete();
141
+ }
142
+ });
143
+ }
144
+ };
145
+
146
+ runAnimation();
147
+
148
+ return () => {
149
+ animatedValue.stopAnimation();
150
+ };
151
+ }, [preset, trigger, animationParams]);
152
+
153
+ // Build animated style from keyframes
154
+ const animatedStyle = useMemo(() => {
155
+ if (!presetConfig) return {};
156
+
157
+ const { keyframes } = presetConfig;
158
+ const transforms: any[] = [];
159
+
160
+ // Extract unique offsets for input range
161
+ const offsets = keyframes.map(kf => kf.offset);
162
+
163
+ // Opacity interpolation
164
+ const opacityValues = keyframes.map(kf => kf.opacity).filter(v => v !== undefined);
165
+ const hasOpacity = opacityValues.length > 0;
166
+
167
+ // Scale interpolation
168
+ const scaleValues = keyframes.map(kf => kf.scale ?? 1);
169
+ const hasScale = keyframes.some(kf => kf.scale !== undefined);
170
+
171
+ // TranslateX interpolation
172
+ const translateXValues = keyframes.map(kf => {
173
+ const val = kf.translateX;
174
+ if (typeof val === 'string' && val.includes('%')) {
175
+ // Convert percentage to pixels (approximate with 300px width)
176
+ return parseFloat(val) * 3;
177
+ }
178
+ return typeof val === 'number' ? val : 0;
179
+ });
180
+ const hasTranslateX = keyframes.some(kf => kf.translateX !== undefined);
181
+
182
+ // TranslateY interpolation
183
+ const translateYValues = keyframes.map(kf => {
184
+ const val = kf.translateY;
185
+ if (typeof val === 'string' && val.includes('%')) {
186
+ return parseFloat(val) * 5; // Approximate with 500px height
187
+ }
188
+ return typeof val === 'number' ? val : 0;
189
+ });
190
+ const hasTranslateY = keyframes.some(kf => kf.translateY !== undefined);
191
+
192
+ // Rotate interpolation
193
+ const rotateValues = keyframes.map(kf => kf.rotate ?? 0);
194
+ const hasRotate = keyframes.some(kf => kf.rotate !== undefined);
195
+
196
+ // Build style object
197
+ const animStyle: any = {};
198
+
199
+ if (hasOpacity) {
200
+ animStyle.opacity = animatedValue.interpolate({
201
+ inputRange: offsets,
202
+ outputRange: keyframes.map(kf => kf.opacity ?? 1),
203
+ });
204
+ }
205
+
206
+ if (hasScale) {
207
+ transforms.push({
208
+ scale: animatedValue.interpolate({
209
+ inputRange: offsets,
210
+ outputRange: scaleValues,
211
+ }),
212
+ });
213
+ }
214
+
215
+ if (hasTranslateX) {
216
+ transforms.push({
217
+ translateX: animatedValue.interpolate({
218
+ inputRange: offsets,
219
+ outputRange: translateXValues,
220
+ }),
221
+ });
222
+ }
223
+
224
+ if (hasTranslateY) {
225
+ transforms.push({
226
+ translateY: animatedValue.interpolate({
227
+ inputRange: offsets,
228
+ outputRange: translateYValues,
229
+ }),
230
+ });
231
+ }
232
+
233
+ if (hasRotate) {
234
+ transforms.push({
235
+ rotate: animatedValue.interpolate({
236
+ inputRange: offsets,
237
+ outputRange: rotateValues.map(r => `${r}deg`),
238
+ }),
239
+ });
240
+ }
241
+
242
+ if (transforms.length > 0) {
243
+ animStyle.transform = transforms;
244
+ }
245
+
246
+ return animStyle;
247
+ }, [presetConfig, animatedValue]);
248
+
249
+ // If no preset, render children without animation
250
+ if (!presetConfig) {
251
+ return <Animated.View style={style}>{children}</Animated.View>;
252
+ }
253
+
254
+ return (
255
+ <Animated.View style={[style, animatedStyle]}>
256
+ {children}
257
+ </Animated.View>
258
+ );
259
+ };
260
+
261
+ /**
262
+ * Hook to get animation style without wrapper component
263
+ */
264
+ export function usePaywallAnimation(
265
+ preset?: string,
266
+ customParams?: {
267
+ duration?: number;
268
+ delay?: number;
269
+ easing?: EasingType;
270
+ iterations?: number;
271
+ }
272
+ ) {
273
+ const animatedValue = useRef(new Animated.Value(0)).current;
274
+ const presetConfig = preset ? ANIMATION_PRESETS[preset] : undefined;
275
+
276
+ const params = useMemo(() => {
277
+ if (!presetConfig) return null;
278
+ return {
279
+ duration: customParams?.duration ?? presetConfig.defaultDuration,
280
+ delay: customParams?.delay ?? presetConfig.defaultDelay,
281
+ easing: customParams?.easing ?? presetConfig.defaultEasing,
282
+ iterations: customParams?.iterations ?? presetConfig.defaultIterations,
283
+ };
284
+ }, [presetConfig, customParams]);
285
+
286
+ const start = () => {
287
+ if (!params) return;
288
+
289
+ animatedValue.setValue(0);
290
+ const animation = Animated.timing(animatedValue, {
291
+ toValue: 1,
292
+ duration: params.duration,
293
+ delay: params.delay,
294
+ easing: getEasingFunction(params.easing),
295
+ useNativeDriver: true,
296
+ });
297
+
298
+ if (params.iterations === -1) {
299
+ Animated.loop(animation).start();
300
+ } else {
301
+ animation.start();
302
+ }
303
+ };
304
+
305
+ const stop = () => {
306
+ animatedValue.stopAnimation();
307
+ };
308
+
309
+ const reset = () => {
310
+ animatedValue.setValue(0);
311
+ };
312
+
313
+ return { animatedValue, start, stop, reset, presetConfig };
314
+ }
315
+
316
+ export default AnimatedWrapper;