react-native-wagmi-charts 1.0.4 → 1.2.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.
Files changed (132) hide show
  1. package/.DS_Store +0 -0
  2. package/.prettierrc.js +5 -0
  3. package/README.md +171 -121
  4. package/example/.DS_Store +0 -0
  5. package/example/README.md +32 -0
  6. package/example/package.json +1 -1
  7. package/example/src/App.tsx +32 -7
  8. package/example/src/CandlestickChart.tsx +23 -11
  9. package/example/src/LineChart.tsx +51 -20
  10. package/example/src/{candlestick-data.json → data/candlestick-data.json} +0 -0
  11. package/example/src/{candlestick-data2.json → data/candlestick-data2.json} +0 -0
  12. package/example/src/{line-data.json → data/line-data.json} +0 -0
  13. package/example/src/{line-data2.json → data/line-data2.json} +0 -0
  14. package/example/yarn.lock +5 -5
  15. package/lib/commonjs/charts/candle/Crosshair.js +6 -17
  16. package/lib/commonjs/charts/candle/Crosshair.js.map +1 -1
  17. package/lib/commonjs/charts/candle/CrosshairTooltip.js +12 -8
  18. package/lib/commonjs/charts/candle/CrosshairTooltip.js.map +1 -1
  19. package/lib/commonjs/charts/candle/DatetimeText.js +7 -8
  20. package/lib/commonjs/charts/candle/DatetimeText.js.map +1 -1
  21. package/lib/commonjs/charts/candle/Line.js.map +1 -1
  22. package/lib/commonjs/charts/candle/PriceText.js +7 -8
  23. package/lib/commonjs/charts/candle/PriceText.js.map +1 -1
  24. package/lib/commonjs/charts/candle/useCandleData.js.map +1 -1
  25. package/lib/commonjs/charts/candle/useCandlestickChart.js.map +1 -1
  26. package/lib/commonjs/charts/candle/useDatetime.js.map +1 -1
  27. package/lib/commonjs/charts/candle/usePrice.js.map +1 -1
  28. package/lib/commonjs/charts/candle/utils.js.map +1 -1
  29. package/lib/commonjs/charts/line/Chart.js.map +1 -1
  30. package/lib/commonjs/charts/line/Cursor.js.map +1 -1
  31. package/lib/commonjs/charts/line/CursorCrosshair.js +4 -3
  32. package/lib/commonjs/charts/line/CursorCrosshair.js.map +1 -1
  33. package/lib/commonjs/charts/line/CursorLine.js +8 -1
  34. package/lib/commonjs/charts/line/CursorLine.js.map +1 -1
  35. package/lib/commonjs/charts/line/DatetimeText.js +7 -8
  36. package/lib/commonjs/charts/line/DatetimeText.js.map +1 -1
  37. package/lib/commonjs/charts/line/Path.js +13 -16
  38. package/lib/commonjs/charts/line/Path.js.map +1 -1
  39. package/lib/commonjs/charts/line/PriceText.js +7 -8
  40. package/lib/commonjs/charts/line/PriceText.js.map +1 -1
  41. package/lib/commonjs/charts/line/interpolatePath.js +600 -0
  42. package/lib/commonjs/charts/line/interpolatePath.js.map +1 -0
  43. package/lib/commonjs/charts/line/useDatetime.js.map +1 -1
  44. package/lib/commonjs/charts/line/usePrice.js.map +1 -1
  45. package/lib/commonjs/charts/line/utils.js +1 -70
  46. package/lib/commonjs/charts/line/utils.js.map +1 -1
  47. package/lib/commonjs/components/AnimatedText.js +63 -0
  48. package/lib/commonjs/components/AnimatedText.js.map +1 -0
  49. package/lib/commonjs/utils.js.map +1 -1
  50. package/lib/module/charts/candle/Crosshair.js +7 -16
  51. package/lib/module/charts/candle/Crosshair.js.map +1 -1
  52. package/lib/module/charts/candle/CrosshairTooltip.js +10 -8
  53. package/lib/module/charts/candle/CrosshairTooltip.js.map +1 -1
  54. package/lib/module/charts/candle/DatetimeText.js +6 -7
  55. package/lib/module/charts/candle/DatetimeText.js.map +1 -1
  56. package/lib/module/charts/candle/Line.js.map +1 -1
  57. package/lib/module/charts/candle/PriceText.js +6 -7
  58. package/lib/module/charts/candle/PriceText.js.map +1 -1
  59. package/lib/module/charts/candle/useCandleData.js.map +1 -1
  60. package/lib/module/charts/candle/useCandlestickChart.js.map +1 -1
  61. package/lib/module/charts/candle/useDatetime.js.map +1 -1
  62. package/lib/module/charts/candle/usePrice.js.map +1 -1
  63. package/lib/module/charts/candle/utils.js.map +1 -1
  64. package/lib/module/charts/line/Chart.js.map +1 -1
  65. package/lib/module/charts/line/Cursor.js.map +1 -1
  66. package/lib/module/charts/line/CursorCrosshair.js +4 -3
  67. package/lib/module/charts/line/CursorCrosshair.js.map +1 -1
  68. package/lib/module/charts/line/CursorLine.js +7 -1
  69. package/lib/module/charts/line/CursorLine.js.map +1 -1
  70. package/lib/module/charts/line/DatetimeText.js +6 -7
  71. package/lib/module/charts/line/DatetimeText.js.map +1 -1
  72. package/lib/module/charts/line/Path.js +11 -15
  73. package/lib/module/charts/line/Path.js.map +1 -1
  74. package/lib/module/charts/line/PriceText.js +6 -7
  75. package/lib/module/charts/line/PriceText.js.map +1 -1
  76. package/lib/module/charts/line/interpolatePath.js +587 -0
  77. package/lib/module/charts/line/interpolatePath.js.map +1 -0
  78. package/lib/module/charts/line/useDatetime.js.map +1 -1
  79. package/lib/module/charts/line/usePrice.js.map +1 -1
  80. package/lib/module/charts/line/utils.js +1 -66
  81. package/lib/module/charts/line/utils.js.map +1 -1
  82. package/lib/module/components/AnimatedText.js +43 -0
  83. package/lib/module/components/AnimatedText.js.map +1 -0
  84. package/lib/module/utils.js.map +1 -1
  85. package/lib/typescript/src/charts/candle/Crosshair.d.ts +4 -4
  86. package/lib/typescript/src/charts/candle/DatetimeText.d.ts +3 -2
  87. package/lib/typescript/src/charts/candle/Line.d.ts +1 -1
  88. package/lib/typescript/src/charts/candle/PriceText.d.ts +3 -3
  89. package/lib/typescript/src/charts/candle/types.d.ts +8 -3
  90. package/lib/typescript/src/charts/candle/useCandleData.d.ts +3 -3
  91. package/lib/typescript/src/charts/candle/useCandlestickChart.d.ts +2 -1
  92. package/lib/typescript/src/charts/candle/useDatetime.d.ts +5 -7
  93. package/lib/typescript/src/charts/candle/usePrice.d.ts +5 -8
  94. package/lib/typescript/src/charts/candle/utils.d.ts +1 -1
  95. package/lib/typescript/src/charts/line/Chart.d.ts +1 -1
  96. package/lib/typescript/src/charts/line/Cursor.d.ts +1 -2
  97. package/lib/typescript/src/charts/line/CursorCrosshair.d.ts +3 -2
  98. package/lib/typescript/src/charts/line/DatetimeText.d.ts +5 -6
  99. package/lib/typescript/src/charts/line/Path.d.ts +17 -1
  100. package/lib/typescript/src/charts/line/PriceText.d.ts +3 -2
  101. package/lib/typescript/src/charts/line/interpolatePath.d.ts +50 -0
  102. package/lib/typescript/src/charts/line/useDatetime.d.ts +4 -5
  103. package/lib/typescript/src/charts/line/usePrice.d.ts +3 -2
  104. package/lib/typescript/src/charts/line/utils.d.ts +0 -13
  105. package/lib/typescript/src/components/AnimatedText.d.ts +9 -0
  106. package/lib/typescript/src/utils.d.ts +2 -4
  107. package/package.json +4 -4
  108. package/src/charts/candle/Crosshair.tsx +20 -20
  109. package/src/charts/candle/CrosshairTooltip.tsx +11 -4
  110. package/src/charts/candle/DatetimeText.tsx +5 -4
  111. package/src/charts/candle/Line.tsx +1 -1
  112. package/src/charts/candle/PriceText.tsx +5 -5
  113. package/src/charts/candle/types.ts +11 -3
  114. package/src/charts/candle/useCandleData.ts +3 -2
  115. package/src/charts/candle/useCandlestickChart.ts +2 -1
  116. package/src/charts/candle/useDatetime.ts +7 -3
  117. package/src/charts/candle/usePrice.ts +10 -3
  118. package/src/charts/candle/utils.ts +1 -1
  119. package/src/charts/line/Chart.tsx +1 -1
  120. package/src/charts/line/Cursor.tsx +7 -3
  121. package/src/charts/line/CursorCrosshair.tsx +4 -3
  122. package/src/charts/line/CursorLine.tsx +9 -1
  123. package/src/charts/line/DatetimeText.tsx +8 -7
  124. package/src/charts/line/Path.tsx +25 -21
  125. package/src/charts/line/PriceText.tsx +5 -4
  126. package/src/charts/line/interpolatePath.ts +650 -0
  127. package/src/charts/line/useDatetime.ts +3 -2
  128. package/src/charts/line/usePrice.ts +2 -1
  129. package/src/charts/line/utils.ts +2 -79
  130. package/src/components/AnimatedText.tsx +53 -0
  131. package/src/utils.ts +3 -3
  132. package/yarn.lock +5 -5
@@ -1,9 +1,10 @@
1
1
  import * as React from 'react';
2
2
  import { StyleSheet, ViewProps } from 'react-native';
3
- import ReactNativeHapticFeedback from 'react-native-haptic-feedback';
4
3
  import {
5
- PanGestureHandler,
6
- PanGestureHandlerProps,
4
+ GestureEvent,
5
+ LongPressGestureHandler,
6
+ LongPressGestureHandlerEventPayload,
7
+ LongPressGestureHandlerProps,
7
8
  } from 'react-native-gesture-handler';
8
9
  import Animated, {
9
10
  useAnimatedGestureHandler,
@@ -19,25 +20,18 @@ import { CandlestickChartLine, CandlestickChartLineProps } from './Line';
19
20
  import { useCandlestickChart } from './useCandlestickChart';
20
21
  import { CandlestickChartCrosshairTooltipContext } from './CrosshairTooltip';
21
22
 
22
- type CandlestickChartCrosshairProps = PanGestureHandlerProps & {
23
+ type CandlestickChartCrosshairProps = LongPressGestureHandlerProps & {
23
24
  color?: string;
24
25
  children?: React.ReactNode;
25
- enableHapticFeedback?: boolean;
26
+ onCurrentXChange?: (value: number) => unknown;
26
27
  horizontalCrosshairProps?: Animated.AnimateProps<ViewProps>;
27
28
  verticalCrosshairProps?: Animated.AnimateProps<ViewProps>;
28
29
  lineProps?: Partial<CandlestickChartLineProps>;
29
30
  };
30
31
 
31
- function invokeHaptic() {
32
- ReactNativeHapticFeedback.trigger('impactLight', {
33
- enableVibrateFallback: true,
34
- ignoreAndroidSystemSettings: false,
35
- });
36
- }
37
-
38
32
  export function CandlestickChartCrosshair({
39
33
  color,
40
- enableHapticFeedback = false,
34
+ onCurrentXChange,
41
35
  children,
42
36
  horizontalCrosshairProps = {},
43
37
  verticalCrosshairProps = {},
@@ -50,7 +44,9 @@ export function CandlestickChartCrosshair({
50
44
  const tooltipPosition = useSharedValue<'left' | 'right'>('left');
51
45
 
52
46
  const opacity = useSharedValue(0);
53
- const onGestureEvent = useAnimatedGestureHandler({
47
+ const onGestureEvent = useAnimatedGestureHandler<
48
+ GestureEvent<LongPressGestureHandlerEventPayload>
49
+ >({
54
50
  onActive: ({ x, y }) => {
55
51
  const boundedX = x <= width - 1 ? x : width - 1;
56
52
  if (boundedX < 100) {
@@ -78,16 +74,20 @@ export function CandlestickChartCrosshair({
78
74
  }));
79
75
 
80
76
  useAnimatedReaction(
81
- () => (enableHapticFeedback ? currentX.value : 0),
82
- (data) => {
83
- if (data !== 0) {
84
- runOnJS(invokeHaptic)();
77
+ () => currentX.value,
78
+ (data, prevData) => {
79
+ if (data !== -1 && data !== prevData && onCurrentXChange) {
80
+ runOnJS(onCurrentXChange)(data);
85
81
  }
86
82
  }
87
83
  );
88
84
 
89
85
  return (
90
- <PanGestureHandler minDist={0} onGestureEvent={onGestureEvent} {...props}>
86
+ <LongPressGestureHandler
87
+ minDurationMs={0}
88
+ onGestureEvent={onGestureEvent}
89
+ {...props}
90
+ >
91
91
  <Animated.View style={StyleSheet.absoluteFill}>
92
92
  <Animated.View
93
93
  style={[StyleSheet.absoluteFill, horizontal]}
@@ -107,6 +107,6 @@ export function CandlestickChartCrosshair({
107
107
  <CandlestickChartLine color={color} x={0} y={height} {...lineProps} />
108
108
  </Animated.View>
109
109
  </Animated.View>
110
- </PanGestureHandler>
110
+ </LongPressGestureHandler>
111
111
  );
112
112
  }
@@ -1,5 +1,6 @@
1
1
  import * as React from 'react';
2
2
  import type { StyleProp, TextStyle, ViewProps } from 'react-native';
3
+ import { StyleSheet } from 'react-native';
3
4
  import Animated, {
4
5
  useAnimatedStyle,
5
6
  useDerivedValue,
@@ -34,8 +35,8 @@ export function CandlestickChartCrosshairTooltip({
34
35
  children,
35
36
  xGutter = 8,
36
37
  yGutter = 8,
37
- tooltipTextProps = {},
38
- textStyle = {},
38
+ tooltipTextProps,
39
+ textStyle,
39
40
  ...props
40
41
  }: CandlestickChartCrosshairTooltipProps) {
41
42
  const { width, height } = React.useContext(CandlestickChartDimensionsContext);
@@ -93,7 +94,7 @@ export function CandlestickChartCrosshairTooltip({
93
94
  {children || (
94
95
  <CandlestickChartPriceText
95
96
  {...tooltipTextProps}
96
- style={[{ fontSize: 14 }, tooltipTextProps.style, textStyle]}
97
+ style={[styles.text, tooltipTextProps?.style, textStyle]}
97
98
  />
98
99
  )}
99
100
  </Animated.View>
@@ -101,10 +102,16 @@ export function CandlestickChartCrosshairTooltip({
101
102
  {children || (
102
103
  <CandlestickChartPriceText
103
104
  {...tooltipTextProps}
104
- style={[{ fontSize: 14 }, tooltipTextProps.style, textStyle]}
105
+ style={[styles.text, tooltipTextProps?.style, textStyle]}
105
106
  />
106
107
  )}
107
108
  </Animated.View>
108
109
  </>
109
110
  );
110
111
  }
112
+
113
+ const styles = StyleSheet.create({
114
+ text: {
115
+ fontSize: 14,
116
+ },
117
+ });
@@ -1,14 +1,15 @@
1
1
  import * as React from 'react';
2
- import { ReText } from 'react-native-redash';
3
2
  import type { TextProps as RNTextProps } from 'react-native';
4
3
  import type Animated from 'react-native-reanimated';
5
4
 
6
5
  import { useCandlestickChartDatetime } from './useDatetime';
6
+ import type { TFormatterFn } from 'react-native-wagmi-charts';
7
+ import { AnimatedText } from '../../components/AnimatedText';
7
8
 
8
9
  type CandlestickChartPriceTextProps = {
9
10
  locale?: string;
10
11
  options?: { [key: string]: string };
11
- format?: any;
12
+ format?: TFormatterFn<number>;
12
13
  variant?: 'formatted' | 'value';
13
14
  style?: Animated.AnimateProps<RNTextProps>['style'];
14
15
  };
@@ -18,8 +19,8 @@ export function CandlestickChartDatetimeText({
18
19
  options,
19
20
  format,
20
21
  variant = 'formatted',
21
- ...props
22
+ style,
22
23
  }: CandlestickChartPriceTextProps) {
23
24
  const datetime = useCandlestickChartDatetime({ format, locale, options });
24
- return <ReText text={datetime[variant]} {...props} />;
25
+ return <AnimatedText text={datetime[variant]} style={style} />;
25
26
  }
@@ -2,7 +2,7 @@ import React from 'react';
2
2
  import { StyleSheet } from 'react-native';
3
3
  import Svg, { Line as SVGLine, LineProps } from 'react-native-svg';
4
4
 
5
- export type CandlestickChartLineProps = LineProps & {
5
+ export type CandlestickChartLineProps = Omit<LineProps, 'x' | 'y'> & {
6
6
  color?: string;
7
7
  x: number;
8
8
  y: number;
@@ -1,13 +1,13 @@
1
1
  import * as React from 'react';
2
- import { ReText } from 'react-native-redash';
3
2
  import type { TextProps as RNTextProps } from 'react-native';
4
3
  import type Animated from 'react-native-reanimated';
5
- import type { TPriceType } from './types';
4
+ import type { TFormatterFn, TPriceType } from './types';
6
5
 
7
6
  import { useCandlestickChartPrice } from './usePrice';
7
+ import { AnimatedText } from '../../components/AnimatedText';
8
8
 
9
9
  export type CandlestickChartPriceTextProps = {
10
- format?: any;
10
+ format?: TFormatterFn<string>;
11
11
  precision?: number;
12
12
  variant?: 'formatted' | 'value';
13
13
  type?: TPriceType;
@@ -19,8 +19,8 @@ export function CandlestickChartPriceText({
19
19
  precision = 2,
20
20
  variant = 'formatted',
21
21
  type = 'crosshair',
22
- ...props
22
+ style,
23
23
  }: CandlestickChartPriceTextProps) {
24
24
  const price = useCandlestickChartPrice({ format, precision, type });
25
- return <ReText text={price[variant]} {...props} />;
25
+ return <AnimatedText text={price[variant]} style={style} />;
26
26
  }
@@ -1,3 +1,4 @@
1
+ import type React from 'react';
1
2
  import type Animated from 'react-native-reanimated';
2
3
 
3
4
  export type TCandle = {
@@ -8,7 +9,7 @@ export type TCandle = {
8
9
  close: number;
9
10
  };
10
11
  export type TData = Array<TCandle>;
11
- export type TDomain = [number, number];
12
+ export type TDomain = [min: number, max: number];
12
13
  export type TContext = {
13
14
  currentX: Animated.SharedValue<number>;
14
15
  currentY: Animated.SharedValue<number>;
@@ -17,7 +18,14 @@ export type TContext = {
17
18
  height: number;
18
19
  domain: TDomain;
19
20
  step: number;
20
- setWidth: any;
21
- setHeight: any;
21
+ setWidth: React.Dispatch<React.SetStateAction<number>>;
22
+ setHeight: React.Dispatch<React.SetStateAction<number>>;
22
23
  };
23
24
  export type TPriceType = 'crosshair' | 'open' | 'close' | 'low' | 'high';
25
+ export type TFormatterFn<T> = ({
26
+ value,
27
+ formatted,
28
+ }: {
29
+ value: T;
30
+ formatted: string;
31
+ }) => string;
@@ -1,8 +1,9 @@
1
- import { useDerivedValue } from 'react-native-reanimated';
1
+ import Animated, { useDerivedValue } from 'react-native-reanimated';
2
+ import type { TCandle } from './types';
2
3
 
3
4
  import { useCandlestickChart } from './useCandlestickChart';
4
5
 
5
- export function useCandleData() {
6
+ export function useCandleData(): Readonly<Animated.SharedValue<TCandle>> {
6
7
  const { currentX, data, step } = useCandlestickChart();
7
8
 
8
9
  const candle = useDerivedValue(() => {
@@ -1,7 +1,8 @@
1
1
  import * as React from 'react';
2
2
 
3
3
  import { CandlestickChartContext } from './Context';
4
+ import type { TContext } from './types';
4
5
 
5
- export function useCandlestickChart() {
6
+ export function useCandlestickChart(): TContext {
6
7
  return React.useContext(CandlestickChartContext);
7
8
  }
@@ -1,6 +1,7 @@
1
- import { useDerivedValue } from 'react-native-reanimated';
1
+ import Animated, { useDerivedValue } from 'react-native-reanimated';
2
2
 
3
3
  import { formatDatetime } from '../../utils';
4
+ import type { TFormatterFn } from './types';
4
5
  import { useCandleData } from './useCandleData';
5
6
 
6
7
  export function useCandlestickChartDatetime({
@@ -8,10 +9,13 @@ export function useCandlestickChartDatetime({
8
9
  locale,
9
10
  options,
10
11
  }: {
11
- format?: any;
12
+ format?: TFormatterFn<number>;
12
13
  locale?: string;
13
14
  options?: { [key: string]: string };
14
- } = {}) {
15
+ } = {}): {
16
+ value: Readonly<Animated.SharedValue<string>>;
17
+ formatted: Readonly<Animated.SharedValue<string>>;
18
+ } {
15
19
  const candle = useCandleData();
16
20
 
17
21
  const timestamp = useDerivedValue(() => {
@@ -1,16 +1,23 @@
1
- import { useDerivedValue } from 'react-native-reanimated';
1
+ import Animated, { useDerivedValue } from 'react-native-reanimated';
2
2
 
3
3
  import { formatPrice } from '../../utils';
4
4
  import { useCandlestickChart } from './useCandlestickChart';
5
5
  import { getPrice } from './utils';
6
- import type { TPriceType } from './types';
6
+ import type { TFormatterFn, TPriceType } from './types';
7
7
  import { useCandleData } from './useCandleData';
8
8
 
9
9
  export function useCandlestickChartPrice({
10
10
  format,
11
11
  precision = 2,
12
12
  type = 'crosshair',
13
- }: { format?: any; precision?: number; type?: TPriceType } = {}) {
13
+ }: {
14
+ format?: TFormatterFn<string>;
15
+ precision?: number;
16
+ type?: TPriceType;
17
+ } = {}): {
18
+ value: Readonly<Animated.SharedValue<string>>;
19
+ formatted: Readonly<Animated.SharedValue<string>>;
20
+ } {
14
21
  const { currentY, domain, height } = useCandlestickChart();
15
22
  const candle = useCandleData();
16
23
 
@@ -2,7 +2,7 @@ import { interpolate, Extrapolate } from 'react-native-reanimated';
2
2
 
3
3
  import type { TCandle, TDomain } from './types';
4
4
 
5
- export function getDomain(rows: TCandle[]): [number, number] {
5
+ export function getDomain(rows: TCandle[]): [min: number, max: number] {
6
6
  'worklet';
7
7
  const values = rows.map(({ high, low }) => [high, low]).flat();
8
8
  const min = Math.min(...values);
@@ -16,7 +16,7 @@ type LineChartProps = ViewProps & {
16
16
  yGutter?: number;
17
17
  width?: number;
18
18
  height?: number;
19
- shape?: any;
19
+ shape?: string;
20
20
  };
21
21
 
22
22
  const { width: screenWidth } = Dimensions.get('window');
@@ -1,7 +1,9 @@
1
1
  import * as React from 'react';
2
2
  import { StyleSheet } from 'react-native';
3
3
  import {
4
+ GestureEvent,
4
5
  LongPressGestureHandler,
6
+ LongPressGestureHandlerEventPayload,
5
7
  LongPressGestureHandlerProps,
6
8
  } from 'react-native-gesture-handler';
7
9
  import Animated, { useAnimatedGestureHandler } from 'react-native-reanimated';
@@ -10,7 +12,7 @@ import { getYForX, parse } from 'react-native-redash';
10
12
  import { LineChartDimensionsContext } from './Chart';
11
13
  import { useLineChart } from './useLineChart';
12
14
 
13
- type LineChartCursorProps = LongPressGestureHandlerProps & {
15
+ export type LineChartCursorProps = LongPressGestureHandlerProps & {
14
16
  children: React.ReactNode;
15
17
  type: 'line' | 'crosshair';
16
18
  };
@@ -30,7 +32,9 @@ export function LineChartCursor({
30
32
  [path]
31
33
  );
32
34
 
33
- const onGestureEvent = useAnimatedGestureHandler({
35
+ const onGestureEvent = useAnimatedGestureHandler<
36
+ GestureEvent<LongPressGestureHandlerEventPayload>
37
+ >({
34
38
  onActive: ({ x }) => {
35
39
  if (parsedPath) {
36
40
  const boundedX = x <= width ? x : width;
@@ -52,7 +56,7 @@ export function LineChartCursor({
52
56
  <CursorContext.Provider value={{ type }}>
53
57
  <LongPressGestureHandler
54
58
  minDurationMs={0}
55
- onGestureEvent={onGestureEvent as any}
59
+ onGestureEvent={onGestureEvent}
56
60
  {...props}
57
61
  >
58
62
  <Animated.View style={StyleSheet.absoluteFill}>
@@ -5,10 +5,10 @@ import Animated, {
5
5
  withSpring,
6
6
  } from 'react-native-reanimated';
7
7
 
8
- import { LineChartCursor } from './Cursor';
8
+ import { LineChartCursor, LineChartCursorProps } from './Cursor';
9
9
  import { useLineChart } from './useLineChart';
10
10
 
11
- type LineChartCursorCrosshairProps = {
11
+ type LineChartCursorCrosshairProps = Omit<LineChartCursorProps, 'type'> & {
12
12
  children?: React.ReactNode;
13
13
  color?: string;
14
14
  size?: number;
@@ -26,6 +26,7 @@ export function LineChartCursorCrosshair({
26
26
  crosshairWrapperProps = {},
27
27
  crosshairProps = {},
28
28
  crosshairOuterProps = {},
29
+ ...props
29
30
  }: LineChartCursorCrosshairProps) {
30
31
  const { currentX, currentY, isActive } = useLineChart();
31
32
 
@@ -42,7 +43,7 @@ export function LineChartCursorCrosshair({
42
43
  }));
43
44
 
44
45
  return (
45
- <LineChartCursor type="crosshair">
46
+ <LineChartCursor type="crosshair" {...props}>
46
47
  <Animated.View
47
48
  {...crosshairWrapperProps}
48
49
  style={[
@@ -30,7 +30,7 @@ export const LineChartCursorLine = ({
30
30
  return (
31
31
  <LineChartCursor type="line">
32
32
  <Animated.View style={vertical}>
33
- <Svg style={StyleSheet.absoluteFill}>
33
+ <Svg style={styles.svg}>
34
34
  <SVGLine
35
35
  x1={0}
36
36
  y1={0}
@@ -47,3 +47,11 @@ export const LineChartCursorLine = ({
47
47
  </LineChartCursor>
48
48
  );
49
49
  };
50
+
51
+ const styles = StyleSheet.create({
52
+ svg: {
53
+ ...StyleSheet.absoluteFillObject,
54
+ // height: 100% is required for <svg /> on web
55
+ height: '100%',
56
+ },
57
+ });
@@ -1,14 +1,15 @@
1
1
  import * as React from 'react';
2
- import { ReText } from 'react-native-redash';
3
2
  import type { TextProps as RNTextProps } from 'react-native';
4
3
  import type Animated from 'react-native-reanimated';
5
4
 
6
5
  import { useLineChartDatetime } from './useDatetime';
6
+ import type { TFormatterFn } from 'react-native-wagmi-charts';
7
+ import { AnimatedText } from '../../components/AnimatedText';
7
8
 
8
- type LineChartPriceTextProps = {
9
+ type LineChartDatetimeProps = {
9
10
  locale?: string;
10
- options?: { [key: string]: any };
11
- format?: any;
11
+ options?: Intl.DateTimeFormatOptions;
12
+ format?: TFormatterFn<number>;
12
13
  variant?: 'formatted' | 'value';
13
14
  style?: Animated.AnimateProps<RNTextProps>['style'];
14
15
  };
@@ -18,8 +19,8 @@ export function LineChartDatetimeText({
18
19
  options,
19
20
  format,
20
21
  variant = 'formatted',
21
- ...props
22
- }: LineChartPriceTextProps) {
22
+ style,
23
+ }: LineChartDatetimeProps) {
23
24
  const datetime = useLineChartDatetime({ format, locale, options });
24
- return <ReText text={datetime[variant]} {...props} />;
25
+ return <AnimatedText text={datetime[variant]} style={style} />;
25
26
  }
@@ -6,11 +6,10 @@ import Animated, {
6
6
  withTiming,
7
7
  } from 'react-native-reanimated';
8
8
  import { Path, PathProps } from 'react-native-svg';
9
- import { mixPath, parse } from 'react-native-redash';
10
9
 
11
10
  import { LineChartDimensionsContext } from './Chart';
11
+ import interpolatePath from './interpolatePath';
12
12
  import { usePrevious } from '../../utils';
13
- import { syncPaths } from './utils';
14
13
 
15
14
  const AnimatedPath = Animated.createAnimatedComponent(Path);
16
15
 
@@ -18,12 +17,29 @@ export type LineChartPathProps = Animated.AnimateProps<PathProps> & {
18
17
  color?: string;
19
18
  width?: number;
20
19
  isInactive?: boolean;
20
+ /**
21
+ * Default: `true`.
22
+ *
23
+ * If `false`, changes in the chart's path will not animate.
24
+ *
25
+ * While this use case is rare, it may be useful on web, where animations might not work as well.
26
+ *
27
+ * **Example**
28
+ *
29
+ * ```tsx
30
+ * <LineChart.Path
31
+ * pathProps={{ isTransitionEnabled: Platform.OS !== 'web' }}
32
+ * />
33
+ * ```
34
+ */
35
+ isTransitionEnabled?: boolean;
21
36
  };
22
37
 
23
38
  export function LineChartPath({
24
39
  color = 'black',
25
40
  width = 3,
26
41
  isInactive,
42
+ isTransitionEnabled = true,
27
43
  ...props
28
44
  }: LineChartPathProps) {
29
45
  const { path } = React.useContext(LineChartDimensionsContext);
@@ -32,11 +48,7 @@ export function LineChartPath({
32
48
 
33
49
  const transition = useSharedValue(0);
34
50
 
35
- const parsedPath = React.useMemo(
36
- () => (path ? parse(path) : undefined),
37
- [path]
38
- );
39
- const previousParsedPath = usePrevious(parsedPath);
51
+ const previousPath = usePrevious(path);
40
52
 
41
53
  useAnimatedReaction(
42
54
  () => {
@@ -52,21 +64,13 @@ export function LineChartPath({
52
64
  );
53
65
 
54
66
  const animatedProps = useAnimatedProps(() => {
55
- if (!parsedPath) return { d: '' };
56
-
57
- const {
58
- parsedPath: newParsedPath,
59
- previousParsedPath: newPreviousParsedPath,
60
- } = syncPaths({
61
- parsedPath,
62
- previousParsedPath,
63
- });
64
-
67
+ let d = path || '';
68
+ if (previousPath && isTransitionEnabled) {
69
+ const pathInterpolator = interpolatePath(previousPath, path, null);
70
+ d = pathInterpolator(transition.value);
71
+ }
65
72
  return {
66
- d:
67
- transition.value === 1
68
- ? path
69
- : mixPath(transition.value, newPreviousParsedPath, newParsedPath),
73
+ d,
70
74
  };
71
75
  });
72
76
 
@@ -1,12 +1,13 @@
1
1
  import * as React from 'react';
2
- import { ReText } from 'react-native-redash';
3
2
  import type { TextProps as RNTextProps } from 'react-native';
4
3
  import type Animated from 'react-native-reanimated';
5
4
 
6
5
  import { useLineChartPrice } from './usePrice';
6
+ import type { TFormatterFn } from '../candle/types';
7
+ import { AnimatedText } from '../../components/AnimatedText';
7
8
 
8
9
  export type LineChartPriceTextProps = {
9
- format?: any;
10
+ format?: TFormatterFn<string>;
10
11
  precision?: number;
11
12
  variant?: 'formatted' | 'value';
12
13
  style?: Animated.AnimateProps<RNTextProps>['style'];
@@ -16,8 +17,8 @@ export function LineChartPriceText({
16
17
  format,
17
18
  precision = 2,
18
19
  variant = 'formatted',
19
- ...props
20
+ style,
20
21
  }: LineChartPriceTextProps) {
21
22
  const price = useLineChartPrice({ format, precision });
22
- return <ReText text={price[variant]} {...props} />;
23
+ return <AnimatedText text={price[variant]} style={style} />;
23
24
  }