Last active
April 3, 2020 15:36
-
-
Save meyt/f31026c2f2894ba0e109de1550e720b6 to your computer and use it in GitHub Desktop.
Enable fullscreen view on android
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import * as app from 'tns-core-modules/application' | |
| import { device } from 'tns-core-modules/platform' | |
| export function hideSystemUi () { | |
| if (!app.android || parseInt(device.sdkVersion) < 21) { return } | |
| const androidViewPkg = android.view // eslint-disable-line no-undef | |
| const View = androidViewPkg.View | |
| const window = app.android.startActivity.getWindow() | |
| const decorView = window.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 | |
| // View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | |
| ) | |
| } | |
| export function showSystemUi () { | |
| if (!app.android || parseInt(device.sdkVersion) < 21) { return } | |
| const androidViewPkg = android.view // eslint-disable-line no-undef | |
| const View = androidViewPkg.View | |
| const window = app.android.startActivity.getWindow() | |
| const decorView = window.getDecorView() | |
| decorView.setSystemUiVisibility( | |
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE | | |
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | | |
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | |
| ) | |
| } | |
| app.android.on(app.AndroidApplication.activityCreatedEvent, hideSystemUi) | |
| app.android.on(app.AndroidApplication.activityResumedEvent, hideSystemUi) | |
| /** | |
| * When keyboard shown up for textfield, application will exit from fullscreen, to prevent this: | |
| * Add '<item name="android:windowFullscreen">true</item>' to | |
| * `/app/App_Resources/Android/src/main/res/values/styles.xml` inside `<style name="AppThemeBase">` tag. | |
| */ | |
Author
Author
Alternative:
// hide
window.addFlags(androidViewPkg.WindowManager.LayoutParams.FLAG_FULLSCREEN)
window.clearFlags(androidViewPkg.WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN)
// show
window.addFlags(androidViewPkg.WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN)
window.clearFlags(androidViewPkg.WindowManager.LayoutParams.FLAG_FULLSCREEN)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Related links:
https://developer.android.com/training/system-ui/immersive.html
https://docs.nativescript.org/core-concepts/application-lifecycle#android-activity-events
https://stackoverflow.com/questions/41611952/statusbar-shows-when-keyboard-shows-up