Esempio n. 1
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();
        }
Esempio n. 2
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);

            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);
        }
Esempio n. 3
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 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));
        }
Esempio n. 5
0
        protected override void OnLaunched(UI.Xaml.LaunchActivatedEventArgs args)
        {
            // Windows running on a different thread will "launch" the app again
            if (Application != null)
            {
                Services.InvokeLifecycleEvents <WindowsLifecycle.OnLaunching>(del => del(this, args));
                Services.InvokeLifecycleEvents <WindowsLifecycle.OnLaunched>(del => del(this, args));
                return;
            }

            var mauiApp = CreateMauiApp();

            var rootContext = new MauiContext(mauiApp.Services);

            var applicationContext = rootContext.MakeApplicationScope(this);

            Services = applicationContext.Services;

            Services.InvokeLifecycleEvents <WindowsLifecycle.OnLaunching>(del => del(this, args));

            Application = Services.GetRequiredService <IApplication>();

            this.SetApplicationHandler(Application, applicationContext);

            this.CreateNativeWindow(Application, args);

            Services.InvokeLifecycleEvents <WindowsLifecycle.OnLaunched>(del => del(this, args));
        }
Esempio n. 6
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.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();
        }
Esempio n. 7
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);
                }
            }
        }
		public static IMauiContext MakeApplicationScope(this IMauiContext mauiContext, NativeApplication platformApplication)
		{
			var scopedContext = new MauiContext(mauiContext.Services);

			scopedContext.AddSpecific(platformApplication);

			scopedContext.InitializeScopedServices();

			return scopedContext;
		}
Esempio n. 9
0
        public override bool WillFinishLaunching(UIApplication application, NSDictionary launchOptions)
        {
            var mauiApp = CreateMauiApp();

            var rootContext = new MauiContext(mauiApp.Services);

            _applicationContext = rootContext.MakeApplicationScope(this);

            Services = _applicationContext.Services;

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

            return(true);
        }
Esempio n. 10
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));
        }
        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);
        }
        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);
        }
Esempio n. 13
0
		public static IMauiContext MakeWindowScope(this IMauiContext mauiContext, NativeWindow platformWindow, out IServiceScope scope)
		{
			scope = mauiContext.Services.CreateScope();

#if __ANDROID__
			var scopedContext = new MauiContext(scope.ServiceProvider, platformWindow);
#else
			var scopedContext = new MauiContext(scope.ServiceProvider);
#endif

			scopedContext.AddWeakSpecific(platformWindow);

#if WINDOWS || __ANDROID__
			scopedContext.AddSpecific(new NavigationRootManager(scopedContext));
#endif

			return scopedContext;
		}
		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;
		}
Esempio n. 15
0
        public override void OnCreate()
        {
            RegisterActivityLifecycleCallbacks(new ActivityLifecycleCallbacks());

            var mauiApp = CreateMauiApp();

            var rootContext = new MauiContext(mauiApp.Services, this);

            var applicationContext = rootContext.MakeApplicationScope(this);

            Services = applicationContext.Services;

            Current.Services?.InvokeLifecycleEvents <AndroidLifecycle.OnApplicationCreating>(del => del(this));

            Application = Services.GetRequiredService <IApplication>();

            this.SetApplicationHandler(Application, applicationContext);

            Current.Services?.InvokeLifecycleEvents <AndroidLifecycle.OnApplicationCreate>(del => del(this));

            base.OnCreate();
        }
Esempio n. 16
0
        protected override void OnPreCreate()
        {
            base.OnPreCreate();

            Elementary.Initialize();
            Elementary.ThemeOverlay();

            var mauiApp = CreateMauiApp();

            var rootContext = new MauiContext(mauiApp.Services);

            var platformWindow = CoreAppExtensions.GetDefaultWindow();

            platformWindow.Initialize();
            rootContext.AddWeakSpecific(platformWindow);

            _applicationContext = rootContext.MakeApplicationScope(this);

            Services = _applicationContext.Services;

            Current.Services?.InvokeLifecycleEvents <TizenLifecycle.OnPreCreate>(del => del(this));
        }
        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);
        }
Esempio n. 18
0
        public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
        {
            if (!(Activator.CreateInstance(typeof(TApplication)) is TApplication app))
            {
                throw new InvalidOperationException($"We weren't able to create the App {typeof(TApplication)}");
            }

            var host = app.CreateBuilder().ConfigureServices(ConfigureNativeServices).Build(app);

            if (MauiApp.Current == null || MauiApp.Current.Services == null)
            {
                throw new InvalidOperationException("App was not intialized");
            }


            var mauiContext = new MauiContext(MauiApp.Current.Services);
            var window      = app.CreateWindow(new ActivationState(mauiContext));

            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;

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

            uiWindow.MakeKeyAndVisible();

            return(true);
        }
Esempio n. 19
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));
        }
Esempio n. 20
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);
                }
            }
        }