rn-marquee-text 1.0.2 → 1.0.3
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 +2 -3
- package/dist/MarqueeText.js +15 -46
- package/package.json +1 -1
package/dist/MarqueeText.d.ts
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { ViewStyle } from 'react-native';
|
|
3
|
-
|
|
4
|
-
interface MarqueeTextProps {
|
|
3
|
+
export interface MarqueeTextProps {
|
|
5
4
|
text: string;
|
|
6
5
|
speed?: number;
|
|
7
6
|
delay?: number;
|
|
8
7
|
fontSize?: number;
|
|
9
8
|
textColor?: string;
|
|
10
9
|
style?: ViewStyle;
|
|
10
|
+
bounce?: boolean;
|
|
11
11
|
fontFamily?: string;
|
|
12
12
|
pauseDuration?: number;
|
|
13
|
-
mode?: MarqueeMode;
|
|
14
13
|
}
|
|
15
14
|
declare const MarqueeText: React.FC<MarqueeTextProps>;
|
|
16
15
|
export default MarqueeText;
|
package/dist/MarqueeText.js
CHANGED
|
@@ -1,19 +1,8 @@
|
|
|
1
|
-
var __assign = (this && this.__assign) || function () {
|
|
2
|
-
__assign = Object.assign || function(t) {
|
|
3
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
-
s = arguments[i];
|
|
5
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
-
t[p] = s[p];
|
|
7
|
-
}
|
|
8
|
-
return t;
|
|
9
|
-
};
|
|
10
|
-
return __assign.apply(this, arguments);
|
|
11
|
-
};
|
|
12
1
|
import React, { useEffect } from 'react';
|
|
13
|
-
import { View, Text, StyleSheet
|
|
14
|
-
import Animated, { useSharedValue, useAnimatedStyle, withTiming, withRepeat,
|
|
2
|
+
import { View, Text, StyleSheet } from 'react-native';
|
|
3
|
+
import Animated, { useSharedValue, useAnimatedStyle, withTiming, withRepeat, Easing, cancelAnimation, } from 'react-native-reanimated';
|
|
15
4
|
var MarqueeText = function (_a) {
|
|
16
|
-
var text = _a.text, _b = _a.speed, speed = _b === void 0 ? 40 : _b, _c = _a.
|
|
5
|
+
var text = _a.text, _b = _a.speed, speed = _b === void 0 ? 40 : _b, _c = _a.fontSize, fontSize = _c === void 0 ? 16 : _c, _d = _a.textColor, textColor = _d === void 0 ? '#333' : _d, _e = _a.style, style = _e === void 0 ? {} : _e, fontFamily = _a.fontFamily;
|
|
17
6
|
var offset = useSharedValue(0);
|
|
18
7
|
var containerWidth = useSharedValue(0);
|
|
19
8
|
var textWidth = useSharedValue(0);
|
|
@@ -30,44 +19,23 @@ var MarqueeText = function (_a) {
|
|
|
30
19
|
var startAnimation = function () {
|
|
31
20
|
if (textWidth.value <= containerWidth.value)
|
|
32
21
|
return;
|
|
33
|
-
var distance = textWidth.value +
|
|
22
|
+
var distance = textWidth.value + 30;
|
|
34
23
|
var duration = (distance / speed) * 1000;
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}), withTiming(0, {
|
|
40
|
-
duration: duration,
|
|
41
|
-
easing: Easing.linear,
|
|
42
|
-
})), -1, false));
|
|
43
|
-
}
|
|
44
|
-
else if (mode === 'once') {
|
|
45
|
-
offset.value = withDelay(delay, withTiming(-distance, {
|
|
46
|
-
duration: duration,
|
|
47
|
-
easing: Easing.linear,
|
|
48
|
-
}));
|
|
49
|
-
}
|
|
50
|
-
else {
|
|
51
|
-
offset.value = withDelay(delay, withRepeat(withSequence(withTiming(-distance, {
|
|
52
|
-
duration: duration,
|
|
53
|
-
easing: Easing.linear,
|
|
54
|
-
}), withTiming(containerWidth.value, { duration: 0 })), -1, false));
|
|
55
|
-
}
|
|
24
|
+
offset.value = withRepeat(withTiming(-distance, {
|
|
25
|
+
duration: duration,
|
|
26
|
+
easing: Easing.linear,
|
|
27
|
+
}), -1, false);
|
|
56
28
|
};
|
|
57
|
-
var animatedTextStyle = useAnimatedStyle(function () { return ({
|
|
58
|
-
transform: [{ translateX: offset.value }],
|
|
59
|
-
}); });
|
|
60
29
|
useEffect(function () {
|
|
61
|
-
return function () {
|
|
62
|
-
cancelAnimation(offset);
|
|
63
|
-
};
|
|
30
|
+
return function () { return cancelAnimation(offset); };
|
|
64
31
|
}, []);
|
|
65
|
-
var
|
|
32
|
+
var animatedStyle = useAnimatedStyle(function () { return ({
|
|
33
|
+
transform: [{ translateX: offset.value }],
|
|
34
|
+
}); });
|
|
66
35
|
return (<View style={[styles.container, style]} onLayout={onContainerLayout}>
|
|
67
|
-
<Animated.View style={
|
|
68
|
-
<Text style={
|
|
36
|
+
<Animated.View style={animatedStyle}>
|
|
37
|
+
<Text style={[styles.text, { fontSize: fontSize, color: textColor, fontFamily: fontFamily }]} onLayout={onTextLayout}>
|
|
69
38
|
{text}
|
|
70
|
-
{mode === 'loop' && ' '}
|
|
71
39
|
</Text>
|
|
72
40
|
</Animated.View>
|
|
73
41
|
</View>);
|
|
@@ -76,5 +44,6 @@ var styles = StyleSheet.create({
|
|
|
76
44
|
container: {
|
|
77
45
|
overflow: 'hidden',
|
|
78
46
|
},
|
|
47
|
+
text: {},
|
|
79
48
|
});
|
|
80
49
|
export default MarqueeText;
|