react-native-wagmi-charts 2.7.3 → 2.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +42 -15
- package/lib/commonjs/charts/candle/Candle.js +177 -93
- package/lib/commonjs/charts/candle/Candle.js.map +1 -1
- package/lib/commonjs/charts/candle/Candles.js +66 -43
- package/lib/commonjs/charts/candle/Candles.js.map +1 -1
- package/lib/commonjs/charts/candle/Chart.js +38 -28
- package/lib/commonjs/charts/candle/Chart.js.map +1 -1
- package/lib/commonjs/charts/candle/Context.js +74 -43
- package/lib/commonjs/charts/candle/Context.js.map +1 -1
- package/lib/commonjs/charts/candle/Crosshair.js +190 -81
- package/lib/commonjs/charts/candle/Crosshair.js.map +1 -1
- package/lib/commonjs/charts/candle/CrosshairTooltip.js +140 -61
- package/lib/commonjs/charts/candle/CrosshairTooltip.js.map +1 -1
- package/lib/commonjs/charts/candle/DatetimeText.js +19 -14
- package/lib/commonjs/charts/candle/DatetimeText.js.map +1 -1
- package/lib/commonjs/charts/candle/Line.js +73 -28
- package/lib/commonjs/charts/candle/Line.js.map +1 -1
- package/lib/commonjs/charts/candle/PriceText.js +19 -14
- package/lib/commonjs/charts/candle/PriceText.js.map +1 -1
- package/lib/commonjs/charts/candle/index.js +67 -64
- package/lib/commonjs/charts/candle/types.js +4 -4
- package/lib/commonjs/charts/candle/useCandleData.js +9 -12
- package/lib/commonjs/charts/candle/useCandlestickChart.js +10 -9
- package/lib/commonjs/charts/candle/useCandlestickChart.js.map +1 -1
- package/lib/commonjs/charts/candle/useDatetime.js +16 -18
- package/lib/commonjs/charts/candle/useDatetime.js.map +1 -1
- package/lib/commonjs/charts/candle/usePrice.js +21 -22
- package/lib/commonjs/charts/candle/usePrice.js.map +1 -1
- package/lib/commonjs/charts/candle/utils/getDomain.js +5 -8
- package/lib/commonjs/charts/candle/utils/getHeight.js +12 -11
- package/lib/commonjs/charts/candle/utils/getPrice.js +12 -11
- package/lib/commonjs/charts/candle/utils/getY.js +12 -11
- package/lib/commonjs/charts/candle/utils/index.js +16 -16
- package/lib/commonjs/charts/line/Axis.js +402 -0
- package/lib/commonjs/charts/line/Axis.js.map +1 -0
- package/lib/commonjs/charts/line/Chart.js +140 -69
- package/lib/commonjs/charts/line/Chart.js.map +1 -1
- package/lib/commonjs/charts/line/ChartPath.js +290 -90
- package/lib/commonjs/charts/line/ChartPath.js.map +1 -1
- package/lib/commonjs/charts/line/Context.js +98 -40
- package/lib/commonjs/charts/line/Context.js.map +1 -1
- package/lib/commonjs/charts/line/Cursor.js +129 -75
- package/lib/commonjs/charts/line/Cursor.js.map +1 -1
- package/lib/commonjs/charts/line/CursorCrosshair.js +151 -58
- package/lib/commonjs/charts/line/CursorCrosshair.js.map +1 -1
- package/lib/commonjs/charts/line/CursorLine.js +251 -45
- package/lib/commonjs/charts/line/CursorLine.js.map +1 -1
- package/lib/commonjs/charts/line/Data.js +73 -35
- package/lib/commonjs/charts/line/Data.js.map +1 -1
- package/lib/commonjs/charts/line/DatetimeText.js +27 -14
- package/lib/commonjs/charts/line/DatetimeText.js.map +1 -1
- package/lib/commonjs/charts/line/Dot.js +150 -57
- package/lib/commonjs/charts/line/Dot.js.map +1 -1
- package/lib/commonjs/charts/line/Gradient.js +124 -54
- package/lib/commonjs/charts/line/Gradient.js.map +1 -1
- package/lib/commonjs/charts/line/Group.js +54 -24
- package/lib/commonjs/charts/line/Group.js.map +1 -1
- package/lib/commonjs/charts/line/Highlight.js +115 -47
- package/lib/commonjs/charts/line/Highlight.js.map +1 -1
- package/lib/commonjs/charts/line/HorizontalLine.js +92 -40
- package/lib/commonjs/charts/line/HorizontalLine.js.map +1 -1
- package/lib/commonjs/charts/line/HoverTrap/index.js +10 -7
- package/lib/commonjs/charts/line/HoverTrap/index.js.map +1 -1
- package/lib/commonjs/charts/line/HoverTrap/index.web.js +115 -86
- package/lib/commonjs/charts/line/HoverTrap/index.web.js.map +1 -1
- package/lib/commonjs/charts/line/LineChartPathContext.js +14 -11
- package/lib/commonjs/charts/line/LineChartPathContext.js.map +1 -1
- package/lib/commonjs/charts/line/Path.js +78 -39
- package/lib/commonjs/charts/line/Path.js.map +1 -1
- package/lib/commonjs/charts/line/PriceText.js +113 -14
- package/lib/commonjs/charts/line/PriceText.js.map +1 -1
- package/lib/commonjs/charts/line/Tooltip.js +236 -106
- package/lib/commonjs/charts/line/Tooltip.js.map +1 -1
- package/lib/commonjs/charts/line/index.js +75 -62
- package/lib/commonjs/charts/line/index.js.map +1 -1
- package/lib/commonjs/charts/line/types.js +4 -4
- package/lib/commonjs/charts/line/useAnimatedPath.js +28 -23
- package/lib/commonjs/charts/line/useAnimatedPath.js.map +1 -1
- package/lib/commonjs/charts/line/useCurrentY.js +17 -17
- package/lib/commonjs/charts/line/useDatetime.js +34 -33
- package/lib/commonjs/charts/line/useDatetime.js.map +1 -1
- package/lib/commonjs/charts/line/useLineChart.js +21 -17
- package/lib/commonjs/charts/line/useLineChart.js.map +1 -1
- package/lib/commonjs/charts/line/usePrice.js +30 -28
- package/lib/commonjs/charts/line/usePrice.js.map +1 -1
- package/lib/commonjs/charts/line/utils/getArea.js +48 -20
- package/lib/commonjs/charts/line/utils/getArea.js.map +1 -1
- package/lib/commonjs/charts/line/utils/getDomain.js +5 -7
- package/lib/commonjs/charts/line/utils/getPath.js +54 -20
- package/lib/commonjs/charts/line/utils/getPath.js.map +1 -1
- package/lib/commonjs/charts/line/utils/getXPositionForCurve.js +8 -5
- package/lib/commonjs/charts/line/utils/getXPositionForCurve.js.map +1 -1
- package/lib/commonjs/charts/line/utils/index.js +19 -19
- package/lib/commonjs/charts/line/utils/interpolatePath.js +102 -62
- package/lib/commonjs/charts/line/utils/interpolatePath.js.map +1 -1
- package/lib/commonjs/charts/line/utils/lineChartDataPropToArray.js +5 -5
- package/lib/commonjs/components/AnimatedText.js +66 -39
- package/lib/commonjs/components/AnimatedText.js.map +1 -1
- package/lib/commonjs/index.js +27 -16
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/types.js +2 -0
- package/lib/commonjs/types.js.map +1 -0
- package/lib/commonjs/utils/formatDatetime.js +5 -9
- package/lib/commonjs/utils/formatPrice.js +13 -9
- package/lib/commonjs/utils/formatPrice.js.map +1 -1
- package/lib/commonjs/utils/index.js +13 -13
- package/lib/commonjs/utils/usePrevious.js +10 -9
- package/lib/commonjs/utils/usePrevious.js.map +1 -1
- package/lib/module/charts/candle/Candle.js +126 -76
- package/lib/module/charts/candle/Candle.js.map +1 -1
- package/lib/module/charts/candle/Candles.js +53 -34
- package/lib/module/charts/candle/Candles.js.map +1 -1
- package/lib/module/charts/candle/Chart.js +23 -20
- package/lib/module/charts/candle/Chart.js.map +1 -1
- package/lib/module/charts/candle/Context.js +53 -23
- package/lib/module/charts/candle/Context.js.map +1 -1
- package/lib/module/charts/candle/Crosshair.js +151 -69
- package/lib/module/charts/candle/Crosshair.js.map +1 -1
- package/lib/module/charts/candle/CrosshairTooltip.js +102 -52
- package/lib/module/charts/candle/CrosshairTooltip.js.map +1 -1
- package/lib/module/charts/candle/DatetimeText.js +5 -5
- package/lib/module/charts/candle/Line.js +37 -19
- package/lib/module/charts/candle/PriceText.js +5 -5
- package/lib/module/charts/candle/PriceText.js.map +1 -1
- package/lib/module/charts/candle/index.js +2 -2
- package/lib/module/charts/candle/types.js +1 -1
- package/lib/module/charts/candle/useCandleData.js +3 -7
- package/lib/module/charts/candle/useCandlestickChart.js +2 -2
- package/lib/module/charts/candle/useCandlestickChart.js.map +1 -1
- package/lib/module/charts/candle/useDatetime.js +10 -12
- package/lib/module/charts/candle/useDatetime.js.map +1 -1
- package/lib/module/charts/candle/usePrice.js +12 -14
- package/lib/module/charts/candle/usePrice.js.map +1 -1
- package/lib/module/charts/candle/utils/getDomain.js +2 -5
- package/lib/module/charts/candle/utils/getHeight.js +8 -7
- package/lib/module/charts/candle/utils/getPrice.js +2 -6
- package/lib/module/charts/candle/utils/getY.js +2 -6
- package/lib/module/charts/candle/utils/index.js +1 -1
- package/lib/module/charts/line/Axis.js +349 -0
- package/lib/module/charts/line/Axis.js.map +1 -0
- package/lib/module/charts/line/Chart.js +82 -46
- package/lib/module/charts/line/Chart.js.map +1 -1
- package/lib/module/charts/line/ChartPath.js +246 -77
- package/lib/module/charts/line/ChartPath.js.map +1 -1
- package/lib/module/charts/line/Context.js +65 -32
- package/lib/module/charts/line/Context.js.map +1 -1
- package/lib/module/charts/line/Cursor.js +86 -60
- package/lib/module/charts/line/Cursor.js.map +1 -1
- package/lib/module/charts/line/CursorCrosshair.js +118 -50
- package/lib/module/charts/line/CursorCrosshair.js.map +1 -1
- package/lib/module/charts/line/CursorLine.js +210 -33
- package/lib/module/charts/line/CursorLine.js.map +1 -1
- package/lib/module/charts/line/Data.js +41 -28
- package/lib/module/charts/line/Data.js.map +1 -1
- package/lib/module/charts/line/DatetimeText.js +14 -6
- package/lib/module/charts/line/DatetimeText.js.map +1 -1
- package/lib/module/charts/line/Dot.js +95 -41
- package/lib/module/charts/line/Dot.js.map +1 -1
- package/lib/module/charts/line/Gradient.js +80 -42
- package/lib/module/charts/line/Gradient.js.map +1 -1
- package/lib/module/charts/line/Group.js +15 -14
- package/lib/module/charts/line/Highlight.js +62 -32
- package/lib/module/charts/line/Highlight.js.map +1 -1
- package/lib/module/charts/line/HorizontalLine.js +49 -27
- package/lib/module/charts/line/HorizontalLine.js.map +1 -1
- package/lib/module/charts/line/HoverTrap/index.js +3 -2
- package/lib/module/charts/line/HoverTrap/index.web.js +102 -76
- package/lib/module/charts/line/HoverTrap/index.web.js.map +1 -1
- package/lib/module/charts/line/LineChartPathContext.js +3 -3
- package/lib/module/charts/line/Path.js +34 -27
- package/lib/module/charts/line/Path.js.map +1 -1
- package/lib/module/charts/line/PriceText.js +80 -6
- package/lib/module/charts/line/PriceText.js.map +1 -1
- package/lib/module/charts/line/Tooltip.js +202 -94
- package/lib/module/charts/line/Tooltip.js.map +1 -1
- package/lib/module/charts/line/index.js +6 -3
- package/lib/module/charts/line/index.js.map +1 -1
- package/lib/module/charts/line/types.js +1 -1
- package/lib/module/charts/line/useAnimatedPath.js +22 -16
- package/lib/module/charts/line/useAnimatedPath.js.map +1 -1
- package/lib/module/charts/line/useCurrentY.js +4 -9
- package/lib/module/charts/line/useDatetime.js +28 -27
- package/lib/module/charts/line/useDatetime.js.map +1 -1
- package/lib/module/charts/line/useLineChart.js +11 -8
- package/lib/module/charts/line/useLineChart.js.map +1 -1
- package/lib/module/charts/line/usePrice.js +24 -22
- package/lib/module/charts/line/usePrice.js.map +1 -1
- package/lib/module/charts/line/utils/getArea.js +16 -11
- package/lib/module/charts/line/utils/getArea.js.map +1 -1
- package/lib/module/charts/line/utils/getDomain.js +2 -4
- package/lib/module/charts/line/utils/getPath.js +22 -11
- package/lib/module/charts/line/utils/getPath.js.map +1 -1
- package/lib/module/charts/line/utils/getXPositionForCurve.js +5 -2
- package/lib/module/charts/line/utils/getXPositionForCurve.js.map +1 -1
- package/lib/module/charts/line/utils/index.js +1 -1
- package/lib/module/charts/line/utils/interpolatePath.js +99 -59
- package/lib/module/charts/line/utils/interpolatePath.js.map +1 -1
- package/lib/module/charts/line/utils/lineChartDataPropToArray.js +2 -2
- package/lib/module/components/AnimatedText.js +24 -30
- package/lib/module/components/AnimatedText.js.map +1 -1
- package/lib/module/index.js +2 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/types.js +1 -0
- package/lib/module/types.js.map +1 -0
- package/lib/module/utils/formatDatetime.js +2 -6
- package/lib/module/utils/formatPrice.js +10 -6
- package/lib/module/utils/formatPrice.js.map +1 -1
- package/lib/module/utils/index.js +1 -1
- package/lib/module/utils/usePrevious.js +2 -2
- package/lib/module/utils/usePrevious.js.map +1 -1
- package/lib/typescript/src/charts/candle/Candle.d.ts +45 -31
- package/lib/typescript/src/charts/candle/Candle.d.ts.map +1 -1
- package/lib/typescript/src/charts/candle/Candles.d.ts +25 -14
- package/lib/typescript/src/charts/candle/Candles.d.ts.map +1 -1
- package/lib/typescript/src/charts/candle/Chart.d.ts +13 -8
- package/lib/typescript/src/charts/candle/Chart.d.ts.map +1 -1
- package/lib/typescript/src/charts/candle/Context.d.ts +15 -8
- package/lib/typescript/src/charts/candle/Context.d.ts.map +1 -1
- package/lib/typescript/src/charts/candle/Crosshair.d.ts +18 -10
- package/lib/typescript/src/charts/candle/Crosshair.d.ts.map +1 -1
- package/lib/typescript/src/charts/candle/CrosshairTooltip.d.ts +16 -9
- package/lib/typescript/src/charts/candle/CrosshairTooltip.d.ts.map +1 -1
- package/lib/typescript/src/charts/candle/DatetimeText.d.ts +16 -10
- package/lib/typescript/src/charts/candle/DatetimeText.d.ts.map +1 -1
- package/lib/typescript/src/charts/candle/Line.d.ts +10 -5
- package/lib/typescript/src/charts/candle/Line.d.ts.map +1 -1
- package/lib/typescript/src/charts/candle/PriceText.d.ts +15 -8
- package/lib/typescript/src/charts/candle/PriceText.d.ts.map +1 -1
- package/lib/typescript/src/charts/candle/index.d.ts +32 -14
- package/lib/typescript/src/charts/candle/index.d.ts.map +1 -1
- package/lib/typescript/src/charts/candle/types.d.ts +16 -19
- package/lib/typescript/src/charts/candle/types.d.ts.map +1 -1
- package/lib/typescript/src/charts/candle/useCandleData.d.ts +1 -1
- package/lib/typescript/src/charts/candle/useCandlestickChart.d.ts +1 -1
- package/lib/typescript/src/charts/candle/useDatetime.d.ts +14 -10
- package/lib/typescript/src/charts/candle/useDatetime.d.ts.map +1 -1
- package/lib/typescript/src/charts/candle/usePrice.d.ts +13 -8
- package/lib/typescript/src/charts/candle/usePrice.d.ts.map +1 -1
- package/lib/typescript/src/charts/candle/utils/getDomain.d.ts +1 -1
- package/lib/typescript/src/charts/candle/utils/getHeight.d.ts +9 -5
- package/lib/typescript/src/charts/candle/utils/getPrice.d.ts +9 -5
- package/lib/typescript/src/charts/candle/utils/getY.d.ts +9 -5
- package/lib/typescript/src/charts/candle/utils/index.d.ts +1 -1
- package/lib/typescript/src/charts/line/Axis.d.ts +33 -0
- package/lib/typescript/src/charts/line/Axis.d.ts.map +1 -0
- package/lib/typescript/src/charts/line/Chart.d.ts +33 -23
- package/lib/typescript/src/charts/line/Chart.d.ts.map +1 -1
- package/lib/typescript/src/charts/line/ChartPath.d.ts +29 -16
- package/lib/typescript/src/charts/line/ChartPath.d.ts.map +1 -1
- package/lib/typescript/src/charts/line/Context.d.ts +17 -10
- package/lib/typescript/src/charts/line/Context.d.ts.map +1 -1
- package/lib/typescript/src/charts/line/Cursor.d.ts +23 -13
- package/lib/typescript/src/charts/line/Cursor.d.ts.map +1 -1
- package/lib/typescript/src/charts/line/CursorCrosshair.d.ts +24 -12
- package/lib/typescript/src/charts/line/CursorCrosshair.d.ts.map +1 -1
- package/lib/typescript/src/charts/line/CursorLine.d.ts +19 -8
- package/lib/typescript/src/charts/line/CursorLine.d.ts.map +1 -1
- package/lib/typescript/src/charts/line/Data.d.ts +17 -13
- package/lib/typescript/src/charts/line/DatetimeText.d.ts +15 -9
- package/lib/typescript/src/charts/line/DatetimeText.d.ts.map +1 -1
- package/lib/typescript/src/charts/line/Dot.d.ts +39 -26
- package/lib/typescript/src/charts/line/Dot.d.ts.map +1 -1
- package/lib/typescript/src/charts/line/Gradient.d.ts +9 -5
- package/lib/typescript/src/charts/line/Gradient.d.ts.map +1 -1
- package/lib/typescript/src/charts/line/Group.d.ts +6 -3
- package/lib/typescript/src/charts/line/Highlight.d.ts +17 -9
- package/lib/typescript/src/charts/line/Highlight.d.ts.map +1 -1
- package/lib/typescript/src/charts/line/HorizontalLine.d.ts +30 -26
- package/lib/typescript/src/charts/line/HorizontalLine.d.ts.map +1 -1
- package/lib/typescript/src/charts/line/HoverTrap/index.d.ts +1 -1
- package/lib/typescript/src/charts/line/HoverTrap/index.web.d.ts +2 -2
- package/lib/typescript/src/charts/line/HoverTrap/index.web.d.ts.map +1 -1
- package/lib/typescript/src/charts/line/LineChartPathContext.d.ts +4 -4
- package/lib/typescript/src/charts/line/Path.d.ts +28 -23
- package/lib/typescript/src/charts/line/Path.d.ts.map +1 -1
- package/lib/typescript/src/charts/line/PriceText.d.ts +29 -13
- package/lib/typescript/src/charts/line/PriceText.d.ts.map +1 -1
- package/lib/typescript/src/charts/line/Tooltip.d.ts +34 -22
- package/lib/typescript/src/charts/line/Tooltip.d.ts.map +1 -1
- package/lib/typescript/src/charts/line/index.d.ts +34 -20
- package/lib/typescript/src/charts/line/index.d.ts.map +1 -1
- package/lib/typescript/src/charts/line/types.d.ts +19 -18
- package/lib/typescript/src/charts/line/types.d.ts.map +1 -1
- package/lib/typescript/src/charts/line/useAnimatedPath.d.ts +10 -7
- package/lib/typescript/src/charts/line/useAnimatedPath.d.ts.map +1 -1
- package/lib/typescript/src/charts/line/useCurrentY.d.ts +2 -2
- package/lib/typescript/src/charts/line/useCurrentY.d.ts.map +1 -1
- package/lib/typescript/src/charts/line/useDatetime.d.ts +12 -8
- package/lib/typescript/src/charts/line/useDatetime.d.ts.map +1 -1
- package/lib/typescript/src/charts/line/useLineChart.d.ts +10 -10
- package/lib/typescript/src/charts/line/usePrice.d.ts +12 -8
- package/lib/typescript/src/charts/line/usePrice.d.ts.map +1 -1
- package/lib/typescript/src/charts/line/utils/getArea.d.ts +17 -9
- package/lib/typescript/src/charts/line/utils/getArea.d.ts.map +1 -1
- package/lib/typescript/src/charts/line/utils/getDomain.d.ts +1 -1
- package/lib/typescript/src/charts/line/utils/getPath.d.ts +21 -11
- package/lib/typescript/src/charts/line/utils/getPath.d.ts.map +1 -1
- package/lib/typescript/src/charts/line/utils/getXPositionForCurve.d.ts +1 -1
- package/lib/typescript/src/charts/line/utils/index.d.ts +1 -1
- package/lib/typescript/src/charts/line/utils/interpolatePath.d.ts +17 -5
- package/lib/typescript/src/charts/line/utils/lineChartDataPropToArray.d.ts +4 -2
- package/lib/typescript/src/components/AnimatedText.d.ts +7 -4
- package/lib/typescript/src/components/AnimatedText.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +2 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/types.d.ts +8 -0
- package/lib/typescript/src/types.d.ts.map +1 -0
- package/lib/typescript/src/utils/formatDatetime.d.ts +9 -5
- package/lib/typescript/src/utils/formatPrice.d.ts +9 -5
- package/lib/typescript/src/utils/formatPrice.d.ts.map +1 -1
- package/lib/typescript/src/utils/index.d.ts +1 -1
- package/lib/typescript/src/utils/usePrevious.d.ts +1 -1
- package/package.json +19 -43
- package/src/charts/candle/Candle.tsx +2 -17
- package/src/charts/candle/Candles.tsx +1 -3
- package/src/charts/candle/Chart.tsx +1 -1
- package/src/charts/candle/Context.tsx +30 -7
- package/src/charts/candle/Crosshair.tsx +20 -8
- package/src/charts/candle/CrosshairTooltip.tsx +3 -1
- package/src/charts/candle/DatetimeText.tsx +1 -1
- package/src/charts/candle/PriceText.tsx +2 -1
- package/src/charts/candle/types.ts +1 -7
- package/src/charts/candle/useCandlestickChart.ts +1 -1
- package/src/charts/candle/useDatetime.ts +3 -1
- package/src/charts/candle/usePrice.ts +5 -1
- package/src/charts/line/Axis.tsx +363 -0
- package/src/charts/line/Chart.tsx +10 -7
- package/src/charts/line/ChartPath.tsx +77 -18
- package/src/charts/line/Context.tsx +29 -18
- package/src/charts/line/Cursor.tsx +15 -11
- package/src/charts/line/CursorCrosshair.tsx +27 -8
- package/src/charts/line/CursorLine.tsx +177 -18
- package/src/charts/line/Data.tsx +6 -4
- package/src/charts/line/DatetimeText.tsx +12 -3
- package/src/charts/line/Dot.tsx +2 -2
- package/src/charts/line/Gradient.tsx +2 -5
- package/src/charts/line/Highlight.tsx +8 -4
- package/src/charts/line/HorizontalLine.tsx +2 -8
- package/src/charts/line/HoverTrap/index.web.tsx +93 -60
- package/src/charts/line/Path.tsx +10 -17
- package/src/charts/line/PriceText.tsx +74 -4
- package/src/charts/line/Tooltip.tsx +135 -69
- package/src/charts/line/index.ts +4 -1
- package/src/charts/line/types.ts +1 -2
- package/src/charts/line/useAnimatedPath.ts +1 -2
- package/src/charts/line/useDatetime.ts +13 -10
- package/src/charts/line/useLineChart.ts +1 -1
- package/src/charts/line/usePrice.ts +6 -4
- package/src/charts/line/utils/getArea.ts +12 -10
- package/src/charts/line/utils/getPath.ts +13 -10
- package/src/charts/line/utils/getXPositionForCurve.ts +1 -1
- package/src/charts/line/utils/interpolatePath.ts +2 -2
- package/src/components/AnimatedText.tsx +13 -20
- package/src/index.ts +1 -0
- package/src/types.ts +7 -0
- package/src/utils/formatPrice.ts +7 -7
- package/src/utils/usePrevious.ts +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import React from 'react';
|
|
2
2
|
|
|
3
3
|
import Animated, {
|
|
4
4
|
useAnimatedStyle,
|
|
@@ -7,6 +7,7 @@ import Animated, {
|
|
|
7
7
|
withTiming,
|
|
8
8
|
AnimatedProps,
|
|
9
9
|
} from 'react-native-reanimated';
|
|
10
|
+
import { StyleSheet } from 'react-native';
|
|
10
11
|
import { LineChartPriceText, LineChartPriceTextProps } from './PriceText';
|
|
11
12
|
|
|
12
13
|
import { CursorContext } from './Cursor';
|
|
@@ -16,7 +17,7 @@ import { getXPositionForCurve } from './utils/getXPositionForCurve';
|
|
|
16
17
|
import { getYForX } from 'react-native-redash';
|
|
17
18
|
import { useLineChart } from './useLineChart';
|
|
18
19
|
import { useMemo } from 'react';
|
|
19
|
-
import type { TFormatterFn } from '
|
|
20
|
+
import type { TFormatterFn } from '../../types';
|
|
20
21
|
|
|
21
22
|
export type LineChartTooltipPosition = 'top' | 'bottom' | 'left' | 'right';
|
|
22
23
|
|
|
@@ -97,74 +98,136 @@ export function LineChartTooltip({
|
|
|
97
98
|
[cursorGutter, position]
|
|
98
99
|
);
|
|
99
100
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
101
|
+
/**
|
|
102
|
+
* Helper function to calculate the X translation offset based on position
|
|
103
|
+
* and boundary constraints
|
|
104
|
+
*/
|
|
105
|
+
const calculateXTranslateOffset = React.useCallback(
|
|
106
|
+
(params: {
|
|
107
|
+
position: LineChartTooltipPosition;
|
|
108
|
+
x: number;
|
|
109
|
+
elementWidth: number;
|
|
110
|
+
width: number;
|
|
111
|
+
xGutter: number;
|
|
112
|
+
cursorGutter: number;
|
|
113
|
+
withHorizontalFloating: boolean;
|
|
114
|
+
}) => {
|
|
115
|
+
'worklet';
|
|
116
|
+
const {
|
|
117
|
+
position,
|
|
118
|
+
x,
|
|
119
|
+
elementWidth,
|
|
120
|
+
width,
|
|
121
|
+
xGutter,
|
|
122
|
+
cursorGutter,
|
|
123
|
+
withHorizontalFloating,
|
|
124
|
+
} = params;
|
|
103
125
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
translateXOffset = -cursorGutter;
|
|
113
|
-
} else {
|
|
114
|
-
translateXOffset = translateXOffset - elementFullWidth + x;
|
|
126
|
+
let translateXOffset = getInitialTranslateXOffset(elementWidth);
|
|
127
|
+
const elementFullWidth = elementWidth + xGutter + cursorGutter;
|
|
128
|
+
|
|
129
|
+
if (position === 'right') {
|
|
130
|
+
if (x < elementFullWidth) {
|
|
131
|
+
translateXOffset = withHorizontalFloating
|
|
132
|
+
? -cursorGutter
|
|
133
|
+
: translateXOffset - elementFullWidth + x;
|
|
115
134
|
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
|
|
135
|
+
} else if (position === 'left') {
|
|
136
|
+
if (x > width - elementFullWidth) {
|
|
137
|
+
translateXOffset = withHorizontalFloating
|
|
138
|
+
? elementWidth + cursorGutter
|
|
139
|
+
: translateXOffset + (x - (width - elementFullWidth));
|
|
140
|
+
}
|
|
141
|
+
} else {
|
|
142
|
+
// Center position
|
|
143
|
+
if (x < elementWidth / 2 + xGutter) {
|
|
144
|
+
translateXOffset -= elementWidth / 2 + xGutter - x;
|
|
145
|
+
}
|
|
146
|
+
if (x > width - elementWidth / 2 - xGutter) {
|
|
147
|
+
translateXOffset += x - (width - elementWidth / 2 - xGutter);
|
|
124
148
|
}
|
|
125
149
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
150
|
+
|
|
151
|
+
return translateXOffset;
|
|
152
|
+
},
|
|
153
|
+
[getInitialTranslateXOffset]
|
|
154
|
+
);
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Helper function to calculate the Y translation offset based on position and
|
|
158
|
+
* boundary constraints
|
|
159
|
+
*/
|
|
160
|
+
const calculateYTranslateOffset = React.useCallback(
|
|
161
|
+
(params: {
|
|
162
|
+
position: LineChartTooltipPosition;
|
|
163
|
+
y: number;
|
|
164
|
+
elementHeight: number;
|
|
165
|
+
height: number;
|
|
166
|
+
yGutter: number;
|
|
167
|
+
cursorGutter: number;
|
|
168
|
+
}) => {
|
|
169
|
+
'worklet';
|
|
170
|
+
const { position, y, elementHeight, height, yGutter, cursorGutter } =
|
|
171
|
+
params;
|
|
172
|
+
let translateYOffset = 0;
|
|
173
|
+
|
|
174
|
+
if (position === 'top') {
|
|
175
|
+
translateYOffset = elementHeight / 2 + cursorGutter;
|
|
176
|
+
if (y - translateYOffset < yGutter) {
|
|
177
|
+
translateYOffset = y - yGutter;
|
|
178
|
+
}
|
|
179
|
+
} else if (position === 'bottom') {
|
|
180
|
+
translateYOffset = -(elementHeight / 2) - cursorGutter / 2;
|
|
181
|
+
if (y - translateYOffset + elementHeight > height - yGutter) {
|
|
182
|
+
translateYOffset = y - (height - yGutter) + elementHeight;
|
|
183
|
+
}
|
|
184
|
+
} else if (position === 'right' || position === 'left') {
|
|
185
|
+
translateYOffset = elementHeight / 2;
|
|
134
186
|
}
|
|
135
|
-
}
|
|
136
187
|
|
|
188
|
+
return translateYOffset;
|
|
189
|
+
},
|
|
190
|
+
[]
|
|
191
|
+
);
|
|
192
|
+
|
|
193
|
+
const animatedCursorStyle = useAnimatedStyle(() => {
|
|
194
|
+
// the tooltip is considered static when the user specified an `at` prop
|
|
195
|
+
const isStatic = atYPosition.value != null;
|
|
196
|
+
|
|
197
|
+
// Calculate X position:
|
|
198
|
+
const x = atXPosition ?? currentX.value;
|
|
199
|
+
const translateXOffset = calculateXTranslateOffset({
|
|
200
|
+
position,
|
|
201
|
+
x,
|
|
202
|
+
elementWidth: elementWidth.value,
|
|
203
|
+
width,
|
|
204
|
+
xGutter,
|
|
205
|
+
cursorGutter,
|
|
206
|
+
withHorizontalFloating,
|
|
207
|
+
});
|
|
137
208
|
const translateX = x - translateXOffset;
|
|
138
209
|
|
|
139
210
|
// Calculate Y position:
|
|
140
|
-
let translateYOffset = 0;
|
|
141
211
|
const y = atYPosition.value ?? currentY.value;
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
translateYOffset = y - (height - yGutter) + elementHeight.value;
|
|
151
|
-
}
|
|
152
|
-
} else if (position === 'right' || position === 'left') {
|
|
153
|
-
translateYOffset = elementHeight.value / 2;
|
|
154
|
-
}
|
|
212
|
+
const translateYOffset = calculateYTranslateOffset({
|
|
213
|
+
position,
|
|
214
|
+
y,
|
|
215
|
+
elementHeight: elementHeight.value,
|
|
216
|
+
height,
|
|
217
|
+
yGutter,
|
|
218
|
+
cursorGutter,
|
|
219
|
+
});
|
|
155
220
|
|
|
156
|
-
//
|
|
157
|
-
let translateY: number
|
|
221
|
+
// Determine final translateY value
|
|
222
|
+
let translateY: number;
|
|
158
223
|
if (type === 'crosshair' || isStatic) {
|
|
159
224
|
translateY = y - translateYOffset;
|
|
160
225
|
} else {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
} else {
|
|
164
|
-
translateY = height - elementHeight.value - yGutter;
|
|
165
|
-
}
|
|
226
|
+
translateY =
|
|
227
|
+
position === 'top' ? yGutter : height - elementHeight.value - yGutter;
|
|
166
228
|
}
|
|
167
229
|
|
|
230
|
+
// Calculate opacity
|
|
168
231
|
let opacity = isActive.value ? 1 : 0;
|
|
169
232
|
if (isStatic) {
|
|
170
233
|
// Only show static when there is no active cursor
|
|
@@ -177,17 +240,20 @@ export function LineChartTooltip({
|
|
|
177
240
|
};
|
|
178
241
|
}, [
|
|
179
242
|
atXPosition,
|
|
180
|
-
atYPosition
|
|
181
|
-
|
|
182
|
-
|
|
243
|
+
atYPosition,
|
|
244
|
+
calculateXTranslateOffset,
|
|
245
|
+
calculateYTranslateOffset,
|
|
246
|
+
currentX,
|
|
247
|
+
currentY,
|
|
183
248
|
cursorGutter,
|
|
184
|
-
elementHeight
|
|
185
|
-
elementWidth
|
|
249
|
+
elementHeight,
|
|
250
|
+
elementWidth,
|
|
186
251
|
height,
|
|
187
|
-
isActive
|
|
252
|
+
isActive,
|
|
188
253
|
position,
|
|
189
254
|
type,
|
|
190
255
|
width,
|
|
256
|
+
withHorizontalFloating,
|
|
191
257
|
xGutter,
|
|
192
258
|
yGutter,
|
|
193
259
|
]);
|
|
@@ -196,15 +262,7 @@ export function LineChartTooltip({
|
|
|
196
262
|
<Animated.View
|
|
197
263
|
onLayout={handleLayout}
|
|
198
264
|
{...props}
|
|
199
|
-
style={[
|
|
200
|
-
{
|
|
201
|
-
position: 'absolute',
|
|
202
|
-
padding: 4,
|
|
203
|
-
alignSelf: 'flex-start',
|
|
204
|
-
},
|
|
205
|
-
animatedCursorStyle,
|
|
206
|
-
props.style,
|
|
207
|
-
]}
|
|
265
|
+
style={[styles.tooltip, animatedCursorStyle, props.style]}
|
|
208
266
|
>
|
|
209
267
|
{children || (
|
|
210
268
|
<LineChartPriceText
|
|
@@ -217,3 +275,11 @@ export function LineChartTooltip({
|
|
|
217
275
|
</Animated.View>
|
|
218
276
|
);
|
|
219
277
|
}
|
|
278
|
+
|
|
279
|
+
const styles = StyleSheet.create({
|
|
280
|
+
tooltip: {
|
|
281
|
+
position: 'absolute',
|
|
282
|
+
padding: 4,
|
|
283
|
+
alignSelf: 'flex-start',
|
|
284
|
+
},
|
|
285
|
+
});
|
package/src/charts/line/index.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { LineChartAxis } from './Axis';
|
|
1
2
|
import { LineChart as _LineChart } from './Chart';
|
|
2
3
|
import { LineChartPathWrapper } from './ChartPath';
|
|
3
4
|
import { LineChartHighlight } from './Highlight';
|
|
@@ -15,8 +16,9 @@ import { LineChartDatetimeText } from './DatetimeText';
|
|
|
15
16
|
import { useLineChartDatetime } from './useDatetime';
|
|
16
17
|
import { useLineChartPrice } from './usePrice';
|
|
17
18
|
import { useLineChart } from './useLineChart';
|
|
18
|
-
import { LineChartHoverTrap } from '
|
|
19
|
+
import { LineChartHoverTrap } from './HoverTrap';
|
|
19
20
|
|
|
21
|
+
export * from './Axis';
|
|
20
22
|
export * from './Chart';
|
|
21
23
|
export * from './ChartPath';
|
|
22
24
|
export * from './Highlight';
|
|
@@ -36,6 +38,7 @@ export * from './usePrice';
|
|
|
36
38
|
export * from './types';
|
|
37
39
|
|
|
38
40
|
export const LineChart = Object.assign(_LineChart, {
|
|
41
|
+
Axis: LineChartAxis,
|
|
39
42
|
Chart: _LineChart,
|
|
40
43
|
Dot: LineChartDot,
|
|
41
44
|
Path: LineChartPathWrapper,
|
package/src/charts/line/types.ts
CHANGED
|
@@ -10,12 +10,11 @@ export type TLineChartDataProp =
|
|
|
10
10
|
[key: string]: TLineChartData;
|
|
11
11
|
};
|
|
12
12
|
export type TLineChartData = Array<TLineChartPoint>;
|
|
13
|
-
export type TLineChartDomain = [number, number];
|
|
14
13
|
export type TLineChartContext = {
|
|
15
14
|
currentX: SharedValue<number>;
|
|
16
15
|
currentIndex: SharedValue<number>;
|
|
17
16
|
isActive: SharedValue<boolean>;
|
|
18
|
-
domain:
|
|
17
|
+
domain: [number, number];
|
|
19
18
|
yDomain: YDomain;
|
|
20
19
|
xLength: number;
|
|
21
20
|
xDomain?: [number, number] | undefined;
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
import { interpolatePath } from './utils';
|
|
9
9
|
import { usePrevious } from '../../utils';
|
|
10
10
|
|
|
11
|
-
export
|
|
11
|
+
export function useAnimatedPath({
|
|
12
12
|
enabled = true,
|
|
13
13
|
path,
|
|
14
14
|
}: {
|
|
@@ -16,7 +16,6 @@ export default function useAnimatedPath({
|
|
|
16
16
|
path: string;
|
|
17
17
|
}) {
|
|
18
18
|
const transition = useSharedValue(0);
|
|
19
|
-
|
|
20
19
|
const previousPath = usePrevious(path);
|
|
21
20
|
|
|
22
21
|
useAnimatedReaction(
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useDerivedValue } from 'react-native-reanimated';
|
|
2
2
|
|
|
3
3
|
import { formatDatetime } from '../../utils';
|
|
4
|
-
import type { TFormatterFn } from '
|
|
4
|
+
import type { TFormatterFn } from '../../types';
|
|
5
5
|
import { useLineChart } from './useLineChart';
|
|
6
6
|
|
|
7
7
|
export function useLineChartDatetime({
|
|
@@ -26,23 +26,26 @@ export function useLineChartDatetime({
|
|
|
26
26
|
return data[currentIndex.value]?.timestamp ?? '';
|
|
27
27
|
}, [currentIndex, data]);
|
|
28
28
|
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
const value = useDerivedValue(
|
|
30
|
+
() => new Date(timestamp.value).getTime(),
|
|
31
|
+
[timestamp]
|
|
32
|
+
);
|
|
33
33
|
|
|
34
34
|
const formatted = useDerivedValue(() => {
|
|
35
|
-
const formattedDatetime =
|
|
35
|
+
const formattedDatetime = value.value
|
|
36
36
|
? formatDatetime({
|
|
37
|
-
value:
|
|
37
|
+
value: value.value,
|
|
38
38
|
locale,
|
|
39
39
|
options,
|
|
40
40
|
})
|
|
41
41
|
: '';
|
|
42
42
|
return format
|
|
43
|
-
? format({
|
|
43
|
+
? format({
|
|
44
|
+
value: value.value || -1,
|
|
45
|
+
formatted: formattedDatetime,
|
|
46
|
+
})
|
|
44
47
|
: formattedDatetime;
|
|
45
|
-
}, [format, locale, options,
|
|
48
|
+
}, [format, locale, options, value]);
|
|
46
49
|
|
|
47
|
-
return { value
|
|
50
|
+
return { value, formatted };
|
|
48
51
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useDerivedValue } from 'react-native-reanimated';
|
|
2
2
|
|
|
3
3
|
import { formatPrice } from '../../utils';
|
|
4
|
-
import type { TFormatterFn } from '
|
|
4
|
+
import type { TFormatterFn } from '../../types';
|
|
5
5
|
import { useLineChart } from './useLineChart';
|
|
6
6
|
|
|
7
7
|
export function useLineChartPrice({
|
|
@@ -24,12 +24,14 @@ export function useLineChartPrice({
|
|
|
24
24
|
return '';
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
const dataPoint =
|
|
28
|
+
data[Math.min(index ?? currentIndex.value, data.length - 1)];
|
|
29
|
+
const price = dataPoint?.value ?? 0;
|
|
29
30
|
return price.toFixed(precision).toString();
|
|
30
31
|
}, [currentIndex, data, precision]);
|
|
32
|
+
|
|
31
33
|
const formatted = useDerivedValue(() => {
|
|
32
|
-
|
|
34
|
+
const value = float.value || '';
|
|
33
35
|
const formattedPrice = value ? formatPrice({ value }) : '';
|
|
34
36
|
return format
|
|
35
37
|
? format({ value, formatted: formattedPrice })
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
// @ts-ignore
|
|
2
1
|
import * as shape from 'd3-shape';
|
|
3
|
-
|
|
4
|
-
import type { TLineChartData, YDomain } from '../types';
|
|
5
|
-
|
|
6
|
-
// @ts-ignore
|
|
7
2
|
import { scaleLinear } from 'd3-scale';
|
|
8
3
|
|
|
4
|
+
import type { TLineChartData, TLineChartPoint, YDomain } from '../types';
|
|
5
|
+
|
|
9
6
|
export function getArea({
|
|
10
7
|
data,
|
|
11
8
|
width,
|
|
@@ -28,14 +25,19 @@ export function getArea({
|
|
|
28
25
|
const scaleX = scaleLinear()
|
|
29
26
|
.domain(xDomain ?? [Math.min(...timestamps), Math.max(...timestamps)])
|
|
30
27
|
.range([0, width]);
|
|
28
|
+
|
|
31
29
|
const scaleY = scaleLinear()
|
|
32
30
|
.domain([yDomain.min, yDomain.max])
|
|
33
31
|
.range([height - gutter, gutter]);
|
|
32
|
+
|
|
34
33
|
const area = shape
|
|
35
|
-
.area()
|
|
36
|
-
.x((_:
|
|
37
|
-
|
|
34
|
+
.area<TLineChartPoint>()
|
|
35
|
+
.x((_: TLineChartPoint, i: number) =>
|
|
36
|
+
scaleX(xDomain ? timestamps[i] ?? i : i)
|
|
37
|
+
)
|
|
38
|
+
.y0((d: TLineChartPoint) => scaleY(d.value))
|
|
38
39
|
.y1(() => height)
|
|
39
|
-
.curve(_shape)(data);
|
|
40
|
-
|
|
40
|
+
.curve(_shape as shape.CurveFactory)(data);
|
|
41
|
+
|
|
42
|
+
return area || '';
|
|
41
43
|
}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
// @ts-ignore
|
|
2
1
|
import * as shape from 'd3-shape';
|
|
3
|
-
// @ts-ignore
|
|
4
2
|
import { scaleLinear } from 'd3-scale';
|
|
5
3
|
|
|
6
|
-
import type { TLineChartData, YDomain } from '../types';
|
|
4
|
+
import type { TLineChartData, TLineChartPoint, YDomain } from '../types';
|
|
7
5
|
|
|
8
6
|
export function getPath({
|
|
9
7
|
data,
|
|
@@ -31,20 +29,25 @@ export function getPath({
|
|
|
31
29
|
const scaleX = scaleLinear()
|
|
32
30
|
.domain(xDomain ?? [Math.min(...timestamps), Math.max(...timestamps)])
|
|
33
31
|
.range([0, width]);
|
|
32
|
+
|
|
34
33
|
const scaleY = scaleLinear()
|
|
35
34
|
.domain([yDomain.min, yDomain.max])
|
|
36
35
|
.range([height - gutter, gutter]);
|
|
36
|
+
|
|
37
37
|
const path = shape
|
|
38
|
-
.line()
|
|
39
|
-
.defined((d:
|
|
38
|
+
.line<TLineChartPoint>()
|
|
39
|
+
.defined((d: TLineChartPoint) =>
|
|
40
40
|
from || to
|
|
41
|
-
? data
|
|
41
|
+
? !!data
|
|
42
42
|
.slice(from, to ? to + 1 : undefined)
|
|
43
43
|
.find((item) => item.timestamp === d.timestamp)
|
|
44
44
|
: true
|
|
45
45
|
)
|
|
46
|
-
.x((_:
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
46
|
+
.x((_: TLineChartPoint, i: number) =>
|
|
47
|
+
scaleX(xDomain ? timestamps[i] ?? i : i)
|
|
48
|
+
)
|
|
49
|
+
.y((d: TLineChartPoint) => scaleY(d.value))
|
|
50
|
+
.curve(_shape as shape.CurveFactory)(data);
|
|
51
|
+
|
|
52
|
+
return path || '';
|
|
50
53
|
}
|
|
@@ -11,7 +11,7 @@ export function getXPositionForCurve(path: Path, index: number) {
|
|
|
11
11
|
if (point === undefined) {
|
|
12
12
|
throw new Error(
|
|
13
13
|
`Index out of bounds: ${index}. ` +
|
|
14
|
-
|
|
14
|
+
`Expected an integer in the range [0, ${path.curves.length}]`
|
|
15
15
|
);
|
|
16
16
|
}
|
|
17
17
|
|
|
@@ -611,8 +611,8 @@ export function interpolatePathCommands(
|
|
|
611
611
|
export function interpolatePath(a, b, excludeSegment) {
|
|
612
612
|
'worklet';
|
|
613
613
|
|
|
614
|
-
|
|
615
|
-
|
|
614
|
+
const aCommands = pathCommandsFromString(a);
|
|
615
|
+
const bCommands = pathCommandsFromString(b);
|
|
616
616
|
|
|
617
617
|
if (!aCommands.length && !bCommands.length) {
|
|
618
618
|
return function nullInterpolator() {
|
|
@@ -18,34 +18,27 @@ interface AnimatedTextProps {
|
|
|
18
18
|
const AnimatedTextInput = Animated.createAnimatedComponent(TextInput);
|
|
19
19
|
|
|
20
20
|
export const AnimatedText = ({ text, style }: AnimatedTextProps) => {
|
|
21
|
-
const inputRef = React.useRef<
|
|
21
|
+
const inputRef = React.useRef<TextInput>(null);
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
useAnimatedReaction(
|
|
24
|
+
() => text.value,
|
|
25
|
+
(data, prevData) => {
|
|
26
|
+
// Only execute for web platform
|
|
27
|
+
if (Platform.OS === 'web' && data !== prevData && inputRef.current) {
|
|
28
|
+
// @ts-expect-error - web TextInput has value property
|
|
29
|
+
inputRef.current.value = data;
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
[text]
|
|
33
|
+
);
|
|
28
34
|
|
|
29
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
30
|
-
useAnimatedReaction(
|
|
31
|
-
() => {
|
|
32
|
-
return text.value;
|
|
33
|
-
},
|
|
34
|
-
(data, prevData) => {
|
|
35
|
-
if (data !== prevData && inputRef.current) {
|
|
36
|
-
inputRef.current.value = data;
|
|
37
|
-
}
|
|
38
|
-
},
|
|
39
|
-
[text]
|
|
40
|
-
);
|
|
41
|
-
}
|
|
42
35
|
const animatedProps = useAnimatedProps(() => {
|
|
43
36
|
return {
|
|
44
37
|
text: text.value,
|
|
45
|
-
// Here we use any because the text prop is not available in the type
|
|
46
38
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
47
39
|
} as any;
|
|
48
40
|
});
|
|
41
|
+
|
|
49
42
|
return (
|
|
50
43
|
<AnimatedTextInput
|
|
51
44
|
underlineColorAndroid="transparent"
|
package/src/index.ts
CHANGED
package/src/types.ts
ADDED
package/src/utils/formatPrice.ts
CHANGED
|
@@ -7,22 +7,22 @@ export function formatPrice({
|
|
|
7
7
|
precision,
|
|
8
8
|
}: {
|
|
9
9
|
value: string;
|
|
10
|
-
defaultPrice?: string;
|
|
10
|
+
defaultPrice?: string | number;
|
|
11
11
|
precision?: number;
|
|
12
12
|
}) {
|
|
13
13
|
'worklet';
|
|
14
14
|
|
|
15
15
|
let defaultPrice = _defaultPrice;
|
|
16
16
|
if (typeof defaultPrice === 'number') {
|
|
17
|
-
defaultPrice =
|
|
17
|
+
defaultPrice = defaultPrice.toString();
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
const value = _value || defaultPrice?.replace?.(',', '');
|
|
21
21
|
if (!value) {
|
|
22
22
|
return `0.00`;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
const decimals =
|
|
26
26
|
precision ??
|
|
27
27
|
(Number(value) < 1
|
|
28
28
|
? Math.min(8, value.toString().slice(2).search(/[^0]/g) + 3)
|
|
@@ -30,9 +30,9 @@ export function formatPrice({
|
|
|
30
30
|
|
|
31
31
|
let res = `${Number(value).toFixed(decimals)}`;
|
|
32
32
|
const vals = res.split('.');
|
|
33
|
-
if (vals.length > 0) {
|
|
34
|
-
res = vals[0]
|
|
35
|
-
if (vals.length === 2) {
|
|
33
|
+
if (vals.length > 0 && vals[0]) {
|
|
34
|
+
res = vals[0].replace(/\B(?=(\d{3})+(?!\d))/g, ',');
|
|
35
|
+
if (vals.length === 2 && vals[1]) {
|
|
36
36
|
return res + '.' + vals[1];
|
|
37
37
|
}
|
|
38
38
|
}
|
package/src/utils/usePrevious.ts
CHANGED