Skip to content

Commit 9789706

Browse files
committed
chore: add aapl prices and swapping
1 parent 875d808 commit 9789706

File tree

2 files changed

+5950
-9
lines changed

2 files changed

+5950
-9
lines changed

example/app/index.tsx

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ import {
55
HoverGestureHandlerOnChangeEventPayload,
66
} from "@codeherence/react-native-graph";
77
import { LinearGradient, vec } from "@shopify/react-native-skia";
8-
import { useCallback, useMemo } from "react";
9-
import { StyleSheet, Text, View, useWindowDimensions } from "react-native";
8+
import { useCallback, useMemo, useReducer } from "react";
9+
import { Button, StyleSheet, Text, View, useWindowDimensions } from "react-native";
1010
import { useAnimatedProps, useSharedValue } from "react-native-reanimated";
1111
import { useSafeAreaInsets } from "react-native-safe-area-context";
1212

1313
import AnimatedText from "../components/AnimatedText";
14+
import aapl_prices from "../data/aapl_prices.json";
1415
import msft_prices from "../data/msft_prices.json";
1516

1617
const formatter = new Intl.NumberFormat("en-US", {
@@ -31,16 +32,23 @@ const uiFormatter = (price: number) => {
3132
}).format(price);
3233
};
3334

35+
const priceMap = {
36+
msft: msft_prices.results
37+
.reverse()
38+
.map<[number, number]>((r) => [new Date(r.date).getTime(), r.close]),
39+
aapl: aapl_prices.results
40+
.reverse()
41+
.map<[number, number]>((r) => [new Date(r.date).getTime(), r.close]),
42+
};
43+
3444
export default () => {
45+
const [counter, increment] = useReducer((s: number) => s + 1, 0);
46+
3547
const { width } = useWindowDimensions();
3648
const { top, bottom } = useSafeAreaInsets();
37-
const data: [number, number][] = useMemo(
38-
() =>
39-
msft_prices.results
40-
.reverse()
41-
.map<[number, number]>((r) => [new Date(r.date).getTime(), r.close]),
42-
[]
43-
);
49+
50+
const symbol: "msft" | "aapl" = counter % 2 === 0 ? "msft" : "aapl";
51+
const data: [number, number][] = useMemo(() => priceMap[symbol], [symbol]);
4452

4553
const latestPrice = useSharedValue("0");
4654

@@ -65,6 +73,7 @@ export default () => {
6573

6674
return (
6775
<View style={[styles.container, { paddingTop: top, paddingBottom: bottom }]}>
76+
<Button title={`Showing ${symbol}. Click to switch.`} onPress={increment} />
6877
<AnimatedText style={styles.price} animatedProps={animatedProps} />
6978
<LineChart
7079
points={data}

0 commit comments

Comments
 (0)