Skip to content

Instantly share code, notes, and snippets.

@phuochau
Last active May 16, 2023 15:09
Show Gist options
  • Save phuochau/af26c22b2b69bf1f7a3a389912d8dbd3 to your computer and use it in GitHub Desktop.
Save phuochau/af26c22b2b69bf1f7a3a389912d8dbd3 to your computer and use it in GitHub Desktop.
Best way to measure layout of view in React Native (works in both iOS & Android)
import {
findNodeHandle
} from 'react-native'
this.childItem.measureLayout(findNodeHandle(this.containerWrapper), (x, y, width, height) => {
console.log('got measurement', x, y, width, height)
})
// example render
<container-wrapper ref={ref => this.containerWrapper = ref}>
<item ref={ref => this.childItem = ref } />
</container-wrapper>
@sxidsvit
Copy link

Thanks,
didn't know about this possibility.
It really very useful

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment