Skip to content

Instantly share code, notes, and snippets.

@meyt
Last active April 3, 2020 15:36
Show Gist options
  • Select an option

  • Save meyt/f31026c2f2894ba0e109de1550e720b6 to your computer and use it in GitHub Desktop.

Select an option

Save meyt/f31026c2f2894ba0e109de1550e720b6 to your computer and use it in GitHub Desktop.
Enable fullscreen view on android
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.
*/
@meyt

meyt commented Apr 3, 2020

Copy link
Copy Markdown
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