Skip to content

Instantly share code, notes, and snippets.

@3luyka
Last active January 2, 2020 11:15
Show Gist options
  • Save 3luyka/b6e80b8ccc6db98663ac349edaed6f1e to your computer and use it in GitHub Desktop.
Save 3luyka/b6e80b8ccc6db98663ac349edaed6f1e to your computer and use it in GitHub Desktop.
RN Svg bug repro
import React, { memo, useRef, useCallback } from 'react';
import {
findNodeHandle,
UIManager,
LayoutRectangle,
StyleSheet,
} from 'react-native';
import { Svg, Circle } from 'react-native-svg';
const measureInWindow = (handler: number): Promise<LayoutRectangle> =>
new Promise(resolve => {
UIManager.measureInWindow(handler, (x, y, width, height) => {
resolve({ x, y, width, height });
});
});
const Repro = () => {
const circle = useRef(null);
const handleLayout = useCallback(async () => {
const handler = findNodeHandle(circle.current);
if (handler === null) {
return;
}
const result = await measureInWindow(handler);
console.warn(result);
}, []);
return (
<Svg style={styles.container}>
<Circle ref={circle} x={50} y={70} r={65} onLayout={handleLayout} />
</Svg>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
},
});
export default memo(Repro);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment