66} from "@codeherence/react-native-graph" ;
77import { LinearGradient , vec } from "@shopify/react-native-skia" ;
88import { useCallback , useMemo , useReducer } from "react" ;
9- import { Button , StyleSheet , Text , View , useWindowDimensions } from "react-native" ;
9+ import { Button , ScrollView , StyleSheet , Text , View } from "react-native" ;
1010import { useAnimatedProps , useSharedValue } from "react-native-reanimated" ;
1111import { useSafeAreaInsets } from "react-native-safe-area-context" ;
1212
@@ -44,13 +44,14 @@ const priceMap = {
4444export default ( ) => {
4545 const [ counter , increment ] = useReducer ( ( s : number ) => s + 1 , 0 ) ;
4646
47- const { width } = useWindowDimensions ( ) ;
48- const { top, bottom } = useSafeAreaInsets ( ) ;
49-
50- const symbol : "msft" | "aapl" = counter % 2 === 0 ? "msft" : "aapl" ;
51- const data : [ number , number ] [ ] = useMemo ( ( ) => priceMap [ symbol ] , [ symbol ] ) ;
47+ const { top, bottom, left, right } = useSafeAreaInsets ( ) ;
5248
5349 const latestPrice = useSharedValue ( "0" ) ;
50+ const symbol : "msft" | "aapl" = counter % 2 === 0 ? "msft" : "aapl" ;
51+ const data : [ number , number ] [ ] = useMemo ( ( ) => {
52+ latestPrice . value = uiFormatter ( priceMap [ symbol ] [ priceMap [ symbol ] . length - 1 ] ! [ 1 ] ) ;
53+ return priceMap [ symbol ] ;
54+ } , [ symbol ] ) ;
5455
5556 const onHoverChangeWorklet = useCallback ( ( evt : HoverGestureHandlerOnChangeEventPayload ) => {
5657 "worklet" ;
@@ -72,12 +73,21 @@ export default () => {
7273 } , [ ] ) ;
7374
7475 return (
75- < View style = { [ styles . container , { paddingTop : top , paddingBottom : bottom } ] } >
76+ < ScrollView
77+ style = { styles . container }
78+ contentContainerStyle = { {
79+ paddingTop : top ,
80+ paddingBottom : bottom ,
81+ paddingLeft : left ,
82+ paddingRight : right ,
83+ } }
84+ showsVerticalScrollIndicator = { false }
85+ >
7686 < Button title = { `Showing ${ symbol } . Click to switch.` } onPress = { increment } />
7787 < AnimatedText style = { styles . price } animatedProps = { animatedProps } />
7888 < LineChart
7989 points = { data }
80- style = { [ styles . chart , { width } ] }
90+ style = { styles . chart }
8191 TopAxisLabel = { AxisLabel }
8292 BottomAxisLabel = { AxisLabel }
8393 onPanGestureChange = { onGestureChangeWorklet }
@@ -93,12 +103,12 @@ export default () => {
93103 />
94104 ) }
95105 />
96- </ View >
106+ </ ScrollView >
97107 ) ;
98108} ;
99109
100110const styles = StyleSheet . create ( {
101111 container : { flex : 1 } ,
102- chart : { flex : 1 , maxHeight : 400 } ,
112+ chart : { flex : 1 , minHeight : 400 } ,
103113 price : { fontSize : 32 } ,
104114} ) ;
0 commit comments