question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

RCTUIManager.measure not working on Android

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:4
  • Comments:17 (6 by maintainers)

github_iconTop GitHub Comments

6reactions
hey99xxcommented, Mar 16, 2017

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

Views that are only used to layout their children or otherwise don’t draw anything may be automatically removed from the native hierarchy as an optimization. Set this property to false to disable this optimization and ensure that this View exists in the native view hierarchy.

However, some of UIManager functions such as measure expect to find a native view; and when it can’t it returns undefined 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.

2reactions
anshuul-kaicommented, Mar 16, 2017

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?

Read more comments on GitHub >

github_iconTop Results From Across the Web

UIManager.measure dose not work on Android #22443 - GitHub
It looks like you are using an older version of React Native. Please update to the latest release, v0.57 and verify if the...
Read more >
React Native android crash UIManager - Stack Overflow
I made an android app with Expo and React-Native and since I upgraded to // package.json "expo": "^20.0.0", "react": "16.0.0-alpha.12", ...
Read more >
A Keyboard Avoiding View for React Native in 2021
A repeating theme I've found in KeyboardAvoidingView issues is the presence of React Navigation in a React Native project - so if you...
Read more >
Prerequisites for Libraries - React Native
The following steps will help ensure your modules and components are ready for the New Architecture.
Read more >
react-native-svg - npm
Troubleshooting. Problems with Proguard. When Proguard is enabled (which it is by default for Android release builds), it causes runtime error.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found