rn-marquee-text 2.0.6 → 2.0.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/README.md +133 -63
- package/dist/MarqueeText.d.ts +110 -3
- package/dist/MarqueeText.js +16 -18
- package/dist/index.d.ts +2 -2
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -27,30 +27,35 @@ npm install rn-marquee-text react-native-reanimated react-native-gesture-handler
|
|
|
27
27
|
|
|
28
28
|
# Using yarn
|
|
29
29
|
yarn add rn-marquee-text react-native-reanimated react-native-gesture-handler
|
|
30
|
-
|
|
31
|
-
Follow Reanimated installation guide
|
|
30
|
+
```
|
|
32
31
|
|
|
33
|
-
|
|
32
|
+
### Peer Dependencies Setup
|
|
33
|
+
- Follow [Reanimated installation guide](https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/installation)
|
|
34
|
+
- Configure [Gesture Handler](https://docs.swmansion.com/react-native-gesture-handler/docs/installation)
|
|
34
35
|
|
|
35
|
-
Basic Usage 🚀
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
## Basic Usage 🚀
|
|
37
|
+
|
|
38
|
+
```jsx
|
|
39
|
+
import Marquee from 'rn-marquee-text';
|
|
38
40
|
|
|
39
41
|
function App() {
|
|
40
42
|
return (
|
|
41
|
-
<MarqueeText
|
|
43
|
+
<Marquee.MarqueeText
|
|
42
44
|
speed={50}
|
|
43
45
|
style={{ height: 40 }}
|
|
44
46
|
textStyle={{ fontSize: 16 }}
|
|
45
47
|
>
|
|
46
48
|
This text will scroll automatically!
|
|
47
|
-
</MarqueeText>
|
|
49
|
+
</Marquee.MarqueeText>
|
|
48
50
|
);
|
|
49
51
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Advanced Usage 🧠
|
|
55
|
+
|
|
56
|
+
### Custom Animation Configuration
|
|
57
|
+
```jsx
|
|
58
|
+
<Marquee.MarqueeText
|
|
54
59
|
mode="bounce"
|
|
55
60
|
direction="vertical"
|
|
56
61
|
speed={30}
|
|
@@ -59,14 +64,16 @@ jsx
|
|
|
59
64
|
spacing={30}
|
|
60
65
|
>
|
|
61
66
|
{yourCustomComponent}
|
|
62
|
-
</MarqueeText>
|
|
63
|
-
|
|
64
|
-
|
|
67
|
+
</Marquee.MarqueeText>
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Imperative Control
|
|
71
|
+
```jsx
|
|
65
72
|
const marqueeRef = useRef(null);
|
|
66
73
|
|
|
67
74
|
// Start/pause programmatically
|
|
68
75
|
<>
|
|
69
|
-
<MarqueeText ref={marqueeRef} />
|
|
76
|
+
<Marquee.MarqueeText ref={marqueeRef} />
|
|
70
77
|
<Button
|
|
71
78
|
title="Toggle"
|
|
72
79
|
onPress={() => marqueeRef.current?.isActive
|
|
@@ -74,37 +81,69 @@ const marqueeRef = useRef(null);
|
|
|
74
81
|
: marqueeRef.current.start()
|
|
75
82
|
}
|
|
76
83
|
/>
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
84
|
+
</>
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## API Reference 📚
|
|
88
|
+
|
|
89
|
+
### Props
|
|
90
|
+
|
|
91
|
+
| Prop | Type | Default | Description |
|
|
92
|
+
|------|------|---------|-------------|
|
|
93
|
+
| `mode` | `'loop' \| 'bounce'` | `'loop'` | Animation behavior |
|
|
94
|
+
| `speed` | `number` | `30` | Scroll speed (px/sec) |
|
|
95
|
+
| `direction` | `'horizontal' \| 'vertical'` | `'horizontal'` | Scroll axis |
|
|
96
|
+
| `delay` | `number` | `1500` | Initial delay (ms) |
|
|
97
|
+
| `endPauseDuration` | `number` | `1000` | Pause duration at end (bounce mode) |
|
|
98
|
+
| `spacing` | `number` | `20` | Space between clones |
|
|
99
|
+
| `enabled` | `boolean` | `true` | Animation state |
|
|
100
|
+
| `withGesture` | `boolean` | `true` | Enable gesture interaction |
|
|
101
|
+
| `reverse` | `boolean` | `false` | Reverse animation direction |
|
|
102
|
+
| `backgroundColor` | `string` | `'transparent'` | Container background color |
|
|
103
|
+
| `frameRate` | `number` | `60` | Animation frame rate |
|
|
104
|
+
| `style` | `ViewStyle` | - | Container style |
|
|
105
|
+
| `textStyle` | `TextStyle` | - | Text style (when children is string) |
|
|
106
|
+
| `onAnimationStart` | `() => void` | - | Animation start callback |
|
|
107
|
+
| `onAnimationStop` | `() => void` | - | Animation stop callback |
|
|
108
|
+
|
|
109
|
+
### Methods (via ref)
|
|
110
|
+
|
|
111
|
+
```typescript
|
|
112
|
+
interface MarqueeTextRef {
|
|
91
113
|
start: () => void;
|
|
92
114
|
stop: () => void;
|
|
93
115
|
isActive: boolean;
|
|
94
116
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## Examples 🎨
|
|
120
|
+
|
|
121
|
+
### News Ticker
|
|
122
|
+
```jsx
|
|
123
|
+
<Marquee.MarqueeText
|
|
99
124
|
style={styles.ticker}
|
|
100
125
|
textStyle={styles.tickerText}
|
|
101
126
|
speed={40}
|
|
102
127
|
>
|
|
103
128
|
BREAKING: React Native Marquee Text released! • New version available • Check out the docs
|
|
104
|
-
</MarqueeText>
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
129
|
+
</Marquee.MarqueeText>
|
|
130
|
+
|
|
131
|
+
const styles = StyleSheet.create({
|
|
132
|
+
ticker: {
|
|
133
|
+
backgroundColor: '#ff0000',
|
|
134
|
+
height: 30,
|
|
135
|
+
},
|
|
136
|
+
tickerText: {
|
|
137
|
+
color: 'white',
|
|
138
|
+
fontSize: 14,
|
|
139
|
+
fontWeight: 'bold',
|
|
140
|
+
},
|
|
141
|
+
});
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### Vertical Product Carousel
|
|
145
|
+
```jsx
|
|
146
|
+
<Marquee.MarqueeText
|
|
108
147
|
direction="vertical"
|
|
109
148
|
mode="bounce"
|
|
110
149
|
speed={20}
|
|
@@ -113,34 +152,65 @@ jsx
|
|
|
113
152
|
<ProductCard {...item1} />
|
|
114
153
|
<ProductCard {...item2} />
|
|
115
154
|
<ProductCard {...item3} />
|
|
116
|
-
</MarqueeText>
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
155
|
+
</Marquee.MarqueeText>
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### Custom Component with High Speed
|
|
159
|
+
```jsx
|
|
160
|
+
<Marquee.MarqueeText
|
|
161
|
+
style={styles.marquee}
|
|
162
|
+
speed={500}
|
|
163
|
+
textStyle={styles.text}
|
|
164
|
+
>
|
|
165
|
+
Smarty was created by the creators of React Native.
|
|
166
|
+
</Marquee.MarqueeText>
|
|
167
|
+
|
|
168
|
+
const styles = StyleSheet.create({
|
|
169
|
+
marquee: {
|
|
170
|
+
width: '100%',
|
|
171
|
+
height: 30,
|
|
172
|
+
},
|
|
173
|
+
text: {
|
|
174
|
+
fontSize: 16,
|
|
175
|
+
color: '#333'
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
## Troubleshooting ⚠️
|
|
181
|
+
|
|
182
|
+
### Animation not smooth?
|
|
183
|
+
- Ensure you're using Reanimated 2+
|
|
184
|
+
- Check for heavy renders in parent components
|
|
185
|
+
- Try reducing the `frameRate` prop
|
|
186
|
+
|
|
187
|
+
### Text not visible?
|
|
188
|
+
- Verify container has explicit dimensions
|
|
189
|
+
- Check text color contrast
|
|
190
|
+
- Ensure `textStyle` is properly applied
|
|
191
|
+
|
|
192
|
+
### Gesture not working?
|
|
193
|
+
- Confirm Gesture Handler installation
|
|
194
|
+
- Wrap root component with `GestureHandlerRootView`
|
|
195
|
+
- Set `withGesture={true}` (default)
|
|
196
|
+
|
|
197
|
+
### Performance Issues?
|
|
198
|
+
- Reduce `speed` for smoother animation
|
|
199
|
+
- Minimize `spacing` to reduce clone count
|
|
200
|
+
- Use `enabled={false}` when not needed
|
|
201
|
+
|
|
202
|
+
## Contributing 🤝
|
|
135
203
|
|
|
136
|
-
Contributing 🤝
|
|
137
204
|
We welcome contributions! Please:
|
|
138
205
|
|
|
139
|
-
Fork the repository
|
|
206
|
+
1. Fork the repository
|
|
207
|
+
2. Create a feature branch
|
|
208
|
+
3. Submit a pull request
|
|
209
|
+
|
|
210
|
+
## License 📄
|
|
140
211
|
|
|
141
|
-
|
|
212
|
+
MIT © PARESH CHAVDA
|
|
142
213
|
|
|
143
|
-
|
|
214
|
+
---
|
|
144
215
|
|
|
145
|
-
|
|
146
|
-
MIT © PARESH CHAVDA
|
|
216
|
+
Made with ❤️ for the React Native community
|
package/dist/MarqueeText.d.ts
CHANGED
|
@@ -1,5 +1,112 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { ViewStyle, TextStyle } from 'react-native';
|
|
3
|
+
/**
|
|
4
|
+
* Animation modes for the marquee text
|
|
5
|
+
*/
|
|
6
|
+
declare enum AnimationMode {
|
|
7
|
+
LOOP = "loop",
|
|
8
|
+
BOUNCE = "bounce"
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Direction of the marquee animation
|
|
12
|
+
*/
|
|
13
|
+
type MarqueeDirection = 'horizontal' | 'vertical';
|
|
14
|
+
/**
|
|
15
|
+
* Props for the MarqueeText component
|
|
16
|
+
*/
|
|
17
|
+
interface MarqueeTextProps {
|
|
18
|
+
/**
|
|
19
|
+
* Content to be scrolled (string or React nodes)
|
|
20
|
+
*/
|
|
21
|
+
children: React.ReactNode;
|
|
22
|
+
/**
|
|
23
|
+
* The animation mode: 'loop' for continuous scrolling or 'bounce' for back-and-forth
|
|
24
|
+
* @default AnimationMode.LOOP
|
|
25
|
+
*/
|
|
26
|
+
mode?: AnimationMode;
|
|
27
|
+
/**
|
|
28
|
+
* Speed of the scrolling animation in pixels per second
|
|
29
|
+
* @default 30
|
|
30
|
+
*/
|
|
31
|
+
speed?: number;
|
|
32
|
+
/**
|
|
33
|
+
* Delay in milliseconds before starting the animation
|
|
34
|
+
* @default 1500
|
|
35
|
+
*/
|
|
36
|
+
delay?: number;
|
|
37
|
+
/**
|
|
38
|
+
* Duration in milliseconds to pause at the end of the content (only for bounce mode)
|
|
39
|
+
* @default 1000
|
|
40
|
+
*/
|
|
41
|
+
endPauseDuration?: number;
|
|
42
|
+
/**
|
|
43
|
+
* Container style
|
|
44
|
+
*/
|
|
45
|
+
style?: ViewStyle;
|
|
46
|
+
/**
|
|
47
|
+
* Text style (when children is a string)
|
|
48
|
+
*/
|
|
49
|
+
textStyle?: TextStyle;
|
|
50
|
+
/**
|
|
51
|
+
* Whether to enable the animation
|
|
52
|
+
* @default true
|
|
53
|
+
*/
|
|
54
|
+
enabled?: boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Direction of scrolling ('horizontal' or 'vertical')
|
|
57
|
+
* @default 'horizontal'
|
|
58
|
+
*/
|
|
59
|
+
direction?: MarqueeDirection;
|
|
60
|
+
/**
|
|
61
|
+
* Spacing between cloned elements
|
|
62
|
+
* @default 20
|
|
63
|
+
*/
|
|
64
|
+
spacing?: number;
|
|
65
|
+
/**
|
|
66
|
+
* Allow user interaction with gesture handling
|
|
67
|
+
* @default true
|
|
68
|
+
*/
|
|
69
|
+
withGesture?: boolean;
|
|
70
|
+
/**
|
|
71
|
+
* Custom frame rate for animation
|
|
72
|
+
*/
|
|
73
|
+
frameRate?: number;
|
|
74
|
+
/**
|
|
75
|
+
* Reverse the animation direction
|
|
76
|
+
* @default false
|
|
77
|
+
*/
|
|
78
|
+
reverse?: boolean;
|
|
79
|
+
/**
|
|
80
|
+
* Background color for the container
|
|
81
|
+
* @default 'transparent'
|
|
82
|
+
*/
|
|
83
|
+
backgroundColor?: string;
|
|
84
|
+
/**
|
|
85
|
+
* Callback when animation starts
|
|
86
|
+
*/
|
|
87
|
+
onAnimationStart?: () => void;
|
|
88
|
+
/**
|
|
89
|
+
* Callback when animation stops
|
|
90
|
+
*/
|
|
91
|
+
onAnimationStop?: () => void;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Reference handle for the MarqueeText component
|
|
95
|
+
*/
|
|
96
|
+
export interface MarqueeTextRef {
|
|
97
|
+
/**
|
|
98
|
+
* Start the marquee animation
|
|
99
|
+
*/
|
|
100
|
+
start: () => void;
|
|
101
|
+
/**
|
|
102
|
+
* Stop the marquee animation
|
|
103
|
+
*/
|
|
104
|
+
stop: () => void;
|
|
105
|
+
/**
|
|
106
|
+
* Whether the animation is currently active
|
|
107
|
+
*/
|
|
108
|
+
isActive: boolean;
|
|
109
|
+
}
|
|
3
110
|
/**
|
|
4
111
|
* MarqueeText component for scrolling text or content
|
|
5
112
|
*
|
|
@@ -8,6 +115,6 @@ import { MarqueeTextRef, MarqueeTextProps, AnimationMode } from './constants';
|
|
|
8
115
|
* modes, and user interaction via gestures.
|
|
9
116
|
*/
|
|
10
117
|
declare const MarqueeText: React.ForwardRefExoticComponent<MarqueeTextProps & React.RefAttributes<MarqueeTextRef>>;
|
|
11
|
-
export default MarqueeText;
|
|
12
118
|
export { AnimationMode };
|
|
13
|
-
export type { MarqueeTextProps };
|
|
119
|
+
export type { MarqueeDirection, MarqueeTextProps };
|
|
120
|
+
export default MarqueeText;
|
package/dist/MarqueeText.js
CHANGED
|
@@ -2,8 +2,14 @@ import * as React from 'react';
|
|
|
2
2
|
import { StyleSheet, View, Text } from 'react-native';
|
|
3
3
|
import { Gesture, GestureDetector } from 'react-native-gesture-handler';
|
|
4
4
|
import Animated, { runOnJS, useAnimatedReaction, useAnimatedStyle, useSharedValue, useFrameCallback, withDecay, } from 'react-native-reanimated';
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Animation modes for the marquee text
|
|
7
|
+
*/
|
|
8
|
+
var AnimationMode;
|
|
9
|
+
(function (AnimationMode) {
|
|
10
|
+
AnimationMode["LOOP"] = "loop";
|
|
11
|
+
AnimationMode["BOUNCE"] = "bounce";
|
|
12
|
+
})(AnimationMode || (AnimationMode = {}));
|
|
7
13
|
/**
|
|
8
14
|
* Component to render a child item in the marquee
|
|
9
15
|
*/
|
|
@@ -121,33 +127,25 @@ var MarqueeText = React.forwardRef(function (_a, ref) {
|
|
|
121
127
|
});
|
|
122
128
|
});
|
|
123
129
|
}, [withGesture, isVertical, anim, start, stop, enabled]);
|
|
124
|
-
// Handle focus/unmount
|
|
125
|
-
useFocusEffect(React.useCallback(function () {
|
|
126
|
-
// Start animation when screen comes into focus
|
|
127
|
-
if (enabled) {
|
|
128
|
-
start();
|
|
129
|
-
}
|
|
130
|
-
return function () {
|
|
131
|
-
// Stop animation when screen loses focus
|
|
132
|
-
stop();
|
|
133
|
-
anim.value = 0;
|
|
134
|
-
};
|
|
135
|
-
}, [start, stop, anim, enabled]));
|
|
136
130
|
// Cleanup on unmount
|
|
137
131
|
React.useEffect(function () {
|
|
138
132
|
return function () {
|
|
139
133
|
isMounted.current = false;
|
|
134
|
+
stop();
|
|
140
135
|
};
|
|
141
|
-
}, []);
|
|
136
|
+
}, [stop]);
|
|
142
137
|
// Start/stop based on enabled prop changes
|
|
143
138
|
React.useEffect(function () {
|
|
144
139
|
if (enabled) {
|
|
145
|
-
|
|
140
|
+
var timer_1 = setTimeout(function () {
|
|
141
|
+
start();
|
|
142
|
+
}, delay);
|
|
143
|
+
return function () { return clearTimeout(timer_1); };
|
|
146
144
|
}
|
|
147
145
|
else {
|
|
148
146
|
stop();
|
|
149
147
|
}
|
|
150
|
-
}, [enabled, start, stop]);
|
|
148
|
+
}, [enabled, start, stop, delay]);
|
|
151
149
|
// Render the content
|
|
152
150
|
var renderContent = function () {
|
|
153
151
|
if (typeof children === 'string') {
|
|
@@ -198,5 +196,5 @@ var styles = StyleSheet.create({
|
|
|
198
196
|
position: 'relative',
|
|
199
197
|
},
|
|
200
198
|
});
|
|
201
|
-
export default MarqueeText;
|
|
202
199
|
export { AnimationMode };
|
|
200
|
+
export default MarqueeText;
|
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export { AnimationMode } from './constants';
|
|
|
3
3
|
declare const Marquee: {
|
|
4
4
|
AutoScroll: ({ children, mode, speed, delay, endPauseDuration, style, textStyle, enabled, direction, }: {
|
|
5
5
|
children: React.ReactNode;
|
|
6
|
-
mode?: AnimationMode;
|
|
6
|
+
mode?: import("./constants").AnimationMode;
|
|
7
7
|
speed?: number;
|
|
8
8
|
delay?: number;
|
|
9
9
|
endPauseDuration?: number;
|
|
@@ -12,7 +12,7 @@ declare const Marquee: {
|
|
|
12
12
|
enabled?: boolean;
|
|
13
13
|
direction?: "horizontal" | "vertical";
|
|
14
14
|
}) => import("react").JSX.Element;
|
|
15
|
-
MarqueeText: import("react").ForwardRefExoticComponent<import("./
|
|
15
|
+
MarqueeText: import("react").ForwardRefExoticComponent<import("./MarqueeText").MarqueeTextProps & import("react").RefAttributes<import("./MarqueeText").MarqueeTextRef>>;
|
|
16
16
|
AnimationMode: typeof AnimationMode;
|
|
17
17
|
};
|
|
18
18
|
export default Marquee;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rn-marquee-text",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.8",
|
|
4
4
|
"description": "A customizable marquee (scrolling) text component for React Native",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
"files": [
|
|
13
13
|
"dist",
|
|
14
14
|
"index.js",
|
|
15
|
-
"README.md"
|
|
15
|
+
"README.md",
|
|
16
|
+
"index.d.ts"
|
|
16
17
|
],
|
|
17
18
|
"keywords": [
|
|
18
19
|
"react-native",
|
|
@@ -52,6 +53,6 @@
|
|
|
52
53
|
"dependencies": {
|
|
53
54
|
"@react-navigation/native": "^7.1.9",
|
|
54
55
|
"react-native-gesture-handler": "^2.25.0",
|
|
55
|
-
"rn-marquee-text": "^1.0.
|
|
56
|
+
"rn-marquee-text": "^1.0.7"
|
|
56
57
|
}
|
|
57
58
|
}
|