Skip to content

Commit 1c8217d

Browse files
authored
Fix victory-native/victory-zoom-container clipping bug (#3026)
Issue summary: Previously, victory-native/victory-zoom-container spread the result of `useVictoryZoomContainer` into `VictoryContainer` ```ts const props = useVictoryZoomContainer(...) return <VictoryContainer {...props} />; ``` Where the return type of `useVictoryZoomContainer` is ``` { props: VictoryZoomContainerMutatedProps; children: React.ReactElement[]; } ``` Because `VictoryContainer` received the entire `props` object as a prop, instead of spreading its properties, values such as `width` and `height` were `undefined` - leading to the viewbox for the svg element to render as `<svg viewBox="0 0 undefined undefined" ...>` thus clipping the rendered chart. Solution: Destructure the props/children result from `useVictoryContainer` and pass correctly to `VictoryContainer`
1 parent cd0f963 commit 1c8217d

File tree

6 files changed

+312
-209
lines changed

6 files changed

+312
-209
lines changed

.changeset/fifty-pears-brake.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"victory-native": patch
3+
---
4+
5+
Fixes clipping/loss of interactivity bug in victory-zoom-container

demo/rn/package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"eject": "expo eject"
1212
},
1313
"dependencies": {
14+
"@expo/metro-runtime": "~3.1.3",
1415
"@react-navigation/native": "^6.1.17",
1516
"@react-navigation/native-stack": "^6.9.26",
1617
"expo": "~50.0.17",
@@ -23,6 +24,7 @@
2324
"react-native-safe-area-context": "4.10.1",
2425
"react-native-screens": "~3.31.1",
2526
"react-native-svg": "14.1.0",
27+
"react-native-web": "~0.19.6",
2628
"victory": "workspace:*",
2729
"victory-area": "workspace:*",
2830
"victory-axis": "workspace:*",
@@ -40,6 +42,7 @@
4042
"victory-histogram": "workspace:*",
4143
"victory-legend": "workspace:*",
4244
"victory-line": "workspace:*",
45+
"victory-native": "workspace:*",
4346
"victory-pie": "workspace:*",
4447
"victory-polar-axis": "workspace:*",
4548
"victory-scatter": "workspace:*",
@@ -49,8 +52,7 @@
4952
"victory-tooltip": "workspace:*",
5053
"victory-voronoi": "workspace:*",
5154
"victory-voronoi-container": "workspace:*",
52-
"victory-zoom-container": "workspace:*",
53-
"victory-native": "workspace:*"
55+
"victory-zoom-container": "workspace:*"
5456
},
5557
"devDependencies": {
5658
"@babel/core": "^7.20.0",

demo/rn/src/screens/chart-screen.tsx

+14-1
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ import {
1010
VictoryArea,
1111
VictoryStack,
1212
VictoryTooltip,
13+
VictoryZoomContainer,
1314
} from "victory-native";
1415
import viewStyles from "../styles/view-styles";
15-
import { getTransitionData } from "../data";
16+
import { getTransitionData, generateRandomData } from "../data";
1617

1718
export const ChartScreen: React.FC = () => {
1819
const [transitionData, setTransitionData] =
@@ -186,6 +187,18 @@ export const ChartScreen: React.FC = () => {
186187
>
187188
<VictoryBar />
188189
</VictoryChart>
190+
<VictoryChart
191+
containerComponent={
192+
<VictoryZoomContainer
193+
zoomDimension="x"
194+
zoomDomain={{
195+
x: [0, 5],
196+
}}
197+
/>
198+
}
199+
>
200+
<VictoryBar barRatio={1.2} data={generateRandomData(10)} />
201+
</VictoryChart>
189202
</ScrollView>
190203
);
191204
};

packages/victory-native/README.md

+6-5
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,12 @@ To open the demo app, just fire up the expo app.
6767
# Install victory and its dependencies
6868
$ git clone https://github.com/FormidableLabs/victory
6969
$ cd victory
70-
$ yarn install
71-
# Open up the React Native demo app
72-
$ cd demo/rn
73-
$ yarn install
74-
$ yarn start
70+
$ pnpm install
71+
$ pnpm run build --watch
72+
# In a new terminal, open up the React Native demo app
73+
$ cd victory/demo/rn
74+
$ pnpm install
75+
$ pnpm start
7576
```
7677

7778
Once Expo has fired up, it should open a web browser window where you can find instructions to open the demo application (either on a simulator or a physical device using the Expo Go app).

packages/victory-native/src/components/victory-zoom-container.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,14 @@ export interface VictoryZoomContainerNativeProps
1919
export const VictoryZoomContainer = (
2020
initialProps: VictoryZoomContainerNativeProps,
2121
) => {
22-
const props = useVictoryZoomContainer({
22+
const { props, children } = useVictoryZoomContainer({
2323
...initialProps,
2424
clipContainerComponent: initialProps.clipContainerComponent ?? (
2525
<VictoryClipContainer />
2626
),
2727
});
28-
return <VictoryContainer {...props} />;
28+
29+
return <VictoryContainer {...props}>{children}</VictoryContainer>;
2930
};
3031

3132
VictoryZoomContainer.role = "container";

0 commit comments

Comments
 (0)