@@ -85,7 +85,7 @@ void OnFlyoutStateChanging(object sender, AndroidX.DrawerLayout.Widget.DrawerLay
8585 // - Keep this minimal.
8686 // - Will be replaced by the planned comprehensive window insets solution.
8787 // - Do not extend; add new logic to the forthcoming implementation instead.
88- internal class WindowsListener : Java . Lang . Object , IOnApplyWindowInsetsListener
88+ internal class WindowsListener : MauiWindowInsetListener , IOnApplyWindowInsetsListener
8989 {
9090 private WeakReference < ImageView > _bgImageRef ;
9191 private WeakReference < AView > _flyoutViewRef ;
@@ -100,10 +100,10 @@ public AView FlyoutView
100100
101101 return null ;
102102 }
103- set
104- {
103+ set
104+ {
105105 _flyoutViewRef = new WeakReference < AView > ( value ) ;
106- }
106+ }
107107 }
108108 public AView FooterView
109109 {
@@ -114,62 +114,68 @@ public AView FooterView
114114
115115 return null ;
116116 }
117- set
118- {
117+ set
118+ {
119119 _footerViewRef = new WeakReference < AView > ( value ) ;
120- }
120+ }
121121 }
122122
123123 public WindowsListener ( ImageView bgImage )
124124 {
125125 _bgImageRef = new WeakReference < ImageView > ( bgImage ) ;
126126 }
127127
128- public WindowInsetsCompat OnApplyWindowInsets ( AView v , WindowInsetsCompat insets )
128+ public override WindowInsetsCompat OnApplyWindowInsets ( AView v , WindowInsetsCompat insets )
129129 {
130130 if ( insets == null || v == null )
131131 return insets ;
132132
133- // The flyout overlaps the status bar so we don't really care about insetting it
134- var systemBars = insets . GetInsets ( WindowInsetsCompat . Type . SystemBars ( ) ) ;
135- var displayCutout = insets . GetInsets ( WindowInsetsCompat . Type . DisplayCutout ( ) ) ;
136- var topInset = Math . Max ( systemBars ? . Top ?? 0 , displayCutout ? . Top ?? 0 ) ;
137- var bottomInset = Math . Max ( systemBars ? . Bottom ?? 0 , displayCutout ? . Bottom ?? 0 ) ;
138- var appbarLayout = v . FindDescendantView < AppBarLayout > ( ( v ) => true ) ;
133+ if ( v is CoordinatorLayout )
134+ {
135+ // The flyout overlaps the status bar so we don't really care about insetting it
136+ var systemBars = insets . GetInsets ( WindowInsetsCompat . Type . SystemBars ( ) ) ;
137+ var displayCutout = insets . GetInsets ( WindowInsetsCompat . Type . DisplayCutout ( ) ) ;
138+ var topInset = Math . Max ( systemBars ? . Top ?? 0 , displayCutout ? . Top ?? 0 ) ;
139+ var bottomInset = Math . Max ( systemBars ? . Bottom ?? 0 , displayCutout ? . Bottom ?? 0 ) ;
140+ var appbarLayout = v . FindDescendantView < AppBarLayout > ( ( v ) => true ) ;
139141
140- int flyoutViewBottomInset = 0 ;
142+ int flyoutViewBottomInset = 0 ;
141143
142- if ( FooterView is not null )
143- {
144- v . SetPadding ( 0 , 0 , 0 , bottomInset ) ;
145- flyoutViewBottomInset = 0 ;
146- }
147- else
148- {
149- flyoutViewBottomInset = bottomInset ;
150- v . SetPadding ( 0 , 0 , 0 , 0 ) ;
151- }
144+ if ( FooterView is not null )
145+ {
146+ v . SetPadding ( 0 , 0 , 0 , bottomInset ) ;
147+ flyoutViewBottomInset = 0 ;
148+ }
149+ else
150+ {
151+ flyoutViewBottomInset = bottomInset ;
152+ v . SetPadding ( 0 , 0 , 0 , 0 ) ;
153+ }
152154
153- if ( appbarLayout . MeasuredHeight > 0 )
154- {
155- FlyoutView ? . SetPadding ( 0 , 0 , 0 , flyoutViewBottomInset ) ;
156- appbarLayout ? . SetPadding ( 0 , topInset , 0 , 0 ) ;
157- }
158- else
159- {
160- FlyoutView ? . SetPadding ( 0 , topInset , 0 , flyoutViewBottomInset ) ;
161- appbarLayout ? . SetPadding ( 0 , 0 , 0 , 0 ) ;
162- }
155+ if ( appbarLayout . MeasuredHeight > 0 )
156+ {
157+ FlyoutView ? . SetPadding ( 0 , 0 , 0 , flyoutViewBottomInset ) ;
158+ appbarLayout ? . SetPadding ( 0 , topInset , 0 , 0 ) ;
159+ }
160+ else
161+ {
162+ FlyoutView ? . SetPadding ( 0 , topInset , 0 , flyoutViewBottomInset ) ;
163+ appbarLayout ? . SetPadding ( 0 , 0 , 0 , 0 ) ;
164+ }
163165
164- if ( _bgImageRef != null && _bgImageRef . TryGetTarget ( out var bgImage ) && bgImage != null )
165- {
166- bgImage . SetPadding ( 0 , topInset , 0 , bottomInset ) ;
166+ if ( _bgImageRef != null && _bgImageRef . TryGetTarget ( out var bgImage ) && bgImage != null )
167+ {
168+ bgImage . SetPadding ( 0 , topInset , 0 , bottomInset ) ;
169+ }
170+
171+ return WindowInsetsCompat . Consumed ;
167172 }
168173
169- return WindowInsetsCompat . Consumed ;
174+
175+ return base . OnApplyWindowInsets ( v , insets ) ;
170176 }
171177 }
172-
178+
173179 protected virtual void LoadView ( IShellContext shellContext )
174180 {
175181 var context = shellContext . AndroidContext ;
@@ -202,7 +208,7 @@ protected virtual void LoadView(IShellContext shellContext)
202208 } ;
203209
204210 _windowsListener = new WindowsListener ( _bgImage ) ;
205- ViewCompat . SetOnApplyWindowInsetsListener ( coordinator , _windowsListener ) ;
211+ MauiWindowInsetListener . SetupViewWithLocalListener ( coordinator , _windowsListener ) ;
206212
207213 UpdateFlyoutHeaderBehavior ( ) ;
208214 _shellContext . Shell . PropertyChanged += OnShellPropertyChanged ;
@@ -718,6 +724,12 @@ public void OnOffsetChanged(AppBarLayout appBarLayout, int verticalOffset)
718724
719725 internal void Disconnect ( )
720726 {
727+
728+ if ( _rootView is CoordinatorLayout coordinator )
729+ {
730+ MauiWindowInsetListener . RemoveViewWithLocalListener ( coordinator ) ;
731+ }
732+
721733 if ( _shellContext ? . Shell != null )
722734 _shellContext . Shell . PropertyChanged -= OnShellPropertyChanged ;
723735
@@ -726,14 +738,12 @@ internal void Disconnect()
726738
727739 _flyoutHeader = null ;
728740
729- if ( _footerView != null )
730- _footerView . View = null ;
741+ _footerView ? . View = null ;
731742
732743 _headerView ? . Disconnect ( ) ;
733744 DisconnectRecyclerView ( ) ;
734745
735- if ( _contentView != null )
736- _contentView . View = null ;
746+ _contentView ? . View = null ;
737747 }
738748
739749 protected override void Dispose ( bool disposing )
@@ -764,8 +774,7 @@ protected override void Dispose(bool disposing)
764774 if ( _headerView != null )
765775 _headerView . LayoutChange -= OnHeaderViewLayoutChange ;
766776
767- if ( _contentView != null )
768- _contentView . View = null ;
777+ _contentView ? . View = null ;
769778
770779 _flyoutContentView ? . Dispose ( ) ;
771780 _headerView ? . Dispose ( ) ;
0 commit comments