rn-marquee-text 2.0.8 → 2.1.0-beta.1
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/dist/MarqueeText.d.ts +3 -3
- package/dist/MarqueeText.js +53 -24
- package/package.json +58 -56
package/dist/MarqueeText.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import * as React from
|
|
2
|
-
import { ViewStyle, TextStyle } from
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { ViewStyle, TextStyle } from "react-native";
|
|
3
3
|
/**
|
|
4
4
|
* Animation modes for the marquee text
|
|
5
5
|
*/
|
|
@@ -10,7 +10,7 @@ declare enum AnimationMode {
|
|
|
10
10
|
/**
|
|
11
11
|
* Direction of the marquee animation
|
|
12
12
|
*/
|
|
13
|
-
type MarqueeDirection =
|
|
13
|
+
type MarqueeDirection = "horizontal" | "vertical";
|
|
14
14
|
/**
|
|
15
15
|
* Props for the MarqueeText component
|
|
16
16
|
*/
|
package/dist/MarqueeText.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import * as React from
|
|
2
|
-
import { StyleSheet, View, Text } from
|
|
3
|
-
import { Gesture, GestureDetector } from
|
|
4
|
-
import Animated, { runOnJS, useAnimatedReaction, useAnimatedStyle, useSharedValue, useFrameCallback, withDecay, } from
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { StyleSheet, View, Text, } from "react-native";
|
|
3
|
+
import { Gesture, GestureDetector } from "react-native-gesture-handler";
|
|
4
|
+
import Animated, { runOnJS, useAnimatedReaction, useAnimatedStyle, useSharedValue, useFrameCallback, withDecay, } from "react-native-reanimated";
|
|
5
5
|
/**
|
|
6
6
|
* Animation modes for the marquee text
|
|
7
7
|
*/
|
|
@@ -17,16 +17,18 @@ var AnimatedChild = React.memo(function (_a) {
|
|
|
17
17
|
var index = _a.index, children = _a.children, anim = _a.anim, contentMeasurement = _a.contentMeasurement, spacing = _a.spacing, direction = _a.direction;
|
|
18
18
|
var style = useAnimatedStyle(function () {
|
|
19
19
|
var _a;
|
|
20
|
-
var isVertical = direction ===
|
|
21
|
-
var dimension = isVertical
|
|
20
|
+
var isVertical = direction === "vertical";
|
|
21
|
+
var dimension = isVertical
|
|
22
|
+
? contentMeasurement.value.height
|
|
23
|
+
: contentMeasurement.value.width;
|
|
22
24
|
if (dimension <= 0)
|
|
23
25
|
return {};
|
|
24
26
|
var position = (index - 1) * (dimension + spacing);
|
|
25
27
|
var translation = -(anim.value % (dimension + spacing));
|
|
26
28
|
return _a = {
|
|
27
|
-
position:
|
|
29
|
+
position: "absolute"
|
|
28
30
|
},
|
|
29
|
-
_a[isVertical ?
|
|
31
|
+
_a[isVertical ? "top" : "left"] = position,
|
|
30
32
|
_a.transform = isVertical
|
|
31
33
|
? [{ translateY: translation }]
|
|
32
34
|
: [{ translateX: translation }],
|
|
@@ -42,8 +44,12 @@ var AnimatedChild = React.memo(function (_a) {
|
|
|
42
44
|
* modes, and user interaction via gestures.
|
|
43
45
|
*/
|
|
44
46
|
var MarqueeText = React.forwardRef(function (_a, ref) {
|
|
45
|
-
var children = _a.children, _b = _a.mode, mode = _b === void 0 ? AnimationMode.LOOP : _b, _c = _a.speed, speed = _c === void 0 ? 30 : _c, _d = _a.delay, delay = _d === void 0 ? 1500 : _d, _e = _a.endPauseDuration, endPauseDuration = _e === void 0 ? 1000 : _e, style = _a.style, textStyle = _a.textStyle, _f = _a.enabled, enabled = _f === void 0 ? true : _f, _g = _a.direction, direction = _g === void 0 ?
|
|
46
|
-
var
|
|
47
|
+
var children = _a.children, _b = _a.mode, mode = _b === void 0 ? AnimationMode.LOOP : _b, _c = _a.speed, speed = _c === void 0 ? 30 : _c, _d = _a.delay, delay = _d === void 0 ? 1500 : _d, _e = _a.endPauseDuration, endPauseDuration = _e === void 0 ? 1000 : _e, style = _a.style, textStyle = _a.textStyle, _f = _a.enabled, enabled = _f === void 0 ? true : _f, _g = _a.direction, direction = _g === void 0 ? "horizontal" : _g, _h = _a.spacing, spacing = _h === void 0 ? 20 : _h, _j = _a.withGesture, withGesture = _j === void 0 ? true : _j, frameRate = _a.frameRate, _k = _a.reverse, reverse = _k === void 0 ? false : _k, _l = _a.backgroundColor, backgroundColor = _l === void 0 ? "transparent" : _l, onAnimationStart = _a.onAnimationStart, onAnimationStop = _a.onAnimationStop;
|
|
48
|
+
var _m = React.useState({
|
|
49
|
+
width: 0,
|
|
50
|
+
height: 0,
|
|
51
|
+
}), contentSize = _m[0], setContentSize = _m[1];
|
|
52
|
+
var isVertical = direction === "vertical";
|
|
47
53
|
var isBounceMode = mode === AnimationMode.BOUNCE;
|
|
48
54
|
var containerMeasurement = useSharedValue({
|
|
49
55
|
width: 0,
|
|
@@ -57,7 +63,7 @@ var MarqueeText = React.forwardRef(function (_a, ref) {
|
|
|
57
63
|
x: 0,
|
|
58
64
|
y: 0,
|
|
59
65
|
});
|
|
60
|
-
var
|
|
66
|
+
var _o = React.useState(0), cloneTimes = _o[0], setCloneTimes = _o[1];
|
|
61
67
|
var anim = useSharedValue(0);
|
|
62
68
|
var isMounted = React.useRef(true);
|
|
63
69
|
var isActive = useSharedValue(false);
|
|
@@ -74,8 +80,12 @@ var MarqueeText = React.forwardRef(function (_a, ref) {
|
|
|
74
80
|
}, false);
|
|
75
81
|
// Calculate how many clones we need to fill the screen
|
|
76
82
|
useAnimatedReaction(function () {
|
|
77
|
-
var contentDim = isVertical
|
|
78
|
-
|
|
83
|
+
var contentDim = isVertical
|
|
84
|
+
? contentMeasurement.value.height
|
|
85
|
+
: contentMeasurement.value.width;
|
|
86
|
+
var containerDim = isVertical
|
|
87
|
+
? containerMeasurement.value.height
|
|
88
|
+
: containerMeasurement.value.width;
|
|
79
89
|
if (contentDim <= 0 || containerDim <= 0)
|
|
80
90
|
return 0;
|
|
81
91
|
// Need enough clones to fill the container plus buffer for continuous scrolling
|
|
@@ -102,7 +112,9 @@ var MarqueeText = React.forwardRef(function (_a, ref) {
|
|
|
102
112
|
React.useImperativeHandle(ref, function () { return ({
|
|
103
113
|
start: start,
|
|
104
114
|
stop: stop,
|
|
105
|
-
get isActive() {
|
|
115
|
+
get isActive() {
|
|
116
|
+
return isActive.value;
|
|
117
|
+
},
|
|
106
118
|
}); });
|
|
107
119
|
// Setup gesture handling
|
|
108
120
|
var pan = React.useMemo(function () {
|
|
@@ -148,7 +160,7 @@ var MarqueeText = React.forwardRef(function (_a, ref) {
|
|
|
148
160
|
}, [enabled, start, stop, delay]);
|
|
149
161
|
// Render the content
|
|
150
162
|
var renderContent = function () {
|
|
151
|
-
if (typeof children ===
|
|
163
|
+
if (typeof children === "string") {
|
|
152
164
|
return <Text style={textStyle}>{children}</Text>;
|
|
153
165
|
}
|
|
154
166
|
return children;
|
|
@@ -156,9 +168,26 @@ var MarqueeText = React.forwardRef(function (_a, ref) {
|
|
|
156
168
|
return (<Animated.View style={[
|
|
157
169
|
styles.container,
|
|
158
170
|
{ backgroundColor: backgroundColor },
|
|
159
|
-
style
|
|
171
|
+
style,
|
|
172
|
+
{
|
|
173
|
+
height: isVertical && contentSize.height > 0
|
|
174
|
+
? contentSize.height
|
|
175
|
+
: isVertical
|
|
176
|
+
? 20 // fallback height
|
|
177
|
+
: undefined,
|
|
178
|
+
width: !isVertical && contentSize.width > 0
|
|
179
|
+
? contentSize.width
|
|
180
|
+
: !isVertical
|
|
181
|
+
? 100 // fallback width
|
|
182
|
+
: undefined,
|
|
183
|
+
},
|
|
160
184
|
]} onLayout={function (ev) {
|
|
161
|
-
|
|
185
|
+
var layout = ev.nativeEvent.layout;
|
|
186
|
+
contentMeasurement.value = layout;
|
|
187
|
+
runOnJS(setContentSize)({
|
|
188
|
+
width: layout.width,
|
|
189
|
+
height: layout.height,
|
|
190
|
+
});
|
|
162
191
|
}} pointerEvents="box-none">
|
|
163
192
|
<GestureDetector gesture={pan}>
|
|
164
193
|
<Animated.View style={isVertical ? styles.column : styles.row} pointerEvents="box-none">
|
|
@@ -168,7 +197,7 @@ var MarqueeText = React.forwardRef(function (_a, ref) {
|
|
|
168
197
|
}}>
|
|
169
198
|
{renderContent()}
|
|
170
199
|
</View>
|
|
171
|
-
|
|
200
|
+
|
|
172
201
|
{/* Visible cloned elements */}
|
|
173
202
|
{cloneTimes > 0 &&
|
|
174
203
|
Array.from({ length: cloneTimes }).map(function (_, index) { return (<AnimatedChild key={"clone-".concat(index)} index={index} anim={anim} contentMeasurement={contentMeasurement} spacing={spacing} direction={direction}>
|
|
@@ -180,20 +209,20 @@ var MarqueeText = React.forwardRef(function (_a, ref) {
|
|
|
180
209
|
});
|
|
181
210
|
var styles = StyleSheet.create({
|
|
182
211
|
container: {
|
|
183
|
-
overflow:
|
|
212
|
+
overflow: "hidden",
|
|
184
213
|
},
|
|
185
214
|
hidden: {
|
|
186
215
|
opacity: 0,
|
|
187
|
-
position:
|
|
216
|
+
position: "absolute",
|
|
188
217
|
zIndex: -1,
|
|
189
218
|
},
|
|
190
219
|
row: {
|
|
191
|
-
flexDirection:
|
|
192
|
-
position:
|
|
220
|
+
flexDirection: "row",
|
|
221
|
+
position: "relative",
|
|
193
222
|
},
|
|
194
223
|
column: {
|
|
195
|
-
flexDirection:
|
|
196
|
-
position:
|
|
224
|
+
flexDirection: "column",
|
|
225
|
+
position: "relative",
|
|
197
226
|
},
|
|
198
227
|
});
|
|
199
228
|
export { AnimationMode };
|
package/package.json
CHANGED
|
@@ -1,58 +1,60 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
"
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
"
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
"
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
"
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
"
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
2
|
+
"name": "rn-marquee-text",
|
|
3
|
+
"version": "2.1.0-beta.1",
|
|
4
|
+
"description": "A customizable marquee (scrolling) text component for React Native",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"types": "index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
9
|
+
"build": "tsc",
|
|
10
|
+
"prepare": "npm run build"
|
|
11
|
+
},
|
|
12
|
+
"publishConfig": {
|
|
13
|
+
"tag": "beta"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"index.js",
|
|
18
|
+
"README.md",
|
|
19
|
+
"index.d.ts"
|
|
20
|
+
],
|
|
21
|
+
"keywords": [
|
|
22
|
+
"react-native",
|
|
23
|
+
"marquee",
|
|
24
|
+
"scrolling-text",
|
|
25
|
+
"text",
|
|
26
|
+
"animation",
|
|
27
|
+
"react-native-component",
|
|
28
|
+
"react",
|
|
29
|
+
"native",
|
|
30
|
+
"expo"
|
|
31
|
+
],
|
|
32
|
+
"author": "Paresh Chavda",
|
|
33
|
+
"license": "MIT",
|
|
34
|
+
"repository": {
|
|
35
|
+
"type": "git",
|
|
36
|
+
"url": "git+https://github.com/pareshchavda/rn-marquee-text-public.git"
|
|
37
|
+
},
|
|
38
|
+
"bugs": {
|
|
39
|
+
"url": "https://github.com/pareshchavda/rn-marquee-text-public/issues"
|
|
40
|
+
},
|
|
41
|
+
"homepage": "https://github.com/pareshchavda/rn-marquee-text-public#readme",
|
|
42
|
+
"peerDependencies": {
|
|
43
|
+
"prop-types": ">=15.0.0",
|
|
44
|
+
"react": "*",
|
|
45
|
+
"react-native": "*",
|
|
46
|
+
"react-native-reanimated": ">=2.0.0"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@types/react": "^19.1.2",
|
|
50
|
+
"prop-types": "^15.8.1",
|
|
51
|
+
"react": "^18.2.0",
|
|
52
|
+
"react-native": "^0.72.17",
|
|
53
|
+
"react-native-reanimated": "^3.17.5",
|
|
54
|
+
"typescript": "^5.0.0"
|
|
55
|
+
},
|
|
56
|
+
"dependencies": {
|
|
57
|
+
"@react-navigation/native": "^7.1.9",
|
|
58
|
+
"react-native-gesture-handler": "^2.25.0"
|
|
59
|
+
}
|
|
58
60
|
}
|