Created
January 29, 2018 01:10
-
-
Save faceyspacey/d1e81027f3b08f988096721a588e60cc to your computer and use it in GitHub Desktop.
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
class MyComponent extends React.Component { | |
render() { | |
// <View> will expand to the dimensions of DropZone within it | |
return <View ref={view => { this.myComponent = view; }}><DropZone /></View> | |
} | |
componentDidMount() { | |
this.myComponent.measure((x, f, width, height, px, py) => { | |
console.log('MyComponent width is: ' + width) | |
console.log('MyComponent height is: ' + height) | |
console.log('X offset to parent view: ' + x) | |
console.log('Y offset to parent view: ' + y) | |
console.log('X offset to page: ' + px) | |
console.log('Y offset to page: ' + py) | |
this.setState({ x, y }) | |
// or (depending on your exact needs): | |
this.setState({ x: px, y: py }) | |
}) | |
} | |
} | |
class MyComponent extends React.Component { | |
render() { | |
// <View> will expand to the dimensions of DropZone within it | |
return <View onLayout={this.measure}><DropZone /></View> | |
} | |
measure = ({ nativeEvent: { layout: { x, y, width, height } } }) => { | |
this.setState({ x, y}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment