Fixed android crash
This commit is contained in:
Родитель
599965c9d5
Коммит
9621223727
|
@ -1,41 +0,0 @@
|
||||||
//using System;
|
|
||||||
//using Android.Runtime;
|
|
||||||
//using Android.Views;
|
|
||||||
//using Android.Widget;
|
|
||||||
//using AView = Android.Views.View;
|
|
||||||
|
|
||||||
//namespace Comet.Android.Controls
|
|
||||||
//{
|
|
||||||
// public class CometContainerView : LinearLayout
|
|
||||||
// {
|
|
||||||
// private AView _mainView;
|
|
||||||
|
|
||||||
// protected CometContainerView(IntPtr javaReference, JniHandleOwnership transfer) : base(javaReference, transfer)
|
|
||||||
// {
|
|
||||||
// }
|
|
||||||
|
|
||||||
// public CometContainerView() : base(AndroidContext.CurrentContext)
|
|
||||||
// {
|
|
||||||
// }
|
|
||||||
|
|
||||||
// public AView MainView
|
|
||||||
// {
|
|
||||||
// get => _mainView;
|
|
||||||
// set
|
|
||||||
// {
|
|
||||||
// if (_mainView != null)
|
|
||||||
// {
|
|
||||||
// RemoveView(_mainView);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// _mainView = value;
|
|
||||||
|
|
||||||
// if (_mainView != null)
|
|
||||||
// {
|
|
||||||
// _mainView.LayoutParameters = new ViewGroup.LayoutParams(LayoutParams.MatchParent, LayoutParams.MatchParent);
|
|
||||||
// AddView(_mainView);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//}
|
|
|
@ -16,7 +16,12 @@ namespace Comet.Android.Controls
|
||||||
|
|
||||||
public void SetRoot(View view)
|
public void SetRoot(View view)
|
||||||
{
|
{
|
||||||
(MauiContext.Context).GetFragmentManager()
|
if (!isAttached)
|
||||||
|
{
|
||||||
|
contentView = view;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
(MauiContext.Context).GetFragmentManager()
|
||||||
.BeginTransaction()
|
.BeginTransaction()
|
||||||
.Replace(Id, new CometFragment(view, MauiContext))
|
.Replace(Id, new CometFragment(view, MauiContext))
|
||||||
.CommitAllowingStateLoss();
|
.CommitAllowingStateLoss();
|
||||||
|
@ -31,6 +36,16 @@ namespace Comet.Android.Controls
|
||||||
.Replace(Id, new CometFragment(view, MauiContext))
|
.Replace(Id, new CometFragment(view, MauiContext))
|
||||||
.CommitAllowingStateLoss();
|
.CommitAllowingStateLoss();
|
||||||
}
|
}
|
||||||
|
bool isAttached = false;
|
||||||
|
View contentView;
|
||||||
|
protected override void OnAttachedToWindow()
|
||||||
|
{
|
||||||
|
base.OnAttachedToWindow();
|
||||||
|
isAttached = true;
|
||||||
|
if(contentView != null)
|
||||||
|
SetRoot(contentView);
|
||||||
|
contentView = null;
|
||||||
|
}
|
||||||
|
|
||||||
public void Pop() =>
|
public void Pop() =>
|
||||||
(MauiContext.Context).GetFragmentManager().PopBackStack();
|
(MauiContext.Context).GetFragmentManager().PopBackStack();
|
||||||
|
|
|
@ -1,51 +0,0 @@
|
||||||
//using System;
|
|
||||||
//using Android.Support.V4.App;
|
|
||||||
//using Comet.Android.Extensions;
|
|
||||||
//using PopBackStackFlags = Android.App.PopBackStackFlags;
|
|
||||||
|
|
||||||
//namespace Comet.Android.Controls
|
|
||||||
//{
|
|
||||||
// public class NavigationViewWrapper : CustomFrameLayout
|
|
||||||
// {
|
|
||||||
// public NavigationViewWrapper(View view) : base(AndroidContext.CurrentContext)
|
|
||||||
// {
|
|
||||||
// SetRoot(view);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// public void SetRoot(View view) => SetView(view, false, false);
|
|
||||||
|
|
||||||
// void Navigate(View view) => Push(view);
|
|
||||||
|
|
||||||
// public void Push(View view, bool animated = true) => SetView(view, animated, true);
|
|
||||||
|
|
||||||
// FragmentManager FragmentManager => AndroidContext.AppCompatActivity.SupportFragmentManager;
|
|
||||||
|
|
||||||
// void SetView(View view, bool animate, bool isNavigate)
|
|
||||||
// {
|
|
||||||
// var manager = FragmentManager;
|
|
||||||
// if (!isNavigate && manager.BackStackEntryCount > 0)
|
|
||||||
// {
|
|
||||||
// manager.PopBackStack(0, (int)PopBackStackFlags.Inclusive);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// var fragment = new CometFragment(view);
|
|
||||||
|
|
||||||
// var transaction = manager.BeginTransaction();
|
|
||||||
|
|
||||||
// if (animate)
|
|
||||||
// transaction.SetTransition((int)global::Android.App.FragmentTransit.FragmentFade);
|
|
||||||
// if (isNavigate)
|
|
||||||
// transaction.AddToBackStack(view.Id);
|
|
||||||
// transaction.Replace(this.Id, fragment);
|
|
||||||
// transaction.CommitAllowingStateLoss();
|
|
||||||
|
|
||||||
// manager.ExecutePendingTransactions();
|
|
||||||
|
|
||||||
// if (view.BuiltView is NavigationView nav)
|
|
||||||
// {
|
|
||||||
// nav.PerformNavigate = Navigate;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//}
|
|
Загрузка…
Ссылка в новой задаче