deanhet / react-native-text-ticker

React Native Text Ticker/Marquee Component
MIT License
453 stars 75 forks source link

Pause/Play The TEXT TICKER #108

Open SonPH088 opened 3 years ago

SonPH088 commented 3 years ago

Hi all!

is there any way to do the button with ref to pause the animation and play again the animation?

Many Thanks!

deanhet commented 3 years ago

Sure there is!

You'll want to do something like this (I haven't tested this).

const tickerRef = useRef(null)

<TextTicker ref={tickerRef}>My animated text</TextTicker>

<TouchableOpacity onPress={() => tickerRef.current.startAnimation()}>
  <Text>Start ticker</Text>
</TouchableOpacity>

<TouchableOpacity onPress={() => tickerRef.current.stopAnimation()}>
  <Text>Stop ticker</Text>
</TouchableOpacity>