public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
        {
            var startup = new TStartup();

            var host = startup
                       .CreateAppHostBuilder()
                       .ConfigureServices(ConfigureNativeServices)
                       .ConfigureUsing(startup)
                       .Build();

            Services    = host.Services;
            Application = Services.GetRequiredService <IApplication>();

            var mauiContext = new MauiContext(Services);

            var activationState = new ActivationState(mauiContext);
            var window          = Application.CreateWindow(activationState);

            window.MauiContext = mauiContext;

            var content = (window.Page as IView) ?? window.Page.View;

            Window = new UIWindow
            {
                RootViewController = new UIViewController
                {
                    View = content.ToNative(window.MauiContext)
                }
            };

            Window.MakeKeyAndVisible();

            return(true);
        }
        protected override void OnCreate(Bundle?savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            var mauiApp = MauiApplication.Current.Application;

            if (mauiApp == null)
            {
                throw new InvalidOperationException($"The {nameof(IApplication)} instance was not found.");
            }

            var services = MauiApplication.Current.Services;

            if (mauiApp == null)
            {
                throw new InvalidOperationException($"The {nameof(IServiceProvider)} instance was not found.");
            }

            var mauiContext = new MauiContext(services, this);

            var state  = new ActivationState(mauiContext, savedInstanceState);
            var window = mauiApp.CreateWindow(state);

            window.MauiContext = mauiContext;

            var content = (window.Page as IView) ?? window.Page.View;

            CoordinatorLayout parent = new CoordinatorLayout(this);

            SetContentView(parent, new ViewGroup.LayoutParams(CoordinatorLayout.LayoutParams.MatchParent, CoordinatorLayout.LayoutParams.MatchParent));

            //AddToolbar(parent);

            parent.AddView(content.ToNative(window.MauiContext), new CoordinatorLayout.LayoutParams(CoordinatorLayout.LayoutParams.MatchParent, CoordinatorLayout.LayoutParams.MatchParent));
        }
Beispiel #3
0
        protected override void OnLaunched(UI.Xaml.LaunchActivatedEventArgs args)
        {
            LaunchActivatedEventArgs = args;

            // TODO: This should not be here. CreateWindow should do it.
            MainWindow = new MauiWinUIWindow();

            var startup = new TStartup();

            var host = startup
                       .CreateAppHostBuilder()
                       .ConfigureServices(ConfigureNativeServices)
                       .ConfigureUsing(startup)
                       .Build();

            Services    = host.Services;
            Application = Services.GetRequiredService <IApplication>();

            var mauiContext = new MauiContext(Services);

            var activationState = new ActivationState(mauiContext, args);
            var window          = Application.CreateWindow(activationState);

            window.MauiContext = mauiContext;

            var content = (window.Page as IView) ?? window.Page.View;

            var canvas = CreateRootContainer();

            canvas.Children.Add(content.ToNative(window.MauiContext));

            MainWindow.Content = canvas;

            MainWindow.Activate();
        }
Beispiel #4
0
        public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
        {
            var startup = new TStartup();

            var host = startup
                       .CreateAppHostBuilder()
                       .ConfigureServices(ConfigureNativeServices)
                       .ConfigureUsing(startup)
                       .Build();

            Services    = host.Services;
            Application = Services.GetRequiredService <IApplication>();

            var mauiContext = new MauiContext(Services);

            var activationState = new ActivationState(mauiContext);
            var window          = Application.CreateWindow(activationState);

            var page = window.View;

            Window = new UIWindow
            {
                RootViewController = window.View.ToUIViewController(mauiContext)
            };

            Window.MakeKeyAndVisible();

            Current.Services?.InvokeLifecycleEvents <iOSLifecycle.FinishedLaunching>(del => del(application, launchOptions));

            return(true);
        }
        protected override void OnLaunched(UI.Xaml.LaunchActivatedEventArgs args)
        {
            LaunchActivatedEventArgs = args;

            // TODO: This should not be here. CreateWindow should do it.
            MainWindow = new MauiWinUIWindow();

            var startup = new TStartup();

            var host = startup
                       .CreateAppHostBuilder()
                       .ConfigureServices(ConfigureNativeServices)
                       .ConfigureUsing(startup)
                       .Build();

            Services    = host.Services;
            Application = Services.GetRequiredService <IApplication>();

            var mauiContext = new MauiContext(Services);

            var activationState = new ActivationState(mauiContext, args);
            var window          = Application.CreateWindow(activationState);

            window.MauiContext = mauiContext;

            var content = (window.Page as IView) ?? window.Page.Content;

            var canvas = CreateRootContainer();

            var nativeContent = content.ToNative(window.MauiContext);

            canvas.Children.Add(nativeContent);

            MainWindow.Content = canvas;

            Current.Services?.InvokeLifecycleEvents <WindowsLifecycle.OnLaunched>(del => del(this, args));

            MainWindow.SizeChanged += (sender, sizeChangedArgs) =>
            {
                // TODO ezhart We need a better signalling mechanism between the PagePanel and the ContentPage for invalidation
                content.InvalidateMeasure();

                // TODO ezhart This is not ideal, but we need to force the canvas to match the window size
                // We probably need a better root control than Canvas, really
                canvas.Width  = MainWindow.Bounds.Width;
                canvas.Height = MainWindow.Bounds.Height;

                // TODO ezhart Once we've got navigation up and running, this will need to be updated so it
                // affects the navigation root or the current page. Again, Canvas is probably not the right root, but
                // I haven't been able to get a custom Panel to handle the drawing correctly yet.
                nativeContent.Width  = canvas.ActualWidth;
                nativeContent.Height = canvas.ActualHeight;
            };

            MainWindow.Activate();
        }
Beispiel #6
0
        protected override void OnCreate(Bundle?savedInstanceState)
        {
            // If the theme has the maui_splash attribute, change the theme
            if (Theme.TryResolveAttribute(Resource.Attribute.maui_splash))
            {
                SetTheme(Resource.Style.Maui_MainTheme_NoActionBar);
            }

            base.OnCreate(savedInstanceState);

            var mauiApp = MauiApplication.Current.Application;

            if (mauiApp == null)
            {
                throw new InvalidOperationException($"The {nameof(IApplication)} instance was not found.");
            }

            var services = MauiApplication.Current.Services;

            if (mauiApp == null)
            {
                throw new InvalidOperationException($"The {nameof(IServiceProvider)} instance was not found.");
            }

            MauiContext mauiContext;
            IWindow     window;

            // TODO Fix once we have multiple windows
            if (mauiApp.Windows.Count > 0)
            {
                window      = mauiApp.Windows[0];
                mauiContext = new MauiContext(services, this);
            }
            else
            {
                mauiContext = new MauiContext(services, this);
                ActivationState state = new ActivationState(mauiContext, savedInstanceState);
                window = mauiApp.CreateWindow(state);
            }

            SetContentView(window.View.ToNative(mauiContext));

            //TODO MAUI
            // Allow users to customize the toolbarid?
            bool?windowActionBar;

            if (Theme.TryResolveAttribute(Resource.Attribute.windowActionBar, out windowActionBar) &&
                windowActionBar == false)
            {
                var toolbar = FindViewById <Toolbar>(Resource.Id.maui_toolbar);
                if (toolbar != null)
                {
                    SetSupportActionBar(toolbar);
                }
            }
        }
Beispiel #7
0
        protected override void OnCreate(Bundle?savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            var mauiApp = MauiApplication.Current.Application;

            if (mauiApp == null)
            {
                throw new InvalidOperationException($"The {nameof(IApplication)} instance was not found.");
            }

            var services = MauiApplication.Current.Services;

            if (mauiApp == null)
            {
                throw new InvalidOperationException($"The {nameof(IServiceProvider)} instance was not found.");
            }

            var mauiContext = new MauiContext(services, this);

            var state  = new ActivationState(mauiContext, savedInstanceState);
            var window = mauiApp.CreateWindow(state);

            window.MauiContext = mauiContext;

            var matchParent = ViewGroup.LayoutParams.MatchParent;

            // Create the root native layout and set the Activity's content to it
            CoordinatorLayout nativeRootLayout = new CoordinatorLayout(this);

            SetContentView(nativeRootLayout, new ViewGroup.LayoutParams(matchParent, matchParent));

            //AddToolbar(parent);

            var page = window.Page;

            // This currently relies on IPage : IView, which may not exactly be right
            // we may have to add another handler extension that works for Page
            // Also, AbstractViewHandler is set to work for IView (obviously); if IPage is not IView,
            // then we'll need to change it to AbstractFrameworkElementHandler or create a separate
            // abstract handler for IPage
            // TODO ezhart Think about all this stuff ^^

            var nativePage = page.ToNative(window.MauiContext);

            // Add the IPage to the root layout; use match parent so the page automatically has the dimensions of the activity
            nativeRootLayout.AddView(nativePage, new CoordinatorLayout.LayoutParams(matchParent, matchParent));
        }
        UI.Xaml.Window CreateNativeWindow(UI.Xaml.LaunchActivatedEventArgs?args = null)
        {
            var winuiWndow = new MauiWinUIWindow();

            var mauiContext = new MauiContext(Services, winuiWndow);

            Services.InvokeLifecycleEvents <WindowsLifecycle.OnMauiContextCreated>(del => del(mauiContext));

            var activationState = new ActivationState(mauiContext, args);
            var window          = Application.CreateWindow(activationState);

            winuiWndow.SetWindow(window, mauiContext);
            Services.InvokeLifecycleEvents <WindowsLifecycle.OnWindowCreated>(del => del(winuiWndow));

            return(winuiWndow);
        }
        UIWindow CreateNativeWindow()
        {
            var uiWindow = new UIWindow();

            var mauiContext = new MauiContext(Services, uiWindow);

            Services.InvokeLifecycleEvents <iOSLifecycle.OnMauiContextCreated>(del => del(mauiContext));

            var activationState = new ActivationState(mauiContext);
            var window          = Application.CreateWindow(activationState);

            _virtualWindow = new WeakReference <IWindow>(window);
            uiWindow.SetWindow(window, mauiContext);

            return(uiWindow);
        }
		public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
		{
			Application = Services.GetRequiredService<IApplication>();

			var mauiContext = new MauiContext(Services);

			var activationState = new ActivationState(mauiContext);
			var window = Application.CreateWindow(activationState);

			var page = window.View;

			Window = new UIWindow
			{
				RootViewController = window.View.ToUIViewController(mauiContext)
			};

			Window.MakeKeyAndVisible();

			Current.Services?.InvokeLifecycleEvents<iOSLifecycle.FinishedLaunching>(del => del(application, launchOptions));

			return true;
		}
        void CreateNativeWindow(Bundle?savedInstanceState = null)
        {
            var mauiApp = MauiApplication.Current.Application;

            if (mauiApp == null)
            {
                throw new InvalidOperationException($"The {nameof(IApplication)} instance was not found.");
            }

            var services = MauiApplication.Current.Services;

            if (services == null)
            {
                throw new InvalidOperationException($"The {nameof(IServiceProvider)} instance was not found.");
            }

            var mauiContext = new MauiContext(services, this);

            services.InvokeLifecycleEvents <AndroidLifecycle.OnMauiContextCreated>(del => del(mauiContext));

            // TODO: Fix once we have multiple windows
            IWindow window;

            if (mauiApp.Windows.Count > 0)
            {
                // assume if there are windows, then this is a "resume" activity
                window = mauiApp.Windows[0];
            }
            else
            {
                // there are no windows, so this is a fresh launch
                var state = new ActivationState(mauiContext, savedInstanceState);
                window = mauiApp.CreateWindow(state);
            }

            _virtualWindow = new WeakReference <IWindow>(window);
            this.SetWindow(window, mauiContext);
        }
Beispiel #12
0
        protected override void OnCreate(Bundle?savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            if (App.Current as MauiApp == null)
            {
                throw new InvalidOperationException($"App is not {nameof(MauiApp)}");
            }

            var mauiApp = (MauiApp)App.Current;

            if (mauiApp.Services == null)
            {
                throw new InvalidOperationException("App was not initialized");
            }

            var mauiContext = new MauiContext(mauiApp.Services, this);
            var state       = new ActivationState(mauiContext, savedInstanceState);
            var window      = mauiApp.CreateWindow(state);

            window.MauiContext = mauiContext;

            //Hack for now we set this on the App Static but this should be on IFrameworkElement
            App.Current.SetHandlerContext(window.MauiContext);

            var content = (window.Page as IView) ??
                          window.Page.View;

            CoordinatorLayout parent = new CoordinatorLayout(this);

            SetContentView(parent, new ViewGroup.LayoutParams(CoordinatorLayout.LayoutParams.MatchParent, CoordinatorLayout.LayoutParams.MatchParent));

            //AddToolbar(parent);

            parent.AddView(content.ToNative(window.MauiContext), new CoordinatorLayout.LayoutParams(CoordinatorLayout.LayoutParams.MatchParent, CoordinatorLayout.LayoutParams.MatchParent));
        }
Beispiel #13
0
        protected override void OnCreate(Bundle?savedInstanceState)
        {
            if (!AllowFragmentRestore)
            {
                // Remove the automatically persisted fragment structure; we don't need them
                // because we're rebuilding everything from scratch. This saves a bit of memory
                // and prevents loading errors from child fragment managers
                savedInstanceState?.Remove("android:support:fragments");
                savedInstanceState?.Remove("androidx.lifecycle.BundlableSavedStateRegistry.key");
            }

            // If the theme has the maui_splash attribute, change the theme
            if (Theme.TryResolveAttribute(Resource.Attribute.maui_splash))
            {
                SetTheme(Resource.Style.Maui_MainTheme_NoActionBar);
            }

            base.OnCreate(savedInstanceState);

            var mauiApp = MauiApplication.Current.Application;

            if (mauiApp == null)
            {
                throw new InvalidOperationException($"The {nameof(IApplication)} instance was not found.");
            }

            var services = MauiApplication.Current.Services;

            if (mauiApp == null)
            {
                throw new InvalidOperationException($"The {nameof(IServiceProvider)} instance was not found.");
            }

            MauiContext mauiContext;
            IWindow     window;

            // TODO Fix once we have multiple windows
            if (mauiApp.Windows.Count > 0)
            {
                window      = mauiApp.Windows[0];
                mauiContext = new MauiContext(services, this);
            }
            else
            {
                mauiContext = new MauiContext(services, this);
                ActivationState state = new ActivationState(mauiContext, savedInstanceState);
                window = mauiApp.CreateWindow(state);
            }

            SetContentView(window.View.ToContainerView(mauiContext));

            //TODO MAUI
            // Allow users to customize the toolbarid?
            bool?windowActionBar;

            if (Theme.TryResolveAttribute(Resource.Attribute.windowActionBar, out windowActionBar) &&
                windowActionBar == false)
            {
                var toolbar = FindViewById <Toolbar>(Resource.Id.maui_toolbar);
                if (toolbar != null)
                {
                    SetSupportActionBar(toolbar);
                }
            }
        }