@@ -147,9 +147,6 @@ const SwipeChartComponent = (params: Props) => {
147147 const [ queryFromTimeOffset , setQueryFromTimeOffset ] = React . useState ( UNIX_SECONDS_MONTH_OFFSET )
148148 const [ isLoading , setIsLoading ] = React . useState ( false )
149149
150- const chartWidth = React . useRef ( 0 )
151- const chartHeight = React . useRef ( 0 )
152-
153150 const fiatSymbol = React . useMemo ( ( ) => getFiatSymbol ( fiatCurrencyCode ) , [ fiatCurrencyCode ] )
154151
155152 // Min/Max Price Calcs
@@ -158,9 +155,7 @@ const SwipeChartComponent = (params: Props) => {
158155 const maxPrice = Math . max ( ...prices )
159156
160157 const sMinPriceLabelX = useSharedValue ( 0 )
161- const sMinPriceLabelY = useSharedValue ( 0 )
162158 const sMaxPriceLabelX = useSharedValue ( 0 )
163- const sMaxPriceLabelY = useSharedValue ( 0 )
164159
165160 const sMinPriceString = useSharedValue ( `` )
166161 const sMaxPriceString = useSharedValue ( `` )
@@ -175,7 +170,8 @@ const SwipeChartComponent = (params: Props) => {
175170 // we measure the parent and pass that width in.
176171 // The chart will freeze the whole app if the width is too narrow,
177172 // so start with the window width:
178- const [ width , setWidth ] = React . useState ( Dimensions . get ( 'window' ) . width )
173+ const [ chartWidth , setChartWidth ] = React . useState ( Dimensions . get ( 'window' ) . width )
174+ const chartHeight = theme . rem ( CHART_HEIGHT_REM )
179175
180176 // Fetch/cache chart data, set shared animation transition values
181177 useAsyncEffect (
@@ -301,14 +297,15 @@ const SwipeChartComponent = (params: Props) => {
301297
302298 // A delayed fadein for the max/min labels, to ensure the labels don't get
303299 // rendered before the price line. Also hidden when gesture is active
300+ const minPriceLabelY = Platform . OS === 'ios' ? chartHeight - theme . rem ( 2.5 ) : chartHeight - theme . rem ( 2.75 )
304301 const aMinLabelStyle = useAnimatedStyle ( ( ) => ( {
305302 left : sMinPriceLabelX . value ,
306- top : sMinPriceLabelY . value ,
303+ top : minPriceLabelY ,
307304 opacity : sMinMaxOpacity . value * ( 1 - sCursorOpacity . value )
308305 } ) )
309306 const aMaxLabelStyle = useAnimatedStyle ( ( ) => ( {
310307 left : sMaxPriceLabelX . value ,
311- top : sMaxPriceLabelY . value ,
308+ top : 0 ,
312309 opacity : sMinMaxOpacity . value * ( 1 - sCursorOpacity . value )
313310 } ) )
314311
@@ -355,7 +352,7 @@ const SwipeChartComponent = (params: Props) => {
355352 // #region Handlers
356353
357354 const handleLayout = useHandler ( ( event : LayoutChangeEvent ) => {
358- setWidth ( event . nativeEvent . layout . width )
355+ setChartWidth ( event . nativeEvent . layout . width )
359356 } )
360357
361358 const handleGradient = useHandler ( ( props : GradientProps ) => {
@@ -367,16 +364,6 @@ const SwipeChartComponent = (params: Props) => {
367364 )
368365 } )
369366
370- /**
371- * Handle the layout event on the chart, set the min price label Y value.
372- */
373- const handleSetChartDimensions = useHandler ( ( event : LayoutChangeEvent ) => {
374- const { width, height } = event . nativeEvent . layout
375- chartWidth . current = width
376- chartHeight . current = height
377- sMinPriceLabelY . value = Platform . OS === 'ios' ? chartHeight . current - theme . rem ( 2.5 ) : chartHeight . current - theme . rem ( 2.75 )
378- } )
379-
380367 /**
381368 * Handle the tap and hold gesture event on the chart.
382369 *
@@ -438,7 +425,7 @@ const SwipeChartComponent = (params: Props) => {
438425 const setMinMaxLabelsX = ( xSharedVal : SharedValue < number > , priceDatapoint ?: ChartDataPoint ) => ( layoutChangeEvent : LayoutChangeEvent ) => {
439426 if ( layoutChangeEvent != null && layoutChangeEvent . nativeEvent != null && minPriceDataPoint != null && chartData != null && priceDatapoint != null ) {
440427 const xIndex = chartData . indexOf ( priceDatapoint )
441- const xPosition = ( chartWidth . current / ( chartData . length - 1 ) ) * xIndex
428+ const xPosition = ( chartWidth / ( chartData . length - 1 ) ) * xIndex
442429 const labelWidth = layoutChangeEvent . nativeEvent . layout . width
443430 const isRightJustified = xPosition > chartData . length / 2
444431
@@ -550,16 +537,16 @@ const SwipeChartComponent = (params: Props) => {
550537
551538 { /* Chart */ }
552539 { chartData . length === 0 || isLoading ? (
553- < View style = { styles . loader } onLayout = { handleSetChartDimensions } >
540+ < View style = { styles . loader } >
554541 < FillLoader />
555542 </ View >
556543 ) : (
557544 < View >
558545 < SlideAreaChart
559546 data = { chartData }
560547 animated
561- height = { theme . rem ( 11 ) }
562- width = { width }
548+ height = { theme . rem ( CHART_HEIGHT_REM ) }
549+ width = { chartWidth }
563550 chartLineColor = { theme . iconTappable }
564551 chartLineWidth = { 1.5 }
565552 renderFillGradient = { handleGradient }
@@ -617,6 +604,8 @@ const SwipeChartComponent = (params: Props) => {
617604 // #endregion Components
618605}
619606
607+ const CHART_HEIGHT_REM = 11
608+
620609const getStyles = cacheStyles ( ( theme : Theme ) => {
621610 return {
622611 baseChart : {
@@ -644,7 +633,7 @@ const getStyles = cacheStyles((theme: Theme) => {
644633 } ,
645634 loader : {
646635 marginTop : theme . rem ( 0 ) ,
647- height : theme . rem ( 11 )
636+ height : theme . rem ( CHART_HEIGHT_REM )
648637 } ,
649638 label : {
650639 color : theme . primaryText ,
0 commit comments