rn-marquee-text 1.0.2 → 1.0.4

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.
@@ -1,16 +1,10 @@
1
1
  import React from 'react';
2
- import { ViewStyle } from 'react-native';
3
- type MarqueeMode = 'loop' | 'bounce' | 'once';
4
- interface MarqueeTextProps {
2
+ import { TextStyle } from 'react-native';
3
+ import { ViewStyle } from 'react-native/Libraries/StyleSheet/StyleSheetTypes';
4
+ declare const MarqueeText: ({ text, speed, containerStyle, textStyle }: {
5
5
  text: string;
6
6
  speed?: number;
7
- delay?: number;
8
- fontSize?: number;
9
- textColor?: string;
10
- style?: ViewStyle;
11
- fontFamily?: string;
12
- pauseDuration?: number;
13
- mode?: MarqueeMode;
14
- }
15
- declare const MarqueeText: React.FC<MarqueeTextProps>;
7
+ containerStyle?: ViewStyle;
8
+ textStyle?: TextStyle;
9
+ }) => React.JSX.Element;
16
10
  export default MarqueeText;
@@ -1,73 +1,48 @@
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
- import React, { useEffect } from 'react';
13
- import { View, Text, StyleSheet, } from 'react-native';
14
- import Animated, { useSharedValue, useAnimatedStyle, withTiming, withRepeat, withSequence, withDelay, cancelAnimation, Easing, } from 'react-native-reanimated';
1
+ import React, { useRef, useEffect, useState } from 'react';
2
+ import { Animated, View, Text, StyleSheet, } from 'react-native';
15
3
  var MarqueeText = function (_a) {
16
- var text = _a.text, _b = _a.speed, speed = _b === void 0 ? 40 : _b, _c = _a.delay, delay = _c === void 0 ? 1000 : _c, _d = _a.fontSize, fontSize = _d === void 0 ? 16 : _d, _e = _a.textColor, textColor = _e === void 0 ? '#333333' : _e, _f = _a.style, style = _f === void 0 ? {} : _f, fontFamily = _a.fontFamily, _g = _a.mode, mode = _g === void 0 ? 'loop' : _g;
17
- var offset = useSharedValue(0);
18
- var containerWidth = useSharedValue(0);
19
- var textWidth = useSharedValue(0);
20
- var onContainerLayout = function (event) {
21
- containerWidth.value = event.nativeEvent.layout.width;
22
- if (textWidth.value > 0)
23
- startAnimation();
24
- };
25
- var onTextLayout = function (event) {
26
- textWidth.value = event.nativeEvent.layout.width;
27
- if (containerWidth.value > 0)
28
- startAnimation();
29
- };
30
- var startAnimation = function () {
31
- if (textWidth.value <= containerWidth.value)
32
- return;
33
- var distance = textWidth.value + containerWidth.value / 3;
34
- var duration = (distance / speed) * 1000;
35
- if (mode === 'bounce') {
36
- offset.value = withDelay(delay, withRepeat(withSequence(withTiming(-distance, {
37
- duration: duration,
38
- easing: Easing.linear,
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));
4
+ var text = _a.text, _b = _a.speed, speed = _b === void 0 ? 50 : _b, _c = _a.containerStyle, containerStyle = _c === void 0 ? {} : _c, _d = _a.textStyle, textStyle = _d === void 0 ? {} : _d;
5
+ // Animation value for text position
6
+ var scrollX = useRef(new Animated.Value(0)).current;
7
+ // State for container and text measurements
8
+ var _e = useState(0), containerWidth = _e[0], setContainerWidth = _e[1];
9
+ var _f = useState(0), textWidth = _f[0], setTextWidth = _f[1];
10
+ // Start animation when we have both widths
11
+ useEffect(function () {
12
+ if (containerWidth > 0 && textWidth > 0) {
13
+ // Only animate if text is wider than container
14
+ if (textWidth > containerWidth) {
15
+ startAnimation();
16
+ }
55
17
  }
18
+ }, [containerWidth, textWidth]);
19
+ // Animation function
20
+ var startAnimation = function () {
21
+ // Reset to starting position
22
+ scrollX.setValue(containerWidth);
23
+ // Create animation
24
+ Animated.timing(scrollX, {
25
+ toValue: -textWidth, // Move text completely off screen to the left
26
+ duration: (textWidth + containerWidth) / speed * 1000, // Time based on distance and speed
27
+ useNativeDriver: true, // This is crucial for performance
28
+ }).start(function (_a) {
29
+ var finished = _a.finished;
30
+ // When animation completes, restart it
31
+ if (finished) {
32
+ startAnimation();
33
+ }
34
+ });
56
35
  };
57
- var animatedTextStyle = useAnimatedStyle(function () { return ({
58
- transform: [{ translateX: offset.value }],
59
- }); });
60
- useEffect(function () {
61
- return function () {
62
- cancelAnimation(offset);
63
- };
64
- }, []);
65
- var textStyle = __assign({ fontSize: fontSize, color: textColor }, (fontFamily ? { fontFamily: fontFamily } : {}));
66
- return (<View style={[styles.container, style]} onLayout={onContainerLayout}>
67
- <Animated.View style={animatedTextStyle}>
68
- <Text style={textStyle} onLayout={onTextLayout} numberOfLines={1}>
36
+ return (<View style={[styles.container, containerStyle]} onLayout={function (event) {
37
+ setContainerWidth(event.nativeEvent.layout.width);
38
+ }}>
39
+ <Animated.View style={{
40
+ transform: [{ translateX: scrollX }]
41
+ }}>
42
+ <Text style={[styles.text, textStyle]} onLayout={function (event) {
43
+ setTextWidth(event.nativeEvent.layout.width);
44
+ }}>
69
45
  {text}
70
- {mode === 'loop' && ' '}
71
46
  </Text>
72
47
  </Animated.View>
73
48
  </View>);
@@ -75,6 +50,13 @@ var MarqueeText = function (_a) {
75
50
  var styles = StyleSheet.create({
76
51
  container: {
77
52
  overflow: 'hidden',
53
+ backgroundColor: 'black',
54
+ height: 40,
55
+ justifyContent: 'center',
56
+ },
57
+ text: {
58
+ color: 'white',
59
+ fontSize: 16,
78
60
  },
79
61
  });
80
62
  export default MarqueeText;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rn-marquee-text",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "A customizable marquee (scrolling) text component for React Native",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -45,8 +45,11 @@
45
45
  "@types/react": "^19.1.2",
46
46
  "prop-types": "^15.8.1",
47
47
  "react": "^18.2.0",
48
- "react-native": "^0.72.6",
48
+ "react-native": "^0.72.17",
49
49
  "react-native-reanimated": "^3.17.5",
50
50
  "typescript": "^5.0.0"
51
+ },
52
+ "dependencies": {
53
+ "react-native-gesture-handler": "^2.25.0"
51
54
  }
52
55
  }