@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,615 @@
1
+ /**
2
+ * Native React Native Carousel with swipe, pagination, and axis support
3
+ * Supports horizontal, vertical, and layered modes
4
+ */
5
+
6
+ import React, { useState, useRef, useCallback, useEffect } from 'react';
7
+ import {
8
+ View,
9
+ ScrollView,
10
+ StyleSheet,
11
+ Dimensions,
12
+ TouchableOpacity,
13
+ NativeSyntheticEvent,
14
+ NativeScrollEvent,
15
+ ViewStyle,
16
+ LayoutAnimation,
17
+ Platform,
18
+ UIManager,
19
+ Text,
20
+ Pressable,
21
+ } from 'react-native';
22
+ import { PaywallComponent, PaywallConfiguration } from '../types';
23
+ import { ComponentRenderer } from '../ComponentRenderer';
24
+
25
+ // Enable LayoutAnimation on Android
26
+ if (Platform.OS === 'android' && UIManager.setLayoutAnimationEnabledExperimental) {
27
+ UIManager.setLayoutAnimationEnabledExperimental(true);
28
+ }
29
+
30
+ type CarouselAxis = 'horizontal' | 'vertical' | 'layered';
31
+
32
+ interface StateManager {
33
+ setState: (key: string, value: any) => void;
34
+ getState: (key: string) => any;
35
+ subscribe: (key: string, callback: (value: any) => void) => () => void;
36
+ }
37
+
38
+ interface CarouselComponentProps {
39
+ component: PaywallComponent;
40
+ configuration: PaywallConfiguration;
41
+ style?: ViewStyle;
42
+ onButtonPress?: (componentId: string, action: string) => void;
43
+ onPageChange?: (page: number) => void;
44
+ stateManager?: StateManager;
45
+ renderChild?: (child: PaywallComponent) => React.ReactNode;
46
+ }
47
+
48
+ export const CarouselComponent: React.FC<CarouselComponentProps> = ({
49
+ component,
50
+ configuration,
51
+ style,
52
+ onButtonPress,
53
+ onPageChange,
54
+ stateManager,
55
+ renderChild,
56
+ }) => {
57
+ const props = component.properties as Record<string, any> || {};
58
+ const containerLayout = (component as any).containerLayout;
59
+
60
+ // Properties
61
+ const showPagination = props.showPagination !== false;
62
+ const showArrows = props.showArrows === true;
63
+ const loop = props.loop === true;
64
+ const dragEnabled = props.dragEnabled !== false;
65
+ const animated = props.animated !== false;
66
+ const defaultIndex = props.defaultIndex ?? 0;
67
+ const paginationColor = props.paginationColor || '#007AFF';
68
+ const paginationInactiveColor = props.paginationInactiveColor || '#CCCCCC';
69
+
70
+ // Slide display settings
71
+ const slideDisplay = props.slideDisplay || 'full'; // 'full' | 'peek'
72
+ const peekAmount = props.peekAmount ?? 15; // percentage 5-40
73
+
74
+ // Transition settings (new)
75
+ const transition = props.transition || 'scroll'; // 'scroll' | 'fade' | 'slide' | 'push' | 'none'
76
+ const transitionDuration = props.transitionDuration ?? 300; // milliseconds
77
+ const keyboardEnabled = props.keyboardEnabled !== false; // keyboard navigation
78
+
79
+ // Auto scroll settings
80
+ const autoScrollEnabled = props.autoScrollEnabled === true;
81
+ const autoScrollInterval = props.autoScrollInterval ?? 3000;
82
+ const autoScrollDirection = props.autoScrollDirection || 'forward';
83
+ const pauseOnTouch = props.pauseOnHover !== false; // pauseOnHover maps to touch on mobile
84
+
85
+ // Axis support: horizontal (default), vertical, or layered
86
+ const axis: CarouselAxis = containerLayout?.axis || props.axis || 'horizontal';
87
+
88
+ const children = component.children || [];
89
+ const itemCount = children.length;
90
+
91
+ const [currentIndex, setCurrentIndex] = useState(
92
+ Math.min(defaultIndex, Math.max(0, itemCount - 1))
93
+ );
94
+ const [containerWidth, setContainerWidth] = useState(Dimensions.get('window').width);
95
+ const [containerHeight, setContainerHeight] = useState(200);
96
+ const scrollViewRef = useRef<ScrollView>(null);
97
+ const isInitialized = useRef(false);
98
+ const isDragging = useRef(false);
99
+ const autoScrollTimerRef = useRef<ReturnType<typeof setInterval> | null>(null);
100
+
101
+ // Calculate slide width for peek mode
102
+ const slideWidth = slideDisplay === 'peek'
103
+ ? containerWidth * (1 - peekAmount / 100)
104
+ : containerWidth;
105
+
106
+ // Initialize scroll position on mount
107
+ useEffect(() => {
108
+ if (scrollViewRef.current && !isInitialized.current && axis !== 'layered') {
109
+ isInitialized.current = true;
110
+ const offset = axis === 'vertical'
111
+ ? { x: 0, y: currentIndex * containerHeight }
112
+ : { x: currentIndex * slideWidth, y: 0 };
113
+
114
+ setTimeout(() => {
115
+ scrollViewRef.current?.scrollTo({ ...offset, animated: false });
116
+ }, 100);
117
+ }
118
+ }, [containerWidth, containerHeight, currentIndex, axis, slideWidth]);
119
+
120
+ // Auto scroll effect
121
+ useEffect(() => {
122
+ if (!autoScrollEnabled || itemCount <= 1) {
123
+ return;
124
+ }
125
+
126
+ const startAutoScroll = () => {
127
+ if (autoScrollTimerRef.current) {
128
+ clearInterval(autoScrollTimerRef.current);
129
+ }
130
+
131
+ autoScrollTimerRef.current = setInterval(() => {
132
+ if (isDragging.current && pauseOnTouch) {
133
+ return;
134
+ }
135
+
136
+ setCurrentIndex((prevIndex) => {
137
+ let nextIndex: number;
138
+ if (autoScrollDirection === 'reverse') {
139
+ nextIndex = prevIndex - 1;
140
+ if (nextIndex < 0) {
141
+ nextIndex = loop ? itemCount - 1 : 0;
142
+ }
143
+ } else {
144
+ nextIndex = prevIndex + 1;
145
+ if (nextIndex >= itemCount) {
146
+ nextIndex = loop ? 0 : itemCount - 1;
147
+ }
148
+ }
149
+ return nextIndex;
150
+ });
151
+ }, autoScrollInterval);
152
+ };
153
+
154
+ startAutoScroll();
155
+
156
+ return () => {
157
+ if (autoScrollTimerRef.current) {
158
+ clearInterval(autoScrollTimerRef.current);
159
+ }
160
+ };
161
+ }, [autoScrollEnabled, autoScrollInterval, autoScrollDirection, loop, itemCount, pauseOnTouch]);
162
+
163
+ // Update state manager when index changes (SDK parity)
164
+ useEffect(() => {
165
+ if (stateManager) {
166
+ stateManager.setState(`element:${component.id}.currentIndex`, currentIndex);
167
+ stateManager.setState(`element:${component.id}.totalPages`, itemCount);
168
+ }
169
+ }, [stateManager, component.id, currentIndex, itemCount]);
170
+
171
+ // Create custom LayoutAnimation based on transition type and duration
172
+ const getTransitionAnimation = useCallback(() => {
173
+ if (transition === 'none' || !animated) {
174
+ return null;
175
+ }
176
+
177
+ const duration = transitionDuration;
178
+
179
+ switch (transition) {
180
+ case 'fade':
181
+ return LayoutAnimation.create(
182
+ duration,
183
+ LayoutAnimation.Types.easeInEaseOut,
184
+ LayoutAnimation.Properties.opacity
185
+ );
186
+ case 'slide':
187
+ case 'push':
188
+ return LayoutAnimation.create(
189
+ duration,
190
+ LayoutAnimation.Types.easeInEaseOut,
191
+ LayoutAnimation.Properties.scaleXY
192
+ );
193
+ case 'scroll':
194
+ default:
195
+ return LayoutAnimation.create(
196
+ duration,
197
+ LayoutAnimation.Types.easeInEaseOut,
198
+ LayoutAnimation.Properties.opacity
199
+ );
200
+ }
201
+ }, [transition, transitionDuration, animated]);
202
+
203
+ const handleScroll = useCallback((event: NativeSyntheticEvent<NativeScrollEvent>) => {
204
+ const offset = axis === 'vertical'
205
+ ? event.nativeEvent.contentOffset.y
206
+ : event.nativeEvent.contentOffset.x;
207
+ const size = axis === 'vertical' ? containerHeight : slideWidth;
208
+ const newIndex = Math.round(offset / size);
209
+
210
+ if (newIndex !== currentIndex && newIndex >= 0 && newIndex < itemCount) {
211
+ const transitionAnim = getTransitionAnimation();
212
+ if (transitionAnim) {
213
+ LayoutAnimation.configureNext(transitionAnim);
214
+ }
215
+ setCurrentIndex(newIndex);
216
+ onPageChange?.(newIndex);
217
+ onButtonPress?.(component.id, `page_changed:${newIndex}`);
218
+ }
219
+ }, [axis, slideWidth, containerHeight, currentIndex, itemCount, onPageChange, onButtonPress, component.id, getTransitionAnimation]);
220
+
221
+ const handleScrollBeginDrag = useCallback(() => {
222
+ isDragging.current = true;
223
+ }, []);
224
+
225
+ const handleScrollEndDrag = useCallback(() => {
226
+ isDragging.current = false;
227
+ }, []);
228
+
229
+ const scrollToIndex = useCallback((index: number) => {
230
+ let targetIndex = index;
231
+
232
+ if (loop) {
233
+ if (index < 0) {
234
+ targetIndex = itemCount - 1;
235
+ } else if (index >= itemCount) {
236
+ targetIndex = 0;
237
+ }
238
+ } else {
239
+ targetIndex = Math.max(0, Math.min(itemCount - 1, index));
240
+ }
241
+
242
+ if (axis === 'layered') {
243
+ // For layered, just update the index with transition animation
244
+ const transitionAnim = getTransitionAnimation();
245
+ if (transitionAnim) {
246
+ LayoutAnimation.configureNext(transitionAnim);
247
+ }
248
+ setCurrentIndex(targetIndex);
249
+ } else {
250
+ const offset = axis === 'vertical'
251
+ ? { x: 0, y: targetIndex * containerHeight }
252
+ : { x: targetIndex * slideWidth, y: 0 };
253
+
254
+ // Use animated based on transition type
255
+ const shouldAnimate = transition !== 'none' && animated;
256
+ scrollViewRef.current?.scrollTo({
257
+ ...offset,
258
+ animated: shouldAnimate,
259
+ });
260
+ }
261
+
262
+ onPageChange?.(targetIndex);
263
+ onButtonPress?.(component.id, `page_changed:${targetIndex}`);
264
+ }, [loop, itemCount, axis, slideWidth, containerHeight, animated, transition, onPageChange, onButtonPress, component.id, getTransitionAnimation]);
265
+
266
+ // Listen for external state changes via state manager (placed after scrollToIndex)
267
+ useEffect(() => {
268
+ if (!stateManager) return;
269
+
270
+ const unsubscribe = stateManager.subscribe(`element:${component.id}.currentIndex`, (value: number) => {
271
+ if (typeof value === 'number' && value !== currentIndex && value >= 0 && value < itemCount) {
272
+ scrollToIndex(value);
273
+ }
274
+ });
275
+
276
+ return unsubscribe;
277
+ }, [stateManager, component.id, currentIndex, itemCount, scrollToIndex]);
278
+
279
+ const goToPrevious = useCallback(() => {
280
+ scrollToIndex(currentIndex - 1);
281
+ }, [currentIndex, scrollToIndex]);
282
+
283
+ const goToNext = useCallback(() => {
284
+ scrollToIndex(currentIndex + 1);
285
+ }, [currentIndex, scrollToIndex]);
286
+
287
+ // Keyboard navigation for web platform
288
+ const handleKeyDown = useCallback((event: any) => {
289
+ if (!keyboardEnabled || itemCount <= 1) return;
290
+
291
+ const key = event.nativeEvent?.key || event.key;
292
+ const isVertical = axis === 'vertical';
293
+
294
+ if (isVertical) {
295
+ if (key === 'ArrowUp') {
296
+ event.preventDefault?.();
297
+ goToPrevious();
298
+ } else if (key === 'ArrowDown') {
299
+ event.preventDefault?.();
300
+ goToNext();
301
+ }
302
+ } else {
303
+ if (key === 'ArrowLeft') {
304
+ event.preventDefault?.();
305
+ goToPrevious();
306
+ } else if (key === 'ArrowRight') {
307
+ event.preventDefault?.();
308
+ goToNext();
309
+ }
310
+ }
311
+ }, [keyboardEnabled, itemCount, axis, goToPrevious, goToNext]);
312
+
313
+ // Empty placeholder
314
+ if (itemCount === 0) {
315
+ return (
316
+ <View style={[styles.emptyContainer, style]}>
317
+ <Text style={styles.emptyText}>Add slides to the carousel</Text>
318
+ </View>
319
+ );
320
+ }
321
+
322
+ const isVertical = axis === 'vertical';
323
+ const isLayered = axis === 'layered';
324
+
325
+ // Render layered carousel
326
+ if (isLayered) {
327
+ // Web keyboard props
328
+ const webKeyboardProps = Platform.OS === 'web' && keyboardEnabled ? {
329
+ tabIndex: 0,
330
+ onKeyDown: handleKeyDown,
331
+ style: { outline: 'none' },
332
+ } : {};
333
+
334
+ return (
335
+ <Pressable
336
+ style={[styles.container, style]}
337
+ onLayout={(e) => {
338
+ setContainerWidth(e.nativeEvent.layout.width);
339
+ setContainerHeight(e.nativeEvent.layout.height);
340
+ }}
341
+ {...webKeyboardProps as any}
342
+ >
343
+ <View style={styles.layeredContainer}>
344
+ {children.map((child, index) => (
345
+ <View
346
+ key={child.id}
347
+ style={[
348
+ styles.layeredItem,
349
+ { opacity: index === currentIndex ? 1 : 0 },
350
+ ]}
351
+ >
352
+ {renderChild ? renderChild(child) : (
353
+ <ComponentRenderer
354
+ component={child}
355
+ configuration={configuration}
356
+ onButtonPress={onButtonPress}
357
+ stateManager={stateManager}
358
+ />
359
+ )}
360
+ </View>
361
+ ))}
362
+ </View>
363
+
364
+ {showPagination && itemCount > 1 && (
365
+ <View style={styles.pagination}>
366
+ {children.map((_, index) => (
367
+ <TouchableOpacity key={index} onPress={() => scrollToIndex(index)}>
368
+ <View
369
+ style={[
370
+ styles.dot,
371
+ {
372
+ backgroundColor: index === currentIndex ? paginationColor : paginationInactiveColor,
373
+ transform: [{ scale: index === currentIndex ? 1.2 : 1 }],
374
+ },
375
+ ]}
376
+ />
377
+ </TouchableOpacity>
378
+ ))}
379
+ </View>
380
+ )}
381
+ </Pressable>
382
+ );
383
+ }
384
+
385
+ // Web keyboard props for horizontal/vertical carousels
386
+ const webKeyboardProps = Platform.OS === 'web' && keyboardEnabled ? {
387
+ tabIndex: 0,
388
+ onKeyDown: handleKeyDown,
389
+ style: { outline: 'none' },
390
+ } : {};
391
+
392
+ return (
393
+ <Pressable
394
+ style={[styles.container, style]}
395
+ onLayout={(e) => {
396
+ setContainerWidth(e.nativeEvent.layout.width);
397
+ setContainerHeight(e.nativeEvent.layout.height);
398
+ }}
399
+ {...webKeyboardProps as any}
400
+ >
401
+ {/* Carousel content */}
402
+ <View style={styles.carouselContainer}>
403
+ <ScrollView
404
+ ref={scrollViewRef}
405
+ horizontal={!isVertical}
406
+ pagingEnabled={slideDisplay !== 'peek'}
407
+ showsHorizontalScrollIndicator={false}
408
+ showsVerticalScrollIndicator={false}
409
+ onMomentumScrollEnd={handleScroll}
410
+ onScrollBeginDrag={handleScrollBeginDrag}
411
+ onScrollEndDrag={handleScrollEndDrag}
412
+ scrollEventThrottle={16}
413
+ decelerationRate="fast"
414
+ bounces={false}
415
+ scrollEnabled={dragEnabled}
416
+ snapToInterval={slideDisplay === 'peek' ? slideWidth : undefined}
417
+ snapToAlignment={slideDisplay === 'peek' ? 'start' : undefined}
418
+ >
419
+ {children.map((child) => (
420
+ <View
421
+ key={child.id}
422
+ style={isVertical
423
+ ? { height: containerHeight, width: containerWidth }
424
+ : { width: slideWidth }
425
+ }
426
+ >
427
+ {renderChild ? renderChild(child) : (
428
+ <ComponentRenderer
429
+ component={child}
430
+ configuration={configuration}
431
+ onButtonPress={onButtonPress}
432
+ stateManager={stateManager}
433
+ />
434
+ )}
435
+ </View>
436
+ ))}
437
+ </ScrollView>
438
+
439
+ {/* Navigation arrows */}
440
+ {showArrows && itemCount > 1 && (
441
+ <>
442
+ <TouchableOpacity
443
+ style={[
444
+ styles.arrow,
445
+ isVertical ? styles.topArrow : styles.leftArrow,
446
+ ]}
447
+ onPress={goToPrevious}
448
+ disabled={!loop && currentIndex === 0}
449
+ >
450
+ <View style={[
451
+ styles.arrowButton,
452
+ { opacity: (!loop && currentIndex === 0) ? 0.3 : 1 }
453
+ ]}>
454
+ <View style={[
455
+ styles.arrowIcon,
456
+ isVertical ? styles.upArrowIcon : styles.leftArrowIcon
457
+ ]} />
458
+ </View>
459
+ </TouchableOpacity>
460
+
461
+ <TouchableOpacity
462
+ style={[
463
+ styles.arrow,
464
+ isVertical ? styles.bottomArrow : styles.rightArrow,
465
+ ]}
466
+ onPress={goToNext}
467
+ disabled={!loop && currentIndex === itemCount - 1}
468
+ >
469
+ <View style={[
470
+ styles.arrowButton,
471
+ { opacity: (!loop && currentIndex === itemCount - 1) ? 0.3 : 1 }
472
+ ]}>
473
+ <View style={[
474
+ styles.arrowIcon,
475
+ isVertical ? styles.downArrowIcon : styles.rightArrowIcon
476
+ ]} />
477
+ </View>
478
+ </TouchableOpacity>
479
+ </>
480
+ )}
481
+ </View>
482
+
483
+ {/* Pagination dots */}
484
+ {showPagination && itemCount > 1 && (
485
+ <View style={[
486
+ styles.pagination,
487
+ isVertical && styles.verticalPagination,
488
+ ]}>
489
+ {children.map((_, index) => (
490
+ <TouchableOpacity
491
+ key={index}
492
+ onPress={() => scrollToIndex(index)}
493
+ >
494
+ <View
495
+ style={[
496
+ styles.dot,
497
+ {
498
+ backgroundColor: index === currentIndex
499
+ ? paginationColor
500
+ : paginationInactiveColor,
501
+ transform: [{ scale: index === currentIndex ? 1.2 : 1 }],
502
+ },
503
+ ]}
504
+ />
505
+ </TouchableOpacity>
506
+ ))}
507
+ </View>
508
+ )}
509
+ </Pressable>
510
+ );
511
+ };
512
+
513
+ const styles = StyleSheet.create({
514
+ container: {
515
+ width: '100%',
516
+ },
517
+ carouselContainer: {
518
+ position: 'relative',
519
+ overflow: 'hidden',
520
+ },
521
+ emptyContainer: {
522
+ height: 100,
523
+ backgroundColor: 'rgba(128, 128, 128, 0.1)',
524
+ borderRadius: 8,
525
+ borderWidth: 1,
526
+ borderColor: 'rgba(128, 128, 128, 0.3)',
527
+ borderStyle: 'dashed',
528
+ justifyContent: 'center',
529
+ alignItems: 'center',
530
+ },
531
+ emptyText: {
532
+ color: '#888',
533
+ fontSize: 12,
534
+ },
535
+ layeredContainer: {
536
+ position: 'relative',
537
+ },
538
+ layeredItem: {
539
+ position: 'absolute',
540
+ top: 0,
541
+ left: 0,
542
+ right: 0,
543
+ },
544
+ pagination: {
545
+ flexDirection: 'row',
546
+ justifyContent: 'center',
547
+ alignItems: 'center',
548
+ paddingVertical: 12,
549
+ gap: 8,
550
+ },
551
+ verticalPagination: {
552
+ position: 'absolute',
553
+ right: 8,
554
+ top: '50%',
555
+ flexDirection: 'column',
556
+ paddingVertical: 0,
557
+ paddingHorizontal: 8,
558
+ },
559
+ dot: {
560
+ width: 8,
561
+ height: 8,
562
+ borderRadius: 4,
563
+ },
564
+ arrow: {
565
+ position: 'absolute',
566
+ zIndex: 10,
567
+ },
568
+ leftArrow: {
569
+ left: 8,
570
+ top: '50%',
571
+ marginTop: -20,
572
+ },
573
+ rightArrow: {
574
+ right: 8,
575
+ top: '50%',
576
+ marginTop: -20,
577
+ },
578
+ topArrow: {
579
+ top: 8,
580
+ left: '50%',
581
+ marginLeft: -20,
582
+ },
583
+ bottomArrow: {
584
+ bottom: 8,
585
+ left: '50%',
586
+ marginLeft: -20,
587
+ },
588
+ arrowButton: {
589
+ width: 40,
590
+ height: 40,
591
+ borderRadius: 20,
592
+ backgroundColor: 'rgba(0, 0, 0, 0.5)',
593
+ justifyContent: 'center',
594
+ alignItems: 'center',
595
+ },
596
+ arrowIcon: {
597
+ width: 12,
598
+ height: 12,
599
+ borderTopWidth: 2,
600
+ borderRightWidth: 2,
601
+ borderColor: '#FFFFFF',
602
+ },
603
+ leftArrowIcon: {
604
+ transform: [{ rotate: '-135deg' }, { translateX: 2 }],
605
+ },
606
+ rightArrowIcon: {
607
+ transform: [{ rotate: '45deg' }, { translateX: -2 }],
608
+ },
609
+ upArrowIcon: {
610
+ transform: [{ rotate: '-45deg' }, { translateY: 2 }],
611
+ },
612
+ downArrowIcon: {
613
+ transform: [{ rotate: '135deg' }, { translateY: -2 }],
614
+ },
615
+ });