react-native-wagmi-charts 2.0.1 → 2.1.0
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/.DS_Store +0 -0
- package/README.md +30 -1
- package/example/.DS_Store +0 -0
- package/example/package.json +11 -13
- package/example/src/App.tsx +39 -34
- package/example/src/LineChart.tsx +2 -1
- package/example/yarn.lock +1819 -8871
- package/lib/commonjs/charts/candle/HoverTrap/index.web.js +120 -0
- package/lib/commonjs/charts/candle/HoverTrap/index.web.js.map +1 -0
- package/lib/commonjs/charts/line/ChartPath.js +8 -3
- package/lib/commonjs/charts/line/ChartPath.js.map +1 -1
- package/lib/commonjs/charts/line/HoverTrap/index.js +15 -0
- package/lib/commonjs/charts/line/HoverTrap/index.js.map +1 -0
- package/lib/commonjs/charts/line/HoverTrap/index.web.js +120 -0
- package/lib/commonjs/charts/line/HoverTrap/index.web.js.map +1 -0
- package/lib/commonjs/charts/line/index.js +4 -1
- package/lib/commonjs/charts/line/index.js.map +1 -1
- package/lib/commonjs/components/AnimatedText.js +3 -5
- package/lib/commonjs/components/AnimatedText.js.map +1 -1
- package/lib/module/charts/candle/HoverTrap/index.web.js +101 -0
- package/lib/module/charts/candle/HoverTrap/index.web.js.map +1 -0
- package/lib/module/charts/line/ChartPath.js +8 -3
- package/lib/module/charts/line/ChartPath.js.map +1 -1
- package/lib/module/charts/line/HoverTrap/index.js +3 -0
- package/lib/module/charts/line/HoverTrap/index.js.map +1 -0
- package/lib/module/charts/line/HoverTrap/index.web.js +101 -0
- package/lib/module/charts/line/HoverTrap/index.web.js.map +1 -0
- package/lib/module/charts/line/index.js +3 -1
- package/lib/module/charts/line/index.js.map +1 -1
- package/lib/module/components/AnimatedText.js +2 -5
- package/lib/module/components/AnimatedText.js.map +1 -1
- package/lib/typescript/src/charts/candle/HoverTrap/index.web.d.ts +2 -0
- package/lib/typescript/src/charts/line/ChartPath.d.ts +3 -3
- package/lib/typescript/src/charts/line/HoverTrap/index.d.ts +2 -0
- package/lib/typescript/src/charts/line/HoverTrap/index.web.d.ts +2 -0
- package/lib/typescript/src/charts/line/index.d.ts +2 -0
- package/package.json +5 -5
- package/src/charts/candle/HoverTrap/index.web.tsx +110 -0
- package/src/charts/line/ChartPath.tsx +19 -14
- package/src/charts/line/HoverTrap/index.tsx +3 -0
- package/src/charts/line/HoverTrap/index.web.tsx +110 -0
- package/src/charts/line/index.ts +2 -0
- package/src/components/AnimatedText.tsx +2 -5
- package/tsconfig.json +1 -1
- package/yarn.lock +1840 -796
- package/example/patches/react-native-reanimated+2.2.2.patch +0 -28
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["ChartPath.tsx"],"names":["React","StyleSheet","View","Svg","Animated","useAnimatedProps","useSharedValue","withTiming","flattenChildren","LineChartDimensionsContext","LineChartPath","useLineChart","BACKGROUND_COMPONENTS","FOREGROUND_COMPONENTS","AnimatedSVG","createAnimatedComponent","LineChartPathContext","createContext","color","isInactive","isTransitionEnabled","LineChartPathWrapper","displayName","animationDuration","animationProps","children","inactiveColor","width","strokeWidth","widthOffset","pathProps","showInactivePath","animateOnMount","mountAnimationDuration","mountAnimationProps","height","pathWidth","useContext","currentX","isActive","isMounted","hasMountedAnimation","useEffect","value","svgProps","shouldAnimateOnMount","inactiveWidth","duration","props","Math","max","Object","assign","viewSize","useMemo","backgroundChildren","foregroundChildren","iterableChildren","filter","child","includes","type","absoluteFill"],"mappings":";;AAAA,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;AACA,SAASC,UAAT,EAAqBC,IAArB,QAAiC,cAAjC;AACA,SAASC,GAAT,QAAoB,kBAApB;AACA,OAAOC,QAAP,IACEC,gBADF,EAEEC,cAFF,EAGEC,UAHF,
|
|
1
|
+
{"version":3,"sources":["ChartPath.tsx"],"names":["React","StyleSheet","View","Svg","Animated","useAnimatedProps","useSharedValue","withTiming","flattenChildren","LineChartDimensionsContext","LineChartPath","useLineChart","BACKGROUND_COMPONENTS","FOREGROUND_COMPONENTS","AnimatedSVG","createAnimatedComponent","LineChartPathContext","createContext","color","isInactive","isTransitionEnabled","LineChartPathWrapper","displayName","animationDuration","animationProps","children","inactiveColor","width","strokeWidth","widthOffset","pathProps","showInactivePath","animateOnMount","mountAnimationDuration","mountAnimationProps","height","pathWidth","useContext","currentX","isActive","isMounted","hasMountedAnimation","useEffect","value","svgProps","shouldAnimateOnMount","inactiveWidth","duration","props","Math","max","Object","assign","viewSize","useMemo","backgroundChildren","foregroundChildren","iterableChildren","filter","child","includes","type","absoluteFill"],"mappings":";;AAAA,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;AACA,SAASC,UAAT,EAAqBC,IAArB,QAAiC,cAAjC;AACA,SAASC,GAAT,QAAoB,kBAApB;AACA,OAAOC,QAAP,IACEC,gBADF,EAEEC,cAFF,EAGEC,UAHF,QAKO,yBALP;AAMA,OAAOC,eAAP,MAA4B,8BAA5B;AAEA,SAASC,0BAAT,QAA2C,SAA3C;AACA,SAASC,aAAT,QAAkD,QAAlD;AACA,SAASC,YAAT,QAA6B,gBAA7B;AAEA,MAAMC,qBAAqB,GAAG,CAC5B,oBAD4B,EAE5B,yBAF4B,EAG5B,mBAH4B,EAI5B,cAJ4B,CAA9B;AAMA,MAAMC,qBAAqB,GAAG,CAAC,oBAAD,EAAuB,cAAvB,CAA9B;AAEA,MAAMC,WAAW,GAAGV,QAAQ,CAACW,uBAAT,CAAiCZ,GAAjC,CAApB;AAEA,OAAO,MAAMa,oBAAoB,gBAAGhB,KAAK,CAACiB,aAAN,CAAoB;AACtDC,EAAAA,KAAK,EAAE,EAD+C;AAEtDC,EAAAA,UAAU,EAAE,KAF0C;AAGtDC,EAAAA,mBAAmB,EAAE;AAHiC,CAApB,CAA7B;AAqBPC,oBAAoB,CAACC,WAArB,GAAmC,sBAAnC;AAEA,OAAO,SAASD,oBAAT,CAA8B;AACnCE,EAAAA,iBAAiB,GAAG,GADe;AAEnCC,EAAAA,cAAc,GAAG,EAFkB;AAGnCC,EAAA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oBAAD,CAAsB,QAAtB;AACE,IAAA,KAAK,EAAE;AACLJ,MAAAA,KADK;AAELC,MAAAA,UAAU,EAAEY,gBAFP;AAGLX,MAAAA,mBAAmB,2BAAEU,SAAS,CAACV,mBAAZ,yEAAmC;AAHjD;AADT,kBAOE,oBAAC,IAAD;AAAM,IAAA,KAAK,EAAEiC;AAAb,kBACE,oBAAC,GAAD;AAAK,IAAA,KAAK,EAAE1B,KAAZ;AAAmB,IAAA,MAAM,EAAEQ;AAA3B,kBACE,oBAAC,aAAD;AACE,IAAA,KAAK,EAAEjB,KADT;AAEE,IAAA,aAAa,EAAEQ,aAFjB;AAGE,IAAA,KAAK,EAAEE;AAHT,KAIME,SAJN,EADF,EAOGyB,kBAPH,CADF,CAPF,CADF,eAoBE,oBAAC,oBAAD,CAAsB,QAAtB;AACE,IAAA,KAAK,EAAE;AACLrC,MAAAA,KADK;AAELC,MAAAA,UAAU,EAAE,KAFP;AAGLC,MAAAA,mBAAmB,4BAAEU,SAAS,CAACV,mBAAZ,2EAAmC;AAHjD;AADT,kBAOE,oBAAC,IAAD;AAAM,IAAA,KAAK,EAAEnB,UAAU,CAAC6D;AAAxB,kBACE,oBAAC,WAAD;AAAa,IAAA,aAAa,EAAElB,QAA5B;AAAsC,IAAA,MAAM,EAAET;AAA9C,kBACE,oBAAC,aAAD;AAAe,IAAA,KAAK,EAAEjB,KAAtB;AAA6B,IAAA,KAAK,EAAEU;AAApC,KAAqDE,SAArD,EADF,EAEG0B,kBAFH,CADF,CAPF,CApBF,CADF;AAqCD","sourcesContent":["import * as React from 'react';\nimport { StyleSheet, View } from 'react-native';\nimport { Svg } from 'react-native-svg';\nimport Animated, {\n useAnimatedProps,\n useSharedValue,\n withTiming,\n WithTimingConfig,\n} from 'react-native-reanimated';\nimport flattenChildren from 'react-keyed-flatten-children';\n\nimport { LineChartDimensionsContext } from './Chart';\nimport { LineChartPath, LineChartPathProps } from './Path';\nimport { useLineChart } from './useLineChart';\n\nconst BACKGROUND_COMPONENTS = [\n 'LineChartHighlight',\n 'LineChartHorizontalLine',\n 'LineChartGradient',\n 'LineChartDot',\n];\nconst FOREGROUND_COMPONENTS = ['LineChartHighlight', 'LineChartDot'];\n\nconst AnimatedSVG = Animated.createAnimatedComponent(Svg);\n\nexport const LineChartPathContext = React.createContext({\n color: '',\n isInactive: false,\n isTransitionEnabled: true,\n});\n\ntype LineChartPathWrapperProps = {\n animationDuration?: number;\n animationProps?: Omit<Partial<WithTimingConfig>, 'duration'>;\n children?: React.ReactNode;\n color?: string;\n inactiveColor?: string;\n width?: number;\n widthOffset?: number;\n pathProps?: Partial<LineChartPathProps>;\n showInactivePath?: boolean;\n animateOnMount?: 'foreground';\n mountAnimationDuration?: number;\n mountAnimationProps?: Partial<WithTimingConfig>;\n};\n\nLineChartPathWrapper.displayName = 'LineChartPathWrapper';\n\nexport function LineChartPathWrapper({\n animationDuration = 300,\n animationProps = {},\n children,\n color = 'black',\n inactiveColor,\n width: strokeWidth = 3,\n widthOffset = 20,\n pathProps = {},\n showInactivePath = true,\n animateOnMount,\n mountAnimationDuration = animationDuration,\n mountAnimationProps = animationProps,\n}: LineChartPathWrapperProps) {\n const { height, pathWidth, width } = React.useContext(\n LineChartDimensionsContext\n );\n const { currentX, isActive } = useLineChart();\n const isMounted = useSharedValue(false);\n const hasMountedAnimation = useSharedValue(false);\n\n React.useEffect(() => {\n isMounted.value = true;\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n ////////////////////////////////////////////////\n\n const svgProps = useAnimatedProps(() => {\n const shouldAnimateOnMount = animateOnMount === 'foreground';\n const inactiveWidth =\n !isMounted.value && shouldAnimateOnMount ? 0 : pathWidth;\n\n let duration =\n shouldAnimateOnMount && !hasMountedAnimation.value\n ? mountAnimationDuration\n : animationDuration;\n const props =\n shouldAnimateOnMount && !hasMountedAnimation.value\n ? mountAnimationProps\n : animationProps;\n\n if (isActive.value) {\n duration = 0;\n }\n\n return {\n width: withTiming(\n isActive.value\n ? // on Web, <svg /> elements don't support negative widths\n // https://github.com/coinjar/react-native-wagmi-charts/issues/24#issuecomment-955789904\n Math.max(currentX.value, 0)\n : inactiveWidth + widthOffset,\n Object.assign({ duration }, props),\n () => {\n hasMountedAnimation.value = true;\n }\n ),\n };\n });\n\n const viewSize = React.useMemo(() => ({ width, height }), [width, height]);\n\n ////////////////////////////////////////////////\n\n let backgroundChildren;\n let foregroundChildren;\n if (children) {\n const iterableChildren = flattenChildren(children);\n backgroundChildren = iterableChildren.filter((child) =>\n // @ts-ignore\n BACKGROUND_COMPONENTS.includes(child?.type?.displayName)\n );\n foregroundChildren = iterableChildren.filter((child) =>\n // @ts-ignore\n FOREGROUND_COMPONENTS.includes(child?.type?.displayName)\n );\n }\n\n ////////////////////////////////////////////////\n\n return (\n <>\n <LineChartPathContext.Provider\n value={{\n color,\n isInactive: showInactivePath,\n isTransitionEnabled: pathProps.isTransitionEnabled ?? true,\n }}\n >\n <View style={viewSize}>\n <Svg width={width} height={height}>\n <LineChartPath\n color={color}\n inactiveColor={inactiveColor}\n width={strokeWidth}\n {...pathProps}\n />\n {backgroundChildren}\n </Svg>\n </View>\n </LineChartPathContext.Provider>\n <LineChartPathContext.Provider\n value={{\n color,\n isInactive: false,\n isTransitionEnabled: pathProps.isTransitionEnabled ?? true,\n }}\n >\n <View style={StyleSheet.absoluteFill}>\n <AnimatedSVG animatedProps={svgProps} height={height}>\n <LineChartPath color={color} width={strokeWidth} {...pathProps} />\n {foregroundChildren}\n </AnimatedSVG>\n </View>\n </LineChartPathContext.Provider>\n </>\n );\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["index.tsx"],"names":["React","LineChartHoverTrap"],"mappings":"AAAA,OAAOA,KAAP,MAAkB,OAAlB;AAEA,OAAO,MAAMC,kBAAkB,GAAG,mBAAM,yCAAjC","sourcesContent":["import React from 'react';\n\nexport const LineChartHoverTrap = () => <></>;\n"]}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { View, StyleSheet } from 'react-native';
|
|
3
|
+
import { parse } from 'react-native-redash';
|
|
4
|
+
import { LineChartDimensionsContext } from '../Chart';
|
|
5
|
+
import { useLineChart } from '../useLineChart'; // @ts-expect-error missing types
|
|
6
|
+
|
|
7
|
+
import { canUseDOM } from 'fbjs/lib/ExecutionEnvironment';
|
|
8
|
+
let isEnabled = false; // the following logic comes from the creator of react-native-web
|
|
9
|
+
// https://gist.github.com/necolas/1c494e44e23eb7f8c5864a2fac66299a
|
|
10
|
+
// it's also used by MotiPressable's hover interactions
|
|
11
|
+
// https://github.com/nandorojo/moti/blob/master/packages/interactions/src/pressable/hoverable.tsx
|
|
12
|
+
|
|
13
|
+
if (canUseDOM) {
|
|
14
|
+
/**
|
|
15
|
+
* Web browsers emulate mouse events (and hover states) after touch events.
|
|
16
|
+
* This code infers when the currently-in-use modality supports hover
|
|
17
|
+
* (including for multi-modality devices) and considers "hover" to be enabled
|
|
18
|
+
* if a mouse movement occurs more than 1 second after the last touch event.
|
|
19
|
+
* This threshold is long enough to account for longer delays between the
|
|
20
|
+
* browser firing touch and mouse events on low-powered devices.
|
|
21
|
+
*/
|
|
22
|
+
const HOVER_THRESHOLD_MS = 1000;
|
|
23
|
+
let lastTouchTimestamp = 0;
|
|
24
|
+
|
|
25
|
+
function enableHover() {
|
|
26
|
+
if (isEnabled || Date.now() - lastTouchTimestamp < HOVER_THRESHOLD_MS) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
isEnabled = true;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function disableHover() {
|
|
34
|
+
lastTouchTimestamp = Date.now();
|
|
35
|
+
|
|
36
|
+
if (isEnabled) {
|
|
37
|
+
isEnabled = false;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
document.addEventListener('touchstart', disableHover, true);
|
|
42
|
+
document.addEventListener('touchmove', disableHover, true);
|
|
43
|
+
document.addEventListener('mousemove', enableHover, true);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function isHoverEnabled() {
|
|
47
|
+
return isEnabled;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export const LineChartHoverTrap = () => {
|
|
51
|
+
const {
|
|
52
|
+
width,
|
|
53
|
+
path
|
|
54
|
+
} = React.useContext(LineChartDimensionsContext);
|
|
55
|
+
const {
|
|
56
|
+
currentX,
|
|
57
|
+
currentIndex,
|
|
58
|
+
isActive,
|
|
59
|
+
data
|
|
60
|
+
} = useLineChart();
|
|
61
|
+
const parsedPath = React.useMemo(() => path ? parse(path) : undefined, [path]);
|
|
62
|
+
const onMouseMove = React.useCallback(({
|
|
63
|
+
x
|
|
64
|
+
}) => {
|
|
65
|
+
if (isHoverEnabled()) {
|
|
66
|
+
if (parsedPath) {
|
|
67
|
+
const boundedX = Math.min(x, width);
|
|
68
|
+
isActive.value = true;
|
|
69
|
+
currentX.value = boundedX; // on Web, we could drag the cursor to be negative, breaking it
|
|
70
|
+
// so we clamp the index at 0 to fix it
|
|
71
|
+
// https://github.com/coinjar/react-native-wagmi-charts/issues/24
|
|
72
|
+
|
|
73
|
+
const minIndex = 0;
|
|
74
|
+
const boundedIndex = Math.max(minIndex, Math.round(boundedX / width / (1 / (data.length - 1))));
|
|
75
|
+
currentIndex.value = boundedIndex;
|
|
76
|
+
}
|
|
77
|
+
} else {
|
|
78
|
+
isActive.value = false;
|
|
79
|
+
currentIndex.value = -1;
|
|
80
|
+
}
|
|
81
|
+
}, [currentIndex, currentX, data.length, isActive, parsedPath, width]);
|
|
82
|
+
const onMouseLeave = React.useCallback(() => {
|
|
83
|
+
isActive.value = false;
|
|
84
|
+
currentIndex.value = -1;
|
|
85
|
+
}, [currentIndex, isActive]);
|
|
86
|
+
return /*#__PURE__*/React.createElement(View, {
|
|
87
|
+
style: StyleSheet.absoluteFill // @ts-expect-error mouse move event
|
|
88
|
+
,
|
|
89
|
+
onMouseMove: React.useCallback( // eslint-disable-next-line no-undef
|
|
90
|
+
e => {
|
|
91
|
+
let rect = e.currentTarget.getBoundingClientRect();
|
|
92
|
+
let x = e.clientX - rect.left; // x position within the element.
|
|
93
|
+
|
|
94
|
+
onMouseMove({
|
|
95
|
+
x
|
|
96
|
+
});
|
|
97
|
+
}, [onMouseMove]),
|
|
98
|
+
onMouseLeave: onMouseLeave
|
|
99
|
+
});
|
|
100
|
+
};
|
|
101
|
+
//# sourceMappingURL=index.web.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["index.web.tsx"],"names":["React","View","StyleSheet","parse","LineChartDimensionsContext","useLineChart","canUseDOM","isEnabled","HOVER_THRESHOLD_MS","lastTouchTimestamp","enableHover","Date","now","disableHover","document","addEventListener","isHoverEnabled","LineChartHoverTrap","width","path","useContext","currentX","currentIndex","isActive","data","parsedPath","useMemo","undefined","onMouseMove","useCallback","x","boundedX","Math","min","value","minIndex","boundedIndex","max","round","length","onMouseLeave","absoluteFill","e","rect","currentTarget","getBoundingClientRect","clientX","left"],"mappings":"AAAA,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;AACA,SAASC,IAAT,EAAeC,UAAf,QAAiC,cAAjC;AACA,SAASC,KAAT,QAAsB,qBAAtB;AAEA,SAASC,0BAAT,QAA2C,UAA3C;AACA,SAASC,YAAT,QAA6B,iBAA7B,C,CAEA;;AACA,SAASC,SAAT,QAA0B,+BAA1B;AAEA,IAAIC,SAAS,GAAG,KAAhB,C,CAEA;AACA;AACA;AACA;;AACA,IAAID,SAAJ,EAAe;AACb;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACE,QAAME,kBAAkB,GAAG,IAA3B;AACA,MAAIC,kBAAkB,GAAG,CAAzB;;AAEA,WAASC,WAAT,GAAuB;AACrB,QAAIH,SAAS,IAAII,IAAI,CAACC,GAAL,KAAaH,kBAAb,GAAkCD,kBAAnD,EAAuE;AACrE;AACD;;AACDD,IAAAA,SAAS,GAAG,IAAZ;AACD;;AAED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';\nimport { parse } from 'react-native-redash';\n\nimport { LineChartDimensionsContext } from '../Chart';\nimport { useLineChart } from '../useLineChart';\n\n// @ts-expect-error missing types\nimport { canUseDOM } from 'fbjs/lib/ExecutionEnvironment';\n\nlet isEnabled = false;\n\n// the following logic comes from the creator of react-native-web\n// https://gist.github.com/necolas/1c494e44e23eb7f8c5864a2fac66299a\n// it's also used by MotiPressable's hover interactions\n// https://github.com/nandorojo/moti/blob/master/packages/interactions/src/pressable/hoverable.tsx\nif (canUseDOM) {\n /**\n * Web browsers emulate mouse events (and hover states) after touch events.\n * This code infers when the currently-in-use modality supports hover\n * (including for multi-modality devices) and considers \"hover\" to be enabled\n * if a mouse movement occurs more than 1 second after the last touch event.\n * This threshold is long enough to account for longer delays between the\n * browser firing touch and mouse events on low-powered devices.\n */\n const HOVER_THRESHOLD_MS = 1000;\n let lastTouchTimestamp = 0;\n\n function enableHover() {\n if (isEnabled || Date.now() - lastTouchTimestamp < HOVER_THRESHOLD_MS) {\n return;\n }\n isEnabled = true;\n }\n\n function disableHover() {\n lastTouchTimestamp = Date.now();\n if (isEnabled) {\n isEnabled = false;\n }\n }\n\n document.addEventListener('touchstart', disableHover, true);\n document.addEventListener('touchmove', disableHover, true);\n document.addEventListener('mousemove', enableHover, true);\n}\n\nfunction isHoverEnabled(): boolean {\n return isEnabled;\n}\n\nexport const LineChartHoverTrap = () => {\n const { width, path } = React.useContext(LineChartDimensionsContext);\n const { currentX, currentIndex, isActive, data } = useLineChart();\n\n const parsedPath = React.useMemo(\n () => (path ? parse(path) : undefined),\n [path]\n );\n\n const onMouseMove = React.useCallback(\n ({ x }: { x: number }) => {\n if (isHoverEnabled()) {\n if (parsedPath) {\n const boundedX = Math.min(x, width);\n isActive.value = true;\n currentX.value = boundedX;\n\n // on Web, we could drag the cursor to be negative, breaking it\n // so we clamp the index at 0 to fix it\n // https://github.com/coinjar/react-native-wagmi-charts/issues/24\n const minIndex = 0;\n const boundedIndex = Math.max(\n minIndex,\n Math.round(boundedX / width / (1 / (data.length - 1)))\n );\n\n currentIndex.value = boundedIndex;\n }\n } else {\n isActive.value = false;\n currentIndex.value = -1;\n }\n },\n [currentIndex, currentX, data.length, isActive, parsedPath, width]\n );\n\n const onMouseLeave = React.useCallback(() => {\n isActive.value = false;\n currentIndex.value = -1;\n }, [currentIndex, isActive]);\n\n return (\n <View\n style={StyleSheet.absoluteFill}\n // @ts-expect-error mouse move event\n onMouseMove={React.useCallback(\n // eslint-disable-next-line no-undef\n (e: React.MouseEvent<HTMLElement>) => {\n let rect = e.currentTarget.getBoundingClientRect();\n let x = e.clientX - rect.left; // x position within the element.\n\n onMouseMove({ x });\n },\n [onMouseMove]\n )}\n onMouseLeave={onMouseLeave}\n />\n );\n};\n"]}
|
|
@@ -15,6 +15,7 @@ import { LineChartDatetimeText } from './DatetimeText';
|
|
|
15
15
|
import { useLineChartDatetime } from './useDatetime';
|
|
16
16
|
import { useLineChartPrice } from './usePrice';
|
|
17
17
|
import { useLineChart } from './useLineChart';
|
|
18
|
+
import { LineChartHoverTrap } from '../line/HoverTrap';
|
|
18
19
|
export * from './Chart';
|
|
19
20
|
export * from './ChartPath';
|
|
20
21
|
export * from './Highlight';
|
|
@@ -49,6 +50,7 @@ export const LineChart = Object.assign(_LineChart, {
|
|
|
49
50
|
DatetimeText: LineChartDatetimeText,
|
|
50
51
|
useDatetime: useLineChartDatetime,
|
|
51
52
|
usePrice: useLineChartPrice,
|
|
52
|
-
useChart: useLineChart
|
|
53
|
+
useChart: useLineChart,
|
|
54
|
+
HoverTrap: LineChartHoverTrap
|
|
53
55
|
});
|
|
54
56
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["index.ts"],"names":["LineChart","_LineChart","LineChartPathWrapper","LineChartHighlight","LineChartProvider","LineChartCursor","LineChartCursorCrosshair","LineChartCursorLine","LineChartDot","LineChartGradient","LineChartGroup","LineChartHorizontalLine","LineChartTooltip","LineChartPriceText","LineChartDatetimeText","useLineChartDatetime","useLineChartPrice","useLineChart","Object","assign","Chart","Dot","Path","Cursor","CursorCrosshair","CursorLine","Gradient","Group","Highlight","HorizontalLine","Tooltip","Provider","PriceText","DatetimeText","useDatetime","usePrice","useChart"],"mappings":"AAAA,SAASA,SAAS,IAAIC,UAAtB,QAAwC,SAAxC;AACA,SAASC,oBAAT,QAAqC,aAArC;AACA,SAASC,kBAAT,QAAmC,aAAnC;AACA,SAASC,iBAAT,QAAkC,WAAlC;AACA,SAASC,eAAT,QAAgC,UAAhC;AACA,SAASC,wBAAT,QAAyC,mBAAzC;AACA,SAASC,mBAAT,QAAoC,cAApC;AACA,SAASC,YAAT,QAA6B,OAA7B;AACA,SAASC,iBAAT,QAAkC,YAAlC;AACA,SAASC,cAAT,QAA+B,SAA/B;AACA,SAASC,uBAAT,QAAwC,kBAAxC;AACA,SAASC,gBAAT,QAAiC,WAAjC;AACA,SAASC,kBAAT,QAAmC,aAAnC;AACA,SAASC,qBAAT,QAAsC,gBAAtC;AACA,SAASC,oBAAT,QAAqC,eAArC;AACA,SAASC,iBAAT,QAAkC,YAAlC;AACA,SAASC,YAAT,QAA6B,gBAA7B;AAEA,cAAc,SAAd;AACA,cAAc,aAAd;AACA,cAAc,aAAd;AACA,cAAc,WAAd;AACA,cAAc,UAAd;AACA,cAAc,mBAAd;AACA,cAAc,cAAd;AACA,cAAc,OAAd;AACA,cAAc,YAAd;AACA,cAAc,WAAd;AACA,cAAc,gBAAd;AACA,cAAc,QAAd;AACA,cAAc,aAAd;AACA,cAAc,eAAd;AACA,cAAc,gBAAd;AACA,cAAc,YAAd;AACA,cAAc,SAAd;AAEA,OAAO,
|
|
1
|
+
{"version":3,"sources":["index.ts"],"names":["LineChart","_LineChart","LineChartPathWrapper","LineChartHighlight","LineChartProvider","LineChartCursor","LineChartCursorCrosshair","LineChartCursorLine","LineChartDot","LineChartGradient","LineChartGroup","LineChartHorizontalLine","LineChartTooltip","LineChartPriceText","LineChartDatetimeText","useLineChartDatetime","useLineChartPrice","useLineChart","LineChartHoverTrap","Object","assign","Chart","Dot","Path","Cursor","CursorCrosshair","CursorLine","Gradient","Group","Highlight","HorizontalLine","Tooltip","Provider","PriceText","DatetimeText","useDatetime","usePrice","useChart","HoverTrap"],"mappings":"AAAA,SAASA,SAAS,IAAIC,UAAtB,QAAwC,SAAxC;AACA,SAASC,oBAAT,QAAqC,aAArC;AACA,SAASC,kBAAT,QAAmC,aAAnC;AACA,SAASC,iBAAT,QAAkC,WAAlC;AACA,SAASC,eAAT,QAAgC,UAAhC;AACA,SAASC,wBAAT,QAAyC,mBAAzC;AACA,SAASC,mBAAT,QAAoC,cAApC;AACA,SAASC,YAAT,QAA6B,OAA7B;AACA,SAASC,iBAAT,QAAkC,YAAlC;AACA,SAASC,cAAT,QAA+B,SAA/B;AACA,SAASC,uBAAT,QAAwC,kBAAxC;AACA,SAASC,gBAAT,QAAiC,WAAjC;AACA,SAASC,kBAAT,QAAmC,aAAnC;AACA,SAASC,qBAAT,QAAsC,gBAAtC;AACA,SAASC,oBAAT,QAAqC,eAArC;AACA,SAASC,iBAAT,QAAkC,YAAlC;AACA,SAASC,YAAT,QAA6B,gBAA7B;AACA,SAASC,kBAAT,QAAmC,mBAAnC;AAEA,cAAc,SAAd;AACA,cAAc,aAAd;AACA,cAAc,aAAd;AACA,cAAc,WAAd;AACA,cAAc,UAAd;AACA,cAAc,mBAAd;AACA,cAAc,cAAd;AACA,cAAc,OAAd;AACA,cAAc,YAAd;AACA,cAAc,WAAd;AACA,cAAc,gBAAd;AACA,cAAc,QAAd;AACA,cAAc,aAAd;AACA,cAAc,eAAd;AACA,cAAc,gBAAd;AACA,cAAc,YAAd;AACA,cAAc,SAAd;AAEA,OAAO,MAAMlB,SAAS,GAAGmB,MAAM,CAACC,MAAP,CAAcnB,UAAd,EAA0B;AACjDoB,EAAAA,KAAK,EAAEpB,UAD0C;AAEjDqB,EAAAA,GAAG,EAAEd,YAF4C;AAGjDe,EAAAA,IAAI,EAAErB,oBAH2C;AAIjDsB,EAAAA,MAAM,EAAEnB,eAJyC;AAKjDoB,EAAAA,eAAe,EAAEnB,wBALgC;AAMjDoB,EAAAA,UAAU,EAAEnB,mBANqC;AAOjDoB,EAAAA,QAAQ,EAAElB,iBAPuC;AAQjDmB,EAAAA,KAAK,EAAElB,cAR0C;AASjDmB,EAAAA,SAAS,EAAE1B,kBATsC;AAUjD2B,EAAAA,cAAc,EAAEnB,uBAViC;AAWjDoB,EAAAA,OAAO,EAAEnB,gBAXwC;AAYjDoB,EAAAA,QAAQ,EAAE5B,iBAZuC;AAajD6B,EAAAA,SAAS,EAAEpB,kBAbsC;AAcjDqB,EAAAA,YAAY,EAAEpB,qBAdmC;AAejDqB,EAAAA,WAAW,EAAEpB,oBAfoC;AAgBjDqB,EAAAA,QAAQ,EAAEpB,iBAhBuC;AAiBjDqB,EAAAA,QAAQ,EAAEpB,YAjBuC;AAkBjDqB,EAAAA,SAAS,EAAEpB;AAlBsC,CAA1B,CAAlB","sourcesContent":["import { LineChart as _LineChart } from './Chart';\nimport { LineChartPathWrapper } from './ChartPath';\nimport { LineChartHighlight } from './Highlight';\nimport { LineChartProvider } from './Context';\nimport { LineChartCursor } from './Cursor';\nimport { LineChartCursorCrosshair } from './CursorCrosshair';\nimport { LineChartCursorLine } from './CursorLine';\nimport { LineChartDot } from './Dot';\nimport { LineChartGradient } from './Gradient';\nimport { LineChartGroup } from './Group';\nimport { LineChartHorizontalLine } from './HorizontalLine';\nimport { LineChartTooltip } from './Tooltip';\nimport { LineChartPriceText } from './PriceText';\nimport { LineChartDatetimeText } from './DatetimeText';\nimport { useLineChartDatetime } from './useDatetime';\nimport { useLineChartPrice } from './usePrice';\nimport { useLineChart } from './useLineChart';\nimport { LineChartHoverTrap } from '../line/HoverTrap';\n\nexport * from './Chart';\nexport * from './ChartPath';\nexport * from './Highlight';\nexport * from './Context';\nexport * from './Cursor';\nexport * from './CursorCrosshair';\nexport * from './CursorLine';\nexport * from './Dot';\nexport * from './Gradient';\nexport * from './Tooltip';\nexport * from './DatetimeText';\nexport * from './Path';\nexport * from './PriceText';\nexport * from './useDatetime';\nexport * from './useLineChart';\nexport * from './usePrice';\nexport * from './types';\n\nexport const LineChart = Object.assign(_LineChart, {\n Chart: _LineChart,\n Dot: LineChartDot,\n Path: LineChartPathWrapper,\n Cursor: LineChartCursor,\n CursorCrosshair: LineChartCursorCrosshair,\n CursorLine: LineChartCursorLine,\n Gradient: LineChartGradient,\n Group: LineChartGroup,\n Highlight: LineChartHighlight,\n HorizontalLine: LineChartHorizontalLine,\n Tooltip: LineChartTooltip,\n Provider: LineChartProvider,\n PriceText: LineChartPriceText,\n DatetimeText: LineChartDatetimeText,\n useDatetime: useLineChartDatetime,\n usePrice: useLineChartPrice,\n useChart: useLineChart,\n HoverTrap: LineChartHoverTrap,\n});\n"]}
|
|
@@ -11,7 +11,7 @@ export const AnimatedText = ({
|
|
|
11
11
|
text,
|
|
12
12
|
style
|
|
13
13
|
}) => {
|
|
14
|
-
const inputRef = React.useRef(null);
|
|
14
|
+
const inputRef = React.useRef(null); // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
15
15
|
|
|
16
16
|
if (Platform.OS === 'web') {
|
|
17
17
|
// For some reason, the worklet reaction evaluates upfront regardless of any
|
|
@@ -23,10 +23,7 @@ export const AnimatedText = ({
|
|
|
23
23
|
return text.value;
|
|
24
24
|
}, (data, prevData) => {
|
|
25
25
|
if (data !== prevData && inputRef.current) {
|
|
26
|
-
inputRef.current.
|
|
27
|
-
value: data,
|
|
28
|
-
style
|
|
29
|
-
});
|
|
26
|
+
inputRef.current.value = data;
|
|
30
27
|
}
|
|
31
28
|
});
|
|
32
29
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["AnimatedText.tsx"],"names":["React","Platform","StyleSheet","TextInput","Animated","useAnimatedProps","useAnimatedReaction","addWhitelistedNativeProps","text","AnimatedTextInput","createAnimatedComponent","AnimatedText","style","inputRef","useRef","OS","value","data","prevData","current","
|
|
1
|
+
{"version":3,"sources":["AnimatedText.tsx"],"names":["React","Platform","StyleSheet","TextInput","Animated","useAnimatedProps","useAnimatedReaction","addWhitelistedNativeProps","text","AnimatedTextInput","createAnimatedComponent","AnimatedText","style","inputRef","useRef","OS","value","data","prevData","current","animatedProps","select","web","styles","create","color"],"mappings":"AAAA;AAEA,OAAOA,KAAP,MAAkB,OAAlB;AACA,SAASC,QAAT,EAAmBC,UAAnB,QAA+D,cAA/D;AACA,SAASC,SAAT,QAA0B,cAA1B;AACA,OAAOC,QAAP,IACEC,gBADF,EAEEC,mBAFF,QAGO,yBAHP;AAKAF,QAAQ,CAACG,yBAAT,CAAmC;AAAEC,EAAAA,IAAI,EAAE;AAAR,CAAnC;AAOA,MAAMC,iBAAiB,GAAGL,QAAQ,CAACM,uBAAT,CAAiCP,SAAjC,CAA1B;AAEA,OAAO,MAAMQ,YAAY,GAAG,CAAC;AAAEH,EAAAA,IAAF;AAAQI,EAAAA;AAAR,CAAD,KAAwC;AAClE,QAAMC,QAAQ,GAAGb,KAAK,CAACc,MAAN,CAAkB,IAAlB,CAAjB,CADkE,CACxB;;AAE1C,MAAIb,QAAQ,CAACc,EAAT,KAAgB,KAApB,EAA2B;AACzB;AACA;AACA;AACA;AAEA;AACAT,IAAAA,mBAAmB,CACjB,MAAM;AACJ,aAAOE,IAAI,CAACQ,KAAZ;AACD,KAHgB,EAIjB,CAACC,IAAD,EAAOC,QAAP,KAAoB;AAClB,UAAID,IAAI,KAAKC,QAAT,IAAqBL,QAAQ,CAACM,OAAlC,EAA2C;AACzCN,QAAAA,QAAQ,CAACM,OAAT,CAAiBH,KAAjB,GAAyBC,IAAzB;AACD;AACF,KARgB,CAAnB;AAUD;;AACD,QAAMG,aAAa,GAAGf,gBAAgB,CAAC,MAAM;AAC3C,WAAO;AACLG,MAAAA,IAAI,EAAEA,IAAI,CAACQ,KADN,CAEL;AACA;;AAHK,KAAP;AAKD,GANqC,CAAtC;AAOA,sBACE,oBAAC,iBAAD;AACE,IAAA,qBAAqB,EAAC,aADxB;AAEE,IAAA,QAAQ,EAAE,KAFZ;AAGE,IAAA,GAAG,EAAEf,QAAQ,CAACoB,MAAT,CAAgB;AAAEC,MAAAA,GAAG,EAAET;AAAP,KAAhB,CAHP;AAIE,IAAA,KAAK,EAAEL,IAAI,CAACQ,KAJd;AAKE,IAAA,KAAK,EAAE,CAACO,MAAM,CAACf,IAAR,EAAcI,KAAd,CALT;AAME,IAAA,aAAa,EAAEQ;AANjB,IADF;AAUD,CAtCM;AAwCP,MAAMG,MAAM,GAAGrB,UAAU,CAACsB,MAAX,CAAkB;AAC/BhB,EAAAA,IAAI,EAAE;AACJiB,IAAAA,KAAK,EAAE;AADH;AADyB,CAAlB,CAAf","sourcesContent":["// forked from https://github.com/wcandillon/react-native-redash/blob/master/src/ReText.tsx\n\nimport React from 'react';\nimport { Platform, StyleSheet, TextProps as RNTextProps } from 'react-native';\nimport { TextInput } from 'react-native';\nimport Animated, {\n useAnimatedProps,\n useAnimatedReaction,\n} from 'react-native-reanimated';\n\nAnimated.addWhitelistedNativeProps({ text: true });\n\ninterface AnimatedTextProps {\n text: Animated.SharedValue<string>;\n style?: Animated.AnimateProps<RNTextProps>['style'];\n}\n\nconst AnimatedTextInput = Animated.createAnimatedComponent(TextInput);\n\nexport const AnimatedText = ({ text, style }: AnimatedTextProps) => {\n const inputRef = React.useRef<any>(null); // eslint-disable-line @typescript-eslint/no-explicit-any\n\n if (Platform.OS === 'web') {\n // For some reason, the worklet reaction evaluates upfront regardless of any\n // conditionals within it, causing Android to crash upon the invokation of `setNativeProps`.\n // We are going to break the rules of hooks here so it doesn't invoke `useAnimatedReaction`\n // for platforms outside of the web.\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n useAnimatedReaction(\n () => {\n return text.value;\n },\n (data, prevData) => {\n if (data !== prevData && inputRef.current) {\n inputRef.current.value = data;\n }\n }\n );\n }\n const animatedProps = useAnimatedProps(() => {\n return {\n text: text.value,\n // Here we use any because the text prop is not available in the type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } as any;\n });\n return (\n <AnimatedTextInput\n underlineColorAndroid=\"transparent\"\n editable={false}\n ref={Platform.select({ web: inputRef })}\n value={text.value}\n style={[styles.text, style]}\n animatedProps={animatedProps}\n />\n );\n};\n\nconst styles = StyleSheet.create({\n text: {\n color: 'black',\n },\n});\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import
|
|
2
|
+
import { WithTimingConfig } from 'react-native-reanimated';
|
|
3
3
|
import { LineChartPathProps } from './Path';
|
|
4
4
|
export declare const LineChartPathContext: React.Context<{
|
|
5
5
|
color: string;
|
|
@@ -8,7 +8,7 @@ export declare const LineChartPathContext: React.Context<{
|
|
|
8
8
|
}>;
|
|
9
9
|
declare type LineChartPathWrapperProps = {
|
|
10
10
|
animationDuration?: number;
|
|
11
|
-
animationProps?: Partial<
|
|
11
|
+
animationProps?: Omit<Partial<WithTimingConfig>, 'duration'>;
|
|
12
12
|
children?: React.ReactNode;
|
|
13
13
|
color?: string;
|
|
14
14
|
inactiveColor?: string;
|
|
@@ -18,7 +18,7 @@ declare type LineChartPathWrapperProps = {
|
|
|
18
18
|
showInactivePath?: boolean;
|
|
19
19
|
animateOnMount?: 'foreground';
|
|
20
20
|
mountAnimationDuration?: number;
|
|
21
|
-
mountAnimationProps?: Partial<
|
|
21
|
+
mountAnimationProps?: Partial<WithTimingConfig>;
|
|
22
22
|
};
|
|
23
23
|
export declare function LineChartPathWrapper({ animationDuration, animationProps, children, color, inactiveColor, width: strokeWidth, widthOffset, pathProps, showInactivePath, animateOnMount, mountAnimationDuration, mountAnimationProps, }: LineChartPathWrapperProps): JSX.Element;
|
|
24
24
|
export declare namespace LineChartPathWrapper {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
1
2
|
import { LineChart as _LineChart } from './Chart';
|
|
2
3
|
import { LineChartPathWrapper } from './ChartPath';
|
|
3
4
|
import { LineChartHighlight } from './Highlight';
|
|
@@ -50,4 +51,5 @@ export declare const LineChart: typeof _LineChart & {
|
|
|
50
51
|
useDatetime: typeof useLineChartDatetime;
|
|
51
52
|
usePrice: typeof useLineChartPrice;
|
|
52
53
|
useChart: typeof useLineChart;
|
|
54
|
+
HoverTrap: () => JSX.Element;
|
|
53
55
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-wagmi-charts",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "A sweet candlestick chart for React Native",
|
|
5
5
|
"main": "lib/commonjs/index.js",
|
|
6
6
|
"module": "lib/module/index.js",
|
|
@@ -56,11 +56,11 @@
|
|
|
56
56
|
"jest": "^27.0.6",
|
|
57
57
|
"pod-install": "^0.1.24",
|
|
58
58
|
"prettier": "^2.3.2",
|
|
59
|
-
"react": "
|
|
60
|
-
"react-native": "
|
|
59
|
+
"react": "17.0.1",
|
|
60
|
+
"react-native": "0.63.4",
|
|
61
61
|
"react-native-builder-bob": "^0.18.1",
|
|
62
|
-
"react-native-gesture-handler": "^1.
|
|
63
|
-
"react-native-reanimated": "2.
|
|
62
|
+
"react-native-gesture-handler": "^2.1.0",
|
|
63
|
+
"react-native-reanimated": "~2.3.1",
|
|
64
64
|
"typescript": "^4.3.5"
|
|
65
65
|
},
|
|
66
66
|
"peerDependencies": {
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { View, StyleSheet } from 'react-native';
|
|
3
|
+
import { parse } from 'react-native-redash';
|
|
4
|
+
|
|
5
|
+
import { LineChartDimensionsContext } from '../../line/Chart';
|
|
6
|
+
import { useLineChart } from '../../line/useLineChart';
|
|
7
|
+
|
|
8
|
+
// @ts-expect-error missing types
|
|
9
|
+
import { canUseDOM } from 'fbjs/lib/ExecutionEnvironment';
|
|
10
|
+
|
|
11
|
+
let isEnabled = false;
|
|
12
|
+
|
|
13
|
+
// the following logic comes from the creator of react-native-web
|
|
14
|
+
// https://gist.github.com/necolas/1c494e44e23eb7f8c5864a2fac66299a
|
|
15
|
+
// it's also used by MotiPressable's hover interactions
|
|
16
|
+
// https://github.com/nandorojo/moti/blob/master/packages/interactions/src/pressable/hoverable.tsx
|
|
17
|
+
if (canUseDOM) {
|
|
18
|
+
/**
|
|
19
|
+
* Web browsers emulate mouse events (and hover states) after touch events.
|
|
20
|
+
* This code infers when the currently-in-use modality supports hover
|
|
21
|
+
* (including for multi-modality devices) and considers "hover" to be enabled
|
|
22
|
+
* if a mouse movement occurs more than 1 second after the last touch event.
|
|
23
|
+
* This threshold is long enough to account for longer delays between the
|
|
24
|
+
* browser firing touch and mouse events on low-powered devices.
|
|
25
|
+
*/
|
|
26
|
+
const HOVER_THRESHOLD_MS = 1000;
|
|
27
|
+
let lastTouchTimestamp = 0;
|
|
28
|
+
|
|
29
|
+
function enableHover() {
|
|
30
|
+
if (isEnabled || Date.now() - lastTouchTimestamp < HOVER_THRESHOLD_MS) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
isEnabled = true;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function disableHover() {
|
|
37
|
+
lastTouchTimestamp = Date.now();
|
|
38
|
+
if (isEnabled) {
|
|
39
|
+
isEnabled = false;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
document.addEventListener('touchstart', disableHover, true);
|
|
44
|
+
document.addEventListener('touchmove', disableHover, true);
|
|
45
|
+
document.addEventListener('mousemove', enableHover, true);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function isHoverEnabled(): boolean {
|
|
49
|
+
return isEnabled;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export const LineChartHoverTrap = () => {
|
|
53
|
+
const { width, path } = React.useContext(LineChartDimensionsContext);
|
|
54
|
+
const { currentX, currentIndex, isActive, data } = useLineChart();
|
|
55
|
+
|
|
56
|
+
const parsedPath = React.useMemo(
|
|
57
|
+
() => (path ? parse(path) : undefined),
|
|
58
|
+
[path]
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
const onMouseMove = React.useCallback(
|
|
62
|
+
({ x }: { x: number }) => {
|
|
63
|
+
if (isHoverEnabled()) {
|
|
64
|
+
if (parsedPath) {
|
|
65
|
+
const boundedX = Math.min(x, width);
|
|
66
|
+
isActive.value = true;
|
|
67
|
+
currentX.value = boundedX;
|
|
68
|
+
|
|
69
|
+
// on Web, we could drag the cursor to be negative, breaking it
|
|
70
|
+
// so we clamp the index at 0 to fix it
|
|
71
|
+
// https://github.com/coinjar/react-native-wagmi-charts/issues/24
|
|
72
|
+
const minIndex = 0;
|
|
73
|
+
const boundedIndex = Math.max(
|
|
74
|
+
minIndex,
|
|
75
|
+
Math.round(boundedX / width / (1 / (data.length - 1)))
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
currentIndex.value = boundedIndex;
|
|
79
|
+
}
|
|
80
|
+
} else {
|
|
81
|
+
isActive.value = false;
|
|
82
|
+
currentIndex.value = -1;
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
[currentIndex, currentX, data.length, isActive, parsedPath, width]
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
const onMouseLeave = React.useCallback(() => {
|
|
89
|
+
isActive.value = false;
|
|
90
|
+
currentIndex.value = -1;
|
|
91
|
+
}, [currentIndex, isActive]);
|
|
92
|
+
|
|
93
|
+
return (
|
|
94
|
+
<View
|
|
95
|
+
style={StyleSheet.absoluteFill}
|
|
96
|
+
// @ts-expect-error mouse move event
|
|
97
|
+
onMouseMove={React.useCallback(
|
|
98
|
+
// eslint-disable-next-line no-undef
|
|
99
|
+
(e: React.MouseEvent<HTMLElement>) => {
|
|
100
|
+
let rect = e.currentTarget.getBoundingClientRect();
|
|
101
|
+
let x = e.clientX - rect.left; // x position within the element.
|
|
102
|
+
|
|
103
|
+
onMouseMove({ x });
|
|
104
|
+
},
|
|
105
|
+
[onMouseMove]
|
|
106
|
+
)}
|
|
107
|
+
onMouseLeave={onMouseLeave}
|
|
108
|
+
/>
|
|
109
|
+
);
|
|
110
|
+
};
|
|
@@ -5,6 +5,7 @@ import Animated, {
|
|
|
5
5
|
useAnimatedProps,
|
|
6
6
|
useSharedValue,
|
|
7
7
|
withTiming,
|
|
8
|
+
WithTimingConfig,
|
|
8
9
|
} from 'react-native-reanimated';
|
|
9
10
|
import flattenChildren from 'react-keyed-flatten-children';
|
|
10
11
|
|
|
@@ -30,7 +31,7 @@ export const LineChartPathContext = React.createContext({
|
|
|
30
31
|
|
|
31
32
|
type LineChartPathWrapperProps = {
|
|
32
33
|
animationDuration?: number;
|
|
33
|
-
animationProps?: Partial<
|
|
34
|
+
animationProps?: Omit<Partial<WithTimingConfig>, 'duration'>;
|
|
34
35
|
children?: React.ReactNode;
|
|
35
36
|
color?: string;
|
|
36
37
|
inactiveColor?: string;
|
|
@@ -40,7 +41,7 @@ type LineChartPathWrapperProps = {
|
|
|
40
41
|
showInactivePath?: boolean;
|
|
41
42
|
animateOnMount?: 'foreground';
|
|
42
43
|
mountAnimationDuration?: number;
|
|
43
|
-
mountAnimationProps?: Partial<
|
|
44
|
+
mountAnimationProps?: Partial<WithTimingConfig>;
|
|
44
45
|
};
|
|
45
46
|
|
|
46
47
|
LineChartPathWrapper.displayName = 'LineChartPathWrapper';
|
|
@@ -78,7 +79,7 @@ export function LineChartPathWrapper({
|
|
|
78
79
|
const inactiveWidth =
|
|
79
80
|
!isMounted.value && shouldAnimateOnMount ? 0 : pathWidth;
|
|
80
81
|
|
|
81
|
-
|
|
82
|
+
let duration =
|
|
82
83
|
shouldAnimateOnMount && !hasMountedAnimation.value
|
|
83
84
|
? mountAnimationDuration
|
|
84
85
|
: animationDuration;
|
|
@@ -87,18 +88,22 @@ export function LineChartPathWrapper({
|
|
|
87
88
|
? mountAnimationProps
|
|
88
89
|
: animationProps;
|
|
89
90
|
|
|
91
|
+
if (isActive.value) {
|
|
92
|
+
duration = 0;
|
|
93
|
+
}
|
|
94
|
+
|
|
90
95
|
return {
|
|
91
|
-
width:
|
|
92
|
-
|
|
93
|
-
//
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
96
|
+
width: withTiming(
|
|
97
|
+
isActive.value
|
|
98
|
+
? // on Web, <svg /> elements don't support negative widths
|
|
99
|
+
// https://github.com/coinjar/react-native-wagmi-charts/issues/24#issuecomment-955789904
|
|
100
|
+
Math.max(currentX.value, 0)
|
|
101
|
+
: inactiveWidth + widthOffset,
|
|
102
|
+
Object.assign({ duration }, props),
|
|
103
|
+
() => {
|
|
104
|
+
hasMountedAnimation.value = true;
|
|
105
|
+
}
|
|
106
|
+
),
|
|
102
107
|
};
|
|
103
108
|
});
|
|
104
109
|
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { View, StyleSheet } from 'react-native';
|
|
3
|
+
import { parse } from 'react-native-redash';
|
|
4
|
+
|
|
5
|
+
import { LineChartDimensionsContext } from '../Chart';
|
|
6
|
+
import { useLineChart } from '../useLineChart';
|
|
7
|
+
|
|
8
|
+
// @ts-expect-error missing types
|
|
9
|
+
import { canUseDOM } from 'fbjs/lib/ExecutionEnvironment';
|
|
10
|
+
|
|
11
|
+
let isEnabled = false;
|
|
12
|
+
|
|
13
|
+
// the following logic comes from the creator of react-native-web
|
|
14
|
+
// https://gist.github.com/necolas/1c494e44e23eb7f8c5864a2fac66299a
|
|
15
|
+
// it's also used by MotiPressable's hover interactions
|
|
16
|
+
// https://github.com/nandorojo/moti/blob/master/packages/interactions/src/pressable/hoverable.tsx
|
|
17
|
+
if (canUseDOM) {
|
|
18
|
+
/**
|
|
19
|
+
* Web browsers emulate mouse events (and hover states) after touch events.
|
|
20
|
+
* This code infers when the currently-in-use modality supports hover
|
|
21
|
+
* (including for multi-modality devices) and considers "hover" to be enabled
|
|
22
|
+
* if a mouse movement occurs more than 1 second after the last touch event.
|
|
23
|
+
* This threshold is long enough to account for longer delays between the
|
|
24
|
+
* browser firing touch and mouse events on low-powered devices.
|
|
25
|
+
*/
|
|
26
|
+
const HOVER_THRESHOLD_MS = 1000;
|
|
27
|
+
let lastTouchTimestamp = 0;
|
|
28
|
+
|
|
29
|
+
function enableHover() {
|
|
30
|
+
if (isEnabled || Date.now() - lastTouchTimestamp < HOVER_THRESHOLD_MS) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
isEnabled = true;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function disableHover() {
|
|
37
|
+
lastTouchTimestamp = Date.now();
|
|
38
|
+
if (isEnabled) {
|
|
39
|
+
isEnabled = false;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
document.addEventListener('touchstart', disableHover, true);
|
|
44
|
+
document.addEventListener('touchmove', disableHover, true);
|
|
45
|
+
document.addEventListener('mousemove', enableHover, true);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function isHoverEnabled(): boolean {
|
|
49
|
+
return isEnabled;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export const LineChartHoverTrap = () => {
|
|
53
|
+
const { width, path } = React.useContext(LineChartDimensionsContext);
|
|
54
|
+
const { currentX, currentIndex, isActive, data } = useLineChart();
|
|
55
|
+
|
|
56
|
+
const parsedPath = React.useMemo(
|
|
57
|
+
() => (path ? parse(path) : undefined),
|
|
58
|
+
[path]
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
const onMouseMove = React.useCallback(
|
|
62
|
+
({ x }: { x: number }) => {
|
|
63
|
+
if (isHoverEnabled()) {
|
|
64
|
+
if (parsedPath) {
|
|
65
|
+
const boundedX = Math.min(x, width);
|
|
66
|
+
isActive.value = true;
|
|
67
|
+
currentX.value = boundedX;
|
|
68
|
+
|
|
69
|
+
// on Web, we could drag the cursor to be negative, breaking it
|
|
70
|
+
// so we clamp the index at 0 to fix it
|
|
71
|
+
// https://github.com/coinjar/react-native-wagmi-charts/issues/24
|
|
72
|
+
const minIndex = 0;
|
|
73
|
+
const boundedIndex = Math.max(
|
|
74
|
+
minIndex,
|
|
75
|
+
Math.round(boundedX / width / (1 / (data.length - 1)))
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
currentIndex.value = boundedIndex;
|
|
79
|
+
}
|
|
80
|
+
} else {
|
|
81
|
+
isActive.value = false;
|
|
82
|
+
currentIndex.value = -1;
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
[currentIndex, currentX, data.length, isActive, parsedPath, width]
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
const onMouseLeave = React.useCallback(() => {
|
|
89
|
+
isActive.value = false;
|
|
90
|
+
currentIndex.value = -1;
|
|
91
|
+
}, [currentIndex, isActive]);
|
|
92
|
+
|
|
93
|
+
return (
|
|
94
|
+
<View
|
|
95
|
+
style={StyleSheet.absoluteFill}
|
|
96
|
+
// @ts-expect-error mouse move event
|
|
97
|
+
onMouseMove={React.useCallback(
|
|
98
|
+
// eslint-disable-next-line no-undef
|
|
99
|
+
(e: React.MouseEvent<HTMLElement>) => {
|
|
100
|
+
let rect = e.currentTarget.getBoundingClientRect();
|
|
101
|
+
let x = e.clientX - rect.left; // x position within the element.
|
|
102
|
+
|
|
103
|
+
onMouseMove({ x });
|
|
104
|
+
},
|
|
105
|
+
[onMouseMove]
|
|
106
|
+
)}
|
|
107
|
+
onMouseLeave={onMouseLeave}
|
|
108
|
+
/>
|
|
109
|
+
);
|
|
110
|
+
};
|