react-native-glitter 1.0.6 → 1.0.7
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/lib/module/index.js +13 -5
- package/package.json +1 -1
- package/src/index.tsx +18 -5
package/lib/module/index.js
CHANGED
|
@@ -208,7 +208,9 @@ function GlitterComponent({ children, duration = 1500, delay = 400, color = 'rgb
|
|
|
208
208
|
}
|
|
209
209
|
return position === 'top' ? -halfHeight : halfHeight;
|
|
210
210
|
}, [mode, position, halfHeight]);
|
|
211
|
-
|
|
211
|
+
// Optimized: reduced layer count for better performance
|
|
212
|
+
// shimmerWidth=60 → 12 layers (was 20), shimmerWidth=100 → 14 layers (was 33)
|
|
213
|
+
const layerCount = useMemo(() => Math.max(7, Math.round(shimmerWidth / 5)), [shimmerWidth]);
|
|
212
214
|
const layerWidth = useMemo(() => shimmerWidth / layerCount, [shimmerWidth, layerCount]);
|
|
213
215
|
const horizontalOpacities = useMemo(() => generateGlitterOpacities(layerCount, 1), [layerCount]);
|
|
214
216
|
const shimmerLayers = useMemo(() => horizontalOpacities.map((opacity, index) => ({
|
|
@@ -217,6 +219,12 @@ function GlitterComponent({ children, duration = 1500, delay = 400, color = 'rgb
|
|
|
217
219
|
})), [horizontalOpacities, layerWidth, shimmerWidth]);
|
|
218
220
|
const isAnimated = mode !== 'normal';
|
|
219
221
|
const segments = isAnimated ? ANIMATED_SEGMENTS : NORMAL_SEGMENTS;
|
|
222
|
+
// Memoize segment styles to avoid creating new objects on every render
|
|
223
|
+
const segmentStyles = useMemo(() => segments.map((segment) => ({
|
|
224
|
+
height: lineHeight * segment.heightRatio,
|
|
225
|
+
backgroundColor: color,
|
|
226
|
+
baseOpacity: segment.opacity,
|
|
227
|
+
})), [segments, lineHeight, color]);
|
|
220
228
|
const shimmerContainerStyle = useMemo(() => [styles.shimmerContainer, { transform: [{ translateX }] }], [translateX]);
|
|
221
229
|
const rotationWrapperStyle = useMemo(() => [
|
|
222
230
|
styles.rotationWrapper,
|
|
@@ -246,12 +254,12 @@ function GlitterComponent({ children, duration = 1500, delay = 400, color = 'rgb
|
|
|
246
254
|
return (_jsxs(View, { style: [styles.container, style], onLayout: onLayout, testID: testID, accessibilityLabel: accessibilityLabel, accessible: accessible, children: [children, active &&
|
|
247
255
|
!reduceMotionEnabled &&
|
|
248
256
|
containerWidth > 0 &&
|
|
249
|
-
containerHeight > 0 && (_jsx(Animated.View, { style: shimmerContainerStyle, pointerEvents: "none", children: _jsx(View, { style: rotationWrapperStyle, children: shimmerLayers.map((layer, layerIndex) => (_jsx(Animated.View, { style: getShimmerLineStyle(layer.position), children:
|
|
257
|
+
containerHeight > 0 && (_jsx(Animated.View, { style: shimmerContainerStyle, pointerEvents: "none", children: _jsx(View, { style: rotationWrapperStyle, children: shimmerLayers.map((layer, layerIndex) => (_jsx(Animated.View, { style: getShimmerLineStyle(layer.position), children: segmentStyles.map((segmentStyle, vIndex) => (_jsx(View, { style: [
|
|
250
258
|
styles.segment,
|
|
251
259
|
{
|
|
252
|
-
height:
|
|
253
|
-
backgroundColor:
|
|
254
|
-
opacity: layer.opacity *
|
|
260
|
+
height: segmentStyle.height,
|
|
261
|
+
backgroundColor: segmentStyle.backgroundColor,
|
|
262
|
+
opacity: layer.opacity * segmentStyle.baseOpacity,
|
|
255
263
|
},
|
|
256
264
|
] }, vIndex))) }, layerIndex))) }) }))] }));
|
|
257
265
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-glitter",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"description": "A beautiful shimmer/glitter effect component for React Native. Add a sparkling diagonal shine animation to any component!",
|
|
5
5
|
"main": "./lib/module/index.js",
|
|
6
6
|
"types": "./lib/typescript/src/index.d.ts",
|
package/src/index.tsx
CHANGED
|
@@ -518,8 +518,10 @@ function GlitterComponent(
|
|
|
518
518
|
return position === 'top' ? -halfHeight : halfHeight;
|
|
519
519
|
}, [mode, position, halfHeight]);
|
|
520
520
|
|
|
521
|
+
// Optimized: reduced layer count for better performance
|
|
522
|
+
// shimmerWidth=60 → 12 layers (was 20), shimmerWidth=100 → 14 layers (was 33)
|
|
521
523
|
const layerCount = useMemo(
|
|
522
|
-
() => Math.max(
|
|
524
|
+
() => Math.max(7, Math.round(shimmerWidth / 5)),
|
|
523
525
|
[shimmerWidth]
|
|
524
526
|
);
|
|
525
527
|
|
|
@@ -545,6 +547,17 @@ function GlitterComponent(
|
|
|
545
547
|
const isAnimated = mode !== 'normal';
|
|
546
548
|
const segments = isAnimated ? ANIMATED_SEGMENTS : NORMAL_SEGMENTS;
|
|
547
549
|
|
|
550
|
+
// Memoize segment styles to avoid creating new objects on every render
|
|
551
|
+
const segmentStyles = useMemo(
|
|
552
|
+
() =>
|
|
553
|
+
segments.map((segment) => ({
|
|
554
|
+
height: lineHeight * segment.heightRatio,
|
|
555
|
+
backgroundColor: color,
|
|
556
|
+
baseOpacity: segment.opacity,
|
|
557
|
+
})),
|
|
558
|
+
[segments, lineHeight, color]
|
|
559
|
+
);
|
|
560
|
+
|
|
548
561
|
const shimmerContainerStyle = useMemo(
|
|
549
562
|
() => [styles.shimmerContainer, { transform: [{ translateX }] }],
|
|
550
563
|
[translateX]
|
|
@@ -603,15 +616,15 @@ function GlitterComponent(
|
|
|
603
616
|
key={layerIndex}
|
|
604
617
|
style={getShimmerLineStyle(layer.position)}
|
|
605
618
|
>
|
|
606
|
-
{
|
|
619
|
+
{segmentStyles.map((segmentStyle, vIndex) => (
|
|
607
620
|
<View
|
|
608
621
|
key={vIndex}
|
|
609
622
|
style={[
|
|
610
623
|
styles.segment,
|
|
611
624
|
{
|
|
612
|
-
height:
|
|
613
|
-
backgroundColor:
|
|
614
|
-
opacity: layer.opacity *
|
|
625
|
+
height: segmentStyle.height,
|
|
626
|
+
backgroundColor: segmentStyle.backgroundColor,
|
|
627
|
+
opacity: layer.opacity * segmentStyle.baseOpacity,
|
|
615
628
|
},
|
|
616
629
|
]}
|
|
617
630
|
/>
|