Skip to content

Commit a8fb956

Browse files
committed
more leak fix
1 parent f0a7b22 commit a8fb956

15 files changed

Lines changed: 140 additions & 64 deletions

File tree

src/library/DIPS.Mobile.UI/API/Camera/Gallery/BottomSheet/GalleryBottomSheet.cs

Lines changed: 37 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -144,18 +144,7 @@ private void GoToEditState()
144144

145145
m_currentlyRotatedImageDisplayed.TranslationY -= m_topToolbar.HeightRequest;
146146

147-
m_currentlyRotatedImageDisplayed.SizeChanged += delegate
148-
{
149-
if (m_startingImageWidth is not null)
150-
return;
151-
152-
m_startingImageWidth = m_currentlyRotatedImageDisplayed.Width;
153-
m_startingImageHeight = m_currentlyRotatedImageDisplayed.Height;
154-
155-
m_carouselView.Opacity = 0;
156-
m_navigatePreviousImageButton.IsVisible = false;
157-
m_navigateNextImageButton.IsVisible = false;
158-
};
147+
m_currentlyRotatedImageDisplayed.SizeChanged += OnRotatedImageSizeChanged;
159148

160149
m_rotatingImageTcs = null;
161150

@@ -169,11 +158,25 @@ private void GoToDefaultState()
169158

170159
m_positionBeforeEdit = m_carouselView!.Position;
171160

161+
m_currentlyRotatedImageDisplayed.SizeChanged -= OnRotatedImageSizeChanged;
172162
m_grid.Remove(m_currentlyRotatedImageDisplayed);
173163
UpdateNavigationButtonsVisibility(m_carouselView.Position);
174164
OnImagesChanged();
175165
}
176166

167+
private void OnRotatedImageSizeChanged(object? sender, EventArgs e)
168+
{
169+
if (m_startingImageWidth is not null)
170+
return;
171+
172+
m_startingImageWidth = m_currentlyRotatedImageDisplayed.Width;
173+
m_startingImageHeight = m_currentlyRotatedImageDisplayed.Height;
174+
175+
m_carouselView!.Opacity = 0;
176+
m_navigatePreviousImageButton.IsVisible = false;
177+
m_navigateNextImageButton.IsVisible = false;
178+
}
179+
177180
async void IGalleryDefaultStateObserver.RemoveImage()
178181
{
179182
if(Images.Count == 0)
@@ -276,6 +279,7 @@ private void OnImagesChanged()
276279

277280
if (m_carouselView is not null)
278281
{
282+
m_carouselView.SizeChanged -= OnCarouselViewSizeChanged;
279283
m_carouselView.PositionChanged -= CarouselViewOnPositionChanged;
280284
try
281285
{
@@ -310,30 +314,32 @@ private void OnImagesChanged()
310314
};
311315
m_carouselViewWrapperView.Content = m_carouselView;
312316

313-
m_carouselView.SizeChanged += delegate
314-
{
315-
if (m_hasSetToolbarHeights)
316-
{
317-
return;
318-
}
319-
320-
var actualImageHeight = m_carouselView.Width / CameraPreview.ThreeFourRatio;
321-
var letterBoxHeight = m_carouselView.Height - actualImageHeight;
322-
323-
m_topToolbar.HeightRequest = letterBoxHeight * CameraPreview.TopToolbarPercentHeightOfLetterBox;
324-
m_bottomToolbar.HeightRequest = letterBoxHeight * CameraPreview.BottomToolbarPercentHeightOfLetterBox;
325-
326-
m_carouselViewWrapperView.TranslationY -= m_topToolbar.HeightRequest;
327-
m_navigatePreviousImageButton.TranslationY -= m_topToolbar.HeightRequest;
328-
m_navigateNextImageButton.TranslationY -= m_topToolbar.HeightRequest;
329-
330-
m_hasSetToolbarHeights = true;
331-
};
317+
m_carouselView.SizeChanged += OnCarouselViewSizeChanged;
332318

333319
m_carouselView.PositionChanged += CarouselViewOnPositionChanged;
334320
m_grid.Insert(0, m_carouselViewWrapperView);
335321
}
336322

323+
private void OnCarouselViewSizeChanged(object? sender, EventArgs e)
324+
{
325+
if (m_hasSetToolbarHeights)
326+
{
327+
return;
328+
}
329+
330+
var actualImageHeight = m_carouselView!.Width / CameraPreview.ThreeFourRatio;
331+
var letterBoxHeight = m_carouselView.Height - actualImageHeight;
332+
333+
m_topToolbar.HeightRequest = letterBoxHeight * CameraPreview.TopToolbarPercentHeightOfLetterBox;
334+
m_bottomToolbar.HeightRequest = letterBoxHeight * CameraPreview.BottomToolbarPercentHeightOfLetterBox;
335+
336+
m_carouselViewWrapperView.TranslationY -= m_topToolbar.HeightRequest;
337+
m_navigatePreviousImageButton.TranslationY -= m_topToolbar.HeightRequest;
338+
m_navigateNextImageButton.TranslationY -= m_topToolbar.HeightRequest;
339+
340+
m_hasSetToolbarHeights = true;
341+
}
342+
337343
private void OnStartingIndexChanged()
338344
{
339345
if(m_carouselView is not null)

src/library/DIPS.Mobile.UI/Components/Alerting/SystemMessage/SystemMessage.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,5 +125,6 @@ public void Dispose()
125125
{
126126
m_timer.Stop();
127127
m_timer.Elapsed -= OnTimerEnded;
128+
m_timer.Dispose();
128129
}
129130
}

src/library/DIPS.Mobile.UI/Components/BottomSheets/Android/BottomSheetHandler.cs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,20 @@ public partial class BottomSheetHandler : ContentViewHandler
3939
private BottomSheetHeader m_bottomSheetHeader;
4040
private List<WeakReference<SearchBar>> m_weakSearchBars = [];
4141
private WeakReference<AView>? m_weakCurrentFocusedSearchBar;
42+
private BottomSheetCallback? m_bottomSheetCallback;
43+
private KeyListener? m_keyListener;
4244

4345
public AView OnBeforeOpening(IMauiContext mauiContext, Context context, AView bottomSheetAndroidView,
4446
RelativeLayout rootLayout, LinearLayout bottomSheetLayout)
4547
{
4648
if (VirtualView is not BottomSheet bottomSheet) return new AView(Context);
4749

4850
m_bottomSheet = bottomSheet;
49-
bottomSheet.BottomSheetDialog.Behavior.AddBottomSheetCallback(
50-
new BottomSheetCallback(this));
51+
m_bottomSheetCallback = new BottomSheetCallback(this);
52+
m_keyListener = new KeyListener(this);
53+
bottomSheet.BottomSheetDialog.Behavior.AddBottomSheetCallback(m_bottomSheetCallback);
5154
bottomSheet.BottomSheetDialog.SetOnShowListener(new DialogInterfaceOnShowListener(this));
52-
bottomSheet.BottomSheetDialog.SetOnKeyListener(new KeyListener(this));
55+
bottomSheet.BottomSheetDialog.SetOnKeyListener(m_keyListener);
5356

5457
//Add a handle, with a innerGrid that works as a big hit box for the user to hit
5558
//Inspired by com.google.android.material.bottomsheet.BottomSheetDragHandleView , which will be added in Xamarin Android Material Design v1.7.0. https://github.com/material-components/material-components-android/commit/ac7b761294808748df167b50b223b591ca9dac06
@@ -234,6 +237,16 @@ protected override void DisconnectHandler(ContentViewGroup platformView)
234237
{
235238
base.DisconnectHandler(platformView);
236239

240+
if (m_bottomSheetCallback is not null)
241+
{
242+
m_bottomSheet.BottomSheetDialog.Behavior.RemoveBottomSheetCallback(m_bottomSheetCallback);
243+
m_bottomSheetCallback = null;
244+
}
245+
246+
m_bottomSheet.BottomSheetDialog.SetOnShowListener(null);
247+
m_bottomSheet.BottomSheetDialog.SetOnKeyListener(null);
248+
m_keyListener = null;
249+
237250
s_mEmptyNonFitToContentView?.RemoveFromParent();
238251
m_bottomSheetHeader.DisconnectHandlers();
239252

src/library/DIPS.Mobile.UI/Components/Loading/Skeleton/SkeletonView.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,16 @@ private BoxView CreateBox(SkeletonShape shape)
134134
return box;
135135
}
136136

137+
protected override void OnHandlerChanging(HandlerChangingEventArgs args)
138+
{
139+
base.OnHandlerChanging(args);
140+
141+
if (args.NewHandler is not null)
142+
return;
143+
144+
StopAnimation();
145+
}
146+
137147
private void StartAnimation()
138148
{
139149
StopAnimation();

src/library/DIPS.Mobile.UI/Components/Loading/StateView/StateView.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,20 @@ private async Task FadeIn(IView? view)
120120
}
121121
}
122122

123+
private StateViewModel? m_previousStateViewModel;
124+
123125
private void OnStateViewModelChanged()
124126
{
125127
if(StateViewModel is null)
126128
return;
127129

130+
if (m_previousStateViewModel is not null)
131+
{
132+
m_previousStateViewModel.OnStateChanged -= OnStateChanged;
133+
}
134+
135+
m_previousStateViewModel = StateViewModel;
136+
128137
ErrorView ??= new ErrorView { BindingContext = StateViewModel.Error };
129138
LoadingView ??= new LoadingView { BindingContext = StateViewModel.Loading };
130139
EmptyView ??= new EmptyView { BindingContext = StateViewModel.Empty };

src/library/DIPS.Mobile.UI/Components/Navigation/FloatingNavigationButton/Android/FloatingNavigationButtonHandler.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,24 @@ private static partial void MapIsClickable(FloatingNavigationButtonHandler handl
1111
if (handler.PlatformView is not global::Android.Views.View aView) return;
1212
if (handler.VirtualView is not FloatingNavigationButton fab) return;
1313

14+
aView.Click -= handler.OnNativeViewClick;
15+
1416
if (floatingNavigationButton.IsClickable)
1517
{
1618
aView.Clickable = true;
17-
aView.Click += (_, _) =>
18-
{
19-
_ = fab.Close();
20-
};
19+
aView.Click += handler.OnNativeViewClick;
2120
}
2221
else
2322
{
2423
aView.Clickable = false;
2524
}
2625
}
26+
27+
private void OnNativeViewClick(object? sender, EventArgs e)
28+
{
29+
if (VirtualView is FloatingNavigationButton fab)
30+
{
31+
_ = fab.Close();
32+
}
33+
}
2734
}

src/library/DIPS.Mobile.UI/Components/Navigation/FloatingNavigationButton/FloatingNavigationButtonService.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ public static void Close()
150150
public static void Remove()
151151
{
152152
PlatformRemove();
153+
FloatingNavigationButton = null;
153154
}
154155

155156
private static partial void PlatformRemove();

src/library/DIPS.Mobile.UI/Components/Pickers/DatePickerShared/iOS/BaseDatePickerHandler.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ protected override void DisconnectHandler(UIDatePicker platformView)
6363
{
6464
base.DisconnectHandler(platformView);
6565

66+
platformView.ValueChanged -= OnValueChanged;
6667
platformView.EditingDidBegin -= OnOpen;
6768
platformView.EditingDidEnd -= OnClose;
6869

src/library/DIPS.Mobile.UI/Components/Pickers/ItemPicker/ItemPicker.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,11 @@ private static void ItemsSourceChanged(BindableObject bindable, object oldValue,
154154
picker.AddContextMenuItems();
155155
}
156156

157+
if (oldValue is INotifyCollectionChanged oldNotifyCollectionChanged)
158+
{
159+
oldNotifyCollectionChanged.CollectionChanged -= picker.OnCollectionChanged;
160+
}
161+
157162
if (newValue is INotifyCollectionChanged notifyCollectionChanged)
158163
{
159164
notifyCollectionChanged.CollectionChanged += picker.OnCollectionChanged;

src/library/DIPS.Mobile.UI/Components/Pickers/NullableDatePickerShared/BaseNullableDatePicker.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ protected override void OnHandlerChanging(HandlerChangingEventArgs args)
2727
base.OnHandlerChanging(args);
2828

2929
if(args.NewHandler is null)
30+
{
31+
DateEnabledSwitch.Toggled -= OnSwitchToggled;
3032
return;
33+
}
3134

3235
m_dateOrTimePicker = CreateDateOrTimePicker();
3336
m_dateOrTimePicker.IsVisible = false;

0 commit comments

Comments
 (0)