@umituz/react-native-onboarding 3.0.2 → 3.0.4
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.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umituz/react-native-onboarding",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.4",
|
|
4
4
|
"description": "Advanced onboarding flow for React Native apps with personalization questions, theme-aware colors, animations, and customizable slides. SOLID, DRY, KISS principles applied.",
|
|
5
5
|
"main": "./src/index.ts",
|
|
6
6
|
"types": "./src/index.ts",
|
|
@@ -18,17 +18,36 @@ interface OnboardingStore extends OnboardingStoreState {
|
|
|
18
18
|
setError: (error: string | null) => void;
|
|
19
19
|
setState: (state: Partial<OnboardingStoreState>) => void;
|
|
20
20
|
getState: () => OnboardingStoreState;
|
|
21
|
+
// Async actions for initialization (match OnboardingStoreActions signatures)
|
|
22
|
+
initialize: (storageKey?: string) => Promise<void>;
|
|
23
|
+
complete: (storageKey?: string) => Promise<void>;
|
|
24
|
+
skip: (storageKey?: string) => Promise<void>;
|
|
25
|
+
reset: (storageKey?: string) => Promise<void>;
|
|
26
|
+
saveAnswer: (questionId: string, answer: any) => Promise<void>;
|
|
27
|
+
setUserData: (data: any) => Promise<void>;
|
|
21
28
|
}
|
|
22
29
|
|
|
23
|
-
export const useOnboardingStore = create<OnboardingStore>((set, get) =>
|
|
24
|
-
|
|
30
|
+
export const useOnboardingStore = create<OnboardingStore>((set, get) => {
|
|
31
|
+
const actions = createOnboardingStoreActions(set as any, get);
|
|
25
32
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
})
|
|
33
|
+
return {
|
|
34
|
+
...initialOnboardingState,
|
|
35
|
+
|
|
36
|
+
setCurrentStep: (step) => set({ currentStep: step }),
|
|
37
|
+
setLoading: (loading) => set({ loading }),
|
|
38
|
+
setError: (error) => set({ error }),
|
|
39
|
+
setState: set,
|
|
40
|
+
getState: get,
|
|
41
|
+
|
|
42
|
+
// Async actions from actions module
|
|
43
|
+
initialize: actions.initialize,
|
|
44
|
+
complete: actions.complete,
|
|
45
|
+
skip: actions.skip,
|
|
46
|
+
reset: actions.reset,
|
|
47
|
+
saveAnswer: actions.saveAnswer,
|
|
48
|
+
setUserData: actions.setUserData,
|
|
49
|
+
};
|
|
50
|
+
});
|
|
32
51
|
|
|
33
52
|
/**
|
|
34
53
|
* Hook for accessing onboarding state
|
|
@@ -47,7 +66,7 @@ export const useOnboarding = () => {
|
|
|
47
66
|
loading: store.loading,
|
|
48
67
|
error: store.error,
|
|
49
68
|
userData: store.userData,
|
|
50
|
-
|
|
69
|
+
|
|
51
70
|
// Actions
|
|
52
71
|
initialize: actions.initialize,
|
|
53
72
|
complete: actions.complete,
|
|
@@ -58,7 +77,7 @@ export const useOnboarding = () => {
|
|
|
58
77
|
setError: store.setError,
|
|
59
78
|
saveAnswer: actions.saveAnswer,
|
|
60
79
|
setUserData: actions.setUserData,
|
|
61
|
-
|
|
80
|
+
|
|
62
81
|
// Selectors
|
|
63
82
|
getAnswer: selectors.getAnswer,
|
|
64
83
|
getUserData: selectors.getUserData,
|
|
@@ -63,22 +63,32 @@ export function createOnboardingStoreActions(
|
|
|
63
63
|
try {
|
|
64
64
|
set({ loading: true, error: null });
|
|
65
65
|
|
|
66
|
+
// Ensure storage write completes before proceeding
|
|
66
67
|
const result = await storageRepository.setString(storageKey, "true");
|
|
67
68
|
|
|
69
|
+
if (!result.success) {
|
|
70
|
+
throw new Error("Failed to save completion status to storage");
|
|
71
|
+
}
|
|
72
|
+
|
|
68
73
|
const userData = { ...get().userData };
|
|
69
74
|
userData.completedAt = new Date().toISOString();
|
|
70
75
|
|
|
71
|
-
await storageRepository.setItem(USER_DATA_STORAGE_KEY, userData);
|
|
76
|
+
const userDataResult = await storageRepository.setItem(USER_DATA_STORAGE_KEY, userData);
|
|
72
77
|
|
|
78
|
+
if (!userDataResult.success) {
|
|
79
|
+
throw new Error("Failed to save user data to storage");
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Only update state after storage write is confirmed
|
|
73
83
|
set({
|
|
74
|
-
isOnboardingComplete:
|
|
84
|
+
isOnboardingComplete: true,
|
|
75
85
|
userData,
|
|
76
86
|
loading: false,
|
|
77
|
-
error:
|
|
87
|
+
error: null,
|
|
78
88
|
});
|
|
79
89
|
|
|
80
90
|
if (__DEV__) {
|
|
81
|
-
console.log('[OnboardingStore] Onboarding completed successfully');
|
|
91
|
+
console.log('[OnboardingStore] Onboarding completed and persisted successfully');
|
|
82
92
|
}
|
|
83
93
|
} catch (error) {
|
|
84
94
|
set({
|
|
@@ -89,6 +99,8 @@ export function createOnboardingStoreActions(
|
|
|
89
99
|
if (__DEV__) {
|
|
90
100
|
console.error('[OnboardingStore] Completion error:', error);
|
|
91
101
|
}
|
|
102
|
+
|
|
103
|
+
throw error;
|
|
92
104
|
}
|
|
93
105
|
},
|
|
94
106
|
|
|
@@ -96,22 +108,33 @@ export function createOnboardingStoreActions(
|
|
|
96
108
|
try {
|
|
97
109
|
set({ loading: true, error: null });
|
|
98
110
|
|
|
111
|
+
// Ensure storage write completes before proceeding
|
|
99
112
|
const result = await storageRepository.setString(storageKey, "true");
|
|
100
113
|
|
|
114
|
+
if (!result.success) {
|
|
115
|
+
throw new Error("Failed to save skip status to storage");
|
|
116
|
+
}
|
|
117
|
+
|
|
101
118
|
const userData = { ...get().userData };
|
|
102
119
|
userData.skipped = true;
|
|
103
120
|
userData.completedAt = new Date().toISOString();
|
|
104
|
-
await storageRepository.setItem(USER_DATA_STORAGE_KEY, userData);
|
|
105
121
|
|
|
122
|
+
const userDataResult = await storageRepository.setItem(USER_DATA_STORAGE_KEY, userData);
|
|
123
|
+
|
|
124
|
+
if (!userDataResult.success) {
|
|
125
|
+
throw new Error("Failed to save user data to storage");
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// Only update state after storage write is confirmed
|
|
106
129
|
set({
|
|
107
|
-
isOnboardingComplete:
|
|
130
|
+
isOnboardingComplete: true,
|
|
108
131
|
userData,
|
|
109
132
|
loading: false,
|
|
110
|
-
error:
|
|
133
|
+
error: null,
|
|
111
134
|
});
|
|
112
135
|
|
|
113
136
|
if (__DEV__) {
|
|
114
|
-
console.log('[OnboardingStore] Onboarding skipped successfully');
|
|
137
|
+
console.log('[OnboardingStore] Onboarding skipped and persisted successfully');
|
|
115
138
|
}
|
|
116
139
|
} catch (error) {
|
|
117
140
|
set({
|
|
@@ -122,6 +145,8 @@ export function createOnboardingStoreActions(
|
|
|
122
145
|
if (__DEV__) {
|
|
123
146
|
console.error('[OnboardingStore] Skip error:', error);
|
|
124
147
|
}
|
|
148
|
+
|
|
149
|
+
throw error;
|
|
125
150
|
}
|
|
126
151
|
},
|
|
127
152
|
|