44 type PanGestureHandlerOnChangeEventPayload ,
55 HoverGestureHandlerOnChangeEventPayload ,
66} from "@codeherence/react-native-graph" ;
7- import { LinearGradient , vec } from "@shopify/react-native-skia" ;
7+ import { Paint } from "@shopify/react-native-skia" ;
88import { useCallback , useMemo , useReducer } from "react" ;
99import { Button , ScrollView , StyleSheet , Text } from "react-native" ;
1010import { useAnimatedProps , useSharedValue } from "react-native-reanimated" ;
@@ -35,7 +35,7 @@ const uiFormatter = (price: number) => {
3535} ;
3636
3737const priceMap = {
38- msft : msft_prices . results
38+ msft : [ ... msft_prices . results ]
3939 . reverse ( )
4040 . map < [ number , number ] > ( ( r ) => [ new Date ( r . date ) . getTime ( ) , r . close ] ) ,
4141 aapl : aapl_prices . results
@@ -52,10 +52,10 @@ const priceMap = {
5252const priceMapKeys = Object . keys ( priceMap ) as ( keyof typeof priceMap ) [ ] ;
5353
5454export default ( ) => {
55- const [ counter , increment ] = useReducer ( ( s : number ) => s + 1 , 0 ) ;
56-
5755 const { bottom, left, right } = useSafeAreaInsets ( ) ;
5856
57+ const [ counter , increment ] = useReducer ( ( s : number ) => s + 1 , 0 ) ;
58+
5959 const latestPrice = useSharedValue ( "0" ) ;
6060 const symbol = priceMapKeys [ counter % priceMapKeys . length ] ! ;
6161 const data : [ number , number ] [ ] = useMemo ( ( ) => {
@@ -85,31 +85,33 @@ export default () => {
8585 return (
8686 < ScrollView
8787 style = { styles . container }
88- contentContainerStyle = { {
89- paddingBottom : bottom ,
90- paddingLeft : left ,
91- paddingRight : right ,
92- } }
88+ contentContainerStyle = { [
89+ styles . contentContainer ,
90+ {
91+ paddingBottom : bottom ,
92+ paddingLeft : left ,
93+ paddingRight : right ,
94+ } ,
95+ ] }
9396 showsVerticalScrollIndicator = { false }
9497 >
95- < Button title = { `Showing ${ symbol } . Click to switch.` } onPress = { increment } />
98+ < Button title = { `Showing ${ symbol } . Press to switch.` } onPress = { increment } />
9699 < AnimatedText style = { styles . price } animatedProps = { animatedProps } />
97100 < LineChart
98101 points = { data }
99102 style = { styles . chart }
103+ cursorColor = "#000"
104+ cursorLineColor = "#000"
105+ cursorLineWidth = { 1 }
100106 TopAxisLabel = { AxisLabel }
101107 BottomAxisLabel = { AxisLabel }
102108 onPanGestureChange = { onGestureChangeWorklet }
103109 onPanGestureEnd = { onEndWorklet }
104110 onHoverGestureEnd = { onEndWorklet }
105111 onHoverGestureChange = { onHoverChangeWorklet }
106112 strokeWidth = { 2 }
107- PathFill = { ( { width } ) => (
108- < LinearGradient
109- start = { vec ( 0 , 0 ) }
110- end = { vec ( width , 0 ) }
111- colors = { [ "blue" , "red" , "purple" ] }
112- />
113+ PathFill = { ( { strokeWidth } ) => (
114+ < Paint style = "stroke" strokeWidth = { strokeWidth } color = "lightblue" />
113115 ) }
114116 />
115117 </ ScrollView >
@@ -118,6 +120,7 @@ export default () => {
118120
119121const styles = StyleSheet . create ( {
120122 container : { flex : 1 } ,
121- chart : { flex : 1 , minHeight : 400 } ,
123+ contentContainer : { flexGrow : 1 } ,
124+ chart : { flex : 1 , maxHeight : 300 } ,
122125 price : { fontSize : 32 } ,
123126} ) ;
0 commit comments