Skip to content

Commit ec79fb4

Browse files
committed
fix: polish controlled progress demo
The example Replay button now works for the controlled playback case. Root README snippets include the imports needed to copy the example. Constraint: Keep this as review follow-up polish without widening playback APIs Confidence: high Scope-risk: narrow Tested: pnpm run format:check Tested: pnpm run lint Tested: pnpm run typecheck Tested: pnpm run example:build Tested: git diff --check Not-tested: Manual device tap-through of the example Replay button
1 parent 4cf634a commit ec79fb4

3 files changed

Lines changed: 30 additions & 3 deletions

File tree

‎README.ko.md‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,14 @@ Controlled progress는 text motion이 component 내부 autoplay가 아니라 외
5757
기본 controlled progress 예시:
5858

5959
```tsx
60+
import {
61+
defineTextMotion,
62+
fade,
63+
nativeText,
64+
rise,
65+
stagger,
66+
words,
67+
} from '@react-native-motion-kit/text-motion';
6068
import { Button } from 'react-native';
6169
import { useSharedValue, withTiming } from 'react-native-reanimated';
6270

‎README.md‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,14 @@ Controlled progress is useful when text motion should follow something outside t
5959
Basic controlled progress usage:
6060

6161
```tsx
62+
import {
63+
defineTextMotion,
64+
fade,
65+
nativeText,
66+
rise,
67+
stagger,
68+
words,
69+
} from '@react-native-motion-kit/text-motion';
6270
import { Button } from 'react-native';
6371
import { useSharedValue, withTiming } from 'react-native-reanimated';
6472

‎example/src/App.tsx‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {
2323
softWave,
2424
} from '@react-native-motion-kit/text-motion/presets';
2525
import { StatusBar } from 'expo-status-bar';
26-
import { useState } from 'react';
26+
import { useEffect, useRef, useState } from 'react';
2727
import { Pressable, SafeAreaView, StyleSheet, Text, View } from 'react-native';
2828
import { useSharedValue, withTiming } from 'react-native-reanimated';
2929

@@ -342,8 +342,19 @@ function nextDemoIndex(index: number): number {
342342
return (index + 1) % demos.length;
343343
}
344344

345-
function ControlledProgressDemo({ text }: { text: string }) {
345+
function ControlledProgressDemo({ replaySignal, text }: { replaySignal: number; text: string }) {
346346
const progress = useSharedValue(0);
347+
const replaySignalRef = useRef(replaySignal);
348+
349+
useEffect(() => {
350+
if (replaySignalRef.current === replaySignal) {
351+
return;
352+
}
353+
354+
replaySignalRef.current = replaySignal;
355+
progress.value = 0;
356+
progress.value = withTiming(1, { duration: 720 });
357+
}, [progress, replaySignal]);
347358

348359
return (
349360
<View style={styles.controlledDemo}>
@@ -438,7 +449,7 @@ export default function App() {
438449

439450
<View style={styles.motionFrame}>
440451
{controlledDemoSelected ? (
441-
<ControlledProgressDemo key={demo.id} text={demo.text} />
452+
<ControlledProgressDemo key={demo.id} replaySignal={replayKey} text={demo.text} />
442453
) : (
443454
MotionText && (
444455
<MotionText

0 commit comments

Comments
 (0)