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.

UIManager.measureInWindow on android not work as document

See original GitHub issue

Description

UIManager.measureInWindow on android not work as document. in ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerModule.java

/**
   * Determines the location on screen, width, and height of the given view relative to the device
   * screen and returns the values via an async callback. This is the absolute position including
   * things like the status bar
   */
  @ReactMethod
  public void measureInWindow(int reactTag, Callback callback) {
    mUIImplementation.measureInWindow(reactTag, callback);
  }

it saids that

This is the absolute position including things like the status bar

.But in _ReactAndroid/src/main/java/com/facebook/react/uimanager/NativeViewHierarchyManager.java React Native version 0.60.5,it removes the status bar from the height

public synchronized void measureInWindow(int tag, int[] outputBuffer) {
    UiThreadUtil.assertOnUiThread();
    View v = mTagsToViews.get(tag);
    if (v == null) {
      throw new NoSuchNativeViewException("No native view for " + tag + " currently exists");
    }

    v.getLocationOnScreen(outputBuffer);

    // We need to remove the status bar from the height.  getLocationOnScreen will include the
    // status bar.
    Resources resources = v.getContext().getResources();
    int statusBarId = resources.getIdentifier("status_bar_height", "dimen", "android");
    if (statusBarId > 0) {
      int height = (int) resources.getDimension(statusBarId);
      outputBuffer[1] -= height;
    }

    // outputBuffer[0,1] already contain what we want
    outputBuffer[2] = v.getWidth();
    outputBuffer[3] = v.getHeight();
  }

and in lateset version ,it subtract visibleWindowCoords(the master version)

public synchronized void measureInWindow(int tag, int[] outputBuffer) {
    UiThreadUtil.assertOnUiThread();
    View v = mTagsToViews.get(tag);
    if (v == null) {
      throw new NoSuchNativeViewException("No native view for " + tag + " currently exists");
    }

    v.getLocationOnScreen(outputBuffer);

    // we need to subtract visibleWindowCoords - to subtract possible window insets, split screen or
    // multi window
    Rect visibleWindowFrame = new Rect();
    v.getWindowVisibleDisplayFrame(visibleWindowFrame);
    outputBuffer[0] = outputBuffer[0] - visibleWindowFrame.left;
    outputBuffer[1] = outputBuffer[1] - visibleWindowFrame.top;

    // outputBuffer[0,1] already contain what we want
    outputBuffer[2] = v.getWidth();
    outputBuffer[3] = v.getHeight();
  }

React Native version:

React Native version 0.60.5

Steps To Reproduce

Expected Results

absolute position including things like the status bar

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
cosmoyoungcommented, Feb 21, 2022

collapsable: false

1reaction
QuentinGprdcommented, Mar 2, 2022

collapsable: false

Thanks! Indeed, measureInWindow return values on Android after adding collapsable={false} as a prop on the measured view.

See https://reactnative.dev/docs/view#collapsable-android

Read more comments on GitHub >

github_iconTop Results From Across the Web

React native UIManager.measureInWindow coords to android ...
What i need to do, is to get the coordinates of a view in react native to be able to use the same...
Read more >
Direct Manipulation - React Native
measureInWindow (callback)​​​ Determines the location of the given view in the window and returns the values via an async callback. If the React ......
Read more >
Best practices for conditional rendering in react-native-React ...
signInWithPhoneNumber() not working for react-native · what is this syntax in javascript of '=>' ... measureInWindow coords to android MotionEvent coords ...
Read more >
react-native UIManager JavaScript Examples
This page shows JavaScript code examples of react-native UIManager. ... you don't like, and go to the original project or source file by...
Read more >
types/react-native/index.d.ts - UNPKG
Not part of react-natives documentation, but present in examples and ... this to work on **Android** you need to set the following flags...
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