11import type { ComponentInterface } from '@stencil/core' ;
2- import { Build , Component , Element , Host , Method , h } from '@stencil/core' ;
3- import type { FocusVisibleUtility } from '@utils/focus-visible' ;
4- import { shouldUseCloseWatcher } from '@utils/hardware-back-button' ;
5- import { printIonWarning } from '@utils/logging' ;
6- import { isPlatform } from '@utils/platform' ;
2+ import { Component , Element , Host , Method , h } from '@stencil/core' ;
3+ import { getOrInitFocusVisibleUtility } from '@utils/focus-visible' ;
74
85import { config } from '../../global/config' ;
96import { getIonTheme } from '../../global/ionic-global' ;
@@ -17,53 +14,8 @@ import { getIonTheme } from '../../global/ionic-global';
1714 styleUrl : 'app.scss' ,
1815} )
1916export class App implements ComponentInterface {
20- private focusVisible ?: FocusVisibleUtility ;
21-
2217 @Element ( ) el ! : HTMLElement ;
2318
24- componentDidLoad ( ) {
25- if ( Build . isBrowser ) {
26- rIC ( async ( ) => {
27- const isHybrid = isPlatform ( window , 'hybrid' ) ;
28- if ( ! config . getBoolean ( '_testing' ) ) {
29- import ( '../../utils/tap-click' ) . then ( ( module ) => module . startTapClick ( config ) ) ;
30- }
31- if ( config . getBoolean ( 'statusTap' , isHybrid ) ) {
32- import ( '../../utils/status-tap' ) . then ( ( module ) => module . startStatusTap ( ) ) ;
33- }
34- if ( config . getBoolean ( 'inputShims' , needInputShims ( ) ) ) {
35- /**
36- * needInputShims() ensures that only iOS and Android
37- * platforms proceed into this block.
38- */
39- const platform = isPlatform ( window , 'ios' ) ? 'ios' : 'android' ;
40- import ( '../../utils/input-shims/input-shims' ) . then ( ( module ) => module . startInputShims ( config , platform ) ) ;
41- }
42- const hardwareBackButtonModule = await import ( '../../utils/hardware-back-button' ) ;
43- const supportsHardwareBackButtonEvents = isHybrid || shouldUseCloseWatcher ( ) ;
44- if ( config . getBoolean ( 'hardwareBackButton' , supportsHardwareBackButtonEvents ) ) {
45- hardwareBackButtonModule . startHardwareBackButton ( ) ;
46- } else {
47- /**
48- * If an app sets hardwareBackButton: false and experimentalCloseWatcher: true
49- * then the close watcher will not be used.
50- */
51- if ( shouldUseCloseWatcher ( ) ) {
52- printIonWarning (
53- 'experimentalCloseWatcher was set to `true`, but hardwareBackButton was set to `false`. Both config options must be `true` for the Close Watcher API to be used.'
54- ) ;
55- }
56-
57- hardwareBackButtonModule . blockHardwareBackButton ( ) ;
58- }
59- if ( typeof ( window as any ) !== 'undefined' ) {
60- import ( '../../utils/keyboard/keyboard' ) . then ( ( module ) => module . startKeyboardAssist ( window ) ) ;
61- }
62- import ( '../../utils/focus-visible' ) . then ( ( module ) => ( this . focusVisible = module . startFocusVisible ( ) ) ) ;
63- } ) ;
64- }
65- }
66-
6719 /**
6820 * @internal
6921 * Used to set focus on an element that uses `ion-focusable`.
@@ -76,9 +28,8 @@ export class App implements ComponentInterface {
7628 */
7729 @Method ( )
7830 async setFocus ( elements : HTMLElement [ ] ) {
79- if ( this . focusVisible ) {
80- this . focusVisible . setFocus ( elements ) ;
81- }
31+ const focusVisible = getOrInitFocusVisibleUtility ( ) ;
32+ focusVisible . setFocus ( elements ) ;
8233 }
8334
8435 render ( ) {
@@ -94,33 +45,3 @@ export class App implements ComponentInterface {
9445 ) ;
9546 }
9647}
97-
98- const needInputShims = ( ) => {
99- /**
100- * iOS always needs input shims
101- */
102- const needsShimsIOS = isPlatform ( window , 'ios' ) && isPlatform ( window , 'mobile' ) ;
103- if ( needsShimsIOS ) {
104- return true ;
105- }
106-
107- /**
108- * Android only needs input shims when running
109- * in the browser and only if the browser is using the
110- * new Chrome 108+ resize behavior: https://developer.chrome.com/blog/viewport-resize-behavior/
111- */
112- const isAndroidMobileWeb = isPlatform ( window , 'android' ) && isPlatform ( window , 'mobileweb' ) ;
113- if ( isAndroidMobileWeb ) {
114- return true ;
115- }
116-
117- return false ;
118- } ;
119-
120- const rIC = ( callback : ( ) => void ) => {
121- if ( 'requestIdleCallback' in window ) {
122- ( window as any ) . requestIdleCallback ( callback ) ;
123- } else {
124- setTimeout ( callback , 32 ) ;
125- }
126- } ;
0 commit comments