@umituz/react-native-onboarding 1.0.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.
- package/LICENSE +22 -0
- package/README.md +175 -0
- package/package.json +63 -0
- package/src/domain/entities/OnboardingOptions.ts +79 -0
- package/src/domain/entities/OnboardingSlide.ts +48 -0
- package/src/index.ts +57 -0
- package/src/infrastructure/hooks/useOnboardingNavigation.ts +71 -0
- package/src/infrastructure/storage/OnboardingStore.ts +128 -0
- package/src/presentation/components/OnboardingFooter.tsx +142 -0
- package/src/presentation/components/OnboardingHeader.tsx +92 -0
- package/src/presentation/components/OnboardingSlide.tsx +107 -0
- package/src/presentation/screens/OnboardingScreen.tsx +169 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Ümit UZ
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
package/README.md
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
# @umituz/react-native-onboarding
|
|
2
|
+
|
|
3
|
+
Generic onboarding flow for React Native apps with gradient backgrounds, animations, and customizable slides. Follows SOLID, DRY, KISS principles - fully reusable across hundreds of apps.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- ✅ **Generic & Reusable**: Works with any app, fully customizable via props
|
|
8
|
+
- ✅ **Gradient Backgrounds**: Beautiful gradient backgrounds for each slide
|
|
9
|
+
- ✅ **Animations**: Smooth transitions and animations
|
|
10
|
+
- ✅ **SOLID Principles**: Clean architecture, easy to extend
|
|
11
|
+
- ✅ **DRY**: No code duplication, generic components
|
|
12
|
+
- ✅ **KISS**: Simple API, easy to understand and use
|
|
13
|
+
- ✅ **Type-Safe**: Full TypeScript support
|
|
14
|
+
- ✅ **Customizable**: Icons, messages, gradients, buttons - all configurable
|
|
15
|
+
- ✅ **Storage Integration**: Uses @umituz/react-native-storage for persistence
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install @umituz/react-native-onboarding
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
### Basic Example
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
import { OnboardingScreen } from '@umituz/react-native-onboarding';
|
|
29
|
+
|
|
30
|
+
const slides = [
|
|
31
|
+
{
|
|
32
|
+
id: '1',
|
|
33
|
+
title: 'Welcome',
|
|
34
|
+
description: 'Welcome to the app',
|
|
35
|
+
icon: '🎉',
|
|
36
|
+
gradient: ['#3B82F6', '#8B5CF6'],
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
id: '2',
|
|
40
|
+
title: 'Features',
|
|
41
|
+
description: 'Discover amazing features',
|
|
42
|
+
icon: '✨',
|
|
43
|
+
gradient: ['#60A5FA', '#A78BFA'],
|
|
44
|
+
},
|
|
45
|
+
];
|
|
46
|
+
|
|
47
|
+
<OnboardingScreen
|
|
48
|
+
slides={slides}
|
|
49
|
+
onComplete={() => {
|
|
50
|
+
// Navigate to main app
|
|
51
|
+
}}
|
|
52
|
+
/>
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Advanced Example with Customization
|
|
56
|
+
|
|
57
|
+
```typescript
|
|
58
|
+
import { OnboardingScreen } from '@umituz/react-native-onboarding';
|
|
59
|
+
|
|
60
|
+
<OnboardingScreen
|
|
61
|
+
slides={slides}
|
|
62
|
+
onComplete={handleComplete}
|
|
63
|
+
onSkip={handleSkip}
|
|
64
|
+
skipButtonText="Skip"
|
|
65
|
+
nextButtonText="Next"
|
|
66
|
+
getStartedButtonText="Get Started"
|
|
67
|
+
showSkipButton={true}
|
|
68
|
+
showBackButton={true}
|
|
69
|
+
showProgressBar={true}
|
|
70
|
+
showDots={true}
|
|
71
|
+
showProgressText={true}
|
|
72
|
+
storageKey="@myapp_onboarding_completed"
|
|
73
|
+
autoComplete={false}
|
|
74
|
+
/>
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### With Features List
|
|
78
|
+
|
|
79
|
+
```typescript
|
|
80
|
+
const slides = [
|
|
81
|
+
{
|
|
82
|
+
id: '1',
|
|
83
|
+
title: 'Powerful Features',
|
|
84
|
+
description: 'Everything you need in one place',
|
|
85
|
+
icon: '🚀',
|
|
86
|
+
gradient: ['#3B82F6', '#8B5CF6'],
|
|
87
|
+
features: [
|
|
88
|
+
'Feature 1: Amazing capability',
|
|
89
|
+
'Feature 2: Another great feature',
|
|
90
|
+
'Feature 3: One more awesome thing',
|
|
91
|
+
],
|
|
92
|
+
},
|
|
93
|
+
];
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### Custom Components
|
|
97
|
+
|
|
98
|
+
```typescript
|
|
99
|
+
<OnboardingScreen
|
|
100
|
+
slides={slides}
|
|
101
|
+
renderHeader={({ isFirstSlide, onBack, onSkip }) => (
|
|
102
|
+
<CustomHeader onBack={onBack} onSkip={onSkip} />
|
|
103
|
+
)}
|
|
104
|
+
renderFooter={({ currentIndex, totalSlides, isLastSlide, onNext }) => (
|
|
105
|
+
<CustomFooter onNext={onNext} />
|
|
106
|
+
)}
|
|
107
|
+
renderSlide={(slide) => <CustomSlide slide={slide} />}
|
|
108
|
+
/>
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## API Reference
|
|
112
|
+
|
|
113
|
+
### `OnboardingSlide`
|
|
114
|
+
|
|
115
|
+
```typescript
|
|
116
|
+
interface OnboardingSlide {
|
|
117
|
+
id: string;
|
|
118
|
+
title: string;
|
|
119
|
+
description: string;
|
|
120
|
+
icon: string; // Emoji or icon name
|
|
121
|
+
gradient: string[]; // [startColor, endColor] or [color1, color2, color3]
|
|
122
|
+
image?: string; // Optional image URL
|
|
123
|
+
features?: string[]; // Optional features list
|
|
124
|
+
}
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### `OnboardingOptions`
|
|
128
|
+
|
|
129
|
+
```typescript
|
|
130
|
+
interface OnboardingOptions {
|
|
131
|
+
slides: OnboardingSlide[];
|
|
132
|
+
onComplete?: () => void | Promise<void>;
|
|
133
|
+
onSkip?: () => void | Promise<void>;
|
|
134
|
+
skipButtonText?: string;
|
|
135
|
+
nextButtonText?: string;
|
|
136
|
+
getStartedButtonText?: string;
|
|
137
|
+
showSkipButton?: boolean;
|
|
138
|
+
showBackButton?: boolean;
|
|
139
|
+
showProgressBar?: boolean;
|
|
140
|
+
showDots?: boolean;
|
|
141
|
+
showProgressText?: boolean;
|
|
142
|
+
storageKey?: string;
|
|
143
|
+
autoComplete?: boolean;
|
|
144
|
+
}
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### `useOnboardingStore`
|
|
148
|
+
|
|
149
|
+
Hook for managing onboarding completion state.
|
|
150
|
+
|
|
151
|
+
```typescript
|
|
152
|
+
const { isOnboardingComplete, complete, skip, reset } = useOnboardingStore();
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### `useOnboardingNavigation`
|
|
156
|
+
|
|
157
|
+
Hook for managing navigation state.
|
|
158
|
+
|
|
159
|
+
```typescript
|
|
160
|
+
const { currentIndex, goToNext, goToPrevious, isLastSlide, isFirstSlide } =
|
|
161
|
+
useOnboardingNavigation(totalSlides, onComplete, onSkip);
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
## Architecture
|
|
165
|
+
|
|
166
|
+
- **Domain Layer**: Entities and interfaces (business logic)
|
|
167
|
+
- **Infrastructure Layer**: Storage and hooks (state management)
|
|
168
|
+
- **Presentation Layer**: Components and screens (UI)
|
|
169
|
+
|
|
170
|
+
No app-specific code, fully generic and reusable.
|
|
171
|
+
|
|
172
|
+
## License
|
|
173
|
+
|
|
174
|
+
MIT
|
|
175
|
+
|
package/package.json
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@umituz/react-native-onboarding",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Generic onboarding flow for React Native apps with gradient backgrounds, animations, and customizable slides. SOLID, DRY, KISS principles applied.",
|
|
5
|
+
"main": "./src/index.ts",
|
|
6
|
+
"types": "./src/index.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"typecheck": "tsc --noEmit",
|
|
9
|
+
"lint": "tsc --noEmit",
|
|
10
|
+
"version:patch": "npm version patch -m 'chore: release v%s'",
|
|
11
|
+
"version:minor": "npm version minor -m 'chore: release v%s'",
|
|
12
|
+
"version:major": "npm version major -m 'chore: release v%s'"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [
|
|
15
|
+
"react-native",
|
|
16
|
+
"onboarding",
|
|
17
|
+
"welcome",
|
|
18
|
+
"tutorial",
|
|
19
|
+
"gradient",
|
|
20
|
+
"animation",
|
|
21
|
+
"ddd",
|
|
22
|
+
"domain-driven-design",
|
|
23
|
+
"solid",
|
|
24
|
+
"dry",
|
|
25
|
+
"kiss"
|
|
26
|
+
],
|
|
27
|
+
"author": "Ümit UZ <umit@umituz.com>",
|
|
28
|
+
"license": "MIT",
|
|
29
|
+
"repository": {
|
|
30
|
+
"type": "git",
|
|
31
|
+
"url": "https://github.com/umituz/react-native-onboarding"
|
|
32
|
+
},
|
|
33
|
+
"peerDependencies": {
|
|
34
|
+
"@umituz/react-native-storage": "latest",
|
|
35
|
+
"@umituz/react-native-localization": "latest",
|
|
36
|
+
"@umituz/react-native-theme": "latest",
|
|
37
|
+
"expo-linear-gradient": "^15.0.0",
|
|
38
|
+
"react": ">=18.2.0",
|
|
39
|
+
"react-native": ">=0.74.0",
|
|
40
|
+
"react-native-safe-area-context": "^5.0.0"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@types/react": "^18.2.45",
|
|
44
|
+
"@types/react-native": "^0.73.0",
|
|
45
|
+
"@umituz/react-native-storage": "^1.1.0",
|
|
46
|
+
"@umituz/react-native-localization": "latest",
|
|
47
|
+
"@umituz/react-native-theme": "latest",
|
|
48
|
+
"expo-linear-gradient": "^15.0.7",
|
|
49
|
+
"react": "^18.2.0",
|
|
50
|
+
"react-native": "^0.74.0",
|
|
51
|
+
"react-native-safe-area-context": "^5.6.0",
|
|
52
|
+
"typescript": "^5.3.3"
|
|
53
|
+
},
|
|
54
|
+
"publishConfig": {
|
|
55
|
+
"access": "public"
|
|
56
|
+
},
|
|
57
|
+
"files": [
|
|
58
|
+
"src",
|
|
59
|
+
"README.md",
|
|
60
|
+
"LICENSE"
|
|
61
|
+
]
|
|
62
|
+
}
|
|
63
|
+
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Onboarding Options
|
|
3
|
+
*
|
|
4
|
+
* Configuration options for onboarding flow
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type { OnboardingSlide } from "./OnboardingSlide";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Onboarding Options
|
|
11
|
+
* Customize the onboarding experience
|
|
12
|
+
*/
|
|
13
|
+
export interface OnboardingOptions {
|
|
14
|
+
/**
|
|
15
|
+
* Array of slides to display
|
|
16
|
+
*/
|
|
17
|
+
slides: OnboardingSlide[];
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Callback when onboarding is completed
|
|
21
|
+
*/
|
|
22
|
+
onComplete?: () => void | Promise<void>;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Callback when onboarding is skipped
|
|
26
|
+
*/
|
|
27
|
+
onSkip?: () => void | Promise<void>;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Custom skip button text (default: "Skip")
|
|
31
|
+
*/
|
|
32
|
+
skipButtonText?: string;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Custom next button text (default: "Next")
|
|
36
|
+
*/
|
|
37
|
+
nextButtonText?: string;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Custom get started button text (default: "Get Started")
|
|
41
|
+
*/
|
|
42
|
+
getStartedButtonText?: string;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Show skip button (default: true)
|
|
46
|
+
*/
|
|
47
|
+
showSkipButton?: boolean;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Show back button (default: true)
|
|
51
|
+
*/
|
|
52
|
+
showBackButton?: boolean;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Show progress bar (default: true)
|
|
56
|
+
*/
|
|
57
|
+
showProgressBar?: boolean;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Show dots indicator (default: true)
|
|
61
|
+
*/
|
|
62
|
+
showDots?: boolean;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Show progress text (default: true)
|
|
66
|
+
*/
|
|
67
|
+
showProgressText?: boolean;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Storage key for completion state (default: "@onboarding_completed")
|
|
71
|
+
*/
|
|
72
|
+
storageKey?: string;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Auto-complete onboarding on last slide (default: false)
|
|
76
|
+
*/
|
|
77
|
+
autoComplete?: boolean;
|
|
78
|
+
}
|
|
79
|
+
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Onboarding Slide Entity
|
|
3
|
+
*
|
|
4
|
+
* Domain entity representing a single onboarding slide
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Onboarding Slide
|
|
9
|
+
* Each slide represents one step in the onboarding flow
|
|
10
|
+
*/
|
|
11
|
+
export interface OnboardingSlide {
|
|
12
|
+
/**
|
|
13
|
+
* Unique identifier for the slide
|
|
14
|
+
*/
|
|
15
|
+
id: string;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Slide title
|
|
19
|
+
*/
|
|
20
|
+
title: string;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Slide description/body text
|
|
24
|
+
*/
|
|
25
|
+
description: string;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Icon to display (emoji or icon name)
|
|
29
|
+
*/
|
|
30
|
+
icon: string;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Gradient colors for the slide background
|
|
34
|
+
* [startColor, endColor] or [color1, color2, color3] for multi-stop gradients
|
|
35
|
+
*/
|
|
36
|
+
gradient: string[];
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Optional image URL (alternative to icon)
|
|
40
|
+
*/
|
|
41
|
+
image?: string;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Optional features list to display
|
|
45
|
+
*/
|
|
46
|
+
features?: string[];
|
|
47
|
+
}
|
|
48
|
+
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React Native Onboarding - Public API
|
|
3
|
+
*
|
|
4
|
+
* Generic onboarding flow for React Native apps with gradient backgrounds,
|
|
5
|
+
* animations, and customizable slides. Follows SOLID, DRY, KISS principles.
|
|
6
|
+
*
|
|
7
|
+
* Architecture:
|
|
8
|
+
* - Domain: Entities and interfaces (business logic)
|
|
9
|
+
* - Infrastructure: Storage and hooks (state management)
|
|
10
|
+
* - Presentation: Components and screens (UI)
|
|
11
|
+
*
|
|
12
|
+
* Usage:
|
|
13
|
+
* import { OnboardingScreen, OnboardingSlide } from '@umituz/react-native-onboarding';
|
|
14
|
+
*
|
|
15
|
+
* <OnboardingScreen
|
|
16
|
+
* slides={[
|
|
17
|
+
* {
|
|
18
|
+
* id: '1',
|
|
19
|
+
* title: 'Welcome',
|
|
20
|
+
* description: 'Welcome to the app',
|
|
21
|
+
* icon: '🎉',
|
|
22
|
+
* gradient: ['#3B82F6', '#8B5CF6'],
|
|
23
|
+
* },
|
|
24
|
+
* ]}
|
|
25
|
+
* onComplete={() => console.log('Completed')}
|
|
26
|
+
* />
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
// =============================================================================
|
|
30
|
+
// DOMAIN LAYER - Entities and Interfaces
|
|
31
|
+
// =============================================================================
|
|
32
|
+
|
|
33
|
+
export type { OnboardingSlide } from "./domain/entities/OnboardingSlide";
|
|
34
|
+
export type { OnboardingOptions } from "./domain/entities/OnboardingOptions";
|
|
35
|
+
|
|
36
|
+
// =============================================================================
|
|
37
|
+
// INFRASTRUCTURE LAYER - Storage and Hooks
|
|
38
|
+
// =============================================================================
|
|
39
|
+
|
|
40
|
+
export {
|
|
41
|
+
useOnboardingStore,
|
|
42
|
+
useOnboarding,
|
|
43
|
+
} from "./infrastructure/storage/OnboardingStore";
|
|
44
|
+
export {
|
|
45
|
+
useOnboardingNavigation,
|
|
46
|
+
type UseOnboardingNavigationReturn,
|
|
47
|
+
} from "./infrastructure/hooks/useOnboardingNavigation";
|
|
48
|
+
|
|
49
|
+
// =============================================================================
|
|
50
|
+
// PRESENTATION LAYER - Components and Screens
|
|
51
|
+
// =============================================================================
|
|
52
|
+
|
|
53
|
+
export { OnboardingScreen, type OnboardingScreenProps } from "./presentation/screens/OnboardingScreen";
|
|
54
|
+
export { OnboardingSlide, type OnboardingSlideProps } from "./presentation/components/OnboardingSlide";
|
|
55
|
+
export { OnboardingHeader, type OnboardingHeaderProps } from "./presentation/components/OnboardingHeader";
|
|
56
|
+
export { OnboardingFooter, type OnboardingFooterProps } from "./presentation/components/OnboardingFooter";
|
|
57
|
+
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* useOnboardingNavigation Hook
|
|
3
|
+
*
|
|
4
|
+
* Manages navigation state and callbacks for onboarding flow
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { useState, useCallback } from "react";
|
|
8
|
+
import { DeviceEventEmitter } from "react-native";
|
|
9
|
+
|
|
10
|
+
export interface UseOnboardingNavigationReturn {
|
|
11
|
+
currentIndex: number;
|
|
12
|
+
goToNext: () => void;
|
|
13
|
+
goToPrevious: () => void;
|
|
14
|
+
isLastSlide: boolean;
|
|
15
|
+
isFirstSlide: boolean;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Hook for managing onboarding navigation
|
|
20
|
+
*
|
|
21
|
+
* @param totalSlides - Total number of slides
|
|
22
|
+
* @param onComplete - Callback when onboarding completes
|
|
23
|
+
* @param onSkip - Callback when onboarding is skipped
|
|
24
|
+
* @returns Navigation state and handlers
|
|
25
|
+
*/
|
|
26
|
+
export const useOnboardingNavigation = (
|
|
27
|
+
totalSlides: number,
|
|
28
|
+
onComplete?: () => void | Promise<void>,
|
|
29
|
+
onSkip?: () => void | Promise<void>,
|
|
30
|
+
): UseOnboardingNavigationReturn => {
|
|
31
|
+
const [currentIndex, setCurrentIndex] = useState(0);
|
|
32
|
+
|
|
33
|
+
const goToNext = useCallback(() => {
|
|
34
|
+
if (currentIndex < totalSlides - 1) {
|
|
35
|
+
setCurrentIndex(currentIndex + 1);
|
|
36
|
+
}
|
|
37
|
+
}, [currentIndex, totalSlides]);
|
|
38
|
+
|
|
39
|
+
const goToPrevious = useCallback(() => {
|
|
40
|
+
if (currentIndex > 0) {
|
|
41
|
+
setCurrentIndex(currentIndex - 1);
|
|
42
|
+
}
|
|
43
|
+
}, [currentIndex]);
|
|
44
|
+
|
|
45
|
+
const complete = useCallback(async () => {
|
|
46
|
+
if (onComplete) {
|
|
47
|
+
await onComplete();
|
|
48
|
+
}
|
|
49
|
+
// Emit event for app-level handling
|
|
50
|
+
DeviceEventEmitter.emit("onboarding-complete");
|
|
51
|
+
}, [onComplete]);
|
|
52
|
+
|
|
53
|
+
const skip = useCallback(async () => {
|
|
54
|
+
if (onSkip) {
|
|
55
|
+
await onSkip();
|
|
56
|
+
}
|
|
57
|
+
// Emit event for app-level handling
|
|
58
|
+
DeviceEventEmitter.emit("onboarding-complete");
|
|
59
|
+
}, [onSkip]);
|
|
60
|
+
|
|
61
|
+
return {
|
|
62
|
+
currentIndex,
|
|
63
|
+
goToNext,
|
|
64
|
+
goToPrevious,
|
|
65
|
+
complete,
|
|
66
|
+
skip,
|
|
67
|
+
isLastSlide: currentIndex === totalSlides - 1,
|
|
68
|
+
isFirstSlide: currentIndex === 0,
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Onboarding Store
|
|
3
|
+
*
|
|
4
|
+
* Zustand store for managing onboarding completion state
|
|
5
|
+
* Uses @umituz/react-native-storage for persistence
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { create } from "zustand";
|
|
9
|
+
import {
|
|
10
|
+
storageRepository,
|
|
11
|
+
StorageKey,
|
|
12
|
+
unwrap,
|
|
13
|
+
} from "@umituz/react-native-storage";
|
|
14
|
+
|
|
15
|
+
interface OnboardingStore {
|
|
16
|
+
// State
|
|
17
|
+
isOnboardingComplete: boolean;
|
|
18
|
+
currentStep: number;
|
|
19
|
+
loading: boolean;
|
|
20
|
+
error: string | null;
|
|
21
|
+
|
|
22
|
+
// Actions
|
|
23
|
+
initialize: (storageKey?: string) => Promise<void>;
|
|
24
|
+
complete: (storageKey?: string) => Promise<void>;
|
|
25
|
+
skip: (storageKey?: string) => Promise<void>;
|
|
26
|
+
setCurrentStep: (step: number) => void;
|
|
27
|
+
reset: (storageKey?: string) => Promise<void>;
|
|
28
|
+
setLoading: (loading: boolean) => void;
|
|
29
|
+
setError: (error: string | null) => void;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const DEFAULT_STORAGE_KEY = StorageKey.ONBOARDING_COMPLETED;
|
|
33
|
+
|
|
34
|
+
export const useOnboardingStore = create<OnboardingStore>((set, get) => ({
|
|
35
|
+
isOnboardingComplete: false,
|
|
36
|
+
currentStep: 0,
|
|
37
|
+
loading: true,
|
|
38
|
+
error: null,
|
|
39
|
+
|
|
40
|
+
initialize: async (storageKey = DEFAULT_STORAGE_KEY) => {
|
|
41
|
+
set({ loading: true, error: null });
|
|
42
|
+
|
|
43
|
+
const result = await storageRepository.getString(storageKey, "false");
|
|
44
|
+
const data = unwrap(result, "false");
|
|
45
|
+
|
|
46
|
+
set({
|
|
47
|
+
isOnboardingComplete: data === "true",
|
|
48
|
+
loading: false,
|
|
49
|
+
error: result.success ? null : result.error?.message || null,
|
|
50
|
+
});
|
|
51
|
+
},
|
|
52
|
+
|
|
53
|
+
complete: async (storageKey = DEFAULT_STORAGE_KEY) => {
|
|
54
|
+
set({ loading: true, error: null });
|
|
55
|
+
|
|
56
|
+
const result = await storageRepository.setString(storageKey, "true");
|
|
57
|
+
|
|
58
|
+
set({
|
|
59
|
+
isOnboardingComplete: result.success,
|
|
60
|
+
loading: false,
|
|
61
|
+
error: result.success ? null : result.error?.message || null,
|
|
62
|
+
});
|
|
63
|
+
},
|
|
64
|
+
|
|
65
|
+
skip: async (storageKey = DEFAULT_STORAGE_KEY) => {
|
|
66
|
+
set({ loading: true, error: null });
|
|
67
|
+
|
|
68
|
+
const result = await storageRepository.setString(storageKey, "true");
|
|
69
|
+
|
|
70
|
+
set({
|
|
71
|
+
isOnboardingComplete: result.success,
|
|
72
|
+
loading: false,
|
|
73
|
+
error: result.success ? null : result.error?.message || null,
|
|
74
|
+
});
|
|
75
|
+
},
|
|
76
|
+
|
|
77
|
+
setCurrentStep: (step) => set({ currentStep: step }),
|
|
78
|
+
|
|
79
|
+
reset: async (storageKey = DEFAULT_STORAGE_KEY) => {
|
|
80
|
+
set({ loading: true, error: null });
|
|
81
|
+
|
|
82
|
+
const result = await storageRepository.removeItem(storageKey);
|
|
83
|
+
|
|
84
|
+
set({
|
|
85
|
+
isOnboardingComplete: false,
|
|
86
|
+
currentStep: 0,
|
|
87
|
+
loading: false,
|
|
88
|
+
error: result.success ? null : result.error?.message || null,
|
|
89
|
+
});
|
|
90
|
+
},
|
|
91
|
+
|
|
92
|
+
setLoading: (loading) => set({ loading }),
|
|
93
|
+
setError: (error) => set({ error }),
|
|
94
|
+
}));
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Hook for accessing onboarding state
|
|
98
|
+
*/
|
|
99
|
+
export const useOnboarding = () => {
|
|
100
|
+
const {
|
|
101
|
+
isOnboardingComplete,
|
|
102
|
+
currentStep,
|
|
103
|
+
loading,
|
|
104
|
+
error,
|
|
105
|
+
initialize,
|
|
106
|
+
complete,
|
|
107
|
+
skip,
|
|
108
|
+
setCurrentStep,
|
|
109
|
+
reset,
|
|
110
|
+
setLoading,
|
|
111
|
+
setError,
|
|
112
|
+
} = useOnboardingStore();
|
|
113
|
+
|
|
114
|
+
return {
|
|
115
|
+
isOnboardingComplete,
|
|
116
|
+
currentStep,
|
|
117
|
+
loading,
|
|
118
|
+
error,
|
|
119
|
+
initialize,
|
|
120
|
+
complete,
|
|
121
|
+
skip,
|
|
122
|
+
setCurrentStep,
|
|
123
|
+
reset,
|
|
124
|
+
setLoading,
|
|
125
|
+
setError,
|
|
126
|
+
};
|
|
127
|
+
};
|
|
128
|
+
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Onboarding Footer Component
|
|
3
|
+
*
|
|
4
|
+
* Displays progress bar, dots, and next/get started button
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import React, { useMemo } from "react";
|
|
8
|
+
import { View, TouchableOpacity, Text, StyleSheet } from "react-native";
|
|
9
|
+
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
|
10
|
+
import { useLocalization } from "@umituz/react-native-localization";
|
|
11
|
+
import { useAppDesignTokens } from "@umituz/react-native-theme";
|
|
12
|
+
|
|
13
|
+
export interface OnboardingFooterProps {
|
|
14
|
+
currentIndex: number;
|
|
15
|
+
totalSlides: number;
|
|
16
|
+
isLastSlide: boolean;
|
|
17
|
+
onNext: () => void;
|
|
18
|
+
showProgressBar?: boolean;
|
|
19
|
+
showDots?: boolean;
|
|
20
|
+
showProgressText?: boolean;
|
|
21
|
+
nextButtonText?: string;
|
|
22
|
+
getStartedButtonText?: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export const OnboardingFooter: React.FC<OnboardingFooterProps> = ({
|
|
26
|
+
currentIndex,
|
|
27
|
+
totalSlides,
|
|
28
|
+
isLastSlide,
|
|
29
|
+
onNext,
|
|
30
|
+
showProgressBar = true,
|
|
31
|
+
showDots = true,
|
|
32
|
+
showProgressText = true,
|
|
33
|
+
nextButtonText,
|
|
34
|
+
getStartedButtonText,
|
|
35
|
+
}) => {
|
|
36
|
+
const insets = useSafeAreaInsets();
|
|
37
|
+
const { t } = useLocalization();
|
|
38
|
+
const tokens = useAppDesignTokens();
|
|
39
|
+
const styles = useMemo(() => getStyles(insets, tokens), [insets, tokens]);
|
|
40
|
+
|
|
41
|
+
const buttonText = isLastSlide
|
|
42
|
+
? getStartedButtonText || t("onboarding.getStarted", "Get Started")
|
|
43
|
+
: nextButtonText || t("general.continue", "Continue");
|
|
44
|
+
|
|
45
|
+
return (
|
|
46
|
+
<View style={styles.footer}>
|
|
47
|
+
{showProgressBar && (
|
|
48
|
+
<View style={styles.progressContainer}>
|
|
49
|
+
<View style={styles.progressBar}>
|
|
50
|
+
<View
|
|
51
|
+
style={[
|
|
52
|
+
styles.progressFill,
|
|
53
|
+
{ width: `${((currentIndex + 1) / totalSlides) * 100}%` },
|
|
54
|
+
]}
|
|
55
|
+
/>
|
|
56
|
+
</View>
|
|
57
|
+
</View>
|
|
58
|
+
)}
|
|
59
|
+
|
|
60
|
+
{showDots && (
|
|
61
|
+
<View style={styles.dots}>
|
|
62
|
+
{Array.from({ length: totalSlides }).map((_, index) => (
|
|
63
|
+
<View
|
|
64
|
+
key={index}
|
|
65
|
+
style={[styles.dot, index === currentIndex && styles.dotActive]}
|
|
66
|
+
/>
|
|
67
|
+
))}
|
|
68
|
+
</View>
|
|
69
|
+
)}
|
|
70
|
+
|
|
71
|
+
<TouchableOpacity style={styles.button} onPress={onNext}>
|
|
72
|
+
<Text style={styles.buttonText}>{buttonText}</Text>
|
|
73
|
+
</TouchableOpacity>
|
|
74
|
+
|
|
75
|
+
{showProgressText && (
|
|
76
|
+
<Text style={styles.progressText}>
|
|
77
|
+
{currentIndex + 1} {t("general.of", "of")} {totalSlides}
|
|
78
|
+
</Text>
|
|
79
|
+
)}
|
|
80
|
+
</View>
|
|
81
|
+
);
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
const getStyles = (
|
|
85
|
+
insets: { bottom: number },
|
|
86
|
+
tokens: ReturnType<typeof useAppDesignTokens>,
|
|
87
|
+
) =>
|
|
88
|
+
StyleSheet.create({
|
|
89
|
+
footer: {
|
|
90
|
+
paddingHorizontal: 30,
|
|
91
|
+
paddingTop: 30,
|
|
92
|
+
paddingBottom: insets.bottom + 20,
|
|
93
|
+
},
|
|
94
|
+
progressContainer: {
|
|
95
|
+
marginBottom: 20,
|
|
96
|
+
},
|
|
97
|
+
progressBar: {
|
|
98
|
+
height: 4,
|
|
99
|
+
backgroundColor: "rgba(255, 255, 255, 0.2)",
|
|
100
|
+
borderRadius: 2,
|
|
101
|
+
overflow: "hidden",
|
|
102
|
+
},
|
|
103
|
+
progressFill: {
|
|
104
|
+
height: "100%",
|
|
105
|
+
backgroundColor: "#FFFFFF",
|
|
106
|
+
borderRadius: 2,
|
|
107
|
+
},
|
|
108
|
+
dots: {
|
|
109
|
+
flexDirection: "row",
|
|
110
|
+
justifyContent: "center",
|
|
111
|
+
marginBottom: 30,
|
|
112
|
+
gap: 8,
|
|
113
|
+
},
|
|
114
|
+
dot: {
|
|
115
|
+
width: 6,
|
|
116
|
+
height: 6,
|
|
117
|
+
borderRadius: 3,
|
|
118
|
+
backgroundColor: "rgba(255, 255, 255, 0.4)",
|
|
119
|
+
},
|
|
120
|
+
dotActive: {
|
|
121
|
+
width: 8,
|
|
122
|
+
backgroundColor: "#FFFFFF",
|
|
123
|
+
},
|
|
124
|
+
button: {
|
|
125
|
+
backgroundColor: "#FFFFFF",
|
|
126
|
+
paddingVertical: 16,
|
|
127
|
+
borderRadius: 28,
|
|
128
|
+
alignItems: "center",
|
|
129
|
+
marginBottom: 12,
|
|
130
|
+
},
|
|
131
|
+
buttonText: {
|
|
132
|
+
color: tokens.colors.primary,
|
|
133
|
+
fontSize: 16,
|
|
134
|
+
fontWeight: "bold",
|
|
135
|
+
},
|
|
136
|
+
progressText: {
|
|
137
|
+
color: "rgba(255, 255, 255, 0.75)",
|
|
138
|
+
fontSize: 12,
|
|
139
|
+
textAlign: "center",
|
|
140
|
+
},
|
|
141
|
+
});
|
|
142
|
+
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Onboarding Header Component
|
|
3
|
+
*
|
|
4
|
+
* Displays back and skip buttons
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import React, { useMemo } from "react";
|
|
8
|
+
import { View, TouchableOpacity, Text, StyleSheet } from "react-native";
|
|
9
|
+
import { useLocalization } from "@umituz/react-native-localization";
|
|
10
|
+
|
|
11
|
+
export interface OnboardingHeaderProps {
|
|
12
|
+
isFirstSlide: boolean;
|
|
13
|
+
onBack: () => void;
|
|
14
|
+
onSkip: () => void;
|
|
15
|
+
showBackButton?: boolean;
|
|
16
|
+
showSkipButton?: boolean;
|
|
17
|
+
skipButtonText?: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const OnboardingHeader: React.FC<OnboardingHeaderProps> = ({
|
|
21
|
+
isFirstSlide,
|
|
22
|
+
onBack,
|
|
23
|
+
onSkip,
|
|
24
|
+
showBackButton = true,
|
|
25
|
+
showSkipButton = true,
|
|
26
|
+
skipButtonText,
|
|
27
|
+
}) => {
|
|
28
|
+
const { t } = useLocalization();
|
|
29
|
+
const styles = useMemo(() => getStyles(), []);
|
|
30
|
+
|
|
31
|
+
const skipText = skipButtonText || t("onboarding.skip", "Skip");
|
|
32
|
+
|
|
33
|
+
return (
|
|
34
|
+
<View style={styles.header}>
|
|
35
|
+
{showBackButton ? (
|
|
36
|
+
<TouchableOpacity
|
|
37
|
+
onPress={onBack}
|
|
38
|
+
disabled={isFirstSlide}
|
|
39
|
+
style={[
|
|
40
|
+
styles.headerButton,
|
|
41
|
+
isFirstSlide && styles.headerButtonDisabled,
|
|
42
|
+
]}
|
|
43
|
+
>
|
|
44
|
+
<Text style={styles.headerButtonText}>←</Text>
|
|
45
|
+
</TouchableOpacity>
|
|
46
|
+
) : (
|
|
47
|
+
<View style={styles.headerButton} />
|
|
48
|
+
)}
|
|
49
|
+
{showSkipButton && (
|
|
50
|
+
<TouchableOpacity onPress={onSkip}>
|
|
51
|
+
<Text style={styles.skipText}>{skipText}</Text>
|
|
52
|
+
</TouchableOpacity>
|
|
53
|
+
)}
|
|
54
|
+
</View>
|
|
55
|
+
);
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const getStyles = () =>
|
|
59
|
+
StyleSheet.create({
|
|
60
|
+
header: {
|
|
61
|
+
flexDirection: "row",
|
|
62
|
+
justifyContent: "space-between",
|
|
63
|
+
alignItems: "center",
|
|
64
|
+
paddingHorizontal: 20,
|
|
65
|
+
paddingTop: 10,
|
|
66
|
+
paddingBottom: 20,
|
|
67
|
+
},
|
|
68
|
+
headerButton: {
|
|
69
|
+
width: 40,
|
|
70
|
+
height: 40,
|
|
71
|
+
borderRadius: 20,
|
|
72
|
+
backgroundColor: "rgba(255, 255, 255, 0.2)",
|
|
73
|
+
alignItems: "center",
|
|
74
|
+
justifyContent: "center",
|
|
75
|
+
borderWidth: 1,
|
|
76
|
+
borderColor: "rgba(255, 255, 255, 0.3)",
|
|
77
|
+
},
|
|
78
|
+
headerButtonDisabled: {
|
|
79
|
+
opacity: 0.3,
|
|
80
|
+
},
|
|
81
|
+
headerButtonText: {
|
|
82
|
+
color: "#FFFFFF",
|
|
83
|
+
fontSize: 20,
|
|
84
|
+
fontWeight: "bold",
|
|
85
|
+
},
|
|
86
|
+
skipText: {
|
|
87
|
+
color: "#FFFFFF",
|
|
88
|
+
fontSize: 16,
|
|
89
|
+
fontWeight: "600",
|
|
90
|
+
},
|
|
91
|
+
});
|
|
92
|
+
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Onboarding Slide Component
|
|
3
|
+
*
|
|
4
|
+
* Displays a single onboarding slide with icon, title, and description
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import React, { useMemo } from "react";
|
|
8
|
+
import { View, Text, StyleSheet, ScrollView } from "react-native";
|
|
9
|
+
import type { OnboardingSlide as OnboardingSlideType } from "../../domain/entities/OnboardingSlide";
|
|
10
|
+
|
|
11
|
+
export interface OnboardingSlideProps {
|
|
12
|
+
slide: OnboardingSlideType;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const OnboardingSlide: React.FC<OnboardingSlideProps> = ({ slide }) => {
|
|
16
|
+
const styles = useMemo(() => getStyles(), []);
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<ScrollView
|
|
20
|
+
contentContainerStyle={styles.content}
|
|
21
|
+
showsVerticalScrollIndicator={false}
|
|
22
|
+
scrollEnabled={false}
|
|
23
|
+
>
|
|
24
|
+
<View style={styles.slideContent}>
|
|
25
|
+
<View style={styles.iconContainer}>
|
|
26
|
+
<Text style={styles.icon}>{slide.icon}</Text>
|
|
27
|
+
</View>
|
|
28
|
+
<Text style={styles.title}>{slide.title}</Text>
|
|
29
|
+
<Text style={styles.description}>{slide.description}</Text>
|
|
30
|
+
{slide.features && slide.features.length > 0 && (
|
|
31
|
+
<View style={styles.featuresContainer}>
|
|
32
|
+
{slide.features.map((feature, index) => (
|
|
33
|
+
<View key={index} style={styles.featureItem}>
|
|
34
|
+
<Text style={styles.featureBullet}>•</Text>
|
|
35
|
+
<Text style={styles.featureText}>{feature}</Text>
|
|
36
|
+
</View>
|
|
37
|
+
))}
|
|
38
|
+
</View>
|
|
39
|
+
)}
|
|
40
|
+
</View>
|
|
41
|
+
</ScrollView>
|
|
42
|
+
);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const getStyles = () =>
|
|
46
|
+
StyleSheet.create({
|
|
47
|
+
content: {
|
|
48
|
+
flex: 1,
|
|
49
|
+
justifyContent: "center",
|
|
50
|
+
alignItems: "center",
|
|
51
|
+
paddingHorizontal: 30,
|
|
52
|
+
},
|
|
53
|
+
slideContent: {
|
|
54
|
+
alignItems: "center",
|
|
55
|
+
maxWidth: 400,
|
|
56
|
+
},
|
|
57
|
+
iconContainer: {
|
|
58
|
+
width: 120,
|
|
59
|
+
height: 120,
|
|
60
|
+
borderRadius: 60,
|
|
61
|
+
backgroundColor: "rgba(255, 255, 255, 0.2)",
|
|
62
|
+
alignItems: "center",
|
|
63
|
+
justifyContent: "center",
|
|
64
|
+
marginBottom: 40,
|
|
65
|
+
borderWidth: 2,
|
|
66
|
+
borderColor: "rgba(255, 255, 255, 0.3)",
|
|
67
|
+
},
|
|
68
|
+
icon: {
|
|
69
|
+
fontSize: 60,
|
|
70
|
+
},
|
|
71
|
+
title: {
|
|
72
|
+
fontSize: 28,
|
|
73
|
+
fontWeight: "bold",
|
|
74
|
+
color: "#FFFFFF",
|
|
75
|
+
textAlign: "center",
|
|
76
|
+
marginBottom: 16,
|
|
77
|
+
},
|
|
78
|
+
description: {
|
|
79
|
+
fontSize: 16,
|
|
80
|
+
color: "rgba(255, 255, 255, 0.95)",
|
|
81
|
+
textAlign: "center",
|
|
82
|
+
lineHeight: 24,
|
|
83
|
+
marginBottom: 20,
|
|
84
|
+
},
|
|
85
|
+
featuresContainer: {
|
|
86
|
+
width: "100%",
|
|
87
|
+
marginTop: 10,
|
|
88
|
+
},
|
|
89
|
+
featureItem: {
|
|
90
|
+
flexDirection: "row",
|
|
91
|
+
alignItems: "flex-start",
|
|
92
|
+
marginBottom: 12,
|
|
93
|
+
},
|
|
94
|
+
featureBullet: {
|
|
95
|
+
color: "#FFFFFF",
|
|
96
|
+
fontSize: 20,
|
|
97
|
+
marginRight: 12,
|
|
98
|
+
marginTop: 2,
|
|
99
|
+
},
|
|
100
|
+
featureText: {
|
|
101
|
+
flex: 1,
|
|
102
|
+
fontSize: 15,
|
|
103
|
+
color: "rgba(255, 255, 255, 0.9)",
|
|
104
|
+
lineHeight: 22,
|
|
105
|
+
},
|
|
106
|
+
});
|
|
107
|
+
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Onboarding Screen
|
|
3
|
+
*
|
|
4
|
+
* Main onboarding screen component with gradient backgrounds
|
|
5
|
+
* Generic and reusable across hundreds of apps
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import React, { useMemo } from "react";
|
|
9
|
+
import { View, StyleSheet, StatusBar } from "react-native";
|
|
10
|
+
import { LinearGradient } from "expo-linear-gradient";
|
|
11
|
+
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
|
12
|
+
import type { OnboardingOptions } from "../../domain/entities/OnboardingOptions";
|
|
13
|
+
import { useOnboardingNavigation } from "../../infrastructure/hooks/useOnboardingNavigation";
|
|
14
|
+
import { useOnboardingStore } from "../../infrastructure/storage/OnboardingStore";
|
|
15
|
+
import { OnboardingHeader } from "../components/OnboardingHeader";
|
|
16
|
+
import { OnboardingSlide } from "../components/OnboardingSlide";
|
|
17
|
+
import { OnboardingFooter } from "../components/OnboardingFooter";
|
|
18
|
+
|
|
19
|
+
export interface OnboardingScreenProps extends OnboardingOptions {
|
|
20
|
+
/**
|
|
21
|
+
* Optional custom header component
|
|
22
|
+
*/
|
|
23
|
+
renderHeader?: (props: {
|
|
24
|
+
isFirstSlide: boolean;
|
|
25
|
+
onBack: () => void;
|
|
26
|
+
onSkip: () => void;
|
|
27
|
+
}) => React.ReactNode;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Optional custom footer component
|
|
31
|
+
*/
|
|
32
|
+
renderFooter?: (props: {
|
|
33
|
+
currentIndex: number;
|
|
34
|
+
totalSlides: number;
|
|
35
|
+
isLastSlide: boolean;
|
|
36
|
+
onNext: () => void;
|
|
37
|
+
}) => React.ReactNode;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Optional custom slide component
|
|
41
|
+
*/
|
|
42
|
+
renderSlide?: (slide: OnboardingOptions["slides"][0]) => React.ReactNode;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Onboarding Screen Component
|
|
47
|
+
*
|
|
48
|
+
* Displays onboarding flow with gradient backgrounds, animations, and navigation
|
|
49
|
+
*/
|
|
50
|
+
export const OnboardingScreen: React.FC<OnboardingScreenProps> = ({
|
|
51
|
+
slides,
|
|
52
|
+
onComplete,
|
|
53
|
+
onSkip,
|
|
54
|
+
skipButtonText,
|
|
55
|
+
nextButtonText,
|
|
56
|
+
getStartedButtonText,
|
|
57
|
+
showSkipButton = true,
|
|
58
|
+
showBackButton = true,
|
|
59
|
+
showProgressBar = true,
|
|
60
|
+
showDots = true,
|
|
61
|
+
showProgressText = true,
|
|
62
|
+
storageKey,
|
|
63
|
+
autoComplete = false,
|
|
64
|
+
renderHeader,
|
|
65
|
+
renderFooter,
|
|
66
|
+
renderSlide,
|
|
67
|
+
}) => {
|
|
68
|
+
const insets = useSafeAreaInsets();
|
|
69
|
+
const onboardingStore = useOnboardingStore();
|
|
70
|
+
|
|
71
|
+
const handleComplete = async () => {
|
|
72
|
+
await onboardingStore.complete(storageKey);
|
|
73
|
+
if (onComplete) {
|
|
74
|
+
await onComplete();
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const handleSkip = async () => {
|
|
79
|
+
await onboardingStore.skip(storageKey);
|
|
80
|
+
if (onSkip) {
|
|
81
|
+
await onSkip();
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const {
|
|
86
|
+
currentIndex,
|
|
87
|
+
goToNext,
|
|
88
|
+
goToPrevious,
|
|
89
|
+
isLastSlide,
|
|
90
|
+
isFirstSlide,
|
|
91
|
+
} = useOnboardingNavigation(slides.length, handleComplete, handleSkip);
|
|
92
|
+
|
|
93
|
+
const handleNext = () => {
|
|
94
|
+
if (isLastSlide) {
|
|
95
|
+
if (autoComplete) {
|
|
96
|
+
handleComplete();
|
|
97
|
+
} else {
|
|
98
|
+
handleComplete();
|
|
99
|
+
}
|
|
100
|
+
} else {
|
|
101
|
+
goToNext();
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
const currentSlide = slides[currentIndex];
|
|
106
|
+
const styles = useMemo(() => getStyles(insets), [insets]);
|
|
107
|
+
|
|
108
|
+
return (
|
|
109
|
+
<View style={styles.container}>
|
|
110
|
+
<StatusBar barStyle="light-content" />
|
|
111
|
+
<LinearGradient
|
|
112
|
+
colors={currentSlide.gradient}
|
|
113
|
+
start={{ x: 0, y: 0 }}
|
|
114
|
+
end={{ x: 1, y: 1 }}
|
|
115
|
+
style={StyleSheet.absoluteFill}
|
|
116
|
+
/>
|
|
117
|
+
{renderHeader ? (
|
|
118
|
+
renderHeader({
|
|
119
|
+
isFirstSlide,
|
|
120
|
+
onBack: goToPrevious,
|
|
121
|
+
onSkip: handleSkip,
|
|
122
|
+
})
|
|
123
|
+
) : (
|
|
124
|
+
<OnboardingHeader
|
|
125
|
+
isFirstSlide={isFirstSlide}
|
|
126
|
+
onBack={goToPrevious}
|
|
127
|
+
onSkip={handleSkip}
|
|
128
|
+
showBackButton={showBackButton}
|
|
129
|
+
showSkipButton={showSkipButton}
|
|
130
|
+
skipButtonText={skipButtonText}
|
|
131
|
+
/>
|
|
132
|
+
)}
|
|
133
|
+
{renderSlide ? (
|
|
134
|
+
renderSlide(currentSlide)
|
|
135
|
+
) : (
|
|
136
|
+
<OnboardingSlide slide={currentSlide} />
|
|
137
|
+
)}
|
|
138
|
+
{renderFooter ? (
|
|
139
|
+
renderFooter({
|
|
140
|
+
currentIndex,
|
|
141
|
+
totalSlides: slides.length,
|
|
142
|
+
isLastSlide,
|
|
143
|
+
onNext: handleNext,
|
|
144
|
+
})
|
|
145
|
+
) : (
|
|
146
|
+
<OnboardingFooter
|
|
147
|
+
currentIndex={currentIndex}
|
|
148
|
+
totalSlides={slides.length}
|
|
149
|
+
isLastSlide={isLastSlide}
|
|
150
|
+
onNext={handleNext}
|
|
151
|
+
showProgressBar={showProgressBar}
|
|
152
|
+
showDots={showDots}
|
|
153
|
+
showProgressText={showProgressText}
|
|
154
|
+
nextButtonText={nextButtonText}
|
|
155
|
+
getStartedButtonText={getStartedButtonText}
|
|
156
|
+
/>
|
|
157
|
+
)}
|
|
158
|
+
</View>
|
|
159
|
+
);
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
const getStyles = (insets: { top: number }) =>
|
|
163
|
+
StyleSheet.create({
|
|
164
|
+
container: {
|
|
165
|
+
flex: 1,
|
|
166
|
+
paddingTop: insets.top,
|
|
167
|
+
},
|
|
168
|
+
});
|
|
169
|
+
|