@@ -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 : MauiWindowInsetListener , IOnApplyWindowInsetsListener
88+ internal class WindowsListener : Java . Lang . Object , 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,68 +114,62 @@ 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 override WindowInsetsCompat OnApplyWindowInsets ( AView v , WindowInsetsCompat insets )
128+ public WindowInsetsCompat OnApplyWindowInsets ( AView v , WindowInsetsCompat insets )
129129 {
130130 if ( insets == null || v == null )
131131 return insets ;
132132
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 ) ;
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 ) ;
141139
142- int flyoutViewBottomInset = 0 ;
143-
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- }
154-
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- }
140+ int flyoutViewBottomInset = 0 ;
165141
166- if ( _bgImageRef != null && _bgImageRef . TryGetTarget ( out var bgImage ) && bgImage != null )
167- {
168- bgImage . SetPadding ( 0 , topInset , 0 , bottomInset ) ;
169- }
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+ }
170152
171- return WindowInsetsCompat . Consumed ;
153+ if ( appbarLayout . MeasuredHeight > 0 )
154+ {
155+ FlyoutView ? . SetPadding ( 0 , 0 , 0 , flyoutViewBottomInset ) ;
156+ appbarLayout ? . SetPadding ( 0 , topInset , 0 , 0 ) ;
172157 }
158+ else
159+ {
160+ FlyoutView ? . SetPadding ( 0 , topInset , 0 , flyoutViewBottomInset ) ;
161+ appbarLayout ? . SetPadding ( 0 , 0 , 0 , 0 ) ;
162+ }
173163
164+ if ( _bgImageRef != null && _bgImageRef . TryGetTarget ( out var bgImage ) && bgImage != null )
165+ {
166+ bgImage . SetPadding ( 0 , topInset , 0 , bottomInset ) ;
167+ }
174168
175- return base . OnApplyWindowInsets ( v , insets ) ;
169+ return WindowInsetsCompat . Consumed ;
176170 }
177171 }
178-
172+
179173 protected virtual void LoadView ( IShellContext shellContext )
180174 {
181175 var context = shellContext . AndroidContext ;
@@ -208,7 +202,7 @@ protected virtual void LoadView(IShellContext shellContext)
208202 } ;
209203
210204 _windowsListener = new WindowsListener ( _bgImage ) ;
211- MauiWindowInsetListener . SetupViewWithLocalListener ( coordinator , _windowsListener ) ;
205+ ViewCompat . SetOnApplyWindowInsetsListener ( coordinator , _windowsListener ) ;
212206
213207 UpdateFlyoutHeaderBehavior ( ) ;
214208 _shellContext . Shell . PropertyChanged += OnShellPropertyChanged ;
@@ -724,12 +718,6 @@ public void OnOffsetChanged(AppBarLayout appBarLayout, int verticalOffset)
724718
725719 internal void Disconnect ( )
726720 {
727-
728- if ( _rootView is CoordinatorLayout coordinator )
729- {
730- MauiWindowInsetListener . RemoveViewWithLocalListener ( coordinator ) ;
731- }
732-
733721 if ( _shellContext ? . Shell != null )
734722 _shellContext . Shell . PropertyChanged -= OnShellPropertyChanged ;
735723
@@ -738,12 +726,14 @@ internal void Disconnect()
738726
739727 _flyoutHeader = null ;
740728
741- _footerView ? . View = null ;
729+ if ( _footerView != null )
730+ _footerView . View = null ;
742731
743732 _headerView ? . Disconnect ( ) ;
744733 DisconnectRecyclerView ( ) ;
745734
746- _contentView ? . View = null ;
735+ if ( _contentView != null )
736+ _contentView . View = null ;
747737 }
748738
749739 protected override void Dispose ( bool disposing )
@@ -774,7 +764,8 @@ protected override void Dispose(bool disposing)
774764 if ( _headerView != null )
775765 _headerView . LayoutChange -= OnHeaderViewLayoutChange ;
776766
777- _contentView ? . View = null ;
767+ if ( _contentView != null )
768+ _contentView . View = null ;
778769
779770 _flyoutContentView ? . Dispose ( ) ;
780771 _headerView ? . Dispose ( ) ;
0 commit comments