@rubixscript/react-native-onboarding 1.0.0 → 1.1.0

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 (59) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +383 -383
  3. package/dist/components/NavigationButtons.d.ts +23 -0
  4. package/dist/components/NavigationButtons.d.ts.map +1 -0
  5. package/dist/components/NavigationButtons.js +106 -0
  6. package/dist/components/Onboarding.d.ts +11 -0
  7. package/dist/components/Onboarding.d.ts.map +1 -0
  8. package/dist/components/Onboarding.js +219 -0
  9. package/dist/components/Pagination.d.ts +5 -0
  10. package/dist/components/Pagination.d.ts.map +1 -0
  11. package/dist/components/Pagination.js +269 -0
  12. package/dist/components/SimpleOnboardingScreen.d.ts +54 -0
  13. package/dist/components/SimpleOnboardingScreen.d.ts.map +1 -0
  14. package/dist/components/SimpleOnboardingScreen.js +184 -0
  15. package/dist/components/index.d.ts +7 -0
  16. package/dist/components/index.d.ts.map +1 -0
  17. package/dist/components/index.js +5 -0
  18. package/dist/index.d.ts +9 -0
  19. package/dist/index.d.ts.map +1 -0
  20. package/dist/index.js +12 -0
  21. package/dist/presets/index.d.ts +27 -0
  22. package/dist/presets/index.d.ts.map +1 -0
  23. package/dist/presets/index.js +370 -0
  24. package/dist/slides/FormSlide.d.ts +12 -0
  25. package/dist/slides/FormSlide.d.ts.map +1 -0
  26. package/dist/slides/FormSlide.js +227 -0
  27. package/dist/slides/IconSlide.d.ts +10 -0
  28. package/dist/slides/IconSlide.d.ts.map +1 -0
  29. package/dist/slides/IconSlide.js +133 -0
  30. package/dist/slides/ImageSlide.d.ts +10 -0
  31. package/dist/slides/ImageSlide.d.ts.map +1 -0
  32. package/dist/slides/ImageSlide.js +99 -0
  33. package/dist/slides/VideoSlide.d.ts +10 -0
  34. package/dist/slides/VideoSlide.d.ts.map +1 -0
  35. package/dist/slides/VideoSlide.js +101 -0
  36. package/dist/slides/index.d.ts +14 -0
  37. package/dist/slides/index.d.ts.map +1 -0
  38. package/dist/slides/index.js +25 -0
  39. package/dist/themes/index.d.ts +35 -0
  40. package/dist/themes/index.d.ts.map +1 -0
  41. package/dist/themes/index.js +547 -0
  42. package/dist/types/index.d.ts +191 -0
  43. package/dist/types/index.d.ts.map +1 -0
  44. package/dist/types/index.js +1 -0
  45. package/package.json +73 -60
  46. package/src/components/NavigationButtons.tsx +198 -198
  47. package/src/components/Onboarding.tsx +337 -340
  48. package/src/components/Pagination.tsx +337 -337
  49. package/src/components/SimpleOnboardingScreen.tsx +266 -0
  50. package/src/components/index.ts +7 -5
  51. package/src/index.ts +69 -65
  52. package/src/presets/index.ts +391 -394
  53. package/src/slides/FormSlide.tsx +314 -314
  54. package/src/slides/IconSlide.tsx +166 -166
  55. package/src/slides/ImageSlide.tsx +132 -132
  56. package/src/slides/VideoSlide.tsx +146 -146
  57. package/src/slides/{index.ts → index.tsx} +37 -44
  58. package/src/themes/index.ts +576 -574
  59. package/src/types/index.ts +247 -247
@@ -1,340 +1,337 @@
1
- import React, { useState, useCallback, useMemo, useEffect } from 'react';
2
- import {
3
- View,
4
- StyleSheet,
5
- SafeAreaView,
6
- Platform,
7
- Modal,
8
- ViewStyle,
9
- Animated,
10
- } from 'react-native';
11
- import { SafeAreaProvider } from 'react-native-safe-area-context';
12
- import AnimatedFlatList, {
13
- FlatList,
14
- AnimatedFlatListType,
15
- } from 'react-native-reanimated';
16
- import { BlurView } from 'expo-blur';
17
- import { LinearGradient } from 'expo-linear-gradient';
18
- import AsyncStorage from '@react-native-async-storage/async-storage';
19
-
20
- import { OnboardingProps, OnboardingConfig } from '../types';
21
- import { mergeTheme, getPreset } from '../themes';
22
- import { SlideRenderer } from '../slides';
23
- import { Pagination, NavigationButtons } from './index';
24
-
25
- const AnimatedFlatListImplemented =
26
- (AnimatedFlatList as any) as AnimatedFlatListType<any>;
27
-
28
- export const Onboarding: React.FC<OnboardingProps> = ({
29
- visible,
30
- slides = [],
31
- theme: customTheme,
32
- navigation: customNavigation,
33
- animation: customAnimation,
34
- storage,
35
- onboardingComplete,
36
- onSlideChange,
37
- onSkip,
38
- initialSlide = 0,
39
- swipeEnabled = true,
40
- containerStyle,
41
- safeAreaEnabled = true,
42
- darkMode = false,
43
- }) => {
44
- // State
45
- const [currentIndex, setCurrentIndex] = useState(initialSlide);
46
- const [isSubmitting, setIsSubmitting] = useState(false);
47
- const [formData, setFormData] = useState<Record<string, any>>({});
48
-
49
- //Refs
50
- const flatListRef = React.useRef<FlatList>(null);
51
-
52
- // Merge theme with preset
53
- const preset = useMemo(() => {
54
- if (!customTheme) return getPreset('modern');
55
- const presetKey = Object.keys(getPreset('modern')).find(
56
- key => (customTheme as any)[key]
57
- );
58
- return presetKey ? getPreset(presetKey) : getPreset('modern');
59
- }, [customTheme]);
60
-
61
- const theme = useMemo(
62
- () => mergeTheme(preset.theme, customTheme),
63
- [preset, customTheme]
64
- );
65
-
66
- const navigationConfig = useMemo(
67
- () => ({ ...preset.navigation, ...customNavigation }),
68
- [preset, customNavigation]
69
- );
70
-
71
- const animationConfig = useMemo(
72
- () => ({ ...preset.animation, ...customAnimation }),
73
- [preset, customAnimation]
74
- );
75
-
76
- // Check storage on mount
77
- useEffect(() => {
78
- if (storage?.enabled) {
79
- checkOnboardingStatus();
80
- }
81
- }, [storage]);
82
-
83
- const checkOnboardingStatus = async () => {
84
- try {
85
- const key = storage?.key || '@onboarding_complete';
86
- const completed = await AsyncStorage.getItem(key);
87
- if (completed && !visible) {
88
- // Already completed, don't show
89
- return;
90
- }
91
- } catch (error) {
92
- console.warn('Error checking onboarding status:', error);
93
- }
94
- };
95
-
96
- const saveOnboardingComplete = async () => {
97
- if (storage?.enabled) {
98
- try {
99
- const key = storage?.key || '@onboarding_complete';
100
- await AsyncStorage.setItem(key, 'true');
101
- if (storage.onComplete) {
102
- await storage.onComplete();
103
- }
104
- } catch (error) {
105
- console.warn('Error saving onboarding status:', error);
106
- }
107
- }
108
- };
109
-
110
- // Handlers
111
- const handleNext = useCallback(async () => {
112
- const currentSlide = slides[currentIndex];
113
-
114
- // Check if form slide and validate
115
- if (currentSlide.type === 'form') {
116
- const formSlide = currentSlide as any;
117
- const requiredFields = formSlide.fields.filter((f: any) => f.required);
118
- const isValid = requiredFields.every((field: any) => formData[field.key]);
119
-
120
- if (!isValid) {
121
- return; // Form validation failed
122
- }
123
-
124
- // Submit form data
125
- if (formSlide.onSubmit) {
126
- setIsSubmitting(true);
127
- try {
128
- await formSlide.onSubmit(formData);
129
- } catch (error) {
130
- console.warn('Form submit error:', error);
131
- }
132
- setIsSubmitting(false);
133
- }
134
- }
135
-
136
- if (currentIndex < slides.length - 1) {
137
- flatListRef.current?.scrollToIndex({ index: currentIndex + 1, animated: true });
138
- } else {
139
- // Complete onboarding
140
- await saveOnboardingComplete();
141
- if (onboardingComplete) {
142
- await onboardingComplete(formData);
143
- }
144
- }
145
- }, [currentIndex, slides, formData, onboardingComplete, storage]);
146
-
147
- const handleBack = useCallback(() => {
148
- if (currentIndex > 0) {
149
- flatListRef.current?.scrollToIndex({ index: currentIndex - 1, animated: true });
150
- }
151
- }, [currentIndex]);
152
-
153
- const handleSkip = useCallback(async () => {
154
- await saveOnboardingComplete();
155
- if (onSkip) {
156
- await onSkip();
157
- } else if (onboardingComplete) {
158
- await onboardingComplete();
159
- }
160
- }, [onSkip, onboardingComplete, storage]);
161
-
162
- const handleMomentumScrollEnd = useCallback(
163
- (event: any) => {
164
- const index = Math.round(event.nativeEvent.contentOffset.x / event.nativeEvent.layoutMeasurement.width);
165
- if (index !== currentIndex) {
166
- setCurrentIndex(index);
167
- if (onSlideChange) {
168
- onSlideChange(index);
169
- }
170
- }
171
- },
172
- [currentIndex, onSlideChange]
173
- );
174
-
175
- const handleFormDataChange = useCallback((key: string, value: any) => {
176
- setFormData(prev => ({ ...prev, [key]: value }));
177
- }, []);
178
-
179
- // Renderers
180
- const renderSlide = useCallback(
181
- ({ item, index }: { item: any; index: number }) => {
182
- return (
183
- <View style={[styles.slide, { width: '100%' }]}>
184
- <SlideRenderer
185
- data={item}
186
- theme={theme}
187
- darkMode={darkMode}
188
- onSubmit={handleFormDataChange}
189
- isSubmitting={isSubmitting}
190
- />
191
- </View>
192
- );
193
- },
194
- [theme, darkMode, isSubmitting, handleFormDataChange]
195
- );
196
-
197
- const getKey = useCallback((item: any, index: number) => item.id || `slide-${index}`, []);
198
-
199
- // Computed values
200
- const isLastSlide = currentIndex === slides.length - 1;
201
- const currentSlide = slides[currentIndex];
202
-
203
- // Determine if we should show navigation (not for form slides that handle their own)
204
- const showNavigation = currentSlide?.type !== 'form';
205
-
206
- if (!visible) return null;
207
-
208
- const content = (
209
- <View style={[styles.container, containerStyle]}>
210
- {/* Background Gradient if applicable */}
211
- {currentSlide?.gradientColors && currentSlide.gradientColors.length > 0 && (
212
- <LinearGradient
213
- colors={currentSlide.gradientColors}
214
- style={StyleSheet.absoluteFillObject}
215
- />
216
- )}
217
-
218
- {/* Pagination */}
219
- {showNavigation && (
220
- <Pagination
221
- currentIndex={currentIndex}
222
- totalSlides={slides.length}
223
- theme={theme}
224
- config={navigationConfig}
225
- />
226
- )}
227
-
228
- {/* Slides */}
229
- <AnimatedFlatListImplemented
230
- ref={flatListRef as any}
231
- data={slides}
232
- renderItem={renderSlide}
233
- keyExtractor={getKey}
234
- horizontal
235
- pagingEnabled
236
- showsHorizontalScrollIndicator={false}
237
- scrollEventThrottle={32}
238
- onMomentumScrollEnd={handleMomentumScrollEnd}
239
- scrollEnabled={swipeEnabled}
240
- bounces={false}
241
- initialScrollIndex={initialSlide}
242
- onScrollToIndexFailed={(info) => {
243
- // Retry if scroll to index fails
244
- setTimeout(() => {
245
- flatListRef.current?.scrollToIndex({
246
- index: info.index,
247
- animated: true,
248
- });
249
- }, 100);
250
- }}
251
- />
252
-
253
- {/* Navigation Buttons */}
254
- {showNavigation && (
255
- <NavigationButtons
256
- currentIndex={currentIndex}
257
- totalSlides={slides.length}
258
- theme={theme}
259
- config={navigationConfig}
260
- onNext={handleNext}
261
- onBack={handleBack}
262
- onSkip={handleSkip}
263
- isLastSlide={isLastSlide}
264
- isLoading={isSubmitting}
265
- darkMode={darkMode}
266
- />
267
- )}
268
- </View>
269
- );
270
-
271
- if (safeAreaEnabled) {
272
- return (
273
- <SafeAreaView style={styles.safeArea}>
274
- <SafeAreaProvider>{content}</SafeAreaProvider>
275
- </SafeAreaView>
276
- );
277
- }
278
-
279
- return content;
280
- };
281
-
282
- // Hook for checking onboarding status
283
- export const useOnboarding = (storageKey: string = '@onboarding_complete') => {
284
- const [hasCompletedOnboarding, setHasCompletedOnboarding] = React.useState<boolean | null>(null);
285
- const [isLoading, setIsLoading] = React.useState(true);
286
-
287
- React.useEffect(() => {
288
- checkStatus();
289
- }, []);
290
-
291
- const checkStatus = async () => {
292
- try {
293
- const completed = await AsyncStorage.getItem(storageKey);
294
- setHasCompletedOnboarding(completed === 'true');
295
- } catch (error) {
296
- console.warn('Error checking onboarding:', error);
297
- setHasCompletedOnboarding(false);
298
- } finally {
299
- setIsLoading(false);
300
- }
301
- };
302
-
303
- const markComplete = async () => {
304
- try {
305
- await AsyncStorage.setItem(storageKey, 'true');
306
- setHasCompletedOnboarding(true);
307
- } catch (error) {
308
- console.warn('Error marking onboarding complete:', error);
309
- }
310
- };
311
-
312
- const reset = async () => {
313
- try {
314
- await AsyncStorage.removeItem(storageKey);
315
- setHasCompletedOnboarding(false);
316
- } catch (error) {
317
- console.warn('Error resetting onboarding:', error);
318
- }
319
- };
320
-
321
- return { hasCompletedOnboarding, isLoading, markComplete, reset };
322
- };
323
-
324
- const styles = StyleSheet.create({
325
- safeArea: {
326
- flex: 1,
327
- backgroundColor: '#FFFFFF',
328
- },
329
- container: {
330
- flex: 1,
331
- backgroundColor: '#FFFFFF',
332
- },
333
- slide: {
334
- flex: 1,
335
- justifyContent: 'center',
336
- alignItems: 'center',
337
- },
338
- });
339
-
340
- export default Onboarding;
1
+ import React, { useState, useCallback, useMemo, useEffect } from 'react';
2
+ import {
3
+ View,
4
+ StyleSheet,
5
+ SafeAreaView,
6
+ Platform,
7
+ Modal,
8
+ ViewStyle,
9
+ Animated,
10
+ } from 'react-native';
11
+ import { SafeAreaProvider } from 'react-native-safe-area-context';
12
+ import FlatList from 'react-native-reanimated';
13
+ import { BlurView } from 'expo-blur';
14
+ import { LinearGradient } from 'expo-linear-gradient';
15
+ import AsyncStorage from '@react-native-async-storage/async-storage';
16
+
17
+ import { OnboardingProps, OnboardingConfig } from '../types';
18
+ import { mergeTheme, getPreset } from '../themes';
19
+ import { SlideRenderer } from '../slides';
20
+ import { Pagination, NavigationButtons } from './index';
21
+
22
+ // Type assertion for AnimatedFlatList from react-native-reanimated
23
+ const AnimatedFlatListImplemented = FlatList as any;
24
+
25
+ export const Onboarding: React.FC<OnboardingProps> = ({
26
+ visible,
27
+ slides = [],
28
+ theme: customTheme,
29
+ navigation: customNavigation,
30
+ animation: customAnimation,
31
+ storage,
32
+ onboardingComplete,
33
+ onSlideChange,
34
+ onSkip,
35
+ initialSlide = 0,
36
+ swipeEnabled = true,
37
+ containerStyle,
38
+ safeAreaEnabled = true,
39
+ darkMode = false,
40
+ }) => {
41
+ // State
42
+ const [currentIndex, setCurrentIndex] = useState(initialSlide);
43
+ const [isSubmitting, setIsSubmitting] = useState(false);
44
+ const [formData, setFormData] = useState<Record<string, any>>({});
45
+
46
+ //Refs
47
+ const flatListRef = React.useRef<any>(null);
48
+
49
+ // Merge theme with preset
50
+ const preset = useMemo(() => {
51
+ if (!customTheme) return getPreset('modern');
52
+ const presetKey = Object.keys(getPreset('modern')).find(
53
+ key => (customTheme as any)[key]
54
+ );
55
+ return presetKey ? getPreset(presetKey) : getPreset('modern');
56
+ }, [customTheme]);
57
+
58
+ const theme = useMemo(
59
+ () => mergeTheme(preset.theme, customTheme),
60
+ [preset, customTheme]
61
+ );
62
+
63
+ const navigationConfig = useMemo(
64
+ () => ({ ...preset.navigation, ...customNavigation }),
65
+ [preset, customNavigation]
66
+ );
67
+
68
+ const animationConfig = useMemo(
69
+ () => ({ ...preset.animation, ...customAnimation }),
70
+ [preset, customAnimation]
71
+ );
72
+
73
+ // Check storage on mount
74
+ useEffect(() => {
75
+ if (storage?.enabled) {
76
+ checkOnboardingStatus();
77
+ }
78
+ }, [storage]);
79
+
80
+ const checkOnboardingStatus = async () => {
81
+ try {
82
+ const key = storage?.key || '@onboarding_complete';
83
+ const completed = await AsyncStorage.getItem(key);
84
+ if (completed && !visible) {
85
+ // Already completed, don't show
86
+ return;
87
+ }
88
+ } catch (error) {
89
+ console.warn('Error checking onboarding status:', error);
90
+ }
91
+ };
92
+
93
+ const saveOnboardingComplete = async () => {
94
+ if (storage?.enabled) {
95
+ try {
96
+ const key = storage?.key || '@onboarding_complete';
97
+ await AsyncStorage.setItem(key, 'true');
98
+ if (storage.onComplete) {
99
+ await storage.onComplete();
100
+ }
101
+ } catch (error) {
102
+ console.warn('Error saving onboarding status:', error);
103
+ }
104
+ }
105
+ };
106
+
107
+ // Handlers
108
+ const handleNext = useCallback(async () => {
109
+ const currentSlide = slides[currentIndex];
110
+
111
+ // Check if form slide and validate
112
+ if (currentSlide.type === 'form') {
113
+ const formSlide = currentSlide as any;
114
+ const requiredFields = formSlide.fields.filter((f: any) => f.required);
115
+ const isValid = requiredFields.every((field: any) => formData[field.key]);
116
+
117
+ if (!isValid) {
118
+ return; // Form validation failed
119
+ }
120
+
121
+ // Submit form data
122
+ if (formSlide.onSubmit) {
123
+ setIsSubmitting(true);
124
+ try {
125
+ await formSlide.onSubmit(formData);
126
+ } catch (error) {
127
+ console.warn('Form submit error:', error);
128
+ }
129
+ setIsSubmitting(false);
130
+ }
131
+ }
132
+
133
+ if (currentIndex < slides.length - 1) {
134
+ flatListRef.current?.scrollToIndex({ index: currentIndex + 1, animated: true });
135
+ } else {
136
+ // Complete onboarding
137
+ await saveOnboardingComplete();
138
+ if (onboardingComplete) {
139
+ await onboardingComplete(formData);
140
+ }
141
+ }
142
+ }, [currentIndex, slides, formData, onboardingComplete, storage]);
143
+
144
+ const handleBack = useCallback(() => {
145
+ if (currentIndex > 0) {
146
+ flatListRef.current?.scrollToIndex({ index: currentIndex - 1, animated: true });
147
+ }
148
+ }, [currentIndex]);
149
+
150
+ const handleSkip = useCallback(async () => {
151
+ await saveOnboardingComplete();
152
+ if (onSkip) {
153
+ await onSkip();
154
+ } else if (onboardingComplete) {
155
+ await onboardingComplete();
156
+ }
157
+ }, [onSkip, onboardingComplete, storage]);
158
+
159
+ const handleMomentumScrollEnd = useCallback(
160
+ (event: any) => {
161
+ const index = Math.round(event.nativeEvent.contentOffset.x / event.nativeEvent.layoutMeasurement.width);
162
+ if (index !== currentIndex) {
163
+ setCurrentIndex(index);
164
+ if (onSlideChange) {
165
+ onSlideChange(index);
166
+ }
167
+ }
168
+ },
169
+ [currentIndex, onSlideChange]
170
+ );
171
+
172
+ const handleFormDataChange = useCallback((data: Record<string, any>) => {
173
+ setFormData(prev => ({ ...prev, ...data }));
174
+ }, []);
175
+
176
+ // Renderers
177
+ const renderSlide = useCallback(
178
+ ({ item, index }: { item: any; index: number }) => {
179
+ return (
180
+ <View style={[styles.slide, { width: '100%' }]}>
181
+ <SlideRenderer
182
+ data={item}
183
+ theme={theme}
184
+ darkMode={darkMode}
185
+ onSubmit={handleFormDataChange}
186
+ isSubmitting={isSubmitting}
187
+ />
188
+ </View>
189
+ );
190
+ },
191
+ [theme, darkMode, isSubmitting, handleFormDataChange]
192
+ );
193
+
194
+ const getKey = useCallback((item: any, index: number) => item.id || `slide-${index}`, []);
195
+
196
+ // Computed values
197
+ const isLastSlide = currentIndex === slides.length - 1;
198
+ const currentSlide = slides[currentIndex];
199
+
200
+ // Determine if we should show navigation (not for form slides that handle their own)
201
+ const showNavigation = currentSlide?.type !== 'form';
202
+
203
+ if (!visible) return null;
204
+
205
+ const content = (
206
+ <View style={[styles.container, containerStyle]}>
207
+ {/* Background Gradient if applicable */}
208
+ {currentSlide?.gradientColors && currentSlide.gradientColors.length > 0 && (
209
+ <LinearGradient
210
+ colors={currentSlide.gradientColors as any}
211
+ style={StyleSheet.absoluteFillObject}
212
+ />
213
+ )}
214
+
215
+ {/* Pagination */}
216
+ {showNavigation && (
217
+ <Pagination
218
+ currentIndex={currentIndex}
219
+ totalSlides={slides.length}
220
+ theme={theme}
221
+ config={navigationConfig}
222
+ />
223
+ )}
224
+
225
+ {/* Slides */}
226
+ <AnimatedFlatListImplemented
227
+ ref={flatListRef as any}
228
+ data={slides}
229
+ renderItem={renderSlide}
230
+ keyExtractor={getKey}
231
+ horizontal
232
+ pagingEnabled
233
+ showsHorizontalScrollIndicator={false}
234
+ scrollEventThrottle={32}
235
+ onMomentumScrollEnd={handleMomentumScrollEnd}
236
+ scrollEnabled={swipeEnabled}
237
+ bounces={false}
238
+ initialScrollIndex={initialSlide}
239
+ onScrollToIndexFailed={(info: any) => {
240
+ // Retry if scroll to index fails
241
+ setTimeout(() => {
242
+ flatListRef.current?.scrollToIndex({
243
+ index: info.index,
244
+ animated: true,
245
+ });
246
+ }, 100);
247
+ }}
248
+ />
249
+
250
+ {/* Navigation Buttons */}
251
+ {showNavigation && (
252
+ <NavigationButtons
253
+ currentIndex={currentIndex}
254
+ totalSlides={slides.length}
255
+ theme={theme}
256
+ config={navigationConfig}
257
+ onNext={handleNext}
258
+ onBack={handleBack}
259
+ onSkip={handleSkip}
260
+ isLastSlide={isLastSlide}
261
+ isLoading={isSubmitting}
262
+ darkMode={darkMode}
263
+ />
264
+ )}
265
+ </View>
266
+ );
267
+
268
+ if (safeAreaEnabled) {
269
+ return (
270
+ <SafeAreaView style={styles.safeArea}>
271
+ <SafeAreaProvider>{content}</SafeAreaProvider>
272
+ </SafeAreaView>
273
+ );
274
+ }
275
+
276
+ return content;
277
+ };
278
+
279
+ // Hook for checking onboarding status
280
+ export const useOnboarding = (storageKey: string = '@onboarding_complete') => {
281
+ const [hasCompletedOnboarding, setHasCompletedOnboarding] = React.useState<boolean | null>(null);
282
+ const [isLoading, setIsLoading] = React.useState(true);
283
+
284
+ React.useEffect(() => {
285
+ checkStatus();
286
+ }, []);
287
+
288
+ const checkStatus = async () => {
289
+ try {
290
+ const completed = await AsyncStorage.getItem(storageKey);
291
+ setHasCompletedOnboarding(completed === 'true');
292
+ } catch (error) {
293
+ console.warn('Error checking onboarding:', error);
294
+ setHasCompletedOnboarding(false);
295
+ } finally {
296
+ setIsLoading(false);
297
+ }
298
+ };
299
+
300
+ const markComplete = async () => {
301
+ try {
302
+ await AsyncStorage.setItem(storageKey, 'true');
303
+ setHasCompletedOnboarding(true);
304
+ } catch (error) {
305
+ console.warn('Error marking onboarding complete:', error);
306
+ }
307
+ };
308
+
309
+ const reset = async () => {
310
+ try {
311
+ await AsyncStorage.removeItem(storageKey);
312
+ setHasCompletedOnboarding(false);
313
+ } catch (error) {
314
+ console.warn('Error resetting onboarding:', error);
315
+ }
316
+ };
317
+
318
+ return { hasCompletedOnboarding, isLoading, markComplete, reset };
319
+ };
320
+
321
+ const styles = StyleSheet.create({
322
+ safeArea: {
323
+ flex: 1,
324
+ backgroundColor: '#FFFFFF',
325
+ },
326
+ container: {
327
+ flex: 1,
328
+ backgroundColor: '#FFFFFF',
329
+ },
330
+ slide: {
331
+ flex: 1,
332
+ justifyContent: 'center',
333
+ alignItems: 'center',
334
+ },
335
+ });
336
+
337
+ export default Onboarding;