3535import androidx .core .graphics .ColorUtils ;
3636import androidx .core .graphics .Insets ;
3737import androidx .core .view .ViewCompat ;
38+ import androidx .core .view .WindowCompat ;
3839import androidx .core .view .WindowInsetsCompat ;
40+ import androidx .core .view .WindowInsetsControllerCompat ;
3941import androidx .fragment .app .DialogFragment ;
4042
4143public class IterableInAppFragmentHTMLNotification extends DialogFragment implements IterableWebView .HTMLNotificationCallbacks {
@@ -125,10 +127,18 @@ public IterableInAppFragmentHTMLNotification() {
125127 public void onStart () {
126128 super .onStart ();
127129
128- // Set dialog positioning after the dialog is created and shown (only for non-fullscreen)
129130 Dialog dialog = getDialog ();
130- if (dialog != null && getInAppLayout (insetPadding ) != InAppLayout .FULLSCREEN ) {
131- applyWindowGravity (dialog .getWindow (), "onStart" );
131+ if (dialog != null ) {
132+ if (getInAppLayout (insetPadding ) == InAppLayout .FULLSCREEN ) {
133+ hideActivitySystemBars ();
134+
135+ Window dialogWindow = dialog .getWindow ();
136+ if (dialogWindow != null ) {
137+ WindowCompat .setDecorFitsSystemWindows (dialogWindow , false );
138+ }
139+ } else {
140+ applyWindowGravity (dialog .getWindow (), "onStart" );
141+ }
132142 }
133143 }
134144
@@ -176,9 +186,7 @@ public void onCancel(DialogInterface dialog) {
176186 applyWindowGravity (dialog .getWindow (), "onCreateDialog" );
177187 }
178188
179- if (getInAppLayout (insetPadding ) == InAppLayout .FULLSCREEN ) {
180- dialog .getWindow ().setFlags (WindowManager .LayoutParams .FLAG_FULLSCREEN , WindowManager .LayoutParams .FLAG_FULLSCREEN );
181- } else if (getInAppLayout (insetPadding ) != InAppLayout .TOP ) {
189+ if (getInAppLayout (insetPadding ) != InAppLayout .FULLSCREEN && getInAppLayout (insetPadding ) != InAppLayout .TOP ) {
182190 // For TOP layout in-app, status bar will be opaque so that the in-app content does not overlap with translucent status bar.
183191 // For other non-fullscreen in-apps layouts (BOTTOM and CENTER), status bar will be translucent
184192 dialog .getWindow ().setFlags (WindowManager .LayoutParams .FLAG_TRANSLUCENT_STATUS , WindowManager .LayoutParams .FLAG_TRANSLUCENT_STATUS );
@@ -191,10 +199,6 @@ public void onCancel(DialogInterface dialog) {
191199 public View onCreateView (@ NonNull LayoutInflater inflater , @ Nullable ViewGroup container , @ Nullable Bundle savedInstanceState ) {
192200 getDialog ().getWindow ().setBackgroundDrawable (new ColorDrawable (Color .TRANSPARENT ));
193201
194- if (getInAppLayout (insetPadding ) == InAppLayout .FULLSCREEN ) {
195- getDialog ().getWindow ().setFlags (WindowManager .LayoutParams .FLAG_FULLSCREEN , WindowManager .LayoutParams .FLAG_FULLSCREEN );
196- }
197-
198202 // Set initial window gravity based on inset padding (only for non-fullscreen)
199203 if (getInAppLayout (insetPadding ) != InAppLayout .FULLSCREEN ) {
200204 applyWindowGravity (getDialog ().getWindow (), "onCreateView" );
@@ -295,9 +299,13 @@ public void run() {
295299 @ Override
296300 public void onViewCreated (@ NonNull View view , @ Nullable Bundle savedInstanceState ) {
297301 super .onViewCreated (view , savedInstanceState );
298- // Handle edge-to-edge insets with modern approach (only for non-fullscreen)
299- // Full screen in-apps should not have padding from system bars
300- if (getInAppLayout (insetPadding ) != InAppLayout .FULLSCREEN ) {
302+
303+ if (getInAppLayout (insetPadding ) == InAppLayout .FULLSCREEN ) {
304+ ViewCompat .setOnApplyWindowInsetsListener (view , (v , insets ) -> {
305+ v .setPadding (0 , 0 , 0 , 0 );
306+ return WindowInsetsCompat .CONSUMED ;
307+ });
308+ } else {
301309 ViewCompat .setOnApplyWindowInsetsListener (view , (v , insets ) -> {
302310 Insets sysBars = insets .getInsets (WindowInsetsCompat .Type .systemBars ());
303311 v .setPadding (0 , sysBars .top , 0 , sysBars .bottom );
@@ -319,13 +327,25 @@ public void onSaveInstanceState(@NonNull Bundle outState) {
319327 outState .putBoolean (IN_APP_OPEN_TRACKED , true );
320328 }
321329
330+ @ Override
331+ public void onResume () {
332+ super .onResume ();
333+ if (getInAppLayout (insetPadding ) == InAppLayout .FULLSCREEN ) {
334+ hideActivitySystemBars ();
335+ }
336+ }
337+
322338 /**
323339 * On Stop of the dialog
324340 */
325341 @ Override
326342 public void onStop () {
327343 orientationListener .disable ();
328344
345+ if (getInAppLayout (insetPadding ) == InAppLayout .FULLSCREEN ) {
346+ restoreActivitySystemBars ();
347+ }
348+
329349 super .onStop ();
330350 }
331351
@@ -623,7 +643,6 @@ public void run() {
623643 if (insetPadding .bottom == 0 && insetPadding .top == 0 ) {
624644 //Handle full screen
625645 window .setLayout (webViewWidth , webViewHeight );
626- getDialog ().getWindow ().setFlags (WindowManager .LayoutParams .FLAG_FULLSCREEN , WindowManager .LayoutParams .FLAG_FULLSCREEN );
627646 } else {
628647 // Resize the WebView directly with explicit size
629648 float relativeHeight = height * getResources ().getDisplayMetrics ().density ;
@@ -747,6 +766,39 @@ InAppLayout getInAppLayout(Rect padding) {
747766 return InAppLayout .CENTER ;
748767 }
749768 }
769+
770+ private void hideActivitySystemBars () {
771+ Activity activity = getActivity ();
772+ if (activity == null || activity .getWindow () == null ) {
773+ return ;
774+ }
775+
776+ try {
777+ Window window = activity .getWindow ();
778+ WindowCompat .setDecorFitsSystemWindows (window , false );
779+ WindowInsetsControllerCompat controller = WindowCompat .getInsetsController (window , window .getDecorView ());
780+ controller .hide (WindowInsetsCompat .Type .systemBars ());
781+ controller .setSystemBarsBehavior (WindowInsetsControllerCompat .BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE );
782+ } catch (Exception e ) {
783+ IterableLogger .d (TAG , "Failed to hide system bars on activity: " + e .getMessage ());
784+ }
785+ }
786+
787+ private void restoreActivitySystemBars () {
788+ Activity activity = getActivity ();
789+ if (activity == null || activity .getWindow () == null ) {
790+ return ;
791+ }
792+
793+ try {
794+ Window window = activity .getWindow ();
795+ WindowInsetsControllerCompat controller = WindowCompat .getInsetsController (window , window .getDecorView ());
796+ controller .show (WindowInsetsCompat .Type .systemBars ());
797+ WindowCompat .setDecorFitsSystemWindows (window , true );
798+ } catch (Exception e ) {
799+ IterableLogger .d (TAG , "Failed to restore system bars on activity: " + e .getMessage ());
800+ }
801+ }
750802}
751803
752804enum InAppLayout {
0 commit comments