@@ -38,7 +38,7 @@ import Reanimated, {
3838 withDelay ,
3939} from 'react-native-reanimated'
4040import { getSixDigitHex } from './utils/getSixDigitHex'
41- import { GestureHandlerRootView , GestureDetector } from 'react-native-gesture-handler'
41+ import { GestureDetector } from 'react-native-gesture-handler'
4242import { usePanGesture } from './hooks/usePanGesture'
4343import { getYForX } from './GetYForX'
4444import { hexToRgba } from './utils/hexToRgba'
@@ -50,22 +50,19 @@ const INDICATOR_PULSE_BLUR_RADIUS_SMALL =
5050const INDICATOR_PULSE_BLUR_RADIUS_BIG =
5151 INDICATOR_RADIUS * INDICATOR_BORDER_MULTIPLIER + 20
5252
53- // weird rea type bug
54- const ReanimatedView = Reanimated . View as any
55-
5653export function AnimatedLineGraph ( {
5754 points,
5855 color,
5956 smoothing = 0.2 ,
60- holdDuration = 300 ,
6157 gradientFillColors,
6258 lineThickness = 3 ,
6359 range,
6460 enableFadeInMask,
65- enablePanGesture,
61+ enablePanGesture = false ,
6662 onPointSelected,
6763 onGestureStart,
6864 onGestureEnd,
65+ panGestureDelay = 300 ,
6966 SelectionDot = DefaultSelectionDot ,
7067 enableIndicator = false ,
7168 indicatorPulsating = false ,
@@ -81,7 +78,10 @@ export function AnimatedLineGraph({
8178 const [ height , setHeight ] = useState ( 0 )
8279 const interpolateProgress = useValue ( 0 )
8380
84- const { gesture, isActive, x } = usePanGesture ( { holdDuration } )
81+ const { gesture, isActive, x } = usePanGesture ( {
82+ enabled : enablePanGesture ,
83+ holdDuration : panGestureDelay ,
84+ } )
8585 const circleX = useValue ( 0 )
8686 const circleY = useValue ( 0 )
8787 const pathEnd = useValue ( 0 )
@@ -460,104 +460,124 @@ export function AnimatedLineGraph({
460460 pulseTrigger
461461 )
462462
463+ const axisLabelContainerStyle = {
464+ paddingTop : TopAxisLabel != null ? 20 : 0 ,
465+ paddingBottom : BottomAxisLabel != null ? 20 : 0 ,
466+ }
467+
463468 return (
464- < GestureHandlerRootView >
465- < View { ...props } >
466- < GestureDetector gesture = { enablePanGesture ? gesture : undefined } >
467- < ReanimatedView style = { [ styles . container , styles . axisLabelContainer ] } >
468- { /* Top Label (max price) */ }
469- { TopAxisLabel != null && (
470- < View style = { styles . axisRow } >
471- < TopAxisLabel />
472- </ View >
473- ) }
474-
475- { /* Actual Skia Graph */ }
476- < View style = { styles . container } onLayout = { onLayout } >
477- < Canvas style = { styles . svg } >
478- < Group >
469+ < View { ...props } >
470+ < GestureDetector gesture = { gesture } >
471+ < Reanimated . View style = { [ styles . container , axisLabelContainerStyle ] } >
472+ { /* Top Label (max price) */ }
473+ { TopAxisLabel != null && (
474+ < View style = { styles . axisRow } >
475+ < TopAxisLabel />
476+ </ View >
477+ ) }
478+
479+ { /* Actual Skia Graph */ }
480+ < View style = { styles . container } onLayout = { onLayout } >
481+ { /* Fix for react-native-skia's incorrect type declarations */ }
482+ < Canvas
483+ style = { styles . svg }
484+ onPointerEnter = { undefined }
485+ onPointerEnterCapture = { undefined }
486+ onPointerLeave = { undefined }
487+ onPointerLeaveCapture = { undefined }
488+ onPointerMove = { undefined }
489+ onPointerMoveCapture = { undefined }
490+ onPointerCancel = { undefined }
491+ onPointerCancelCapture = { undefined }
492+ onPointerDown = { undefined }
493+ onPointerDownCapture = { undefined }
494+ onPointerUp = { undefined }
495+ onPointerUpCapture = { undefined }
496+ accessibilityLabelledBy = { undefined }
497+ accessibilityLanguage = { undefined }
498+ >
499+ < Group >
500+ < Path
501+ // @ts -ignore
502+ path = { path }
503+ strokeWidth = { lineThickness }
504+ style = "stroke"
505+ strokeJoin = "round"
506+ strokeCap = "round"
507+ >
508+ < LinearGradient
509+ start = { vec ( 0 , 0 ) }
510+ end = { vec ( width , 0 ) }
511+ colors = { gradientColors }
512+ positions = { positions }
513+ />
514+ </ Path >
515+
516+ { shouldFillGradient && (
479517 < Path
480518 // @ts -ignore
481- path = { path }
482- strokeWidth = { lineThickness }
483- style = "stroke"
484- strokeJoin = "round"
485- strokeCap = "round"
519+ path = { gradientPath }
486520 >
487521 < LinearGradient
488522 start = { vec ( 0 , 0 ) }
489- end = { vec ( width , 0 ) }
490- colors = { gradientColors }
491- positions = { positions }
523+ end = { vec ( 0 , height ) }
524+ colors = { gradientFillColors }
492525 />
493526 </ Path >
494-
495- { shouldFillGradient && (
496- < Path
497- // @ts -ignore
498- path = { gradientPath }
499- >
500- < LinearGradient
501- start = { vec ( 0 , 0 ) }
502- end = { vec ( 0 , height ) }
503- colors = { gradientFillColors }
504- />
505- </ Path >
506- ) }
507- </ Group >
508-
509- { SelectionDot != null && (
510- < SelectionDot
511- isActive = { isActive }
512- color = { color }
513- lineThickness = { lineThickness }
514- circleX = { circleX }
515- circleY = { circleY }
516- />
517527 ) }
518-
519- { enableIndicator && (
520- < Group >
521- { indicatorPulsating && (
522- < Circle
523- cx = { indicatorX }
524- cy = { indicatorY }
525- r = { indicatorPulseRadius }
526- opacity = { indicatorPulseOpacity }
527- color = { indicatorPulseColor }
528- style = "fill"
529- />
530- ) }
531-
532- < Circle
533- cx = { indicatorX }
534- cy = { indicatorY }
535- r = { indicatorBorderRadius }
536- color = { '#ffffff' }
537- >
538- < Shadow dx = { 2 } dy = { 2 } color = "rgba(0,0,0,0.2)" blur = { 4 } />
539- </ Circle >
528+ </ Group >
529+
530+ { SelectionDot != null && (
531+ < SelectionDot
532+ isActive = { isActive }
533+ color = { color }
534+ lineThickness = { lineThickness }
535+ circleX = { circleX }
536+ circleY = { circleY }
537+ />
538+ ) }
539+
540+ { enableIndicator && (
541+ < Group >
542+ { indicatorPulsating && (
540543 < Circle
541544 cx = { indicatorX }
542545 cy = { indicatorY }
543- r = { indicatorRadius }
544- color = { color }
546+ r = { indicatorPulseRadius }
547+ opacity = { indicatorPulseOpacity }
548+ color = { indicatorPulseColor }
549+ style = "fill"
545550 />
546- </ Group >
547- ) }
548- </ Canvas >
549- </ View >
551+ ) }
550552
551- { /* Bottom Label (min price) */ }
552- { BottomAxisLabel != null && (
553- < View style = { styles . axisRow } >
554- < BottomAxisLabel />
555- </ View >
556- ) }
557- </ ReanimatedView >
558- </ GestureDetector >
559- </ View >
560- </ GestureHandlerRootView >
553+ < Circle
554+ cx = { indicatorX }
555+ cy = { indicatorY }
556+ r = { indicatorBorderRadius }
557+ color = { '#ffffff' }
558+ >
559+ < Shadow dx = { 2 } dy = { 2 } color = "rgba(0,0,0,0.2)" blur = { 4 } />
560+ </ Circle >
561+ < Circle
562+ cx = { indicatorX }
563+ cy = { indicatorY }
564+ r = { indicatorRadius }
565+ color = { color }
566+ />
567+ </ Group >
568+ ) }
569+ </ Canvas >
570+ </ View >
571+
572+ { /* Bottom Label (min price) */ }
573+ { BottomAxisLabel != null && (
574+ < View style = { styles . axisRow } >
575+ < BottomAxisLabel />
576+ </ View >
577+ ) }
578+ </ Reanimated . View >
579+ </ GestureDetector >
580+ </ View >
561581 )
562582}
563583
@@ -568,9 +588,6 @@ const styles = StyleSheet.create({
568588 container : {
569589 flex : 1 ,
570590 } ,
571- axisLabelContainer : {
572- paddingVertical : 20 ,
573- } ,
574591 axisRow : {
575592 height : 17 ,
576593 } ,
0 commit comments