Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added RTL direction support #54

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ MarqueeText component basically inherits TextProps and the followings are additi
| delay | number | true | 0 | Duration to delay the animation after render, in milliseconds
| onMarqueeComplete | function | true | void | A callback for when the marquee finishes animation and stops
| consecutive | boolean | true | false | A flag to enable consecutive mode that imitates the default behavior of HTML marquee element. Does not take effect if loop is false
| isRTL | boolean | true | I18nManager.isRTL | A flag to override animation direction

## Methods

Expand Down
10 changes: 9 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
StyleSheet,
Text,
View,
I18nManager,
} from 'react-native';

const { UIManager } = NativeModules;
Expand Down Expand Up @@ -41,6 +42,10 @@ export interface MarqueeTextProps extends TextProps {
* Does not take effect if loop is false
*/
consecutive?: boolean;
/**
* A flag to override animation direction
*/
isRTL?: boolean;
}

export interface MarqueeTextHandles {
Expand Down Expand Up @@ -108,6 +113,7 @@ const MarqueeText = (props: MarqueeTextProps, ref: Ref<MarqueeTextHandles>): JSX
loop = true,
delay = 0,
consecutive = false,
isRTL = I18nManager.isRTL,
onMarqueeComplete,
children,
...restProps
Expand All @@ -127,12 +133,14 @@ const MarqueeText = (props: MarqueeTextProps, ref: Ref<MarqueeTextHandles>): JSX
loop: boolean;
delay: number;
consecutive: boolean;
isRTL: boolean;
}>({
marqueeOnStart,
speed,
loop,
delay,
consecutive,
isRTL,
});

const stopAnimation = useCallback(() => {
Expand Down Expand Up @@ -163,7 +171,7 @@ const MarqueeText = (props: MarqueeTextProps, ref: Ref<MarqueeTextHandles>): JSX
animatedValue.current,
{
...config.current,
toValue: isConsecutive ? -marqueeTextWidth.current : -distance,
toValue: (isConsecutive ? marqueeTextWidth.current : distance) * (config.current.isRTL ? 1 : -1),
duration: isConsecutive ? baseDuration * (marqueeTextWidth.current / distance) : baseDuration,
},
isConsecutive
Expand Down