Last active
January 2, 2020 11:15
-
-
Save 3luyka/b6e80b8ccc6db98663ac349edaed6f1e to your computer and use it in GitHub Desktop.
RN Svg bug repro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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