UIManager.measureInWindow on android not work as document
See original GitHub issueDescription
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:
- Created 3 years ago
- Comments:9 (3 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
collapsable: false
Thanks! Indeed,
measureInWindow
return values on Android after addingcollapsable={false}
as a prop on the measured view.See https://reactnative.dev/docs/view#collapsable-android