Skip to content

Commit 6f1d8ec

Browse files
committed
chore: Demonstrate Marquee component
1 parent 784bc57 commit 6f1d8ec

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

sample/app/testComponents/AppContainer.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as React from "react";
22
import { StyleSheet } from "react-nativescript";
3-
import { Clock, ClockFC, Counter } from "./stateful";
3+
import { Clock, ClockFC, Counter, MarqueeFC } from "./stateful";
44

55
function AppContainer(){
66
return (
@@ -9,6 +9,7 @@ function AppContainer(){
99
<Clock/>
1010
<ClockFC/>
1111
<Counter/>
12+
<MarqueeFC text="The quick brown fox jumps over the lazy dog."/>
1213
</stackLayout>
1314
);
1415
}

sample/app/testComponents/stateful.tsx

+26
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,26 @@ export class Marquee extends React.Component<{ text: string }, { index: number }
138138
}
139139
}
140140

141+
export function MarqueeFC({ text }: { text: string }){
142+
const [index, setIndex] = useState(0);
143+
144+
useEffect(() => {
145+
let frame;
146+
function retry(){
147+
frame = requestAnimationFrame(() => {
148+
setIndex(prevIndex => (prevIndex + 1) % text.length);
149+
150+
retry();
151+
});
152+
}
153+
retry();
154+
155+
return () => cancelAnimationFrame(frame);
156+
}, []);
157+
158+
return <label>{text.slice(index, text.length)}</label>;
159+
}
160+
141161
// React.createElement(
142162
// MyButton,
143163
// {
@@ -232,6 +252,12 @@ export function Counter(){
232252
<label>{count}</label>
233253
<button
234254
onTap={(eventData) => {
255+
/**
256+
* The useState() hook can take a callback (just like the setState() API
257+
* of Class components) which allows you to do a state update based on the
258+
* current state value.
259+
* @see https://reactjs.org/docs/hooks-reference.html#functional-updates
260+
*/
235261
setCount((currentCount: number) => {
236262
const nextCount = currentCount + 1;
237263
console.log(`Increasing count from ${currentCount} -> ${nextCount}`);

0 commit comments

Comments
 (0)