Skip to content

Commit

Permalink
Add NotNullWhen to IsAlive() (#13214)
Browse files Browse the repository at this point in the history
  • Loading branch information
PureWeen authored Feb 9, 2023
1 parent 47802aa commit 820c37a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -257,13 +257,13 @@ protected override void OnDetachedFromWindow()

void UpdateRootView(AView? rootView)
{
if (_rootView.IsAlive() && _rootView != null)
if (_rootView.IsAlive())
{
_rootView.LayoutChange -= OnRootViewLayoutChanged;
_rootView = null;
}

if (rootView.IsAlive() && rootView != null)
if (rootView.IsAlive())
{
rootView.LayoutChange += OnRootViewLayoutChanged;
_rootView = rootView;
Expand Down
5 changes: 3 additions & 2 deletions src/Core/src/Platform/Android/JavaObjectExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Diagnostics.CodeAnalysis;

namespace Microsoft.Maui
{
Expand All @@ -14,15 +15,15 @@ public static bool IsDisposed(this global::Android.Runtime.IJavaObject obj)
return obj.Handle == IntPtr.Zero;
}

public static bool IsAlive(this Java.Lang.Object? obj)
public static bool IsAlive([NotNullWhen(true)] this Java.Lang.Object? obj)
{
if (obj == null)
return false;

return !obj.IsDisposed();
}

public static bool IsAlive(this global::Android.Runtime.IJavaObject? obj)
public static bool IsAlive([NotNullWhen(true)] this global::Android.Runtime.IJavaObject? obj)
{
if (obj == null)
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ protected virtual void OnDestinationChanged(NavController navController, NavDest
// If you try to access `ChildFragmentManager` and the `NavHost`
// isn't attached to a context then android will throw an IllegalStateException
if (_navHost.IsAlive() &&
_navHost?.Context != null &&
_navHost.Context is not null &&
_navHost.ChildFragmentManager.IsAlive())
{
return _navHost.ChildFragmentManager;
Expand Down

0 comments on commit 820c37a

Please sign in to comment.