@rubixscript/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.
@@ -0,0 +1,314 @@
1
+ import React, { useMemo, useState } from 'react';
2
+ import {
3
+ View,
4
+ Text,
5
+ TextInput,
6
+ TouchableOpacity,
7
+ StyleSheet,
8
+ ScrollView,
9
+ KeyboardAvoidingView,
10
+ Platform,
11
+ ViewStyle,
12
+ } from 'react-native';
13
+ import Animated, { FadeIn } from 'react-native-reanimated';
14
+ import { LinearGradient } from 'expo-linear-gradient';
15
+ import { Ionicons } from '@expo/vector-icons';
16
+ import { FormSlideData, OnboardingTheme, FormFieldConfig } from '../types';
17
+
18
+ interface FormSlideProps {
19
+ data: FormSlideData;
20
+ theme: OnboardingTheme;
21
+ onSubmit: (formData: Record<string, any>) => void;
22
+ darkMode?: boolean;
23
+ isSubmitting?: boolean;
24
+ }
25
+
26
+ export const FormSlide: React.FC<FormSlideProps> = ({
27
+ data,
28
+ theme,
29
+ onSubmit,
30
+ darkMode,
31
+ isSubmitting = false,
32
+ }) => {
33
+ const { title, description, fields, submitLabel = 'Get Started', gradientColors } = data;
34
+ const [formData, setFormData] = useState<Record<string, any>>({});
35
+ const [errors, setErrors] = useState<Record<string, string>>({});
36
+
37
+ const containerStyle = useMemo(() => {
38
+ const styles: any = {
39
+ flex: 1,
40
+ };
41
+
42
+ if (data.backgroundColor) {
43
+ styles.backgroundColor = data.backgroundColor;
44
+ } else if (gradientColors && gradientColors.length > 0) {
45
+ // Will use LinearGradient
46
+ } else {
47
+ styles.backgroundColor = theme.colors.background;
48
+ }
49
+
50
+ return styles;
51
+ }, [data, theme]);
52
+
53
+ const updateField = (key: string, value: any) => {
54
+ setFormData(prev => ({ ...prev, [key]: value }));
55
+ // Clear error when user starts typing
56
+ if (errors[key]) {
57
+ setErrors(prev => {
58
+ const newErrors = { ...prev };
59
+ delete newErrors[key];
60
+ return newErrors;
61
+ });
62
+ }
63
+ };
64
+
65
+ const validateForm = (): boolean => {
66
+ const newErrors: Record<string, string> = {};
67
+
68
+ fields.forEach(field => {
69
+ if (field.required && !formData[field.key]) {
70
+ newErrors[field.key] = `${field.label} is required`;
71
+ } else if (field.validation && formData[field.key]) {
72
+ const validationResult = field.validation(formData[field.key]);
73
+ if (typeof validationResult === 'string') {
74
+ newErrors[field.key] = validationResult;
75
+ } else if (!validationResult) {
76
+ newErrors[field.key] = `${field.label} is invalid`;
77
+ }
78
+ }
79
+ });
80
+
81
+ setErrors(newErrors);
82
+ return Object.keys(newErrors).length === 0;
83
+ };
84
+
85
+ const handleSubmit = () => {
86
+ if (validateForm()) {
87
+ onSubmit(formData);
88
+ }
89
+ };
90
+
91
+ const renderField = (field: FormFieldConfig) => {
92
+ const value = formData[field.key];
93
+ const error = errors[field.key];
94
+
95
+ if (field.type === 'select') {
96
+ return (
97
+ <View key={field.key} style={styles.fieldContainer}>
98
+ <Text style={styles.label}>{field.label}</Text>
99
+ <View style={styles.optionsContainer}>
100
+ {field.options?.map(option => (
101
+ <TouchableOpacity
102
+ key={option.value}
103
+ style={[
104
+ styles.optionCard,
105
+ value === option.value && styles.optionCardActive,
106
+ { borderColor: theme.colors.border },
107
+ ]}
108
+ onPress={() => updateField(field.key, option.value)}
109
+ >
110
+ {option.icon && (
111
+ <Ionicons
112
+ name={option.icon as any}
113
+ size={20}
114
+ color={value === option.value ? theme.colors.text.inverse : theme.colors.text.secondary}
115
+ style={{ marginRight: 8 }}
116
+ />
117
+ )}
118
+ <Text
119
+ style={[
120
+ styles.optionLabel,
121
+ value === option.value && { color: theme.colors.text.inverse },
122
+ ]}
123
+ >
124
+ {option.label}
125
+ </Text>
126
+ </TouchableOpacity>
127
+ ))}
128
+ </View>
129
+ {error && <Text style={styles.errorText}>{error}</Text>}
130
+ </View>
131
+ );
132
+ }
133
+
134
+ return (
135
+ <View key={field.key} style={styles.fieldContainer}>
136
+ <Text style={styles.label}>{field.label}</Text>
137
+ <TextInput
138
+ style={[
139
+ styles.input,
140
+ { borderColor: error ? theme.colors.text.secondary : theme.colors.border },
141
+ ]}
142
+ placeholder={field.placeholder}
143
+ placeholderTextColor={theme.colors.text.secondary}
144
+ value={value}
145
+ onChangeText={text => updateField(field.key, text)}
146
+ keyboardType={field.type === 'number' ? 'numeric' : field.type === 'email' ? 'email-address' : 'default'}
147
+ secureTextEntry={field.type === 'password'}
148
+ multiline={field.multiline}
149
+ numberOfLines={field.numberOfLines}
150
+ />
151
+ {error && <Text style={styles.errorText}>{error}</Text>}
152
+ </View>
153
+ );
154
+ };
155
+
156
+ const headerStyle = useMemo(() => ({
157
+ ...styles.header,
158
+ backgroundColor: 'transparent',
159
+ }), []);
160
+
161
+ const titleStyle = useMemo(() => ({
162
+ ...styles.title,
163
+ color: gradientColors?.length ? theme.colors.text.primary : theme.colors.text.primary,
164
+ }), [gradientColors, theme]);
165
+
166
+ const descriptionStyle = useMemo(() => ({
167
+ ...styles.description,
168
+ color: gradientColors?.length ? theme.colors.text.secondary : theme.colors.text.secondary,
169
+ }), [gradientColors, theme]);
170
+
171
+ const content = (
172
+ <KeyboardAvoidingView
173
+ style={styles.keyboardContainer}
174
+ behavior={Platform.OS === 'ios' ? 'padding' : 'height'}
175
+ keyboardVerticalOffset={Platform.OS === 'ios' ? 0 : 20}
176
+ >
177
+ <ScrollView
178
+ style={styles.scrollView}
179
+ contentContainerStyle={styles.scrollContent}
180
+ showsVerticalScrollIndicator={false}
181
+ >
182
+ {/* Header */}
183
+ <Animated.View entering={FadeIn.duration(300)} style={headerStyle}>
184
+ {title && <Text style={titleStyle}>{title}</Text>}
185
+ {description && <Text style={descriptionStyle}>{description}</Text>}
186
+ </Animated.View>
187
+
188
+ {/* Form Fields */}
189
+ <View style={styles.formContainer}>
190
+ {fields.map(renderField)}
191
+ </View>
192
+
193
+ {/* Submit Button */}
194
+ <Animated.View entering={FadeIn.delay(300).duration(300)} style={styles.buttonContainer}>
195
+ <TouchableOpacity
196
+ style={[styles.submitButton, { backgroundColor: theme.colors.primary }]}
197
+ onPress={handleSubmit}
198
+ disabled={isSubmitting}
199
+ activeOpacity={0.8}
200
+ >
201
+ <Text style={styles.submitButtonText}>{isSubmitting ? 'Submitting...' : submitLabel}</Text>
202
+ </TouchableOpacity>
203
+ </Animated.View>
204
+ </ScrollView>
205
+ </KeyboardAvoidingView>
206
+ );
207
+
208
+ if (gradientColors && gradientColors.length > 0) {
209
+ return (
210
+ <LinearGradient colors={gradientColors} style={StyleSheet.absoluteFillObject}>
211
+ <View style={containerStyle}>{content}</View>
212
+ </LinearGradient>
213
+ );
214
+ }
215
+
216
+ return <View style={containerStyle}>{content}</View>;
217
+ };
218
+
219
+ const styles = StyleSheet.create({
220
+ keyboardContainer: {
221
+ flex: 1,
222
+ },
223
+ scrollView: {
224
+ flex: 1,
225
+ },
226
+ scrollContent: {
227
+ padding: 24,
228
+ paddingBottom: 40,
229
+ },
230
+ header: {
231
+ marginBottom: 32,
232
+ alignItems: 'center',
233
+ },
234
+ title: {
235
+ fontSize: 28,
236
+ fontWeight: '700',
237
+ textAlign: 'center',
238
+ marginBottom: 12,
239
+ },
240
+ description: {
241
+ fontSize: 15,
242
+ textAlign: 'center',
243
+ paddingHorizontal: 20,
244
+ lineHeight: 22,
245
+ },
246
+ formContainer: {
247
+ width: '100%',
248
+ gap: 20,
249
+ },
250
+ fieldContainer: {
251
+ width: '100%',
252
+ },
253
+ label: {
254
+ fontSize: 14,
255
+ fontWeight: '600',
256
+ marginBottom: 8,
257
+ marginLeft: 4,
258
+ },
259
+ input: {
260
+ borderWidth: 1.5,
261
+ borderRadius: 12,
262
+ paddingHorizontal: 16,
263
+ paddingVertical: 14,
264
+ fontSize: 16,
265
+ backgroundColor: 'rgba(255, 255, 255, 0.9)',
266
+ },
267
+ optionsContainer: {
268
+ flexDirection: 'row',
269
+ flexWrap: 'wrap',
270
+ gap: 12,
271
+ },
272
+ optionCard: {
273
+ flexDirection: 'row',
274
+ alignItems: 'center',
275
+ paddingHorizontal: 16,
276
+ paddingVertical: 12,
277
+ borderRadius: 12,
278
+ borderWidth: 1.5,
279
+ backgroundColor: 'rgba(255, 255, 255, 0.9)',
280
+ minWidth: 100,
281
+ },
282
+ optionCardActive: {
283
+ backgroundColor: '#6B4EFF',
284
+ borderColor: '#6B4EFF',
285
+ },
286
+ optionLabel: {
287
+ fontSize: 14,
288
+ fontWeight: '500',
289
+ },
290
+ errorText: {
291
+ fontSize: 12,
292
+ color: '#EF4444',
293
+ marginTop: 4,
294
+ marginLeft: 4,
295
+ },
296
+ buttonContainer: {
297
+ marginTop: 24,
298
+ alignItems: 'center',
299
+ },
300
+ submitButton: {
301
+ paddingHorizontal: 48,
302
+ paddingVertical: 16,
303
+ borderRadius: 9999,
304
+ minWidth: 200,
305
+ alignItems: 'center',
306
+ },
307
+ submitButtonText: {
308
+ color: '#FFFFFF',
309
+ fontSize: 16,
310
+ fontWeight: '600',
311
+ },
312
+ });
313
+
314
+ export default FormSlide;
@@ -0,0 +1,166 @@
1
+ import React, { useMemo } from 'react';
2
+ import { View, Text, StyleSheet, ViewStyle } from 'react-native';
3
+ import Animated, { FadeIn, FadeInDown, withSpring, useSharedValue, useAnimatedStyle, withDelay } from 'react-native-reanimated';
4
+ import { Ionicons, MaterialIcons, MaterialCommunityIcons, FontAwesome, Octicons, Feather } from '@expo/vector-icons';
5
+ import { LinearGradient } from 'expo-linear-gradient';
6
+ import { IconSlideData, OnboardingTheme } from '../types';
7
+
8
+ interface IconSlideProps {
9
+ data: IconSlideData;
10
+ theme: OnboardingTheme;
11
+ darkMode?: boolean;
12
+ }
13
+
14
+ export const IconSlide: React.FC<IconSlideProps> = ({ data, theme, darkMode }) => {
15
+ const { icon, title, description, subtitle, gradientColors } = data;
16
+
17
+ const scale = useSharedValue(0);
18
+ const rotate = useSharedValue(0);
19
+
20
+ React.useEffect(() => {
21
+ scale.value = withSpring(1, { damping: 15, stiffness: 150 });
22
+ rotate.value = withDelay(200, withSpring(0, { damping: 20, stiffness: 100 }));
23
+ }, []);
24
+
25
+ const iconAnimatedStyle = useAnimatedStyle(() => ({
26
+ transform: [
27
+ { scale: scale.value },
28
+ { rotate: `${rotate.value}deg` },
29
+ ],
30
+ }));
31
+
32
+ const containerStyle = useMemo(() => {
33
+ const styles: any = {
34
+ flex: 1,
35
+ justifyContent: 'center',
36
+ alignItems: 'center',
37
+ padding: theme.spacing.lg,
38
+ };
39
+
40
+ if (data.backgroundColor) {
41
+ styles.backgroundColor = data.backgroundColor;
42
+ } else if (gradientColors && gradientColors.length > 0) {
43
+ // Will use LinearGradient
44
+ } else {
45
+ styles.backgroundColor = theme.colors.background;
46
+ }
47
+
48
+ return styles;
49
+ }, [data, theme]);
50
+
51
+ const iconContainerStyle: ViewStyle = useMemo(() => ({
52
+ width: icon.backgroundSize || 160,
53
+ height: icon.backgroundSize || 160,
54
+ borderRadius: (icon.backgroundSize || 160) / 2,
55
+ backgroundColor: icon.backgroundColor || theme.colors.primary,
56
+ justifyContent: 'center',
57
+ alignItems: 'center',
58
+ marginBottom: theme.spacing.lg,
59
+ }), [icon, theme]);
60
+
61
+ const renderIcon = () => {
62
+ const iconProps = {
63
+ name: icon.name as any,
64
+ size: icon.size || 64,
65
+ color: icon.color || theme.colors.text.inverse,
66
+ };
67
+
68
+ switch (icon.type) {
69
+ case 'material':
70
+ return <MaterialIcons {...iconProps} />;
71
+ case 'material-community':
72
+ return <MaterialCommunityIcons {...iconProps} />;
73
+ case 'font-awesome':
74
+ return <FontAwesome {...iconProps} />;
75
+ case 'octicons':
76
+ return <Octicons {...iconProps} />;
77
+ case 'feather':
78
+ return <Feather {...iconProps} />;
79
+ case 'ionicons':
80
+ default:
81
+ return <Ionicons {...iconProps} />;
82
+ }
83
+ };
84
+
85
+ const titleStyle = useMemo(() => ({
86
+ ...styles.title,
87
+ color: gradientColors?.length ? theme.colors.text.primary : theme.colors.text.primary,
88
+ }), [gradientColors, theme]);
89
+
90
+ const subtitleStyle = useMemo(() => ({
91
+ ...styles.subtitle,
92
+ color: gradientColors?.length ? theme.colors.text.secondary : theme.colors.text.secondary,
93
+ }), [gradientColors, theme]);
94
+
95
+ const descriptionStyle = useMemo(() => ({
96
+ ...styles.description,
97
+ color: gradientColors?.length ? theme.colors.text.secondary : theme.colors.text.secondary,
98
+ }), [gradientColors, theme]);
99
+
100
+ const content = (
101
+ <>
102
+ {/* Icon */}
103
+ <Animated.View style={iconAnimatedStyle}>
104
+ <View style={iconContainerStyle}>
105
+ {renderIcon()}
106
+ </View>
107
+ </Animated.View>
108
+
109
+ {/* Title */}
110
+ {title && (
111
+ <Animated.Text entering={FadeInDown.delay(100).springify()} style={titleStyle}>
112
+ {title}
113
+ </Animated.Text>
114
+ )}
115
+
116
+ {/* Subtitle */}
117
+ {subtitle && (
118
+ <Animated.Text entering={FadeInDown.delay(200).springify()} style={subtitleStyle}>
119
+ {subtitle}
120
+ </Animated.Text>
121
+ )}
122
+
123
+ {/* Description */}
124
+ {description && (
125
+ <Animated.Text entering={FadeInDown.delay(300).springify()} style={descriptionStyle}>
126
+ {description}
127
+ </Animated.Text>
128
+ )}
129
+ </>
130
+ );
131
+
132
+ if (gradientColors && gradientColors.length > 0) {
133
+ return (
134
+ <LinearGradient colors={gradientColors} style={StyleSheet.absoluteFillObject}>
135
+ <View style={containerStyle}>{content}</View>
136
+ </LinearGradient>
137
+ );
138
+ }
139
+
140
+ return <View style={containerStyle}>{content}</View>;
141
+ };
142
+
143
+ const styles = StyleSheet.create({
144
+ title: {
145
+ fontSize: 24,
146
+ fontWeight: '700',
147
+ textAlign: 'center',
148
+ marginBottom: 8,
149
+ paddingHorizontal: 20,
150
+ },
151
+ subtitle: {
152
+ fontSize: 18,
153
+ fontWeight: '600',
154
+ textAlign: 'center',
155
+ marginBottom: 12,
156
+ paddingHorizontal: 20,
157
+ },
158
+ description: {
159
+ fontSize: 15,
160
+ textAlign: 'center',
161
+ paddingHorizontal: 32,
162
+ lineHeight: 22,
163
+ },
164
+ });
165
+
166
+ export default IconSlide;
@@ -0,0 +1,132 @@
1
+ import React, { useMemo } from 'react';
2
+ import { View, Text, Image, StyleSheet, ImageStyle, Dimensions } from 'react-native';
3
+ import Animated, { FadeIn, FadeInDown } from 'react-native-reanimated';
4
+ import { LinearGradient } from 'expo-linear-gradient';
5
+ import { Ionicons } from '@expo/vector-icons';
6
+ import { ImageSlideData, OnboardingTheme } from '../types';
7
+
8
+ interface ImageSlideProps {
9
+ data: ImageSlideData;
10
+ theme: OnboardingTheme;
11
+ darkMode?: boolean;
12
+ }
13
+
14
+ const { width: SCREEN_WIDTH } = Dimensions.get('window');
15
+
16
+ export const ImageSlide: React.FC<ImageSlideProps> = ({ data, theme, darkMode }) => {
17
+ const { image, title, description, imageResizeMode = 'cover', imageStyle, overlayIcon, gradientColors } = data;
18
+
19
+ const containerStyle = useMemo(() => {
20
+ const styles: any = {
21
+ flex: 1,
22
+ justifyContent: 'center',
23
+ alignItems: 'center',
24
+ padding: theme.spacing.lg,
25
+ };
26
+
27
+ if (data.backgroundColor) {
28
+ styles.backgroundColor = data.backgroundColor;
29
+ } else if (gradientColors && gradientColors.length > 0) {
30
+ // Will use LinearGradient
31
+ } else {
32
+ styles.backgroundColor = theme.colors.background;
33
+ }
34
+
35
+ return styles;
36
+ }, [data, theme]);
37
+
38
+ const imageContainerStyle = useMemo(() => ({
39
+ ...styles.imageContainer,
40
+ marginBottom: theme.spacing.lg,
41
+ }), [theme]);
42
+
43
+ const baseImageStyle: ImageStyle = useMemo(() => ({
44
+ width: SCREEN_WIDTH - theme.spacing.xl * 2,
45
+ height: 280,
46
+ borderRadius: theme.borderRadius.lg,
47
+ resizeMode: imageResizeMode,
48
+ ...imageStyle,
49
+ }), [theme, imageResizeMode, imageStyle]);
50
+
51
+ const titleStyle = useMemo(() => ({
52
+ ...styles.title,
53
+ color: gradientColors?.length ? theme.colors.text.primary : theme.colors.text.primary,
54
+ }), [gradientColors, theme]);
55
+
56
+ const descriptionStyle = useMemo(() => ({
57
+ ...styles.description,
58
+ color: gradientColors?.length ? theme.colors.text.secondary : theme.colors.text.secondary,
59
+ }), [gradientColors, theme]);
60
+
61
+ const content = (
62
+ <>
63
+ {/* Image with optional overlay icon */}
64
+ <Animated.View entering={FadeIn.duration(400).springify()} style={imageContainerStyle}>
65
+ <Image source={image} style={baseImageStyle} />
66
+ {overlayIcon && (
67
+ <View style={styles.overlayIcon}>
68
+ <Ionicons
69
+ name={overlayIcon.name as any}
70
+ size={overlayIcon.size || 48}
71
+ color={overlayIcon.color || '#FFFFFF'}
72
+ />
73
+ </View>
74
+ )}
75
+ </Animated.View>
76
+
77
+ {/* Title */}
78
+ {title && (
79
+ <Animated.Text entering={FadeInDown.delay(100).springify()} style={titleStyle}>
80
+ {title}
81
+ </Animated.Text>
82
+ )}
83
+
84
+ {/* Description */}
85
+ {description && (
86
+ <Animated.Text entering={FadeInDown.delay(200).springify()} style={descriptionStyle}>
87
+ {description}
88
+ </Animated.Text>
89
+ )}
90
+ </>
91
+ );
92
+
93
+ if (gradientColors && gradientColors.length > 0) {
94
+ return (
95
+ <LinearGradient colors={gradientColors} style={StyleSheet.absoluteFillObject}>
96
+ <View style={containerStyle}>{content}</View>
97
+ </LinearGradient>
98
+ );
99
+ }
100
+
101
+ return <View style={containerStyle}>{content}</View>;
102
+ };
103
+
104
+ const styles = StyleSheet.create({
105
+ imageContainer: {
106
+ width: '100%',
107
+ alignItems: 'center',
108
+ },
109
+ overlayIcon: {
110
+ position: 'absolute',
111
+ top: 20,
112
+ right: 20,
113
+ backgroundColor: 'rgba(0, 0, 0, 0.3)',
114
+ borderRadius: 20,
115
+ padding: 8,
116
+ },
117
+ title: {
118
+ fontSize: 28,
119
+ fontWeight: '700',
120
+ textAlign: 'center',
121
+ marginBottom: 12,
122
+ paddingHorizontal: 20,
123
+ },
124
+ description: {
125
+ fontSize: 15,
126
+ textAlign: 'center',
127
+ paddingHorizontal: 32,
128
+ lineHeight: 22,
129
+ },
130
+ });
131
+
132
+ export default ImageSlide;