@@ -21,7 +21,12 @@ import {fetchUtils} from './FetchUtils';
2121import { findSuitableIcon , generatePackageId , validateNotEmpty } from './util' ;
2222import Color = require( 'color' ) ;
2323import { ConsoleLog } from './Log' ;
24- import { ShareTarget , WebManifestIcon , WebManifestJson } from './types/WebManifest' ;
24+ import {
25+ ShareTarget ,
26+ WebManifestDisplayOverrideValue ,
27+ WebManifestIcon ,
28+ WebManifestJson ,
29+ } from './types/WebManifest' ;
2530import { processProtocolHandlers , ProtocolHandler } from './types/ProtocolHandler' ;
2631import { ShortcutInfo } from './ShortcutInfo' ;
2732import { AppsFlyerConfig } from './features/AppsFlyerFeature' ;
@@ -50,6 +55,20 @@ export function asDisplayMode(input: string): DisplayMode | null {
5055 return DISPLAY_MODE_VALUES . includes ( input ) ? input as DisplayMode : null ;
5156}
5257
58+ // Supported display overrides for TWA
59+ export type DisplayOverrideValue = WebManifestDisplayOverrideValue | 'fullscreen-sticky' ;
60+ export const DisplayOverrideValues : DisplayOverrideValue [ ] = [ 'standalone' , 'minimal-ui' ,
61+ 'fullscreen' , 'fullscreen-sticky' , 'browser' , 'window-controls-overlay' , 'tabbed' ] ;
62+
63+ export function resolveDisplayOverride (
64+ displayOverride : WebManifestDisplayOverrideValue [ ] | undefined ,
65+ ) : DisplayOverrideValue [ ] {
66+ if ( ! displayOverride ) return [ ] ;
67+
68+ return displayOverride . filter (
69+ ( displayOverrideValue ) => DisplayOverrideValues . includes ( displayOverrideValue ) ) ;
70+ }
71+
5372// Possible values for screen orientation, as defined in `android-browser-helper`:
5473// https://github.com/GoogleChrome/android-browser-helper/blob/alpha/androidbrowserhelper/src/main/java/com/google/androidbrowserhelper/trusted/LauncherActivityMetadata.java#L191-L216
5574const ORIENTATION_VALUES = [ 'default' , 'any' , 'natural' , 'landscape' , 'portrait' ,
@@ -139,6 +158,7 @@ export class TwaManifest {
139158 name : string ;
140159 launcherName : string ;
141160 display : DisplayMode ;
161+ displayOverride : DisplayOverrideValue [ ] ;
142162 themeColor : Color ;
143163 themeColorDark : Color ;
144164 navigationColor : Color ;
@@ -228,6 +248,7 @@ export class TwaManifest {
228248 this . protocolHandlers = data . protocolHandlers ;
229249 this . fileHandlers = data . fileHandlers ;
230250 this . launchHandlerClientMode = data . launchHandlerClientMode ;
251+ this . displayOverride = data . displayOverride || [ ] ;
231252 }
232253
233254 /**
@@ -340,6 +361,7 @@ export class TwaManifest {
340361 launcherName : webManifest [ 'short_name' ] ||
341362 webManifest [ 'name' ] ?. substring ( 0 , SHORT_NAME_MAX_SIZE ) || DEFAULT_APP_NAME ,
342363 display : asDisplayMode ( webManifest [ 'display' ] ! ) || DEFAULT_DISPLAY_MODE ,
364+ displayOverride : resolveDisplayOverride ( webManifest [ 'display_override' ] ) ,
343365 themeColor : webManifest [ 'theme_color' ] || DEFAULT_THEME_COLOR ,
344366 themeColorDark : DEFAULT_THEME_COLOR_DARK ,
345367 navigationColor : DEFAULT_NAVIGATION_COLOR ,
@@ -540,6 +562,8 @@ export class TwaManifest {
540562 webManifest [ 'name' ] ?. substring ( 0 , SHORT_NAME_MAX_SIZE ) ) ,
541563 display : this . getNewFieldValue ( 'display' , fieldsToIgnore , oldTwaManifest . display ,
542564 asDisplayMode ( webManifest [ 'display' ] ! ) ! ) ,
565+ displayOverride : this . getNewFieldValue ( 'displayOverride' , fieldsToIgnore ,
566+ oldTwaManifest . displayOverride , resolveDisplayOverride ( webManifest [ 'display_override' ] ) ) ,
543567 fullScopeUrl : this . getNewFieldValue ( 'fullScopeUrl' , fieldsToIgnore ,
544568 oldTwaManifest . fullScopeUrl ?. toString ( ) , fullScopeUrl . toString ( ) ) ,
545569 themeColor : this . getNewFieldValue ( 'themeColor' , fieldsToIgnore ,
@@ -571,6 +595,7 @@ export interface TwaManifestJson {
571595 name : string ;
572596 launcherName ?: string ; // Older Manifests may not have this field.
573597 display ?: string ; // Older Manifests may not have this field.
598+ displayOverride ?: DisplayOverrideValue [ ] ;
574599 themeColor : string ;
575600 themeColorDark ?: string ;
576601 navigationColor : string ;
0 commit comments