Exemplo n.º 1
0
        void UpdateDetailsFragmentView()
        {
            _ = MauiContext ?? throw new InvalidOperationException($"{nameof(MauiContext)} should have been set by base class.");
            var newDetailsView = VirtualView.Detail?.ToPlatform(MauiContext);

            if (_detailView == newDetailsView)
            {
                return;
            }

            if (newDetailsView != null)
            {
                newDetailsView.RemoveFromParent();
            }

            _detailView = newDetailsView;

            if (_detailView != null)
            {
                MauiContext
                .GetFragmentManager()
                .BeginTransaction()
                .Replace(Resource.Id.navigationlayout_content, new ViewFragment(_detailView))
                .SetReorderingAllowed(true)
                .Commit();
            }
        }
Exemplo n.º 2
0
        Task RunWindowTest <THandler>(IWindow window, Func <THandler, Task> action)
            where THandler : class, IElementHandler
        {
            return(InvokeOnMainThreadAsync(async() =>
            {
                AViewGroup rootView = MauiContext.Context.GetActivity().Window.DecorView as AViewGroup;
                var linearLayoutCompat = new LinearLayoutCompat(MauiContext.Context);

                var fragmentManager = MauiContext.GetFragmentManager();
                var viewFragment = new WindowTestFragment(MauiContext, window);

                try
                {
                    linearLayoutCompat.Id = AView.GenerateViewId();
                    fragmentManager
                    .BeginTransaction()
                    .Add(linearLayoutCompat.Id, viewFragment)
                    .Commit();

                    rootView.AddView(linearLayoutCompat);
                    await viewFragment.FinishedLoading;

                    if (typeof(THandler).IsAssignableFrom(window.Handler.GetType()))
                    {
                        await action((THandler)window.Handler);
                    }
                    else if (typeof(THandler).IsAssignableFrom(window.Content.Handler.GetType()))
                    {
                        await action((THandler)window.Content.Handler);
                    }
                }
                finally
                {
                    if (window.Handler != null)
                    {
                        window.Handler.DisconnectHandler();
                    }

                    rootView.RemoveView(linearLayoutCompat);

                    fragmentManager
                    .BeginTransaction()
                    .Remove(viewFragment)
                    .Commit();

                    await linearLayoutCompat.OnUnloadedAsync();
                    if (viewFragment.View != null)
                    {
                        await viewFragment.View.OnUnloadedAsync();
                    }
                }
            }));
        }
        Task CreateNavigationViewHandlerAsync(IStackNavigationView navigationView, Func <NavigationViewHandler, Task> action)
        {
            return(InvokeOnMainThreadAsync(async() =>
            {
                var context = MauiProgram.DefaultContext;

                var rootView = (context as AppCompatActivity).Window.DecorView as ViewGroup;
                var linearLayoutCompat = new LinearLayoutCompat(context);
                var fragmentManager = MauiContext.GetFragmentManager();
                var viewFragment = new NavViewFragment(MauiContext);

                try
                {
                    linearLayoutCompat.Id = View.GenerateViewId();

                    fragmentManager
                    .BeginTransaction()
                    .Add(linearLayoutCompat.Id, viewFragment)
                    .Commit();

                    rootView.AddView(linearLayoutCompat);
                    await viewFragment.FinishedLoading;
                    var handler = CreateHandler(navigationView, viewFragment.ScopedMauiContext);

                    if (navigationView is NavigationViewStub nvs && nvs.NavigationStack?.Count > 0)
                    {
                        navigationView.RequestNavigation(new NavigationRequest(nvs.NavigationStack, false));
                        await nvs.OnNavigationFinished;
                    }

                    await action(handler);
                }
                finally
                {
                    rootView.RemoveView(linearLayoutCompat);

                    fragmentManager
                    .BeginTransaction()
                    .Remove(viewFragment)
                    .Commit();
                }
            }));
        }
Exemplo n.º 4
0
        void UpdateDetail()
        {
            _ = MauiContext ?? throw new InvalidOperationException($"{nameof(MauiContext)} should have been set by base class.");
            _ = VirtualView.Detail?.ToNative(MauiContext);

            var newDetailView = VirtualView.Detail?.GetNative(true);

            if (_detailView == newDetailView)
            {
                return;
            }

            if (_detailView != null)
            {
                _detailView.RemoveFromParent();
            }

            _detailView = newDetailView;

            MauiContext
            .GetNavigationRootManager()
            .SetContentView(_detailView, MauiContext.GetFragmentManager());
        }
Exemplo n.º 5
0
        void UpdateDetailsFragmentView()
        {
            _ = MauiContext ?? throw new InvalidOperationException($"{nameof(MauiContext)} should have been set by base class.");

            if (_detailViewFragment != null && _detailViewFragment?.DetailView == VirtualView.Detail)
            {
                return;
            }

            if (VirtualView.Detail?.Handler is IPlatformViewHandler pvh)
            {
                pvh.DisconnectHandler();
            }

            if (VirtualView.Detail == null)
            {
                if (_detailViewFragment != null)
                {
                    MauiContext
                    .GetFragmentManager()
                    .BeginTransaction()
                    .Remove(_detailViewFragment)
                    .SetReorderingAllowed(true)
                    .Commit();
                }
            }
            else
            {
                _detailViewFragment = new ScopedFragment(VirtualView.Detail, MauiContext);
                MauiContext
                .GetFragmentManager()
                .BeginTransaction()
                .Replace(Resource.Id.navigationlayout_content, _detailViewFragment)
                .SetReorderingAllowed(true)
                .Commit();
            }
        }
Exemplo n.º 6
0
        Task RunWindowTest <THandler>(IWindow window, Func <THandler, Task> action)
            where THandler : class, IElementHandler
        {
            return(InvokeOnMainThreadAsync(async() =>
            {
                AViewGroup rootView = MauiContext.Context.GetActivity().Window.DecorView as AViewGroup;
                _decorDrawable ??= rootView.Background;
                var linearLayoutCompat = new LinearLayoutCompat(MauiContext.Context);

                var fragmentManager = MauiContext.GetFragmentManager();
                var viewFragment = new WindowTestFragment(MauiContext, window);

                try
                {
                    linearLayoutCompat.Id = AView.GenerateViewId();
                    rootView.AddView(linearLayoutCompat);

                    fragmentManager
                    .BeginTransaction()
                    .Add(linearLayoutCompat.Id, viewFragment)
                    .Commit();

                    await viewFragment.FinishedLoading;

                    if (window.Content is Shell shell)
                    {
                        await OnLoadedAsync(shell.CurrentPage);
                    }

                    if (typeof(THandler).IsAssignableFrom(window.Handler.GetType()))
                    {
                        await action((THandler)window.Handler);
                    }
                    else if (typeof(THandler).IsAssignableFrom(window.Content.Handler.GetType()))
                    {
                        await action((THandler)window.Content.Handler);
                    }
                    else if (window.Content is ContentPage cp && typeof(THandler).IsAssignableFrom(cp.Content.Handler.GetType()))
                    {
                        await action((THandler)cp.Content.Handler);
                    }
                    else
                    {
                        throw new Exception($"I can't work with {typeof(THandler)}");
                    }
                }
                finally
                {
                    if (window.Handler != null)
                    {
                        window.Handler.DisconnectHandler();
                    }

                    fragmentManager
                    .BeginTransaction()
                    .Remove(viewFragment)
                    .Commit();

                    rootView.RemoveView(linearLayoutCompat);

                    await linearLayoutCompat.OnUnloadedAsync();
                    if (viewFragment.View != null)
                    {
                        await viewFragment.View.OnUnloadedAsync();
                    }

                    await viewFragment.FinishedDestroying;

                    // This is mainly to remove changes to the decor view that shell imposes
                    if (_decorDrawable != rootView.Background)
                    {
                        rootView.Background = _decorDrawable;
                    }

                    // Unset the Support Action bar if the calling code has set the support action bar
                    if (MauiContext.Context.GetActivity() is AppCompatActivity aca)
                    {
                        aca.SetSupportActionBar(null);
                    }

                    // Ideally this wouldn't be needed but I haven't found the right platform
                    // component I can key into for knowing when the world can move on
                    await Task.Delay(1000);
                    fragmentManager.ExecutePendingTransactions();
                }
            }));
Exemplo n.º 7
0
        Task RunWindowTest <THandler>(IWindow window, Func <THandler, Task> action)
            where THandler : class, IElementHandler
        {
            return(InvokeOnMainThreadAsync(async() =>
            {
                AViewGroup rootView = MauiContext.Context.GetActivity().Window.DecorView as AViewGroup;
                var decorBackground = rootView.Background;
                var linearLayoutCompat = new LinearLayoutCompat(MauiContext.Context);

                var fragmentManager = MauiContext.GetFragmentManager();
                var viewFragment = new WindowTestFragment(MauiContext, window);

                try
                {
                    linearLayoutCompat.Id = AView.GenerateViewId();
                    rootView.AddView(linearLayoutCompat);
                    fragmentManager
                    .BeginTransaction()
                    .Add(linearLayoutCompat.Id, viewFragment)
                    .Commit();

                    await viewFragment.FinishedLoading;

                    if (typeof(THandler).IsAssignableFrom(window.Handler.GetType()))
                    {
                        await action((THandler)window.Handler);
                    }
                    else if (typeof(THandler).IsAssignableFrom(window.Content.Handler.GetType()))
                    {
                        await action((THandler)window.Content.Handler);
                    }
                    else if (window.Content is ContentPage cp && typeof(THandler).IsAssignableFrom(cp.Content.Handler.GetType()))
                    {
                        await action((THandler)cp.Content.Handler);
                    }
                    else
                    {
                        throw new Exception($"I can't work with {typeof(THandler)}");
                    }
                }
                finally
                {
                    if (window.Handler != null)
                    {
                        window.Handler.DisconnectHandler();
                    }

                    rootView.RemoveView(linearLayoutCompat);

                    fragmentManager
                    .BeginTransaction()
                    .Remove(viewFragment)
                    .Commit();

                    await linearLayoutCompat.OnUnloadedAsync();
                    if (viewFragment.View != null)
                    {
                        await viewFragment.View.OnUnloadedAsync();
                    }

                    // This is mainly to remove changes to the decor view that shell imposes
                    if (decorBackground != rootView.Background)
                    {
                        rootView.Background = decorBackground;
                    }

                    // Unset the Support Action bar if the calling code has set the support action bar
                    if (MauiContext.Context.GetActivity() is AppCompatActivity aca)
                    {
                        aca.SetSupportActionBar(null);
                    }
                }
            }));
Exemplo n.º 8
0
        Task SetupWindowForTests <THandler>(IWindow window, Func <Task> runTests, IMauiContext mauiContext = null)
            where THandler : class, IElementHandler
        {
            mauiContext ??= MauiContext;
            return(InvokeOnMainThreadAsync(async() =>
            {
                AViewGroup rootView = MauiContext.Context.GetActivity().Window.DecorView as AViewGroup;
                _decorDrawable ??= rootView.Background;
                var linearLayoutCompat = new LinearLayoutCompat(MauiContext.Context);
                var fragmentManager = MauiContext.GetFragmentManager();
                var viewFragment = new WindowTestFragment(MauiContext, window);

                try
                {
                    linearLayoutCompat.Id = AView.GenerateViewId();
                    rootView.AddView(linearLayoutCompat);

                    fragmentManager
                    .BeginTransaction()
                    .Add(linearLayoutCompat.Id, viewFragment)
                    .Commit();

                    await viewFragment.FinishedLoading;
                    await runTests.Invoke();
                }
                finally
                {
                    if (window.Handler != null)
                    {
                        window.Handler.DisconnectHandler();
                    }

                    fragmentManager
                    .BeginTransaction()
                    .Remove(viewFragment)
                    .Commit();

                    rootView.RemoveView(linearLayoutCompat);

                    await linearLayoutCompat.OnUnloadedAsync();
                    if (viewFragment.View != null)
                    {
                        await viewFragment.View.OnUnloadedAsync();
                    }

                    await viewFragment.FinishedDestroying;

                    // This is mainly to remove changes to the decor view that shell imposes
                    if (_decorDrawable != rootView.Background)
                    {
                        rootView.Background = _decorDrawable;
                    }

                    // Unset the Support Action bar if the calling code has set the support action bar
                    if (MauiContext.Context.GetActivity() is AppCompatActivity aca)
                    {
                        aca.SetSupportActionBar(null);
                    }
                }
            }));
        }