Пример #1
0
        public virtual FragmentNavigator.Destination AddFragmentDestination()
        {
            var destination = new FragmentNavigator.Destination(FragmentNavigator);

            destination.SetClassName(Java.Lang.Class.FromType(typeof(NavigationViewFragment)).CanonicalName);
            destination.Id = AView.GenerateViewId();
            NavGraph.AddDestination(destination);
            return(destination);
        }
Пример #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();
                    }
                }
            }));
        }
Пример #3
0
        public static void EnsureId(this AView view)
        {
            if (!view.IsAlive())
            {
                return;
            }

            if (view.Id == AView.NoId)
            {
                view.Id = AView.GenerateViewId();
            }
        }
 public RvViewContainer(IMauiContext context)
     : base(context.Context ?? throw new ArgumentNullException($"{nameof(context.Context)}"))
 {
     MauiContext = context;
     Id          = AView.GenerateViewId();
 }
Пример #5
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();
                }
            }));
Пример #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;
                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);
                    }
                }
            }));
Пример #7
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);
                    }
                }
            }));
        }
Пример #8
0
 public FakeActivityRootView(Context context) : base(context)
 {
     Id = AView.GenerateViewId();
 }