react-native: RCTUIManager.measure not working on Android
Description
RCTUIManager.measure
is not working on Android
. Trying this.refs.myRef.measure()
doesn’t give any results either.
Reproduction
import { findNodeHandle } from 'react-native';
const RCTUIManager = require('NativeModules').UIManager;
RCTUIManager.measure(findNodeHandle(this.refs.myRef), (x, y, width, height, pageX, pageY) => {
// Returns valid values on iOS but undefined on Android
});
Additional Information
- React Native version: 0.42.0
- Platform: Android
- Operating System: MacOS
- Dev tools: Android Studio 2.3
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 4
- Comments: 17 (6 by maintainers)
So
style={{opacity: 1}}
is what I used until I understood the issue.Collapsable property is explained in https://facebook.github.io/react-native/docs/view.html#collapsable
However, some of UIManager functions such as
measure
expect to find a native view; and when it can’t it returnsundefined
values instead of throwing an error. Really it would be better to throw an error. React unfortunately is not intelligent to know you would be measuring the view in the first place.Putting an explicit style is one way to disable the optimization; because now the view has to be created with special drawing properties. But the real fix is putting
collapsable={false}
on the view you will be measuring to disable the optimization by the documentation.Adding
style={{opacity: 1}}
did the trick. Thanks a lot!Referring to your comment in #9382, what exactly do you mean by collapsable property?
Now I always force it to be created with collapsable property.
Although an annoyance, should I just follow your lead and close out this issue?
Also, unless you have infinite scrolling and/or very long lists with lots of images (basically heavy-weight rendering needs) I wouldn’t worry too much about clipping views.
@itinance That’s a shame. I was not aware it wouldn’t get further bug fixes. You can look at if the new alternative
FlatList
has a way to do the same thing, possible throughonViewableItemsChanged
. I never usedFlatList
so I wouldn’t be able to help you there. Good luck!