Skip to content

Commit

Permalink
chore: Demonstrate Marquee component
Browse files Browse the repository at this point in the history
  • Loading branch information
shirakaba committed Jan 16, 2021
1 parent 784bc57 commit 6f1d8ec
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
3 changes: 2 additions & 1 deletion sample/app/testComponents/AppContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from "react";
import { StyleSheet } from "react-nativescript";
import { Clock, ClockFC, Counter } from "./stateful";
import { Clock, ClockFC, Counter, MarqueeFC } from "./stateful";

function AppContainer(){
return (
Expand All @@ -9,6 +9,7 @@ function AppContainer(){
<Clock/>
<ClockFC/>
<Counter/>
<MarqueeFC text="The quick brown fox jumps over the lazy dog."/>
</stackLayout>
);
}
Expand Down
26 changes: 26 additions & 0 deletions sample/app/testComponents/stateful.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,26 @@ export class Marquee extends React.Component<{ text: string }, { index: number }
}
}

export function MarqueeFC({ text }: { text: string }){
const [index, setIndex] = useState(0);

useEffect(() => {
let frame;
function retry(){
frame = requestAnimationFrame(() => {
setIndex(prevIndex => (prevIndex + 1) % text.length);

retry();
});
}
retry();

return () => cancelAnimationFrame(frame);
}, []);

return <label>{text.slice(index, text.length)}</label>;
}

// React.createElement(
// MyButton,
// {
Expand Down Expand Up @@ -232,6 +252,12 @@ export function Counter(){
<label>{count}</label>
<button
onTap={(eventData) => {
/**
* The useState() hook can take a callback (just like the setState() API
* of Class components) which allows you to do a state update based on the
* current state value.
* @see https://reactjs.org/docs/hooks-reference.html#functional-updates
*/
setCount((currentCount: number) => {
const nextCount = currentCount + 1;
console.log(`Increasing count from ${currentCount} -> ${nextCount}`);
Expand Down

0 comments on commit 6f1d8ec

Please sign in to comment.