Skip to content

Instantly share code, notes, and snippets.

@faceyspacey
Created January 29, 2018 01:10
Show Gist options
  • Save faceyspacey/d1e81027f3b08f988096721a588e60cc to your computer and use it in GitHub Desktop.
Save faceyspacey/d1e81027f3b08f988096721a588e60cc to your computer and use it in GitHub Desktop.
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