react-native-skelo 0.1.0-alpha.0 → 0.1.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 (68) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +147 -75
  3. package/lib/commonjs/animations/PulseAnimation.js +17 -42
  4. package/lib/commonjs/animations/PulseAnimation.js.map +1 -1
  5. package/lib/commonjs/animations/ShimmerAnimation.js +54 -65
  6. package/lib/commonjs/animations/ShimmerAnimation.js.map +1 -1
  7. package/lib/commonjs/components/Skeleton.js +37 -23
  8. package/lib/commonjs/components/Skeleton.js.map +1 -1
  9. package/lib/commonjs/components/SkeletonProvider.js +38 -0
  10. package/lib/commonjs/components/SkeletonProvider.js.map +1 -0
  11. package/lib/commonjs/components/withSkeleton.js +1 -0
  12. package/lib/commonjs/components/withSkeleton.js.map +1 -1
  13. package/lib/commonjs/core/deepRegistry.js +18 -0
  14. package/lib/commonjs/core/deepRegistry.js.map +1 -0
  15. package/lib/commonjs/core/parser/expandLists.js +67 -0
  16. package/lib/commonjs/core/parser/expandLists.js.map +1 -0
  17. package/lib/commonjs/deep.js +18 -0
  18. package/lib/commonjs/deep.js.map +1 -0
  19. package/lib/commonjs/index.js +8 -0
  20. package/lib/commonjs/index.js.map +1 -1
  21. package/lib/module/animations/PulseAnimation.js +18 -43
  22. package/lib/module/animations/PulseAnimation.js.map +1 -1
  23. package/lib/module/animations/ShimmerAnimation.js +55 -66
  24. package/lib/module/animations/ShimmerAnimation.js.map +1 -1
  25. package/lib/module/components/Skeleton.js +37 -23
  26. package/lib/module/components/Skeleton.js.map +1 -1
  27. package/lib/module/components/SkeletonProvider.js +30 -0
  28. package/lib/module/components/SkeletonProvider.js.map +1 -0
  29. package/lib/module/components/withSkeleton.js +1 -0
  30. package/lib/module/components/withSkeleton.js.map +1 -1
  31. package/lib/module/core/deepRegistry.js +11 -0
  32. package/lib/module/core/deepRegistry.js.map +1 -0
  33. package/lib/module/core/parser/expandLists.js +61 -0
  34. package/lib/module/core/parser/expandLists.js.map +1 -0
  35. package/lib/module/deep.js +11 -0
  36. package/lib/module/deep.js.map +1 -0
  37. package/lib/module/index.js +5 -0
  38. package/lib/module/index.js.map +1 -1
  39. package/lib/typescript/animations/PulseAnimation.d.ts +0 -44
  40. package/lib/typescript/animations/PulseAnimation.d.ts.map +1 -1
  41. package/lib/typescript/animations/ShimmerAnimation.d.ts +0 -44
  42. package/lib/typescript/animations/ShimmerAnimation.d.ts.map +1 -1
  43. package/lib/typescript/components/Skeleton.d.ts +1 -1
  44. package/lib/typescript/components/Skeleton.d.ts.map +1 -1
  45. package/lib/typescript/components/SkeletonProvider.d.ts +10 -0
  46. package/lib/typescript/components/SkeletonProvider.d.ts.map +1 -0
  47. package/lib/typescript/components/withSkeleton.d.ts.map +1 -1
  48. package/lib/typescript/core/deepRegistry.d.ts +7 -0
  49. package/lib/typescript/core/deepRegistry.d.ts.map +1 -0
  50. package/lib/typescript/core/parser/expandLists.d.ts +3 -0
  51. package/lib/typescript/core/parser/expandLists.d.ts.map +1 -0
  52. package/lib/typescript/deep.d.ts +2 -0
  53. package/lib/typescript/deep.d.ts.map +1 -0
  54. package/lib/typescript/index.d.ts +3 -0
  55. package/lib/typescript/index.d.ts.map +1 -1
  56. package/lib/typescript/types/skeleton.d.ts +8 -0
  57. package/lib/typescript/types/skeleton.d.ts.map +1 -1
  58. package/package.json +23 -12
  59. package/src/animations/PulseAnimation.tsx +17 -89
  60. package/src/animations/ShimmerAnimation.tsx +39 -118
  61. package/src/components/Skeleton.tsx +39 -23
  62. package/src/components/SkeletonProvider.tsx +40 -0
  63. package/src/components/withSkeleton.tsx +1 -0
  64. package/src/core/deepRegistry.ts +16 -0
  65. package/src/core/parser/expandLists.tsx +77 -0
  66. package/src/deep.ts +12 -0
  67. package/src/index.ts +6 -0
  68. package/src/types/skeleton.ts +9 -0
@@ -1,77 +1,19 @@
1
- import React, { useEffect } from 'react';
1
+ import React, { useEffect, useRef } from 'react';
2
2
  import type { DimensionValue, StyleProp, ViewStyle } from 'react-native';
3
- import { StyleSheet } from 'react-native';
4
- import Animated, {
5
- useSharedValue,
6
- useAnimatedStyle,
7
- withRepeat,
8
- withSequence,
9
- withTiming,
10
- Easing,
11
- } from 'react-native-reanimated';
3
+ import { Animated, Easing, StyleSheet } from 'react-native';
12
4
 
13
5
  interface PulseProps {
14
- /**
15
- * Width of the pulse container
16
- */
17
6
  width?: DimensionValue;
18
-
19
- /**
20
- * Height of the pulse container
21
- */
22
7
  height?: DimensionValue;
23
-
24
- /**
25
- * Base color of the skeleton
26
- * @default '#E1E9EE'
27
- */
28
8
  baseColor?: string;
29
-
30
- /**
31
- * Highlight color for pulse
32
- * @default '#F2F8FC'
33
- */
34
9
  highlightColor?: string;
35
-
36
- /**
37
- * Animation duration in milliseconds
38
- * @default 1000
39
- */
40
10
  duration?: number;
41
-
42
- /**
43
- * Border radius
44
- */
45
11
  borderRadius?: number;
46
-
47
- /**
48
- * Additional styles
49
- */
50
12
  style?: StyleProp<ViewStyle>;
51
-
52
- /**
53
- * Child content (rendered inside pulse)
54
- */
55
13
  children?: React.ReactNode;
56
14
  }
57
15
 
58
- /**
59
- * Pulse animation component using Reanimated 3
60
- *
61
- * Creates a subtle breathing/pulsing effect using:
62
- * - Shared values for performance
63
- * - Worklets for 60 FPS on UI thread
64
- * - Opacity animation for pulse effect
65
- *
66
- * @example
67
- * ```tsx
68
- * <PulseAnimation
69
- * width={200}
70
- * height={20}
71
- * borderRadius={4}
72
- * />
73
- * ```
74
- */
16
+ // Breathing opacity loop using React Native's built-in Animated (native driver).
75
17
  export function PulseAnimation({
76
18
  width,
77
19
  height,
@@ -81,48 +23,34 @@ export function PulseAnimation({
81
23
  style,
82
24
  children,
83
25
  }: PulseProps) {
84
- // Shared value for opacity (0 to 1)
85
- const opacity = useSharedValue(1);
26
+ const opacity = useRef(new Animated.Value(1)).current;
86
27
 
87
28
  useEffect(() => {
88
- // Start infinite pulse animation
89
- // Sequence: fade out -> fade in
90
- opacity.value = withRepeat(
91
- withSequence(
92
- withTiming(0.5, {
29
+ const loop = Animated.loop(
30
+ Animated.sequence([
31
+ Animated.timing(opacity, {
32
+ toValue: 0.5,
93
33
  duration: duration / 2,
94
34
  easing: Easing.inOut(Easing.ease),
35
+ useNativeDriver: true,
95
36
  }),
96
- withTiming(1, {
37
+ Animated.timing(opacity, {
38
+ toValue: 1,
97
39
  duration: duration / 2,
98
40
  easing: Easing.inOut(Easing.ease),
99
- })
100
- ),
101
- -1, // Infinite repeat
102
- false // Don't reverse
41
+ useNativeDriver: true,
42
+ }),
43
+ ])
103
44
  );
45
+ loop.start();
46
+ return () => loop.stop();
104
47
  }, [duration, opacity]);
105
48
 
106
- // Animated style for pulse effect
107
- const animatedStyle = useAnimatedStyle(() => {
108
- 'worklet';
109
-
110
- return {
111
- opacity: opacity.value,
112
- };
113
- }, []);
114
-
115
49
  return (
116
50
  <Animated.View
117
51
  style={[
118
52
  styles.container,
119
- {
120
- width,
121
- height,
122
- borderRadius,
123
- backgroundColor: baseColor,
124
- },
125
- animatedStyle,
53
+ { width, height, borderRadius, backgroundColor: baseColor, opacity },
126
54
  style,
127
55
  ]}
128
56
  >
@@ -1,78 +1,21 @@
1
- import React, { useEffect } from 'react';
2
- import type { DimensionValue, StyleProp, ViewStyle } from 'react-native';
3
- import { StyleSheet, View } from 'react-native';
4
- import Animated, {
5
- useSharedValue,
6
- useAnimatedStyle,
7
- withRepeat,
8
- withTiming,
9
- interpolate,
10
- Easing,
11
- } from 'react-native-reanimated';
12
- import { LinearGradient } from 'react-native-linear-gradient';
1
+ import React, { useEffect, useRef, useState } from 'react';
2
+ import type { DimensionValue, LayoutChangeEvent, StyleProp, ViewStyle } from 'react-native';
3
+ import { Animated, Easing, StyleSheet, View } from 'react-native';
13
4
 
14
5
  interface ShimmerProps {
15
- /**
16
- * Width of the shimmer container
17
- */
18
6
  width?: DimensionValue;
19
-
20
- /**
21
- * Height of the shimmer container
22
- */
23
7
  height?: DimensionValue;
24
-
25
- /**
26
- * Base color of the skeleton
27
- * @default '#E1E9EE'
28
- */
29
8
  baseColor?: string;
30
-
31
- /**
32
- * Highlight color that shimmers across
33
- * @default '#F2F8FC'
34
- */
35
9
  highlightColor?: string;
36
-
37
- /**
38
- * Animation duration in milliseconds
39
- * @default 1500
40
- */
41
10
  duration?: number;
42
-
43
- /**
44
- * Border radius
45
- */
46
11
  borderRadius?: number;
47
-
48
- /**
49
- * Additional styles
50
- */
51
12
  style?: StyleProp<ViewStyle>;
52
-
53
- /**
54
- * Child content (rendered on top of shimmer)
55
- */
56
13
  children?: React.ReactNode;
57
14
  }
58
15
 
59
- /**
60
- * Shimmer animation component using Reanimated 3
61
- *
62
- * Creates a smooth left-to-right shimmer effect using:
63
- * - Shared values for performance
64
- * - Worklets for 60 FPS on UI thread
65
- * - Linear gradient for shimmer effect
66
- *
67
- * @example
68
- * ```tsx
69
- * <ShimmerAnimation
70
- * width={200}
71
- * height={20}
72
- * borderRadius={4}
73
- * />
74
- * ```
75
- */
16
+ // Zero-dependency shimmer: a highlight band (dim/bright/dim segments to fake a
17
+ // soft gradient) sweeps across the base, driven by React Native's built-in
18
+ // Animated native driver. Plain Views only — guaranteed to render and animate.
76
19
  export function ShimmerAnimation({
77
20
  width,
78
21
  height,
@@ -83,77 +26,49 @@ export function ShimmerAnimation({
83
26
  style,
84
27
  children,
85
28
  }: ShimmerProps) {
86
- // Shared value for animation progress (0 to 1)
87
- const progress = useSharedValue(0);
29
+ const progress = useRef(new Animated.Value(0)).current;
30
+ const [measuredWidth, setMeasuredWidth] = useState(0);
88
31
 
89
32
  useEffect(() => {
90
- // Start infinite shimmer animation
91
- progress.value = withRepeat(
92
- withTiming(1, {
33
+ const loop = Animated.loop(
34
+ Animated.timing(progress, {
35
+ toValue: 1,
93
36
  duration,
94
37
  easing: Easing.linear,
95
- }),
96
- -1, // Infinite repeat
97
- false // Don't reverse
38
+ useNativeDriver: true,
39
+ })
98
40
  );
41
+ loop.start();
42
+ return () => loop.stop();
99
43
  }, [duration, progress]);
100
44
 
101
- // Animated style for shimmer overlay
102
- const animatedStyle = useAnimatedStyle(() => {
103
- 'worklet';
45
+ const onLayout = (event: LayoutChangeEvent) => {
46
+ const w = event.nativeEvent.layout.width;
47
+ setMeasuredWidth(prev => (prev === w ? prev : w));
48
+ };
104
49
 
105
- // Calculate shimmer position
106
- // Interpolate from -100% to 100% to create left-to-right sweep
107
- const translateX = interpolate(progress.value, [0, 1], [-1, 1]);
50
+ const containerWidth = typeof width === 'number' ? width : measuredWidth || 200;
51
+ const bandWidth = Math.max(containerWidth * 0.6, 80);
108
52
 
109
- return {
110
- transform: [{ translateX: translateX * (typeof width === 'number' ? width : 200) }],
111
- };
112
- }, [width]);
53
+ const translateX = progress.interpolate({
54
+ inputRange: [0, 1],
55
+ outputRange: [-bandWidth, containerWidth],
56
+ });
113
57
 
114
58
  return (
115
59
  <View
116
- style={[
117
- styles.container,
118
- {
119
- width,
120
- height,
121
- borderRadius,
122
- backgroundColor: baseColor,
123
- },
124
- style,
125
- ]}
60
+ onLayout={onLayout}
61
+ style={[styles.container, { width, height, borderRadius, backgroundColor: baseColor }, style]}
126
62
  >
127
- {/* Shimmer gradient overlay */}
128
63
  <Animated.View
129
- style={[
130
- StyleSheet.absoluteFill,
131
- {
132
- overflow: 'hidden',
133
- borderRadius,
134
- },
135
- ]}
64
+ pointerEvents="none"
65
+ style={[styles.band, { width: bandWidth, transform: [{ translateX }] }]}
136
66
  >
137
- <Animated.View
138
- style={[
139
- styles.shimmer,
140
- {
141
- width: typeof width === 'number' ? width : '100%',
142
- height: '100%',
143
- },
144
- animatedStyle,
145
- ]}
146
- >
147
- <LinearGradient
148
- colors={[baseColor, highlightColor, highlightColor, baseColor]}
149
- start={{ x: 0, y: 0 }}
150
- end={{ x: 1, y: 0 }}
151
- style={StyleSheet.absoluteFill}
152
- />
153
- </Animated.View>
67
+ <View style={[styles.segment, { backgroundColor: highlightColor, opacity: 0.25 }]} />
68
+ <View style={[styles.segment, { backgroundColor: highlightColor, opacity: 0.9 }]} />
69
+ <View style={[styles.segment, { backgroundColor: highlightColor, opacity: 0.25 }]} />
154
70
  </Animated.View>
155
71
 
156
- {/* Child content */}
157
72
  {children}
158
73
  </View>
159
74
  );
@@ -163,7 +78,13 @@ const styles = StyleSheet.create({
163
78
  container: {
164
79
  overflow: 'hidden',
165
80
  },
166
- shimmer: {
81
+ band: {
167
82
  position: 'absolute',
83
+ top: 0,
84
+ bottom: 0,
85
+ flexDirection: 'row',
86
+ },
87
+ segment: {
88
+ flex: 1,
168
89
  },
169
90
  });
@@ -4,8 +4,9 @@ import { Parser } from '../core/parser';
4
4
  import { SkeletonRenderer } from './SkeletonRenderer';
5
5
  import { SkeletonIgnore } from './SkeletonIgnore';
6
6
  import { StyleSkeleton } from '../core/generator/StyleSkeleton';
7
- import { expandToComponentNodes } from '../core/parser/expandOffline';
8
- import { DEFAULT_CONFIG } from '../constants/defaults';
7
+ import { getDeepExpander } from '../core/deepRegistry';
8
+ import { expandListPlaceholders } from '../core/parser/expandLists';
9
+ import { useSkeletonTheme } from './SkeletonProvider';
9
10
 
10
11
  /**
11
12
  * Main Skeleton component
@@ -35,21 +36,24 @@ import { DEFAULT_CONFIG } from '../constants/defaults';
35
36
  * </Skeleton>
36
37
  * ```
37
38
  */
38
- export function Skeleton({
39
- loading,
40
- children,
41
- styles,
42
- excludeStyles,
43
- deep = false,
44
- animation = DEFAULT_CONFIG.animation,
45
- duration = DEFAULT_CONFIG.duration,
46
- baseColor = DEFAULT_CONFIG.baseColor,
47
- highlightColor = DEFAULT_CONFIG.highlightColor,
48
- borderRadius = DEFAULT_CONFIG.borderRadius,
49
- accessible = true,
50
- accessibilityLabel = 'Loading content',
51
- debug = false,
52
- }: SkeletonProps) {
39
+ export function Skeleton(props: SkeletonProps) {
40
+ const theme = useSkeletonTheme();
41
+ const {
42
+ loading,
43
+ children,
44
+ styles,
45
+ excludeStyles,
46
+ deep,
47
+ count = 6,
48
+ animation = theme.animation,
49
+ duration = theme.duration,
50
+ baseColor = theme.baseColor,
51
+ highlightColor = theme.highlightColor,
52
+ borderRadius = theme.borderRadius,
53
+ accessible = true,
54
+ accessibilityLabel = 'Loading content',
55
+ debug = theme.debug,
56
+ } = props;
53
57
  // Parse component tree and generate skeleton.
54
58
  // Hooks must run unconditionally (rules of hooks), but parsing stays lazy:
55
59
  // we skip the work entirely when not loading or in styles-driven mode.
@@ -63,19 +67,31 @@ export function Skeleton({
63
67
  }
64
68
 
65
69
  try {
66
- // Deep mode: expand opaque components into their real host tree by
67
- // rendering them offline. Falls back to static parsing on failure.
68
- if (deep) {
69
- const expanded = expandToComponentNodes(<>{children}</>);
70
+ // Turn FlatList/SectionList into placeholder rows so lists show a
71
+ // skeleton even though their data (and rows) don't exist yet.
72
+ const prepared = expandListPlaceholders(children, count);
73
+
74
+ // Deep mode: expand opaque components into their real host tree via the
75
+ // opt-in expander (registered by importing 'react-native-skelo/deep').
76
+ // When `deep` is not set explicitly, it's used automatically whenever the
77
+ // expander is available. Falls back to static parsing otherwise.
78
+ const expand = getDeepExpander();
79
+ const wantDeep = deep === undefined ? expand !== null : deep;
80
+ if (wantDeep && expand) {
81
+ const expanded = expand(<>{prepared}</>);
70
82
  if (expanded && expanded.length > 0) {
71
83
  return expanded;
72
84
  }
73
85
  if (__DEV__) {
74
86
  console.warn('[Skelo] deep expansion returned nothing; falling back to static parsing.');
75
87
  }
88
+ } else if (deep === true && !expand && __DEV__) {
89
+ console.warn(
90
+ "[Skelo] `deep` requires react-reconciler. Install it and add `import 'react-native-skelo/deep';` in your app entry."
91
+ );
76
92
  }
77
93
 
78
- const parsed = Parser.parse(children);
94
+ const parsed = Parser.parse(prepared);
79
95
 
80
96
  if (__DEV__ && debug) {
81
97
  // Log a lightweight summary: the raw nodes hold React elements
@@ -96,7 +112,7 @@ export function Skeleton({
96
112
  }
97
113
  return [];
98
114
  }
99
- }, [loading, styles, deep, children, debug]);
115
+ }, [loading, styles, deep, count, children, debug]);
100
116
 
101
117
  // Create skeleton config
102
118
  const config = useMemo(
@@ -0,0 +1,40 @@
1
+ import React, { createContext, useContext, useMemo } from 'react';
2
+ import type { ReactNode } from 'react';
3
+ import type { SkeletonConfig } from '../types';
4
+ import { DEFAULT_CONFIG } from '../constants/defaults';
5
+
6
+ const SkeletonThemeContext = createContext<Required<SkeletonConfig>>(DEFAULT_CONFIG);
7
+
8
+ export interface SkeletonProviderProps extends SkeletonConfig {
9
+ children: ReactNode;
10
+ }
11
+
12
+ /** App-wide skeleton defaults. Nested providers inherit unspecified values. */
13
+ export function SkeletonProvider({
14
+ children,
15
+ animation,
16
+ duration,
17
+ baseColor,
18
+ highlightColor,
19
+ borderRadius,
20
+ debug,
21
+ }: SkeletonProviderProps) {
22
+ const parent = useContext(SkeletonThemeContext);
23
+ const value = useMemo(
24
+ () => ({
25
+ animation: animation ?? parent.animation,
26
+ duration: duration ?? parent.duration,
27
+ baseColor: baseColor ?? parent.baseColor,
28
+ highlightColor: highlightColor ?? parent.highlightColor,
29
+ borderRadius: borderRadius ?? parent.borderRadius,
30
+ debug: debug ?? parent.debug,
31
+ }),
32
+ [parent, animation, duration, baseColor, highlightColor, borderRadius, debug]
33
+ );
34
+
35
+ return <SkeletonThemeContext.Provider value={value}>{children}</SkeletonThemeContext.Provider>;
36
+ }
37
+
38
+ export function useSkeletonTheme() {
39
+ return useContext(SkeletonThemeContext);
40
+ }
@@ -44,6 +44,7 @@ export function withSkeleton<P extends object>(
44
44
  loading={loading}
45
45
  styles={options.styles}
46
46
  excludeStyles={options.excludeStyles}
47
+ debug={options.debug}
47
48
  animation={options.animation}
48
49
  duration={options.duration}
49
50
  baseColor={options.baseColor}
@@ -0,0 +1,16 @@
1
+ import type { ReactElement } from 'react';
2
+ import type { ComponentNode } from '../types';
3
+
4
+ // Deep expansion is opt-in so the core bundle never depends on react-reconciler.
5
+ // `react-native-skelo/deep` registers the expander; Skeleton reads it here.
6
+ type DeepExpander = (element: ReactElement) => ComponentNode[] | null;
7
+
8
+ let expander: DeepExpander | null = null;
9
+
10
+ export function setDeepExpander(fn: DeepExpander): void {
11
+ expander = fn;
12
+ }
13
+
14
+ export function getDeepExpander(): DeepExpander | null {
15
+ return expander;
16
+ }
@@ -0,0 +1,77 @@
1
+ import React, { isValidElement } from 'react';
2
+ import type { ReactElement, ReactNode } from 'react';
3
+ import { View } from 'react-native';
4
+ import { getComponentName } from '../../utils/componentUtils';
5
+
6
+ // List components whose rows come from `renderItem` (not JSX children).
7
+ const LIST_TYPES = new Set(['FlatList', 'SectionList', 'VirtualizedList', 'FlashList']);
8
+
9
+ const NOOP_SEPARATORS = {
10
+ highlight: () => {},
11
+ unhighlight: () => {},
12
+ updateProps: () => {},
13
+ };
14
+
15
+ // Renders `count` sample rows from a list's `renderItem` so there's something
16
+ // to skeletonize while the real data is still loading (the rows don't exist in
17
+ // the tree yet). Rows that throw on placeholder data are skipped.
18
+ function renderSampleRows(list: ReactElement, count: number): ReactNode {
19
+ const props = (list.props || {}) as {
20
+ renderItem?: (info: {
21
+ item: unknown;
22
+ index: number;
23
+ section?: unknown;
24
+ separators: typeof NOOP_SEPARATORS;
25
+ }) => ReactNode;
26
+ data?: unknown[];
27
+ contentContainerStyle?: unknown;
28
+ };
29
+
30
+ const data = Array.isArray(props.data) ? props.data : [];
31
+ const sample = data.length > 0 ? data[0] : {};
32
+
33
+ const rows: ReactNode[] = [];
34
+ for (let i = 0; i < count; i++) {
35
+ try {
36
+ const row = props.renderItem?.({
37
+ item: sample,
38
+ index: i,
39
+ section: {},
40
+ separators: NOOP_SEPARATORS,
41
+ });
42
+ if (row) {
43
+ rows.push(<React.Fragment key={i}>{row}</React.Fragment>);
44
+ }
45
+ } catch {
46
+ // Row couldn't render with placeholder data — skip it.
47
+ }
48
+ }
49
+
50
+ return <View style={props.contentContainerStyle as never}>{rows}</View>;
51
+ }
52
+
53
+ // Walks a child tree and replaces FlatList/SectionList with sample rows so a
54
+ // plain `<Skeleton><FlatList/></Skeleton>` produces a skeleton while loading.
55
+ export function expandListPlaceholders(children: ReactNode, count: number): ReactNode {
56
+ return React.Children.map(children, child => {
57
+ if (!isValidElement(child)) {
58
+ return child;
59
+ }
60
+
61
+ const name = getComponentName(child);
62
+ const props = (child.props || {}) as { children?: ReactNode };
63
+
64
+ if (
65
+ LIST_TYPES.has(name) &&
66
+ typeof (props as { renderItem?: unknown }).renderItem === 'function'
67
+ ) {
68
+ return renderSampleRows(child, count);
69
+ }
70
+
71
+ if (props.children) {
72
+ return React.cloneElement(child, undefined, expandListPlaceholders(props.children, count));
73
+ }
74
+
75
+ return child;
76
+ });
77
+ }
package/src/deep.ts ADDED
@@ -0,0 +1,12 @@
1
+ // Opt-in deep mode. Import once in your app entry to enable `<Skeleton deep>`:
2
+ //
3
+ // import 'react-native-skelo/deep';
4
+ //
5
+ // This is the only module that pulls in react-reconciler, so apps that don't
6
+ // use deep mode never bundle it. Requires `react-reconciler` to be installed.
7
+ import { setDeepExpander } from './core/deepRegistry';
8
+ import { expandToComponentNodes } from './core/parser/expandOffline';
9
+
10
+ setDeepExpander(expandToComponentNodes);
11
+
12
+ export const deepEnabled = true;
package/src/index.ts CHANGED
@@ -6,7 +6,13 @@
6
6
  * @packageDocumentation
7
7
  */
8
8
 
9
+ // Auto-register deep expansion (react-reconciler ships as a dependency), so
10
+ // `<Skeleton deep>` / opaque components work with zero setup.
11
+ import './deep';
12
+
9
13
  // Main component
14
+ export { SkeletonProvider } from './components/SkeletonProvider';
15
+ export type { SkeletonProviderProps } from './components/SkeletonProvider';
10
16
  export { Skeleton } from './components/Skeleton';
11
17
  export { SkeletonIgnore } from './components/SkeletonIgnore';
12
18
  export { withSkeleton } from './components/withSkeleton';
@@ -79,6 +79,15 @@ export interface SkeletonProps {
79
79
  */
80
80
  excludeStyles?: string[];
81
81
 
82
+ /**
83
+ * Number of placeholder rows to render for a `FlatList` / `SectionList`
84
+ * while its data is still loading (its rows don't exist yet, so Skelo calls
85
+ * `renderItem` with a placeholder and repeats it `count` times).
86
+ *
87
+ * @default 6
88
+ */
89
+ count?: number;
90
+
82
91
  /**
83
92
  * Deep mode: expand opaque (custom) child components into their real
84
93
  * host-element tree via offline rendering, producing a structured skeleton