react-native-glitter 0.2.0 → 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.
- package/README.md +16 -0
- package/lib/module/index.js +5 -2
- package/lib/typescript/src/index.d.ts +3 -1
- package/package.json +1 -1
- package/src/index.tsx +8 -1
package/README.md
CHANGED
|
@@ -163,6 +163,7 @@ function ControlledGlitter() {
|
|
|
163
163
|
| `easing` | `(value: number) => number` | - | Custom easing function for the animation |
|
|
164
164
|
| `mode` | `'normal' \| 'expand' \| 'shrink'` | `'normal'` | Animation mode for the shimmer line |
|
|
165
165
|
| `position` | `'top' \| 'center' \| 'bottom'` | `'center'` | Position where the line shrinks/expands (for shrink/expand modes) |
|
|
166
|
+
| `direction` | `'left-to-right' \| 'right-to-left'` | `'left-to-right'` | Direction of the shimmer animation |
|
|
166
167
|
|
|
167
168
|
## Examples
|
|
168
169
|
|
|
@@ -222,6 +223,20 @@ function ControlledGlitter() {
|
|
|
222
223
|
</Glitter>
|
|
223
224
|
```
|
|
224
225
|
|
|
226
|
+
### Direction
|
|
227
|
+
|
|
228
|
+
```tsx
|
|
229
|
+
// Left to right (default)
|
|
230
|
+
<Glitter direction="left-to-right">
|
|
231
|
+
<View style={styles.box} />
|
|
232
|
+
</Glitter>
|
|
233
|
+
|
|
234
|
+
// Right to left
|
|
235
|
+
<Glitter direction="right-to-left">
|
|
236
|
+
<View style={styles.box} />
|
|
237
|
+
</Glitter>
|
|
238
|
+
```
|
|
239
|
+
|
|
225
240
|
## TypeScript
|
|
226
241
|
|
|
227
242
|
This library is written in TypeScript and includes type definitions:
|
|
@@ -232,6 +247,7 @@ import {
|
|
|
232
247
|
type GlitterProps,
|
|
233
248
|
type GlitterMode,
|
|
234
249
|
type GlitterPosition,
|
|
250
|
+
type GlitterDirection,
|
|
235
251
|
} from 'react-native-glitter';
|
|
236
252
|
|
|
237
253
|
const customProps: GlitterProps = {
|
package/lib/module/index.js
CHANGED
|
@@ -48,7 +48,7 @@ function generateVerticalSegments(fadeRatioParam) {
|
|
|
48
48
|
}
|
|
49
49
|
return segments;
|
|
50
50
|
}
|
|
51
|
-
export function Glitter({ children, duration = 1500, delay = 400, color = 'rgba(255, 255, 255, 0.8)', angle = 20, shimmerWidth = 60, active = true, style, easing, mode = 'normal', position = 'center', }) {
|
|
51
|
+
export function Glitter({ children, duration = 1500, delay = 400, color = 'rgba(255, 255, 255, 0.8)', angle = 20, shimmerWidth = 60, active = true, style, easing, mode = 'normal', position = 'center', direction = 'left-to-right', }) {
|
|
52
52
|
const animatedValue = useRef(new Animated.Value(0)).current;
|
|
53
53
|
const [containerWidth, setContainerWidth] = useState(0);
|
|
54
54
|
const [containerHeight, setContainerHeight] = useState(0);
|
|
@@ -88,9 +88,12 @@ export function Glitter({ children, duration = 1500, delay = 400, color = 'rgba(
|
|
|
88
88
|
setContainerHeight(height);
|
|
89
89
|
}, []);
|
|
90
90
|
const extraWidth = Math.tan((angle * Math.PI) / 180) * 200;
|
|
91
|
+
const isLeftToRight = direction === 'left-to-right';
|
|
91
92
|
const translateX = animatedValue.interpolate({
|
|
92
93
|
inputRange: [0, 1],
|
|
93
|
-
outputRange:
|
|
94
|
+
outputRange: isLeftToRight
|
|
95
|
+
? [-shimmerWidth - extraWidth, containerWidth + shimmerWidth]
|
|
96
|
+
: [containerWidth + shimmerWidth, -shimmerWidth - extraWidth],
|
|
94
97
|
});
|
|
95
98
|
const heightMultiplier = 1.5;
|
|
96
99
|
const lineHeight = containerHeight * heightMultiplier;
|
|
@@ -2,6 +2,7 @@ import { type ReactNode, type ReactElement } from 'react';
|
|
|
2
2
|
import { type StyleProp, type ViewStyle } from 'react-native';
|
|
3
3
|
export type GlitterMode = 'normal' | 'expand' | 'shrink';
|
|
4
4
|
export type GlitterPosition = 'top' | 'center' | 'bottom';
|
|
5
|
+
export type GlitterDirection = 'left-to-right' | 'right-to-left';
|
|
5
6
|
export interface GlitterProps {
|
|
6
7
|
children: ReactNode;
|
|
7
8
|
duration?: number;
|
|
@@ -14,6 +15,7 @@ export interface GlitterProps {
|
|
|
14
15
|
easing?: (value: number) => number;
|
|
15
16
|
mode?: GlitterMode;
|
|
16
17
|
position?: GlitterPosition;
|
|
18
|
+
direction?: GlitterDirection;
|
|
17
19
|
}
|
|
18
|
-
export declare function Glitter({ children, duration, delay, color, angle, shimmerWidth, active, style, easing, mode, position, }: GlitterProps): ReactElement;
|
|
20
|
+
export declare function Glitter({ children, duration, delay, color, angle, shimmerWidth, active, style, easing, mode, position, direction, }: GlitterProps): ReactElement;
|
|
19
21
|
export default Glitter;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-glitter",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
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
|
@@ -20,6 +20,8 @@ export type GlitterMode = 'normal' | 'expand' | 'shrink';
|
|
|
20
20
|
|
|
21
21
|
export type GlitterPosition = 'top' | 'center' | 'bottom';
|
|
22
22
|
|
|
23
|
+
export type GlitterDirection = 'left-to-right' | 'right-to-left';
|
|
24
|
+
|
|
23
25
|
export interface GlitterProps {
|
|
24
26
|
children: ReactNode;
|
|
25
27
|
duration?: number;
|
|
@@ -32,6 +34,7 @@ export interface GlitterProps {
|
|
|
32
34
|
easing?: (value: number) => number;
|
|
33
35
|
mode?: GlitterMode;
|
|
34
36
|
position?: GlitterPosition;
|
|
37
|
+
direction?: GlitterDirection;
|
|
35
38
|
}
|
|
36
39
|
|
|
37
40
|
function generateGlitterOpacities(count: number, peak: number = 1): number[] {
|
|
@@ -107,6 +110,7 @@ export function Glitter({
|
|
|
107
110
|
easing,
|
|
108
111
|
mode = 'normal',
|
|
109
112
|
position = 'center',
|
|
113
|
+
direction = 'left-to-right',
|
|
110
114
|
}: GlitterProps): ReactElement {
|
|
111
115
|
const animatedValue = useRef(new Animated.Value(0)).current;
|
|
112
116
|
const [containerWidth, setContainerWidth] = useState(0);
|
|
@@ -159,9 +163,12 @@ export function Glitter({
|
|
|
159
163
|
|
|
160
164
|
const extraWidth = Math.tan((angle * Math.PI) / 180) * 200;
|
|
161
165
|
|
|
166
|
+
const isLeftToRight = direction === 'left-to-right';
|
|
162
167
|
const translateX = animatedValue.interpolate({
|
|
163
168
|
inputRange: [0, 1],
|
|
164
|
-
outputRange:
|
|
169
|
+
outputRange: isLeftToRight
|
|
170
|
+
? [-shimmerWidth - extraWidth, containerWidth + shimmerWidth]
|
|
171
|
+
: [containerWidth + shimmerWidth, -shimmerWidth - extraWidth],
|
|
165
172
|
});
|
|
166
173
|
|
|
167
174
|
const heightMultiplier = 1.5;
|