react-native icon indicating copy to clipboard operation
react-native copied to clipboard

useWindowDimensions() wrong height on Android Fullscreen Landscape

Open lgxm3z opened this issue 2 years ago • 9 comments

Android landscape, fullscreen without system's Status Bar or Navigation Bar.

Version

^0.65.2

Output of npx react-native info

System: OS: macOS 12.3.1 CPU: (8) arm64 Apple M1 Memory: 151.89 MB / 8.00 GB Shell: 5.8 - /bin/zsh Binaries: Node: 16.14.0 - /usr/local/bin/node Yarn: 1.22.17 - /usr/local/bin/yarn npm: 8.9.0 - /usr/local/bin/npm Watchman: 2022.03.21.00 - /opt/homebrew/bin/watchman Managers: CocoaPods: 1.11.3 - /opt/homebrew/bin/pod SDKs: iOS SDK: Platforms: DriverKit 21.4, iOS 15.4, macOS 12.3, tvOS 15.4, watchOS 8.5 Android SDK: API Levels: 28, 29, 30, 31, 32 Build Tools: 29.0.2, 30.0.2, 31.0.0, 32.0.0, 32.1.0, 33.0.0 System Images: android-32 | Google APIs ARM 64 v8a Android NDK: 23.1.7779620 IDEs: Android Studio: 2021.1 AI-211.7628.21.2111.8193401 Xcode: 13.3/13E113 - /usr/bin/xcodebuild Languages: Java: 11.0.14.1 - /usr/bin/javac npmPackages: @react-native-community/cli: Not Found react: 17.0.2 => 17.0.2 react-native: 0.65.2 => 0.65.2 react-native-macos: Not Found npmGlobalPackages: react-native: Not Found

Snack, code example, screenshot, or link to a repository

My MainActivity.java's onCreate:

@Override
 protected void onCreate(Bundle savedInstanceState) {
   setTheme(R.style.AppTheme);
   super.onCreate(null);

   if(Build.VERSION.SDK_INT < 19){ 
       View v = this.getWindow().getDecorView();
       v.setSystemUiVisibility(View.GONE);
   } else {
       View decorView = getWindow().getDecorView(); 
       decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
       | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
       | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
       | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION 
       | View.SYSTEM_UI_FLAG_FULLSCREEN
       | View.SYSTEM_UI_FLAG_IMMERSIVE);
   }
 }
// Scenario 01
// I noticed that the "red rectangle" had a kind of vertical margin,

const {width, height} = useWindowDimensions();
<View style={{position: 'absolute', backgroundColor: 'red', width: width, height: height}}/>

// Scenario 02 
// Solved it using the height as "100%"

<View style={{position: 'absolute', backgroundColor: 'red', width: '100%', height: '100%'}}/>
Screen Shot 2022-04-29 at 18 01 00 Screen Shot 2022-04-29 at 18 00 39

Originally posted by @runtothedoor in https://github.com/facebook/react-native/issues/29290#issuecomment-1113730907

lgxm3z avatar Apr 29 '22 21:04 lgxm3z

Setting both padding and margin to 0 didn't solve the issue

{
        width: width,
        height: height,
        margin: 0,
        padding: 0
}

lgxm3z avatar Apr 29 '22 21:04 lgxm3z

Hi @3GOMESz, could you update the issue with one of the template we provide? It will give us more information to help you with the issue (if it is still valid)

cipolleschi avatar May 18 '22 11:05 cipolleschi

Hi @3GOMESz, could you update the issue with one of the template we provide? It will give us more information to help you with the issue (if it is still valid)

Done

lgxm3z avatar May 18 '22 14:05 lgxm3z

This bug also exists in portrait mode on Android when using full screen mode for react native version 0.67.4. You can easily verify it by getting the height from useWindowDimensions and then getting the height of any view covering the entire screen using the onLayout callback. You'll see that the height of the view is larger than the height returned from useWindowDimensions.

@cipolleschi this seems like a critical bug with useWindowDimension. What do you suggest we do?

MetaBenji avatar Feb 15 '23 17:02 MetaBenji

I just see that the version is 0.65. We don't support that version anymore. Could you try and verify if the error persists in 0.69, 0.70 or 0.71 which are the versions we are committed to support at the moment?

Thank you so much.

cipolleschi avatar Mar 01 '23 12:03 cipolleschi

:warning: Unsupported Version of React Native
:information_source: It looks like your issue or the example you provided uses an unsupported version of React Native. Due to the number of issues we receive, we're currently only accepting new issues against one of the supported versions. Please upgrade to latest and verify if the issue persists (alternatively, create a new project and repro the issue in it). If you cannot upgrade, please open your issue on StackOverflow to get further community support.

github-actions[bot] avatar Mar 01 '23 13:03 github-actions[bot]

@cipolleschi the bug in portrait mode exists in the supported versions. I think if the app is in full screen mode on Android, window height should include the status bar and bottom navigation bar

MetaBenji avatar Mar 06 '23 14:03 MetaBenji

@cortinico any idea on this? can we onboard someone else with more experience in the runtime to have a look at this issue?

cipolleschi avatar Mar 08 '23 13:03 cipolleschi

@cortinico any idea on this? can we onboard someone else with more experience in the runtime to have a look at this issue?

@javache do you have any insights here?

cortinico avatar Mar 09 '23 13:03 cortinico

This issue is waiting for author's feedback since 24 days. Please provide the requested feedback or this will be closed in 7 days.

github-actions[bot] avatar Apr 02 '23 18:04 github-actions[bot]

This issue was closed because the author hasn't provided the requested feedback after 7 days.

github-actions[bot] avatar Apr 09 '23 18:04 github-actions[bot]

This issue is waiting for author's feedback since 24 days. Please provide the requested feedback or this will be closed in 7 days.

github-actions[bot] avatar May 05 '23 18:05 github-actions[bot]

This issue is waiting for author's feedback since 24 days. Please provide the requested feedback or this will be closed in 7 days.

github-actions[bot] avatar May 05 '23 18:05 github-actions[bot]

The issue still exists. I worked around this limitation for Android by using Dimensions.get('screen').height instead of Dimensions.get('window').height.

brandtnewlabs avatar Oct 08 '23 11:10 brandtnewlabs

Issue still happening. React-native v0.68.0

Workaround suggested by @brandtnewww works for me.

its-acarn avatar Oct 11 '23 13:10 its-acarn

Sorry @its-acarn, but React Native 0.68 is not supported anymore, as per our Support Window Policy. Please update to a supported version of React Native.

cipolleschi avatar Oct 11 '23 13:10 cipolleschi

Will do - thanks.

its-acarn avatar Oct 11 '23 13:10 its-acarn

I'm still seeing this issue as of November 3, 2023, with the following library versions: react-native: 0.72.6 expo: 49.0.0 expo-dev-client: 2.4.11

I have been using a view with flex: 1 and catching the dimensions of that in its onLayout event, then using that to set state as a workaround. I'm going to try @brandtnewww's suggestion, though, as it sounds like it might be more elegant.

TheRealMikeD avatar Nov 03 '23 17:11 TheRealMikeD

This issue applies to newer supported versions of react native too. Can we remove the "Unsupported Version" label?

joeporpeglia avatar Dec 07 '23 19:12 joeporpeglia

This issue applies to newer supported versions of react native too. Can we remove the "Unsupported Version" label?

As the original author is unresponsive, @joeporpeglia could you open a new issue + reproducer against 0.73?

cortinico avatar Dec 08 '23 13:12 cortinico

Yup, see https://github.com/facebook/react-native/issues/41918

joeporpeglia avatar Dec 12 '23 23:12 joeporpeglia

Great thank you, closing in favor of https://github.com/facebook/react-native/issues/41918

cortinico avatar Dec 13 '23 09:12 cortinico