@umituz/react-native-splash 2.1.6 → 2.1.8

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,7 +1,7 @@
1
1
  {
2
2
  "name": "@umituz/react-native-splash",
3
- "version": "2.1.6",
4
- "description": "Ultra minimal splash screen for React Native apps with design system integration and theme provider pattern.",
3
+ "version": "2.1.8",
4
+ "description": "Minimal prop-driven splash screen for React Native apps with design system integration.",
5
5
  "main": "./src/index.ts",
6
6
  "types": "./src/index.ts",
7
7
  "scripts": {
@@ -18,7 +18,7 @@
18
18
  "loading",
19
19
  "minimal",
20
20
  "design-system",
21
- "theme-provider"
21
+ "prop-driven"
22
22
  ],
23
23
  "author": "Ümit UZ <umit@umituz.com>",
24
24
  "license": "MIT",
@@ -29,16 +29,14 @@
29
29
  "peerDependencies": {
30
30
  "@umituz/react-native-design-system": "latest",
31
31
  "expo-linear-gradient": ">=13.0.0",
32
- "expo-splash-screen": ">=0.23.0",
33
32
  "react": ">=18.2.0",
34
33
  "react-native": ">=0.74.0",
35
34
  "react-native-safe-area-context": ">=4.0.0"
36
35
  },
37
36
  "devDependencies": {
38
37
  "@umituz/react-native-design-system": "latest",
39
- "expo-linear-gradient": "~15.0.7",
40
- "expo-splash-screen": "~0.27.0",
41
38
  "@types/react": "~19.1.10",
39
+ "expo-linear-gradient": "~15.0.7",
42
40
  "react": "19.1.0",
43
41
  "react-native": "0.81.5",
44
42
  "react-native-safe-area-context": "^5.6.0",
@@ -0,0 +1,181 @@
1
+ /**
2
+ * Splash Screen Component
3
+ * Supports both prop-driven and provider-based theming
4
+ * Main app controls all styling via props or SplashThemeProvider
5
+ */
6
+
7
+ import React, { useEffect, useState, useCallback } from "react";
8
+ import { View, Image, StyleSheet } from "react-native";
9
+ import { LinearGradient } from "expo-linear-gradient";
10
+ import { useSafeAreaInsets } from "react-native-safe-area-context";
11
+ import { AtomicText } from "@umituz/react-native-design-system";
12
+ import type { SplashScreenProps, SplashColors } from "../types";
13
+ import { useSplashTheme } from "../providers/SplashThemeProvider";
14
+
15
+ const ICON_SIZE = 120;
16
+ const ICON_PLACEHOLDER_SIZE = 100;
17
+ const CONTENT_PADDING = 24;
18
+
19
+ const DEFAULT_COLORS: SplashColors = {
20
+ background: "#000000",
21
+ text: "#FFFFFF",
22
+ };
23
+
24
+ export const SplashScreen: React.FC<SplashScreenProps> = ({
25
+ icon,
26
+ appName,
27
+ tagline,
28
+ colors: propColors,
29
+ gradientColors: propGradientColors,
30
+ visible = true,
31
+ maxDuration,
32
+ onTimeout,
33
+ onReady,
34
+ style,
35
+ }) => {
36
+ const insets = useSafeAreaInsets();
37
+ const [timedOut, setTimedOut] = useState(false);
38
+ const themeContext = useSplashTheme();
39
+
40
+ const colors = propColors ?? themeContext?.colors ?? DEFAULT_COLORS;
41
+ const gradientColors = propGradientColors ?? themeContext?.gradientColors;
42
+
43
+ const handleTimeout = useCallback(() => {
44
+ if (__DEV__) {
45
+ console.log(`[SplashScreen] Timeout reached: ${maxDuration}ms`);
46
+ }
47
+ setTimedOut(true);
48
+ onTimeout?.();
49
+ }, [maxDuration, onTimeout]);
50
+
51
+ useEffect(() => {
52
+ if (__DEV__) {
53
+ console.log("[SplashScreen] Mounted", { appName, visible });
54
+ }
55
+ onReady?.();
56
+ }, [appName, visible, onReady]);
57
+
58
+ useEffect(() => {
59
+ if (!maxDuration || !visible) return;
60
+
61
+ const timer = setTimeout(handleTimeout, maxDuration);
62
+ return () => clearTimeout(timer);
63
+ }, [maxDuration, visible, handleTimeout]);
64
+
65
+ if (!visible) {
66
+ if (__DEV__) {
67
+ console.log("[SplashScreen] Not visible, returning null");
68
+ }
69
+ return null;
70
+ }
71
+
72
+ const iconPlaceholderColor = colors.iconPlaceholder ?? `${colors.text}30`;
73
+
74
+ const contentStyle = {
75
+ paddingTop: insets.top + CONTENT_PADDING,
76
+ paddingBottom: insets.bottom + CONTENT_PADDING,
77
+ };
78
+
79
+ const content = (
80
+ <View style={[styles.content, contentStyle]}>
81
+ <View style={styles.center}>
82
+ {icon ? (
83
+ <Image source={icon} style={styles.icon} resizeMode="contain" />
84
+ ) : (
85
+ <View
86
+ style={[
87
+ styles.iconPlaceholder,
88
+ { backgroundColor: iconPlaceholderColor },
89
+ ]}
90
+ />
91
+ )}
92
+
93
+ {appName ? (
94
+ <AtomicText
95
+ type="displaySmall"
96
+ style={[styles.title, { color: colors.text }]}
97
+ >
98
+ {appName}
99
+ </AtomicText>
100
+ ) : null}
101
+
102
+ {tagline ? (
103
+ <AtomicText
104
+ type="bodyLarge"
105
+ style={[styles.tagline, { color: colors.text }]}
106
+ >
107
+ {tagline}
108
+ </AtomicText>
109
+ ) : null}
110
+
111
+ {timedOut && __DEV__ ? (
112
+ <AtomicText
113
+ type="labelSmall"
114
+ style={[styles.timeoutText, { color: colors.text }]}
115
+ >
116
+ Initialization timeout
117
+ </AtomicText>
118
+ ) : null}
119
+ </View>
120
+ </View>
121
+ );
122
+
123
+ if (gradientColors && gradientColors.length >= 2) {
124
+ return (
125
+ <LinearGradient
126
+ colors={gradientColors as [string, string, ...string[]]}
127
+ style={[styles.container, style]}
128
+ start={{ x: 0, y: 0 }}
129
+ end={{ x: 0, y: 1 }}
130
+ >
131
+ {content}
132
+ </LinearGradient>
133
+ );
134
+ }
135
+
136
+ return (
137
+ <View style={[styles.container, { backgroundColor: colors.background }, style]}>
138
+ {content}
139
+ </View>
140
+ );
141
+ };
142
+
143
+ const styles = StyleSheet.create({
144
+ container: {
145
+ flex: 1,
146
+ },
147
+ content: {
148
+ flex: 1,
149
+ justifyContent: "space-between",
150
+ },
151
+ center: {
152
+ flex: 1,
153
+ alignItems: "center",
154
+ justifyContent: "center",
155
+ paddingHorizontal: CONTENT_PADDING,
156
+ },
157
+ icon: {
158
+ width: ICON_SIZE,
159
+ height: ICON_SIZE,
160
+ marginBottom: CONTENT_PADDING,
161
+ },
162
+ iconPlaceholder: {
163
+ width: ICON_PLACEHOLDER_SIZE,
164
+ height: ICON_PLACEHOLDER_SIZE,
165
+ borderRadius: ICON_PLACEHOLDER_SIZE / 2,
166
+ marginBottom: CONTENT_PADDING,
167
+ },
168
+ title: {
169
+ textAlign: "center",
170
+ fontWeight: "800",
171
+ marginBottom: 8,
172
+ },
173
+ tagline: {
174
+ textAlign: "center",
175
+ opacity: 0.9,
176
+ },
177
+ timeoutText: {
178
+ textAlign: "center",
179
+ marginTop: 16,
180
+ },
181
+ });
package/src/index.ts CHANGED
@@ -1,28 +1,42 @@
1
1
  /**
2
2
  * React Native Splash - Public API
3
3
  *
4
- * Ultra minimal splash screen for React Native apps.
5
- * Centralized theme management with provider pattern.
4
+ * Splash screen for React Native apps with theme support.
5
+ * Supports both prop-driven and provider-based theming.
6
6
  *
7
- * Usage:
8
- * import { SplashThemeProvider, SplashScreen } from '@umituz/react-native-splash';
7
+ * Usage with provider:
8
+ * import { SplashScreen, SplashThemeProvider } from '@umituz/react-native-splash';
9
9
  *
10
- * <SplashThemeProvider gradientColors={['#FF0080', '#7928CA']}>
10
+ * <SplashThemeProvider
11
+ * gradientColors={[tokens.colors.primary, tokens.colors.secondary]}
12
+ * customColors={{ textColor: tokens.colors.onPrimary }}
13
+ * >
11
14
  * <SplashScreen
12
- * icon={require('./assets/icon.png')}
13
15
  * appName="My App"
14
16
  * tagline="Your tagline here"
15
- * visible={showSplash}
16
- * maxDuration={10000}
17
- * onTimeout={() => console.warn('Splash timeout')}
17
+ * icon={require('./assets/icon.png')}
18
18
  * />
19
19
  * </SplashThemeProvider>
20
+ *
21
+ * Usage with props:
22
+ * <SplashScreen
23
+ * appName="My App"
24
+ * colors={{ background: '#000', text: '#fff' }}
25
+ * gradientColors={['#FF0080', '#7928CA']}
26
+ * />
20
27
  */
21
28
 
22
- export type { SplashOptions } from "./domain/entities/SplashOptions";
23
- export { SplashScreen, type SplashScreenProps } from "./presentation/components/SplashScreen";
24
- export {
25
- SplashThemeProvider,
26
- type SplashThemeProviderProps,
27
- useSplashTheme,
28
- } from "./presentation/providers/SplashThemeProvider";
29
+ // Types
30
+ export type {
31
+ SplashScreenProps,
32
+ SplashColors,
33
+ SplashCustomColors,
34
+ SplashThemeProviderProps,
35
+ SplashThemeContextValue,
36
+ } from "./types";
37
+
38
+ // Components
39
+ export { SplashScreen } from "./components/SplashScreen";
40
+
41
+ // Providers
42
+ export { SplashThemeProvider, useSplashTheme } from "./providers";
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Splash Theme Provider
3
+ * Provides theme context for SplashScreen components
4
+ */
5
+
6
+ import React, { createContext, useContext, useMemo } from "react";
7
+ import type {
8
+ SplashThemeProviderProps,
9
+ SplashThemeContextValue,
10
+ } from "../types";
11
+
12
+ const DEFAULT_COLORS = {
13
+ background: "#000000",
14
+ text: "#FFFFFF",
15
+ };
16
+
17
+ const SplashThemeContext = createContext<SplashThemeContextValue | null>(null);
18
+
19
+ export const useSplashTheme = (): SplashThemeContextValue | null => {
20
+ return useContext(SplashThemeContext);
21
+ };
22
+
23
+ export const SplashThemeProvider: React.FC<SplashThemeProviderProps> = ({
24
+ children,
25
+ gradientColors,
26
+ customColors,
27
+ }) => {
28
+ const value = useMemo<SplashThemeContextValue>(() => {
29
+ const background =
30
+ customColors?.backgroundColor ??
31
+ (gradientColors?.[0] || DEFAULT_COLORS.background);
32
+
33
+ return {
34
+ colors: {
35
+ background,
36
+ text: customColors?.textColor ?? DEFAULT_COLORS.text,
37
+ iconPlaceholder: customColors?.iconPlaceholderColor,
38
+ },
39
+ gradientColors,
40
+ };
41
+ }, [gradientColors, customColors]);
42
+
43
+ return (
44
+ <SplashThemeContext.Provider value={value}>
45
+ {children}
46
+ </SplashThemeContext.Provider>
47
+ );
48
+ };
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Splash Providers
3
+ */
4
+
5
+ export { SplashThemeProvider, useSplashTheme } from "./SplashThemeProvider";
@@ -0,0 +1,90 @@
1
+ /**
2
+ * Splash Screen Types
3
+ * All type definitions for the splash screen package
4
+ */
5
+
6
+ import type { ImageSourcePropType, StyleProp, ViewStyle } from "react-native";
7
+ import type { ReactNode } from "react";
8
+
9
+ /**
10
+ * Splash screen color configuration
11
+ * All colors should be provided by the main app via design tokens
12
+ */
13
+ export interface SplashColors {
14
+ /** Background color when not using gradient */
15
+ background: string;
16
+ /** Text color for app name and tagline */
17
+ text: string;
18
+ /** Background color for icon placeholder circle */
19
+ iconPlaceholder?: string;
20
+ }
21
+
22
+ /**
23
+ * Custom colors for SplashThemeProvider
24
+ */
25
+ export interface SplashCustomColors {
26
+ /** Text color for app name and tagline */
27
+ textColor: string;
28
+ /** Background color when not using gradient */
29
+ backgroundColor?: string;
30
+ /** Background color for icon placeholder circle */
31
+ iconPlaceholderColor?: string;
32
+ }
33
+
34
+ /**
35
+ * SplashThemeProvider props
36
+ */
37
+ export interface SplashThemeProviderProps {
38
+ /** Children components */
39
+ children: ReactNode;
40
+ /** Gradient colors for background */
41
+ gradientColors?: readonly [string, string, ...string[]];
42
+ /** Custom color configuration */
43
+ customColors?: SplashCustomColors;
44
+ }
45
+
46
+ /**
47
+ * Splash theme context value
48
+ */
49
+ export interface SplashThemeContextValue {
50
+ /** Resolved colors for splash screen */
51
+ colors: SplashColors;
52
+ /** Gradient colors if provided */
53
+ gradientColors?: readonly [string, string, ...string[]];
54
+ }
55
+
56
+ /**
57
+ * Splash screen component props
58
+ * Can be used standalone with colors prop or with SplashThemeProvider
59
+ */
60
+ export interface SplashScreenProps {
61
+ /** App name to display */
62
+ appName?: string;
63
+
64
+ /** Tagline or subtitle */
65
+ tagline?: string;
66
+
67
+ /** App icon/logo image source */
68
+ icon?: ImageSourcePropType;
69
+
70
+ /** Color configuration - optional when using SplashThemeProvider */
71
+ colors?: SplashColors;
72
+
73
+ /** Optional gradient colors (overrides background color) */
74
+ gradientColors?: readonly [string, string, ...string[]];
75
+
76
+ /** Control visibility */
77
+ visible?: boolean;
78
+
79
+ /** Maximum duration before timeout callback */
80
+ maxDuration?: number;
81
+
82
+ /** Callback when max duration is reached */
83
+ onTimeout?: () => void;
84
+
85
+ /** Callback when splash is ready/mounted */
86
+ onReady?: () => void;
87
+
88
+ /** Additional container style */
89
+ style?: StyleProp<ViewStyle>;
90
+ }
@@ -1,17 +0,0 @@
1
- /**
2
- * Splash Options - Ultra Minimal Configuration
3
- * Theme/colors managed by SplashThemeProvider
4
- */
5
-
6
- import type { ImageSourcePropType } from "react-native";
7
-
8
- export interface SplashOptions {
9
- /** App icon/logo image source */
10
- icon?: ImageSourcePropType;
11
-
12
- /** App name to display */
13
- appName?: string;
14
-
15
- /** Tagline or subtitle */
16
- tagline?: string;
17
- }
@@ -1,184 +0,0 @@
1
- /**
2
- * Splash Screen Component
3
- * Ultra minimal splash screen with design system integration
4
- * Parent component controls visibility and timing
5
- */
6
-
7
- import React, { useEffect, useState } from "react";
8
- import { View, Image, StyleSheet } from "react-native";
9
- import { LinearGradient } from "expo-linear-gradient";
10
- import { useSafeAreaInsets } from "react-native-safe-area-context";
11
- import { AtomicText, useAppDesignTokens } from "@umituz/react-native-design-system";
12
- import type { SplashOptions } from "../../domain/entities/SplashOptions";
13
- import { useSplashTheme } from "../providers/SplashThemeProvider";
14
-
15
- export interface SplashScreenProps extends SplashOptions {
16
- visible?: boolean;
17
- maxDuration?: number;
18
- onTimeout?: () => void;
19
- }
20
-
21
- export const SplashScreen: React.FC<SplashScreenProps> = ({
22
- icon,
23
- appName = "",
24
- tagline = "",
25
- visible = true,
26
- maxDuration,
27
- onTimeout,
28
- }) => {
29
- const insets = useSafeAreaInsets();
30
- const tokens = useAppDesignTokens();
31
- const { colors, gradientColors } = useSplashTheme();
32
- const [timedOut, setTimedOut] = useState(false);
33
-
34
- useEffect(() => {
35
- if (__DEV__) {
36
- console.log(`[SplashScreen] Mounted - appName: ${appName}, visible: ${visible}`);
37
- }
38
- }, [appName, visible]);
39
-
40
- useEffect(() => {
41
- if (!maxDuration || !visible) return;
42
-
43
- const timer = setTimeout(() => {
44
- if (__DEV__) {
45
- console.log(`[SplashScreen] Timeout reached: ${maxDuration}ms`);
46
- }
47
- setTimedOut(true);
48
- onTimeout?.();
49
- }, maxDuration);
50
-
51
- return () => clearTimeout(timer);
52
- }, [maxDuration, visible, onTimeout]);
53
-
54
- if (!visible) {
55
- if (__DEV__) console.log("[SplashScreen] Not visible, returning null");
56
- return null;
57
- }
58
-
59
- const content = (
60
- <View
61
- style={[
62
- styles.content,
63
- {
64
- paddingTop: insets.top + tokens.spacing.xl,
65
- paddingBottom: insets.bottom + tokens.spacing.xl,
66
- },
67
- ]}
68
- >
69
- <View style={styles.center}>
70
- {icon ? (
71
- <Image source={icon} style={styles.icon} resizeMode="contain" />
72
- ) : (
73
- <View
74
- style={[
75
- styles.iconPlaceholder,
76
- { backgroundColor: colors.iconPlaceholderBg },
77
- ]}
78
- />
79
- )}
80
-
81
- {appName ? (
82
- <AtomicText
83
- type="displaySmall"
84
- style={[
85
- styles.title,
86
- {
87
- color: colors.textColor,
88
- marginBottom: tokens.spacing.sm,
89
- },
90
- ]}
91
- >
92
- {appName}
93
- </AtomicText>
94
- ) : null}
95
-
96
- {tagline ? (
97
- <AtomicText
98
- type="bodyLarge"
99
- style={[
100
- styles.subtitle,
101
- {
102
- color: colors.textColor,
103
- opacity: 0.9,
104
- },
105
- ]}
106
- >
107
- {tagline}
108
- </AtomicText>
109
- ) : null}
110
-
111
- {timedOut && __DEV__ ? (
112
- <AtomicText
113
- type="labelSmall"
114
- style={[
115
- styles.timeoutWarning,
116
- {
117
- color: colors.textColor,
118
- marginTop: tokens.spacing.md,
119
- },
120
- ]}
121
- >
122
- ⚠️ Initialization timeout
123
- </AtomicText>
124
- ) : null}
125
- </View>
126
- </View>
127
- );
128
-
129
- if (gradientColors && gradientColors.length >= 2) {
130
- return (
131
- <LinearGradient
132
- colors={gradientColors as [string, string, ...string[]]}
133
- style={styles.container}
134
- start={{ x: 0, y: 0 }}
135
- end={{ x: 0, y: 1 }}
136
- >
137
- {content}
138
- </LinearGradient>
139
- );
140
- }
141
-
142
- return (
143
- <View style={[styles.container, { backgroundColor: colors.backgroundColor }]}>
144
- {content}
145
- </View>
146
- );
147
- };
148
-
149
- const styles = StyleSheet.create({
150
- container: {
151
- flex: 1,
152
- },
153
- content: {
154
- flex: 1,
155
- justifyContent: "space-between",
156
- },
157
- center: {
158
- flex: 1,
159
- alignItems: "center",
160
- justifyContent: "center",
161
- paddingHorizontal: 24,
162
- },
163
- icon: {
164
- width: 120,
165
- height: 120,
166
- marginBottom: 24,
167
- },
168
- iconPlaceholder: {
169
- width: 100,
170
- height: 100,
171
- borderRadius: 50,
172
- marginBottom: 24,
173
- },
174
- title: {
175
- textAlign: "center",
176
- fontWeight: "800",
177
- },
178
- subtitle: {
179
- textAlign: "center",
180
- },
181
- timeoutWarning: {
182
- textAlign: "center",
183
- },
184
- });
@@ -1,63 +0,0 @@
1
- /**
2
- * Splash Theme Provider
3
- * Centralized theme management for splash screen
4
- * Follows provider pattern like onboarding package
5
- */
6
-
7
- import React, { createContext, useContext, useMemo } from "react";
8
- import { useAppDesignTokens } from "@umituz/react-native-design-system";
9
-
10
- interface SplashColors {
11
- backgroundColor: string;
12
- textColor: string;
13
- iconPlaceholderBg: string;
14
- }
15
-
16
- interface SplashThemeValue {
17
- colors: SplashColors;
18
- gradientColors?: readonly [string, string, ...string[]];
19
- }
20
-
21
- const SplashTheme = createContext<SplashThemeValue | null>(null);
22
-
23
- export interface SplashThemeProviderProps {
24
- children: React.ReactNode;
25
- gradientColors?: readonly [string, string, ...string[]];
26
- customColors?: Partial<SplashColors>;
27
- }
28
-
29
- export const SplashThemeProvider = ({
30
- children,
31
- gradientColors,
32
- customColors,
33
- }: SplashThemeProviderProps) => {
34
- const tokens = useAppDesignTokens();
35
-
36
- const colors = useMemo<SplashColors>(() => {
37
- const defaults: SplashColors = {
38
- backgroundColor: tokens.colors.primary,
39
- textColor: tokens.colors.onPrimary,
40
- iconPlaceholderBg: tokens.colors.onPrimary + "30",
41
- };
42
-
43
- return {
44
- ...defaults,
45
- ...customColors,
46
- };
47
- }, [tokens, customColors]);
48
-
49
- const value = useMemo(
50
- () => ({ colors, gradientColors }),
51
- [colors, gradientColors]
52
- );
53
-
54
- return <SplashTheme.Provider value={value}>{children}</SplashTheme.Provider>;
55
- };
56
-
57
- export const useSplashTheme = (): SplashThemeValue => {
58
- const theme = useContext(SplashTheme);
59
- if (!theme) {
60
- throw new Error("useSplashTheme must be used within SplashThemeProvider");
61
- }
62
- return theme;
63
- };