Display your PWA / website fullscreen

Display your PWA / website fullscreen:

Standalone Mode

As soon as the user has added your PWA to the home screen and opened it, it runs in a standalone mode, where e.g. the navigation bar of the browser will disappear and we can produce more app-like designs.

We can detect if the PWA is running in standalone mode inside our application like this:

// on iOS Safari
window.navigator.standalone

// on Android Chrome
window.matchMedia(
  '(display-mode: standalone)'
).matches

Because of the platform difference, a more popular approach is to define a start_url inside your manifest.json file, where we can add a parameter that will be added, when the app is started in standalone mode. Then we can check for the parameter inside our application to make changes to our UI.

To display it fullscreen and remove native control elements, we also have to add the display property with the value standalone (fullscreen won’t work). Here’s our current manifest:

// manifest.json
{
"name": "Example App",
"display": "standalone",
"start_url": "/?standalone=true"
}

Meta Tags

To display your app fullscreen, we will also have to add a few meta tags.

You might already have a viewport meta tag, but make sure viewport-fit=cover is inside it (separated by ;):


Then we have to add the mobile-web-app-capable and status-bar-style meta tags:






Note that we can decide, whether the status bar should have a white (default), black or transparent (with white color) background. Take into account that this meta tag is only used when the app starts, so it’s app-wide and we can’t modify the meta tag later to change the color dynamically.

Because we also want to be able to display content underneath the status bar, we’ll use the transparent background (black-translucent). This will also shift our app up to the top of the screen.

Now we can produce fancy headers that look like this:

Safe Area

Since we can display content underneath the status bar now, we’ll have to make sure that the white text will always be readable (e.g. with a decorative shadow or ensuring dark background colors) and that there will be no interactive elements underneath. Also we might have to take the notch into account, which some newer iOS versions have:

To solve those problems we can utilize the safe-area CSS env variables (supported since iOS >= 11.1 and Chrome >= 69):

.element {
    height: env(safe-area-inset-top);
    width: env(safe-area-inset-left);
    margin: env(safe-area-inset-right);
    // you can also use fallback values
    padding: env(safe-area-inset-bottom, 20px);
}

As an example, I implemented a sticky navigation bar vue component for my app, which has an element with the top safe-area applied as height. It will be transparent as long as the transparent property is true and the user has not scrolled down. Here’s the crucial of the component:


0) }" >
...
.h-safe-area-inset-top { height: env(safe-area-inset-top); } .bg-black { background-color: #444; } export default { data() { return { scrollTop: 0 } }, props: { transparent: { type: Boolean, default: false } }, methods: { scrollListener(e) { this.scrollTop = e.target.scrollTop; } }, mounted() { window.addEventListener('scroll', this.scrollListener); } }

from Tumblr https://generouspiratequeen.tumblr.com/post/639741422928642048

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s