* Android - Fix old root page dispose when main page change.
* Revert dead code cleanup.
* Use direct cast for IApplicationController
Co-Authored-By: kvpt <kevin.petit@outlook.com>
* Use direct cast for IApplicationController (bis).
* Unsubscribe the event handler on the right application object.
* Prevent disruptive layout request from toolbar + Revert renderer clearing modification.
* If the page change, do nothing (dont dispose).
* Unsubscribe activity from application on destroy.
* Paused activity must not react to application changes
* Use nameof.
using AColor = Android.Graphics.Color;
using ARelativeLayout = Android.Widget.RelativeLayout;
using Xamarin.Forms.Internals;
-using System.Threading.Tasks;
#endregion
protected void LoadApplication(Application application)
{
- if(!_activityCreated)
+ if (!_activityCreated)
{
- throw new InvalidOperationException("Activity OnCreate was not called prior to loading the application. Did you forget a base.OnCreate call?");
+ throw new InvalidOperationException("Activity OnCreate was not called prior to loading the application. Did you forget a base.OnCreate call?");
}
-
+
if (!_renderersAdded)
{
RegisterHandlerForDefaultRenderer(typeof(NavigationPage), typeof(NavigationPageRenderer), typeof(NavigationRenderer));
_renderersAdded = true;
}
+ if (_application != null)
+ _application.PropertyChanged -= AppOnPropertyChanged;
+
_application = application ?? throw new ArgumentNullException(nameof(application));
- (application as IApplicationController)?.SetAppIndexingProvider(new AndroidAppIndexProvider(this));
+ ((IApplicationController)application).SetAppIndexingProvider(new AndroidAppIndexProvider(this));
Xamarin.Forms.Application.SetCurrentApplication(application);
if (Xamarin.Forms.Application.Current.OnThisPlatform().GetWindowSoftInputModeAdjust() != WindowSoftInputModeAdjust.Unspecified)
application.PropertyChanged += AppOnPropertyChanged;
- if (application?.MainPage != null)
- {
- var iver = Android.Platform.GetRenderer(application.MainPage);
- if (iver != null)
- {
- iver.Dispose();
- application.MainPage.ClearValue(Android.Platform.RendererProperty);
- }
- }
-
SetMainPage();
}
if (Forms.IsLollipopOrNewer)
{
- // Listen for the device going into power save mode so we can handle animations being disabled
+ // Listen for the device going into power save mode so we can handle animations being disabled
_powerSaveModeBroadcastReceiver = new PowerSaveModeBroadcastReceiver();
}
}
protected override void OnDestroy()
{
+ if (_application != null)
+ _application.PropertyChanged -= AppOnPropertyChanged;
+
PopupManager.Unsubscribe(this);
+
Platform?.Dispose();
// call at the end to avoid race conditions with Platform dispose
void AppOnPropertyChanged(object sender, PropertyChangedEventArgs args)
{
- if (args.PropertyName == "MainPage")
+ // Activity in pause must not react to application changes
+ if (_currentState >= AndroidApplicationLifecycleState.OnPause)
+ {
+ return;
+ }
+
+ if (args.PropertyName == nameof(_application.MainPage))
InternalSetPage(_application.MainPage);
if (args.PropertyName == PlatformConfiguration.AndroidSpecific.Application.WindowSoftInputModeAdjustProperty.PropertyName)
SetSoftInputMode();
PopupManager.ResetBusyCount(this);
Platform = new AppCompat.Platform(this);
-
+
Platform.SetPage(page);
_layout.AddView(Platform);
_layout.BringToFront();
using Xamarin.Forms.Internals;
using ActionBarDrawerToggle = Android.Support.V7.App.ActionBarDrawerToggle;
using AView = Android.Views.View;
-using AColor = Android.Graphics.Color;
using AToolbar = Android.Support.V7.Widget.Toolbar;
using Fragment = Android.Support.V4.App.Fragment;
using FragmentManager = Android.Support.V4.App.FragmentManager;
{
if (_toolbarVisible == value)
return;
+
_toolbarVisible = value;
- RequestLayout();
+
+ if (!IsLayoutRequested)
+ RequestLayout();
}
}
using Android.OS;
using Android.Views;
using Android.Views.Animations;
-using ARelativeLayout = Android.Widget.RelativeLayout;
using AView = Android.Views.View;
using Xamarin.Forms.Internals;
internal void SetPage(Page newRoot)
{
+ if (Page == newRoot)
+ {
+ return;
+ }
+
if (Page != null)
{
foreach (var rootPage in _navModel.Roots)
pageRenderer.View.ImportantForAccessibility = importantForAccessibility;
if (forceFocus)
pageRenderer.View.SendAccessibilityEvent(global::Android.Views.Accessibility.EventTypes.ViewFocused);
-
+
}
void SetPageInternal(Page newRoot)
using System;
-using System.Collections.Concurrent;
using System.ComponentModel;
-using System.Linq;
using Android.App;
using Android.Content;
using Android.Content.Res;
using Android.Views;
using Android.Widget;
using Xamarin.Forms.PlatformConfiguration.AndroidSpecific;
-using Xamarin.Forms.Internals;
namespace Xamarin.Forms.Platform.Android
{
{
base.OnConfigurationChanged(newConfig);
EventHandler handler = ConfigurationChanged;
- if (handler != null)
- handler(this, new EventArgs());
+ handler?.Invoke(this, new EventArgs());
}
// FIXME: THIS SHOULD NOT BE MANDATORY
protected void LoadApplication(Application application)
{
- if (application == null)
- throw new ArgumentNullException("application");
-
- (application as IApplicationController)?.SetAppIndexingProvider(new AndroidAppIndexProvider(this));
+ if (_application != null)
+ _application.PropertyChanged -= AppOnPropertyChanged;
- _application = application;
+ _application = application ?? throw new ArgumentNullException(nameof(application));
+ ((IApplicationController)application).SetAppIndexingProvider(new AndroidAppIndexProvider(this));
Xamarin.Forms.Application.SetCurrentApplication(application);
SetSoftInputMode();
application.PropertyChanged += AppOnPropertyChanged;
- if (application?.MainPage != null)
- {
- var iver = Platform.GetRenderer(application.MainPage);
- if (iver != null)
- {
- iver.Dispose();
- application.MainPage.ClearValue(Platform.RendererProperty);
- }
- }
-
SetMainPage();
}
if (Forms.IsLollipopOrNewer)
{
- // Listen for the device going into power save mode so we can handle animations being disabled
+ // Listen for the device going into power save mode so we can handle animations being disabled
_powerSaveModeBroadcastReceiver = new PowerSaveModeBroadcastReceiver();
}
// may never be called
base.OnDestroy();
+ if (_application != null)
+ _application.PropertyChanged -= AppOnPropertyChanged;
+
PopupManager.Unsubscribe(this);
- if (Platform != null)
- ((IDisposable)Platform).Dispose();
+ ((IDisposable) Platform)?.Dispose();
}
protected override void OnPause()
internal void SetPage(Page newRoot)
{
+ if (Page == newRoot)
+ {
+ return;
+ }
+
var layout = false;
List<IVisualElementRenderer> toDispose = null;