@react-native-ohos/victory-native-xl 41.17.5-rc.1 → 41.18.0-beta.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/src/index.ts CHANGED
@@ -1,52 +1,56 @@
1
- /**
2
- * Cartesian chart exports (including useful types)
3
- */
4
- export { CartesianChart } from "./cartesian/CartesianChart";
5
- export { PolarChart } from "./polar/PolarChart";
6
-
7
-
8
- export { type CurveType } from "victory-native";
9
- export { type RoundedCorners } from "victory-native";
10
-
11
- export { useAnimatedPath } from "victory-native";
12
- export { AnimatedPath } from "victory-native";
13
- export { usePrevious } from "victory-native";
14
- export {
15
- useChartPressState,
16
- type ChartPressState,
17
- } from "victory-native";
18
-
19
- // Line
20
- export { useLinePath } from "victory-native";
21
- export { Line } from "victory-native";
22
-
23
- // Bar
24
- export { useBarPath } from "victory-native";
25
- export { Bar } from "victory-native";
26
-
27
- // Bar group
28
- export { useBarGroupPaths } from "victory-native";
29
- export { BarGroup } from "victory-native";
30
-
31
- // Area
32
- export { useAreaPath } from "victory-native";
33
- export { Area } from "victory-native";
34
-
35
- // Scatter
36
- export { Scatter, type ScatterShape } from "victory-native";
37
-
38
- // Grid and Axis
39
- export { CartesianAxis } from "victory-native";
40
-
41
- /**
42
- * Polar chart exports
43
- */
44
-
45
- /**
46
- * Pie chart exports (including useful types)
47
- */
48
- export { Pie, type PieSliceData } from "victory-native";
49
-
50
- export { useSlicePath } from "victory-native";
51
- export { useSliceAngularInsetPath } from "victory-native";
52
- export { useChartTransformState } from "victory-native";
1
+ /**
2
+ * Cartesian chart exports (including useful types)
3
+ */
4
+ export {
5
+ CartesianChart,
6
+ type CartesianActionsHandle,
7
+ type CartesianChartRef,
8
+ } from "./cartesian/CartesianChart";
9
+ export { PolarChart } from "./polar/PolarChart";
10
+
11
+ export { type CurveType } from "victory-native";
12
+ export { type RoundedCorners } from "victory-native";
13
+ export { type AxisScaleType, type AxisScales } from "victory-native/src/types";
14
+
15
+ export { useAnimatedPath } from "victory-native";
16
+ export { AnimatedPath } from "victory-native";
17
+ export { usePrevious } from "victory-native";
18
+ export {
19
+ useChartPressState,
20
+ type ChartPressState,
21
+ } from "victory-native";
22
+
23
+ // Line
24
+ export { useLinePath } from "victory-native";
25
+ export { Line } from "victory-native";
26
+
27
+ // Bar
28
+ export { useBarPath } from "victory-native";
29
+ export { Bar } from "victory-native";
30
+
31
+ // Bar group
32
+ export { useBarGroupPaths } from "victory-native";
33
+ export { BarGroup } from "victory-native";
34
+
35
+ // Area
36
+ export { useAreaPath } from "victory-native";
37
+ export { Area } from "victory-native";
38
+
39
+ // Scatter
40
+ export { Scatter, type ScatterShape } from "victory-native";
41
+
42
+ // Grid and Axis
43
+ export { CartesianAxis } from "victory-native";
44
+
45
+ /**
46
+ * Polar chart exports
47
+ */
48
+
49
+ /**
50
+ * Pie chart exports (including useful types)
51
+ */
52
+ export { Pie, type PieSliceData } from "victory-native";
53
+
54
+ export { useSlicePath } from "victory-native";
55
+ export { useSliceAngularInsetPath } from "victory-native";
56
+ export { useChartTransformState } from "victory-native";
@@ -1,144 +1,146 @@
1
- import * as React from "react";
2
-
3
- import { Canvas } from "@shopify/react-native-skia";
4
- import { useContextBridge, FiberProvider } from "its-fine";
5
- import {
6
- StyleSheet,
7
- View,
8
- type ViewStyle,
9
- type LayoutChangeEvent,
10
- type StyleProp,
11
- } from "react-native";
12
- import {
13
- PolarChartProvider,
14
- usePolarChartContext,
15
- } from "victory-native/src/polar/contexts/PolarChartContext";
16
- import type {
17
- ColorFields,
18
- InputFields,
19
- NumericalFields,
20
- StringKeyOf,
21
- } from "victory-native/src/types";
22
-
23
- type PolarChartBaseProps = {
24
- onLayout: ({ nativeEvent: { layout } }: LayoutChangeEvent) => void;
25
- hasMeasuredLayoutSize: boolean;
26
- canvasSize: { width: number; height: number };
27
- containerStyle?: StyleProp<ViewStyle>;
28
- canvasStyle?: StyleProp<ViewStyle>;
29
- };
30
-
31
- interface PolarChartContext {
32
- data: Record<string, unknown>[];
33
- canvasSize: { width: number; height: number };
34
- labelKey: string;
35
- valueKey: string;
36
- colorKey: string;
37
- }
38
-
39
- const PolarChartBase = (
40
- props: React.PropsWithChildren<PolarChartBaseProps>,
41
- ) => {
42
- const {
43
- containerStyle,
44
- canvasStyle,
45
- children,
46
- onLayout,
47
- hasMeasuredLayoutSize,
48
- canvasSize,
49
- } = props;
50
- const { width, height } = canvasSize;
51
-
52
- const ctx = usePolarChartContext();
53
- const ContextBridge = useContextBridge();
54
- return (
55
- <View style={[styles.baseContainer, containerStyle]}>
56
- <Canvas
57
- onLayout={onLayout}
58
- style={StyleSheet.flatten([
59
- styles.canvasContainer,
60
- hasMeasuredLayoutSize ? { width, height } : null,
61
- canvasStyle,
62
- ])}
63
- >
64
- {/* https://shopify.github.io/react-native-skia/docs/canvas/contexts/
65
- we have to re-inject our context to make it available in the skia renderer
66
- */}
67
- <ContextBridge {...ctx}>
68
- {children}
69
- </ContextBridge>
70
- {/* <PolarChartProvider {...ctx} canvasSize={canvasSize}>
71
- {children}
72
- </PolarChartProvider> */}
73
- </Canvas>
74
- </View>
75
- );
76
- };
77
-
78
- type PolarChartProps<
79
- RawData extends Record<string, unknown>,
80
- LabelKey extends StringKeyOf<InputFields<RawData>>,
81
- ValueKey extends StringKeyOf<NumericalFields<RawData>>,
82
- ColorKey extends StringKeyOf<ColorFields<RawData>>,
83
- > = {
84
- data: RawData[];
85
- colorKey: ColorKey;
86
- labelKey: LabelKey;
87
- valueKey: ValueKey;
88
- } & Omit<
89
- PolarChartBaseProps,
90
- "canvasSize" | "onLayout" | "hasMeasuredLayoutSize" // omit exposing internal props for calculating canvas layout/size
91
- >;
92
- export const PolarChart = <
93
- RawData extends Record<string, unknown>,
94
- LabelKey extends StringKeyOf<InputFields<RawData>>,
95
- ValueKey extends StringKeyOf<NumericalFields<RawData>>,
96
- ColorKey extends StringKeyOf<ColorFields<RawData>>,
97
- >(
98
- props: React.PropsWithChildren<
99
- PolarChartProps<RawData, LabelKey, ValueKey, ColorKey>
100
- >,
101
- ) => {
102
- const { data, labelKey, colorKey, valueKey } = props;
103
-
104
- const [canvasSize, setCanvasSize] = React.useState({ width: 0, height: 0 });
105
-
106
- const [hasMeasuredLayoutSize, setHasMeasuredLayoutSize] =
107
- React.useState(false);
108
-
109
- const onLayout = React.useCallback(
110
- ({ nativeEvent: { layout } }: LayoutChangeEvent) => {
111
- setHasMeasuredLayoutSize(true);
112
- setCanvasSize(layout);
113
- },
114
- [],
115
- );
116
-
117
- return (
118
- <FiberProvider>
119
- <PolarChartProvider
120
- data={data}
121
- labelKey={labelKey.toString()}
122
- colorKey={colorKey.toString()}
123
- valueKey={valueKey.toString()}
124
- canvasSize={canvasSize}
125
- >
126
- <PolarChartBase
127
- {...props}
128
- onLayout={onLayout}
129
- hasMeasuredLayoutSize={hasMeasuredLayoutSize}
130
- canvasSize={canvasSize}
131
- />
132
- </PolarChartProvider>
133
- </FiberProvider>
134
- );
135
- };
136
-
137
- const styles = StyleSheet.create({
138
- baseContainer: {
139
- flex: 1,
140
- },
141
- canvasContainer: {
142
- flex: 1,
143
- },
144
- });
1
+ import * as React from "react";
2
+
3
+ import { Canvas } from "@shopify/react-native-skia";
4
+ import { useContextBridge, FiberProvider } from "its-fine";
5
+ import {
6
+ StyleSheet,
7
+ View,
8
+ type ViewStyle,
9
+ type LayoutChangeEvent,
10
+ type StyleProp,
11
+ } from "react-native";
12
+ import {
13
+ PolarChartProvider,
14
+ usePolarChartContext,
15
+ } from "victory-native/src/polar/contexts/PolarChartContext";
16
+ import type {
17
+ ColorFields,
18
+ InputFields,
19
+ NumericalFields,
20
+ StringKeyOf,
21
+ } from "victory-native/src/types";
22
+
23
+ type PolarChartBaseProps = {
24
+ onLayout: ({ nativeEvent: { layout } }: LayoutChangeEvent) => void;
25
+ hasMeasuredLayoutSize: boolean;
26
+ canvasSize: { width: number; height: number };
27
+ containerStyle?: StyleProp<ViewStyle>;
28
+ canvasStyle?: StyleProp<ViewStyle>;
29
+ };
30
+
31
+ interface PolarChartContext {
32
+ data: Record<string, unknown>[];
33
+ canvasSize: { width: number; height: number };
34
+ labelKey: string;
35
+ valueKey: string;
36
+ colorKey: string;
37
+ }
38
+
39
+ const PolarChartBase = (
40
+ props: React.PropsWithChildren<PolarChartBaseProps>,
41
+ ) => {
42
+ const {
43
+ containerStyle,
44
+ canvasStyle,
45
+ children,
46
+ onLayout,
47
+ hasMeasuredLayoutSize,
48
+ canvasSize,
49
+ } = props;
50
+ const { width, height } = canvasSize;
51
+
52
+ const ctx = usePolarChartContext();
53
+ const ContextBridge = useContextBridge();
54
+ return (
55
+ <View
56
+ style={[styles.baseContainer, containerStyle]}
57
+ onLayout={onLayout}
58
+ >
59
+ <Canvas
60
+ style={StyleSheet.flatten([
61
+ styles.canvasContainer,
62
+ hasMeasuredLayoutSize ? { width, height } : null,
63
+ canvasStyle,
64
+ ])}
65
+ >
66
+ {/* https://shopify.github.io/react-native-skia/docs/canvas/contexts/
67
+ we have to re-inject our context to make it available in the skia renderer
68
+ */}
69
+ <ContextBridge {...ctx}>
70
+ {children}
71
+ </ContextBridge>
72
+ {/* <PolarChartProvider {...ctx} canvasSize={canvasSize}>
73
+ {children}
74
+ </PolarChartProvider> */}
75
+ </Canvas>
76
+ </View>
77
+ );
78
+ };
79
+
80
+ type PolarChartProps<
81
+ RawData extends Record<string, unknown>,
82
+ LabelKey extends StringKeyOf<InputFields<RawData>>,
83
+ ValueKey extends StringKeyOf<NumericalFields<RawData>>,
84
+ ColorKey extends StringKeyOf<ColorFields<RawData>>,
85
+ > = {
86
+ data: RawData[];
87
+ colorKey: ColorKey;
88
+ labelKey: LabelKey;
89
+ valueKey: ValueKey;
90
+ } & Omit<
91
+ PolarChartBaseProps,
92
+ "canvasSize" | "onLayout" | "hasMeasuredLayoutSize" // omit exposing internal props for calculating canvas layout/size
93
+ >;
94
+ export const PolarChart = <
95
+ RawData extends Record<string, unknown>,
96
+ LabelKey extends StringKeyOf<InputFields<RawData>>,
97
+ ValueKey extends StringKeyOf<NumericalFields<RawData>>,
98
+ ColorKey extends StringKeyOf<ColorFields<RawData>>,
99
+ >(
100
+ props: React.PropsWithChildren<
101
+ PolarChartProps<RawData, LabelKey, ValueKey, ColorKey>
102
+ >,
103
+ ) => {
104
+ const { data, labelKey, colorKey, valueKey } = props;
105
+
106
+ const [canvasSize, setCanvasSize] = React.useState({ width: 0, height: 0 });
107
+
108
+ const [hasMeasuredLayoutSize, setHasMeasuredLayoutSize] =
109
+ React.useState(false);
110
+
111
+ const onLayout = React.useCallback(
112
+ ({ nativeEvent: { layout } }: LayoutChangeEvent) => {
113
+ setHasMeasuredLayoutSize(true);
114
+ setCanvasSize(layout);
115
+ },
116
+ [],
117
+ );
118
+
119
+ return (
120
+ <FiberProvider>
121
+ <PolarChartProvider
122
+ data={data}
123
+ labelKey={labelKey.toString()}
124
+ colorKey={colorKey.toString()}
125
+ valueKey={valueKey.toString()}
126
+ canvasSize={canvasSize}
127
+ >
128
+ <PolarChartBase
129
+ {...props}
130
+ onLayout={onLayout}
131
+ hasMeasuredLayoutSize={hasMeasuredLayoutSize}
132
+ canvasSize={canvasSize}
133
+ />
134
+ </PolarChartProvider>
135
+ </FiberProvider>
136
+ );
137
+ };
138
+
139
+ const styles = StyleSheet.create({
140
+ baseContainer: {
141
+ flex: 1,
142
+ },
143
+ canvasContainer: {
144
+ flex: 1,
145
+ },
146
+ });
@@ -0,0 +1,45 @@
1
+ import {
2
+ type ComposedGesture,
3
+ GestureDetector,
4
+ type GestureType,
5
+ } from "react-native-gesture-handler";
6
+ import { type SkRect } from "@shopify/react-native-skia";
7
+ import Animated, { useAnimatedStyle } from "react-native-reanimated";
8
+ import * as React from "react";
9
+ import { type ChartTransformState } from "victory-native/src/cartesian/hooks/useChartTransformState";
10
+ import type { GestureHandlerConfig } from "victory-native/src/types";
11
+
12
+ type GestureHandlerProps = {
13
+ gesture: ComposedGesture | GestureType;
14
+ dimensions?: SkRect;
15
+ transformState?: ChartTransformState;
16
+ debug?: boolean;
17
+ config?: GestureHandlerConfig;
18
+ };
19
+
20
+ /**
21
+ * OHOS: Keep the gesture overlay fixed to the chart container instead of
22
+ * following transformState.matrix. Upstream 41.20.2 moves the overlay with
23
+ * matrix transforms, which breaks pan/pinch on HarmonyOS RNGH (e.g. Y pan
24
+ * requires a horizontal move first). Aligns with upstream main PR #664.
25
+ */
26
+ export const GestureHandler = ({
27
+ gesture,
28
+ debug = false,
29
+ config,
30
+ }: GestureHandlerProps) => {
31
+ const style = useAnimatedStyle(() => ({
32
+ position: "absolute",
33
+ top: 0,
34
+ left: 0,
35
+ right: 0,
36
+ bottom: 0,
37
+ backgroundColor: debug ? "rgba(100, 200, 255, 0.4)" : "transparent",
38
+ }));
39
+
40
+ return (
41
+ <GestureDetector {...config} gesture={gesture}>
42
+ <Animated.View style={style} />
43
+ </GestureDetector>
44
+ );
45
+ };