Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

useWindowDimensions() wrong height on Android Fullscreen Landscape #33735

Closed
gomes042 opened this issue Apr 29, 2022 · 22 comments
Closed

useWindowDimensions() wrong height on Android Fullscreen Landscape #33735

gomes042 opened this issue Apr 29, 2022 · 22 comments
Labels
Impact: Bug The issue represents a bug somewhere Platform: Android Android applications. Resolution: Duplicate Stale There has been a lack of activity on this issue and it may be closed soon. Tech: React Native Core Issue related to the Core of React Native Type: Unsupported Version Issues reported to a version of React Native that is no longer supported

Comments

@gomes042
Copy link

gomes042 commented Apr 29, 2022

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 #29290 (comment)

@gomes042
Copy link
Author

gomes042 commented Apr 29, 2022

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

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

@gomes042 gomes042 changed the title useWindowDimensions wrong height on Android Fullscreen Landscape useWindowDimensions() wrong height on Android Fullscreen Landscape May 2, 2022
@cipolleschi
Copy link
Contributor

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 cipolleschi added Needs: Author Feedback Platform: Android Android applications. Tech: React Native Core Issue related to the Core of React Native Impact: Bug The issue represents a bug somewhere labels May 18, 2022
@gomes042
Copy link
Author

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

@github-actions github-actions bot added Needs: Attention Issues where the author has responded to feedback. and removed Needs: Author Feedback labels May 18, 2022
@MetaBenji
Copy link

MetaBenji commented Feb 15, 2023

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?

@cipolleschi
Copy link
Contributor

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.

@cortinico cortinico added the Type: Unsupported Version Issues reported to a version of React Native that is no longer supported label Mar 1, 2023
@github-actions
Copy link

github-actions bot commented Mar 1, 2023

⚠️ Unsupported Version of React Native
ℹ️ 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.

@MetaBenji
Copy link

@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

@cipolleschi
Copy link
Contributor

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

@cortinico
Copy link
Contributor

@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?

@github-actions
Copy link

github-actions bot commented Apr 2, 2023

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 github-actions bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Apr 2, 2023
@github-actions
Copy link

github-actions bot commented Apr 9, 2023

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

@github-actions github-actions bot closed this as completed Apr 9, 2023
@cipolleschi cipolleschi reopened this Apr 11, 2023
@github-actions github-actions bot removed the Stale There has been a lack of activity on this issue and it may be closed soon. label Apr 11, 2023
@github-actions
Copy link

github-actions bot commented May 5, 2023

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

1 similar comment
@github-actions
Copy link

github-actions bot commented May 5, 2023

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 github-actions bot added Stale There has been a lack of activity on this issue and it may be closed soon. and removed Needs: Author Feedback labels May 5, 2023
@brandtnewlabs
Copy link

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

@its-acarn
Copy link

Issue still happening. React-native v0.68.0

Workaround suggested by @brandtnewww works for me.

@cipolleschi
Copy link
Contributor

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.

@its-acarn
Copy link

Will do - thanks.

@TheRealMikeD
Copy link

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.

@joeporpeglia
Copy link

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

@cortinico
Copy link
Contributor

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?

@joeporpeglia
Copy link

Yup, see #41918

@cortinico
Copy link
Contributor

Great thank you, closing in favor of #41918

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Impact: Bug The issue represents a bug somewhere Platform: Android Android applications. Resolution: Duplicate Stale There has been a lack of activity on this issue and it may be closed soon. Tech: React Native Core Issue related to the Core of React Native Type: Unsupported Version Issues reported to a version of React Native that is no longer supported
Projects
None yet
Development

No branches or pull requests

8 participants