@umituz/react-native-splash 1.7.1 → 1.9.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 (35) hide show
  1. package/package.json +11 -36
  2. package/src/presentation/components/SplashErrorBoundary.tsx +13 -18
  3. package/src/presentation/components/SplashLoading.tsx +0 -8
  4. package/src/presentation/components/SplashLogo.tsx +0 -10
  5. package/src/presentation/components/SplashScreen.tsx +1 -1
  6. package/src/presentation/components/SplashTypography.tsx +0 -6
  7. package/src/presentation/hooks/useSplash.ts +1 -1
  8. package/lib/__tests__/mocks/expoLinearGradient.js +0 -7
  9. package/lib/__tests__/mocks/reactNative.js +0 -16
  10. package/lib/__tests__/setup.ts +0 -57
  11. package/lib/__tests__/utils/testUtils.tsx +0 -86
  12. package/lib/domain/entities/SplashOptions.ts +0 -74
  13. package/lib/index.ts +0 -31
  14. package/lib/presentation/components/SplashDecorations.tsx +0 -56
  15. package/lib/presentation/components/SplashErrorBoundary.tsx +0 -63
  16. package/lib/presentation/components/SplashLoading.tsx +0 -74
  17. package/lib/presentation/components/SplashLogo.tsx +0 -80
  18. package/lib/presentation/components/SplashScreen.tsx +0 -175
  19. package/lib/presentation/components/SplashTypography.tsx +0 -72
  20. package/lib/presentation/hooks/useSplash.ts +0 -70
  21. package/lib/presentation/utils/splashGradient.utils.ts +0 -47
  22. package/lib/types/expo-linear-gradient.d.ts +0 -12
  23. package/src/__tests__/SplashScreen.test.tsx +0 -161
  24. package/src/__tests__/accessibility/Accessibility.test.tsx +0 -264
  25. package/src/__tests__/basic/Basic.test.tsx +0 -106
  26. package/src/__tests__/basic/Simple.test.tsx +0 -32
  27. package/src/__tests__/edge-cases/EdgeCases.test.tsx +0 -446
  28. package/src/__tests__/integration/SplashScreen.integration.test.tsx +0 -200
  29. package/src/__tests__/mocks/expoLinearGradient.js +0 -7
  30. package/src/__tests__/mocks/reactNative.js +0 -16
  31. package/src/__tests__/performance/Performance.test.tsx +0 -297
  32. package/src/__tests__/setup.ts +0 -57
  33. package/src/__tests__/useSplash.test.tsx +0 -123
  34. package/src/__tests__/utils/testUtils.tsx +0 -86
  35. package/src/__tests__/visual/VisualRegression.test.tsx +0 -338
@@ -1,80 +0,0 @@
1
- /**
2
- * Splash Logo Component
3
- * Single Responsibility: Render splash screen logo
4
- */
5
-
6
- import React from "react";
7
- import { View, StyleSheet } from "react-native";
8
- import { AtomicIcon } from "@umituz/react-native-design-system-atoms";
9
-
10
- export interface SplashLogoProps {
11
- logo?: string | React.ReactNode;
12
- logoSize?: number;
13
- glowSize?: number;
14
- iconColor?: string;
15
- }
16
-
17
- export const SplashLogo: React.FC<SplashLogoProps> = ({
18
- logo,
19
- logoSize = 140,
20
- glowSize = 160,
21
- iconColor = "#FFFFFF",
22
- }) => {
23
- const styles = getStyles(logoSize, glowSize);
24
-
25
- return (
26
- <View style={styles.container}>
27
- <View style={styles.glow} />
28
- <View style={styles.background}>
29
- {typeof logo === "string" ? (
30
- <AtomicIcon name={logo || "sparkles"} size="xxl" customColor={iconColor} />
31
- ) : logo ? (
32
- logo
33
- ) : (
34
- <AtomicIcon name="sparkles" size="xxl" customColor={iconColor} />
35
- )}
36
- </View>
37
- </View>
38
- );
39
- };
40
-
41
- const getStyles = (logoSize: number, glowSize: number) => {
42
- const radius = logoSize / 2;
43
- const glowRadius = glowSize / 2;
44
-
45
- return StyleSheet.create({
46
- container: {
47
- alignItems: "center",
48
- justifyContent: "center",
49
- position: "relative",
50
- },
51
- glow: {
52
- position: "absolute",
53
- width: glowSize,
54
- height: glowSize,
55
- borderRadius: glowRadius,
56
- backgroundColor: "rgba(255, 255, 255, 0.15)",
57
- shadowColor: "#FFFFFF",
58
- shadowOffset: { width: 0, height: 0 },
59
- shadowOpacity: 0.5,
60
- shadowRadius: 30,
61
- elevation: 10,
62
- },
63
- background: {
64
- width: logoSize,
65
- height: logoSize,
66
- borderRadius: radius,
67
- backgroundColor: "rgba(255, 255, 255, 0.2)",
68
- alignItems: "center",
69
- justifyContent: "center",
70
- borderWidth: 2,
71
- borderColor: "rgba(255, 255, 255, 0.3)",
72
- shadowColor: "#000",
73
- shadowOffset: { width: 0, height: 4 },
74
- shadowOpacity: 0.3,
75
- shadowRadius: 8,
76
- elevation: 8,
77
- },
78
- });
79
- };
80
-
@@ -1,175 +0,0 @@
1
- /**
2
- * Splash Screen Component
3
- * Single Responsibility: Orchestrate splash screen UI
4
- */
5
-
6
- import React, { useEffect, useRef } from "react";
7
- import { View, StyleSheet } from "react-native";
8
- import { LinearGradient } from "expo-linear-gradient";
9
- import { useSafeAreaInsets } from "react-native-safe-area-context";
10
- import { useLocalization } from "@umituz/react-native-localization";
11
- import { useAppDesignTokens } from "@umituz/react-native-design-system-theme";
12
- import { SplashLogo } from "./SplashLogo";
13
- import { SplashTypography } from "./SplashTypography";
14
- import { SplashLoading } from "./SplashLoading";
15
- import { SplashDecorations } from "./SplashDecorations";
16
- import { SplashErrorBoundary } from "./SplashErrorBoundary";
17
- import type { SplashOptions } from "../../domain/entities/SplashOptions";
18
-
19
- export interface SplashScreenProps extends SplashOptions {
20
- visible?: boolean;
21
- textColor?: string;
22
- iconColor?: string;
23
- decorationColor?: string;
24
- }
25
-
26
- /**
27
- * Splash Screen Component
28
- */
29
- export const SplashScreen: React.FC<SplashScreenProps> = ({
30
- appName,
31
- tagline,
32
- logo,
33
- backgroundColor,
34
- gradientColors,
35
- loadingText,
36
- showLoading = true,
37
- minimumDisplayTime = 1500,
38
- onReady,
39
- renderLogo,
40
- renderContent,
41
- renderFooter,
42
- visible = true,
43
- textColor,
44
- iconColor,
45
- decorationColor,
46
- }) => {
47
- const insets = useSafeAreaInsets();
48
- const { t } = useLocalization();
49
- const tokens = useAppDesignTokens();
50
-
51
- const styles = getStyles(insets, tokens.spacing);
52
-
53
- const timerRef = useRef<NodeJS.Timeout>();
54
-
55
- useEffect(() => {
56
- if (!visible) return;
57
-
58
- timerRef.current = setTimeout(() => {
59
- if (onReady) {
60
- onReady();
61
- }
62
- }, minimumDisplayTime);
63
-
64
- return () => {
65
- if (timerRef.current) {
66
- clearTimeout(timerRef.current);
67
- }
68
- };
69
- }, [visible, minimumDisplayTime, onReady]);
70
-
71
- if (!visible) return null;
72
-
73
- const displayAppName = appName || t("branding.appName", "");
74
- const displayTagline = tagline || t("branding.tagline", "");
75
- const displayLoadingText = loadingText || t("general.loading", "");
76
-
77
- // Use gradientColors if provided, otherwise use backgroundColor as solid color
78
- const finalBackgroundColor = gradientColors
79
- ? undefined
80
- : backgroundColor || tokens.colors.primary;
81
-
82
- // Use LinearGradient only if gradientColors provided (length > 1)
83
- const hasGradient = gradientColors && gradientColors.length > 1;
84
-
85
- // For LinearGradient, ensure at least 2 colors (tuple type requirement)
86
- const finalGradientColors: [string, string, ...string[]] = hasGradient
87
- ? (gradientColors.length >= 2
88
- ? (gradientColors as [string, string, ...string[]])
89
- : [gradientColors[0], gradientColors[0] || finalBackgroundColor!])
90
- : [finalBackgroundColor!, finalBackgroundColor!];
91
-
92
- const content = (
93
- <>
94
- <SplashDecorations decorationColor={decorationColor} />
95
-
96
- <View style={styles.content}>
97
- {renderLogo ? (
98
- renderLogo()
99
- ) : (
100
- <SplashLogo logo={logo} iconColor={iconColor} />
101
- )}
102
-
103
- {renderContent ? (
104
- renderContent()
105
- ) : (
106
- <SplashTypography
107
- appName={displayAppName}
108
- tagline={displayTagline}
109
- tokens={tokens}
110
- textColor={textColor}
111
- />
112
- )}
113
- </View>
114
-
115
- {showLoading && (
116
- <SplashLoading
117
- loadingText={displayLoadingText}
118
- tokens={tokens}
119
- bottomInset={insets.bottom}
120
- textColor={textColor}
121
- />
122
- )}
123
-
124
- {renderFooter && renderFooter()}
125
- </>
126
- );
127
-
128
- return (
129
- <SplashErrorBoundary>
130
- <View style={styles.container}>
131
- {hasGradient ? (
132
- <LinearGradient
133
- colors={finalGradientColors}
134
- start={{ x: 0, y: 0 }}
135
- end={{ x: 1, y: 1 }}
136
- style={styles.gradient}
137
- >
138
- {content}
139
- </LinearGradient>
140
- ) : (
141
- <View
142
- style={[styles.gradient, { backgroundColor: finalBackgroundColor }]}
143
- >
144
- {content}
145
- </View>
146
- )}
147
- </View>
148
- </SplashErrorBoundary>
149
- );
150
- };
151
-
152
- const getStyles = (
153
- insets: { top: number; bottom: number },
154
- spacing: any,
155
- ) => {
156
- return StyleSheet.create({
157
- container: {
158
- flex: 1,
159
- },
160
- gradient: {
161
- flex: 1,
162
- paddingTop: insets.top,
163
- paddingBottom: insets.bottom,
164
- position: "relative",
165
- overflow: "hidden",
166
- },
167
- content: {
168
- flex: 1,
169
- alignItems: "center",
170
- justifyContent: "center",
171
- paddingHorizontal: spacing.xl,
172
- zIndex: 1,
173
- },
174
- });
175
- };
@@ -1,72 +0,0 @@
1
- /**
2
- * Splash Typography Component
3
- * Single Responsibility: Render splash screen typography
4
- */
5
-
6
- import React from "react";
7
- import { View, Text, StyleSheet } from "react-native";
8
- import type { DesignTokens } from "@umituz/react-native-design-system-theme";
9
-
10
- export interface SplashTypographyProps {
11
- appName: string;
12
- tagline?: string;
13
- tokens: DesignTokens;
14
- textColor?: string;
15
- }
16
-
17
- export const SplashTypography: React.FC<SplashTypographyProps> = ({
18
- appName,
19
- tagline,
20
- tokens,
21
- textColor = "#FFFFFF",
22
- }) => {
23
- const styles = getStyles(tokens, textColor);
24
-
25
- return (
26
- <View style={styles.container}>
27
- <Text style={styles.appName} numberOfLines={1}>
28
- {appName}
29
- </Text>
30
- {tagline && (
31
- <Text style={styles.tagline} numberOfLines={2}>
32
- {tagline}
33
- </Text>
34
- )}
35
- </View>
36
- );
37
- };
38
-
39
- const getStyles = (tokens: DesignTokens, textColor: string) => {
40
- return StyleSheet.create({
41
- container: {
42
- alignItems: "center",
43
- marginTop: tokens.spacing.xl,
44
- },
45
- appName: {
46
- fontSize: 48,
47
- fontWeight: "800" as const,
48
- color: textColor,
49
- textAlign: "center" as const,
50
- marginBottom: tokens.spacing.md,
51
- letterSpacing: -1.2,
52
- lineHeight: 56,
53
- textShadowColor: "rgba(0, 0, 0, 0.25)",
54
- textShadowOffset: { width: 0, height: 2 },
55
- textShadowRadius: 6,
56
- },
57
- tagline: {
58
- fontSize: 17,
59
- color: textColor,
60
- textAlign: "center" as const,
61
- opacity: 0.95,
62
- maxWidth: 320,
63
- lineHeight: 24,
64
- fontWeight: "500" as const,
65
- letterSpacing: 0.2,
66
- textShadowColor: "rgba(0, 0, 0, 0.2)",
67
- textShadowOffset: { width: 0, height: 1 },
68
- textShadowRadius: 3,
69
- },
70
- });
71
- };
72
-
@@ -1,70 +0,0 @@
1
- /**
2
- * Use Splash Hook
3
- * Single Responsibility: Manage splash screen state and timing
4
- */
5
-
6
- import { useEffect, useState, useRef } from "react";
7
-
8
- interface UseSplashOptions {
9
- minimumDisplayTime?: number;
10
- onReady?: () => void | Promise<void>;
11
- autoHide?: boolean;
12
- }
13
-
14
- export const useSplash = ({
15
- minimumDisplayTime = 1500,
16
- onReady,
17
- autoHide = true,
18
- }: UseSplashOptions = {}) => {
19
- const [isVisible, setIsVisible] = useState(true);
20
- const [isReady, setIsReady] = useState(false);
21
- const timerRef = useRef<NodeJS.Timeout>();
22
- const isReadyRef = useRef(false);
23
-
24
- const hide = () => {
25
- setIsVisible(false);
26
- };
27
-
28
- const show = () => {
29
- setIsVisible(true);
30
- };
31
-
32
- const markReady = async () => {
33
- if (isReadyRef.current) return;
34
-
35
- isReadyRef.current = true;
36
- setIsReady(true);
37
-
38
- if (onReady) {
39
- try {
40
- await onReady();
41
- } catch (error) {
42
- if (__DEV__) {
43
- console.error("Splash onReady error:", error);
44
- }
45
- }
46
- }
47
-
48
- if (autoHide) {
49
- timerRef.current = setTimeout(() => {
50
- hide();
51
- }, minimumDisplayTime);
52
- }
53
- };
54
-
55
- useEffect(() => {
56
- return () => {
57
- if (timerRef.current) {
58
- clearTimeout(timerRef.current);
59
- }
60
- };
61
- }, []);
62
-
63
- return {
64
- isVisible,
65
- isReady,
66
- hide,
67
- show,
68
- markReady,
69
- };
70
- };
@@ -1,47 +0,0 @@
1
- /**
2
- * Splash Gradient Utilities
3
- * Single Responsibility: Gradient color generation
4
- */
5
-
6
- /**
7
- * Adjust color brightness
8
- */
9
- export const adjustColorBrightness = (hex: string, percent: number): string => {
10
- const num = parseInt(hex.replace("#", ""), 16);
11
- const amt = Math.round(2.55 * percent);
12
- const R = (num >> 16) + amt;
13
- const G = ((num >> 8) & 0x00ff) + amt;
14
- const B = (num & 0x0000ff) + amt;
15
- return (
16
- "#" +
17
- (
18
- 0x1000000 +
19
- (R < 255 ? (R < 1 ? 0 : R) : 255) * 0x10000 +
20
- (G < 255 ? (G < 1 ? 0 : G) : 255) * 0x100 +
21
- (B < 255 ? (B < 1 ? 0 : B) : 255)
22
- )
23
- .toString(16)
24
- .slice(1)
25
- );
26
- };
27
-
28
- /**
29
- * Generate gradient colors from backgroundColor
30
- */
31
- export const generateGradientFromColor = (
32
- backgroundColor: string,
33
- isDark: boolean,
34
- ): readonly string[] => {
35
- return isDark
36
- ? ([
37
- backgroundColor,
38
- adjustColorBrightness(backgroundColor, -20),
39
- adjustColorBrightness(backgroundColor, -30),
40
- ] as const)
41
- : ([
42
- backgroundColor,
43
- adjustColorBrightness(backgroundColor, 10),
44
- adjustColorBrightness(backgroundColor, 20),
45
- ] as const);
46
- };
47
-
@@ -1,12 +0,0 @@
1
- declare module 'expo-linear-gradient' {
2
- import { View, ViewProps } from 'react-native';
3
-
4
- export interface LinearGradientProps extends ViewProps {
5
- colors: readonly string[];
6
- start?: { x: number; y: number };
7
- end?: { x: number; y: number };
8
- locations?: readonly number[];
9
- }
10
-
11
- export const LinearGradient: React.FC<LinearGradientProps>;
12
- }
@@ -1,161 +0,0 @@
1
- /**
2
- * Splash Screen Tests
3
- */
4
-
5
- import React from "react";
6
- import { render, fireEvent } from "@testing-library/react-native";
7
- import { SplashScreen } from "../presentation/components/SplashScreen";
8
-
9
- // Mock dependencies
10
- jest.mock("react-native-safe-area-context", () => ({
11
- useSafeAreaInsets: () => ({ top: 44, bottom: 34 }),
12
- }));
13
-
14
- jest.mock("@umituz/react-native-localization", () => ({
15
- useLocalization: () => ({
16
- t: (key: string, fallback: string) => fallback,
17
- }),
18
- }));
19
-
20
- jest.mock("@umituz/react-native-design-system-theme", () => ({
21
- useAppDesignTokens: () => ({
22
- colors: { primary: "#007AFF" },
23
- spacing: { xl: 24, md: 16, xxxl: 48 },
24
- }),
25
- }));
26
-
27
- jest.mock("@umituz/react-native-design-system-atoms", () => ({
28
- AtomicIcon: ({ name, size, customColor }: any) => (
29
- <div testID={`icon-${name}`} data-size={size} data-color={customColor} />
30
- ),
31
- }));
32
-
33
- jest.mock("expo-linear-gradient", () => ({
34
- LinearGradient: ({ children, testID }: any) => (
35
- <div testID={testID || "linear-gradient"}>{children}</div>
36
- ),
37
- }));
38
-
39
- describe("SplashScreen", () => {
40
- const defaultProps = {
41
- appName: "Test App",
42
- tagline: "Test Tagline",
43
- visible: true,
44
- };
45
-
46
- beforeEach(() => {
47
- jest.useFakeTimers();
48
- });
49
-
50
- afterEach(() => {
51
- jest.useRealTimers();
52
- });
53
-
54
- it("renders correctly with basic props", () => {
55
- const { getByText } = render(<SplashScreen {...defaultProps} />);
56
-
57
- expect(getByText("Test App")).toBeTruthy();
58
- expect(getByText("Test Tagline")).toBeTruthy();
59
- });
60
-
61
- it("renders without tagline when not provided", () => {
62
- const props = { ...defaultProps, tagline: undefined };
63
- const { getByText, queryByText } = render(<SplashScreen {...props} />);
64
-
65
- expect(getByText("Test App")).toBeTruthy();
66
- expect(queryByText("Test Tagline")).toBeFalsy();
67
- });
68
-
69
- it("calls onReady after minimum display time", () => {
70
- const onReady = jest.fn();
71
- const props = { ...defaultProps, onReady };
72
-
73
- render(<SplashScreen {...props} />);
74
-
75
- expect(onReady).not.toHaveBeenCalled();
76
-
77
- jest.advanceTimersByTime(1500);
78
-
79
- expect(onReady).toHaveBeenCalledTimes(1);
80
- });
81
-
82
- it("does not render when visible is false", () => {
83
- const props = { ...defaultProps, visible: false };
84
- const { queryByText } = render(<SplashScreen {...props} />);
85
-
86
- expect(queryByText("Test App")).toBeFalsy();
87
- });
88
-
89
- it("uses custom colors when provided", () => {
90
- const props = {
91
- ...defaultProps,
92
- textColor: "#FF0000",
93
- iconColor: "#00FF00",
94
- decorationColor: "rgba(255, 0, 0, 0.1)",
95
- };
96
-
97
- render(<SplashScreen {...props} />);
98
-
99
- // Color props are passed down to child components
100
- // This test ensures the props are accepted without error
101
- expect(true).toBeTruthy();
102
- });
103
-
104
- it("uses gradient colors when provided", () => {
105
- const props = {
106
- ...defaultProps,
107
- gradientColors: ["#FF0000", "#00FF00", "#0000FF"],
108
- };
109
-
110
- const { getByTestId } = render(<SplashScreen {...props} />);
111
-
112
- expect(getByTestId("linear-gradient")).toBeTruthy();
113
- });
114
-
115
- it("renders custom logo when provided", () => {
116
- const CustomLogo = () => <div testID="custom-logo" />;
117
- const props = { ...defaultProps, renderLogo: () => <CustomLogo /> };
118
-
119
- const { getByTestId } = render(<SplashScreen {...props} />);
120
-
121
- expect(getByTestId("custom-logo")).toBeTruthy();
122
- });
123
-
124
- it("renders custom content when provided", () => {
125
- const CustomContent = () => <div testID="custom-content" />;
126
- const props = { ...defaultProps, renderContent: () => <CustomContent /> };
127
-
128
- const { getByTestId } = render(<SplashScreen {...props} />);
129
-
130
- expect(getByTestId("custom-content")).toBeTruthy();
131
- });
132
-
133
- it("renders custom footer when provided", () => {
134
- const CustomFooter = () => <div testID="custom-footer" />;
135
- const props = { ...defaultProps, renderFooter: () => <CustomFooter /> };
136
-
137
- const { getByTestId } = render(<SplashScreen {...props} />);
138
-
139
- expect(getByTestId("custom-footer")).toBeTruthy();
140
- });
141
-
142
- it("hides loading indicator when showLoading is false", () => {
143
- const props = { ...defaultProps, showLoading: false };
144
- const { queryByText } = render(<SplashScreen {...props} />);
145
-
146
- expect(queryByText("Loading...")).toBeFalsy();
147
- });
148
-
149
- it("uses custom minimum display time", () => {
150
- const onReady = jest.fn();
151
- const props = { ...defaultProps, onReady, minimumDisplayTime: 3000 };
152
-
153
- render(<SplashScreen {...props} />);
154
-
155
- jest.advanceTimersByTime(1500);
156
- expect(onReady).not.toHaveBeenCalled();
157
-
158
- jest.advanceTimersByTime(1500);
159
- expect(onReady).toHaveBeenCalledTimes(1);
160
- });
161
- });