Exemplo n.º 1
0
        static MauiAppBuilder SetupDefaults(this MauiAppBuilder builder)
        {
#if WINDOWS || ANDROID || IOS || MACCATALYST || TIZEN
            // initialize compatibility DependencyService
            DependencyService.SetToInitialized();
            DependencyService.Register <Xaml.ResourcesLoader>();
            DependencyService.Register <Xaml.ValueConverterProvider>();
            DependencyService.Register <PlatformSizeService>();
            DependencyService.Register <PlatformInvalidate>();

#pragma warning disable CS0612 // Type or member is obsolete
            DependencyService.Register <ResourcesProvider>();
            DependencyService.Register <FontNamedSizeService>();
#pragma warning restore CS0612 // Type or member is obsolete
#endif

            builder.ConfigureImageSourceHandlers();
            builder
            .ConfigureMauiHandlers(handlers =>
            {
                handlers.AddMauiControlsHandlers();
            });

#if WINDOWS
            builder.Services.TryAddEnumerable(ServiceDescriptor.Transient <IMauiInitializeService, MauiControlsInitializer>());
#endif
            builder.RemapForControls();

            return(builder);
        }
        static MauiAppBuilder SetupDefaults(this MauiAppBuilder builder)
        {
#if ANDROID || IOS || WINDOWS
            // initialize compatibility DependencyService
            DependencyService.SetToInitialized();
            DependencyService.Register <Xaml.ResourcesLoader>();
            DependencyService.Register <NativeBindingService>();
            DependencyService.Register <NativeValueConverterService>();
            DependencyService.Register <Deserializer>();
            DependencyService.Register <ResourcesProvider>();
            DependencyService.Register <Xaml.ValueConverterProvider>();
            DependencyService.Register <PlatformInvalidate>();
            DependencyService.Register <FontNamedSizeService>();
#endif

            builder.ConfigureCompatibilityLifecycleEvents();
            builder.ConfigureImageSourceHandlers();
            builder
            .ConfigureMauiHandlers(handlers =>
            {
                handlers.AddMauiControlsHandlers();

#if ANDROID || IOS || WINDOWS
                handlers.AddHandler(typeof(ListView), typeof(Handlers.Compatibility.ListViewRenderer));
                handlers.AddHandler(typeof(Cell), typeof(Handlers.Compatibility.CellRenderer));
                handlers.AddHandler(typeof(ImageCell), typeof(Handlers.Compatibility.ImageCellRenderer));
                handlers.AddHandler(typeof(EntryCell), typeof(Handlers.Compatibility.EntryCellRenderer));
                handlers.AddHandler(typeof(TextCell), typeof(Handlers.Compatibility.TextCellRenderer));
                handlers.AddHandler(typeof(ViewCell), typeof(Handlers.Compatibility.ViewCellRenderer));
                handlers.AddHandler(typeof(SwitchCell), typeof(Handlers.Compatibility.SwitchCellRenderer));
                handlers.AddHandler(typeof(TableView), typeof(Handlers.Compatibility.TableViewRenderer));
                handlers.AddHandler(typeof(Frame), typeof(Handlers.Compatibility.FrameRenderer));

                handlers.TryAddCompatibilityRenderer(typeof(BoxView), typeof(BoxRenderer));
                handlers.TryAddCompatibilityRenderer(typeof(Entry), typeof(EntryRenderer));
                handlers.TryAddCompatibilityRenderer(typeof(Editor), typeof(EditorRenderer));
                handlers.TryAddCompatibilityRenderer(typeof(Label), typeof(LabelRenderer));
                handlers.TryAddCompatibilityRenderer(typeof(Image), typeof(ImageRenderer));
                handlers.TryAddCompatibilityRenderer(typeof(Button), typeof(ButtonRenderer));
                handlers.TryAddCompatibilityRenderer(typeof(ImageButton), typeof(ImageButtonRenderer));
                handlers.TryAddCompatibilityRenderer(typeof(CollectionView), typeof(CollectionViewRenderer));
                handlers.TryAddCompatibilityRenderer(typeof(CarouselView), typeof(CarouselViewRenderer));
                handlers.TryAddCompatibilityRenderer(typeof(Path), typeof(PathRenderer));
                handlers.TryAddCompatibilityRenderer(typeof(Ellipse), typeof(EllipseRenderer));
                handlers.TryAddCompatibilityRenderer(typeof(Line), typeof(LineRenderer));
                handlers.TryAddCompatibilityRenderer(typeof(Polyline), typeof(PolylineRenderer));
                handlers.TryAddCompatibilityRenderer(typeof(Polygon), typeof(PolygonRenderer));
                handlers.TryAddCompatibilityRenderer(typeof(Shapes.Rectangle), typeof(RectangleRenderer));
                handlers.TryAddCompatibilityRenderer(typeof(RadioButton), typeof(RadioButtonRenderer));
                handlers.TryAddCompatibilityRenderer(typeof(Slider), typeof(SliderRenderer));
                handlers.TryAddCompatibilityRenderer(typeof(WebView), typeof(WebViewRenderer));
                handlers.TryAddCompatibilityRenderer(typeof(SearchBar), typeof(SearchBarRenderer));
                handlers.TryAddCompatibilityRenderer(typeof(Switch), typeof(SwitchRenderer));
                handlers.TryAddCompatibilityRenderer(typeof(SwipeView), typeof(SwipeViewRenderer));
                handlers.TryAddCompatibilityRenderer(typeof(DatePicker), typeof(DatePickerRenderer));
                handlers.TryAddCompatibilityRenderer(typeof(TimePicker), typeof(TimePickerRenderer));
                handlers.TryAddCompatibilityRenderer(typeof(Picker), typeof(PickerRenderer));
                handlers.TryAddCompatibilityRenderer(typeof(Stepper), typeof(StepperRenderer));
                handlers.TryAddCompatibilityRenderer(typeof(ProgressBar), typeof(ProgressBarRenderer));
                handlers.TryAddCompatibilityRenderer(typeof(ScrollView), typeof(ScrollViewRenderer));
                handlers.TryAddCompatibilityRenderer(typeof(ActivityIndicator), typeof(ActivityIndicatorRenderer));
                handlers.TryAddCompatibilityRenderer(typeof(CheckBox), typeof(CheckBoxRenderer));
#if !WINDOWS
#if !(MACCATALYST || MACOS)
                handlers.TryAddCompatibilityRenderer(typeof(OpenGLView), typeof(OpenGLViewRenderer));
#endif
#else
                handlers.TryAddCompatibilityRenderer(typeof(Layout), typeof(LayoutRenderer));
#endif
                handlers.TryAddCompatibilityRenderer(typeof(CarouselPage), typeof(CarouselPageRenderer));
                handlers.TryAddCompatibilityRenderer(typeof(Page), typeof(PageRenderer));
                handlers.TryAddCompatibilityRenderer(typeof(RefreshView), typeof(RefreshViewRenderer));
                handlers.TryAddCompatibilityRenderer(typeof(NativeViewWrapper), typeof(NativeViewWrapperRenderer));

                handlers.TryAddCompatibilityRenderer(typeof(Microsoft.Maui.Controls.Compatibility.Layout <View>), typeof(DefaultRenderer));
                handlers.TryAddCompatibilityRenderer(typeof(Microsoft.Maui.Controls.Compatibility.RelativeLayout), typeof(DefaultRenderer));
                handlers.TryAddCompatibilityRenderer(typeof(Microsoft.Maui.Controls.Compatibility.AbsoluteLayout), typeof(DefaultRenderer));

                // Shimmed renderers go directly to the registrar to load Image Handlers
                Internals.Registrar.Registered.Register(typeof(FileImageSource), typeof(FileImageSourceHandler));
                Internals.Registrar.Registered.Register(typeof(StreamImageSource), typeof(StreamImagesourceHandler));
                Internals.Registrar.Registered.Register(typeof(UriImageSource), typeof(ImageLoaderSourceHandler));
                Internals.Registrar.Registered.Register(typeof(FontImageSource), typeof(FontImageSourceHandler));
                Internals.Registrar.Registered.Register(typeof(Microsoft.Maui.EmbeddedFont), typeof(Microsoft.Maui.EmbeddedFontLoader));
#endif

#if IOS || MACCATALYST
                Internals.Registrar.RegisterEffect("Xamarin", "ShadowEffect", typeof(ShadowEffect));
                handlers.AddHandler(typeof(NavigationPage), typeof(Handlers.Compatibility.NavigationRenderer));
                handlers.AddHandler(typeof(TabbedPage), typeof(Handlers.Compatibility.TabbedRenderer));
                handlers.AddHandler(typeof(Shell), typeof(Handlers.Compatibility.ShellRenderer));
                handlers.AddHandler(typeof(FlyoutPage), typeof(Handlers.Compatibility.PhoneFlyoutPageRenderer));
#endif
            });

            builder.AddMauiCompat();
            builder.RemapForControls();

            return(builder);
        }
        static MauiAppBuilder SetupDefaults(this MauiAppBuilder builder)
        {
            builder.ConfigureCompatibilityLifecycleEvents();
            builder.ConfigureImageSourceHandlers();
            builder
            .ConfigureMauiHandlers(handlers =>
            {
                handlers.AddMauiControlsHandlers();
                DependencyService.SetToInitialized();

#if __ANDROID__ || __IOS__ || WINDOWS || MACCATALYST
                handlers.TryAddCompatibilityRenderer(typeof(BoxView), typeof(BoxRenderer));
                handlers.TryAddCompatibilityRenderer(typeof(Entry), typeof(EntryRenderer));
                handlers.TryAddCompatibilityRenderer(typeof(Editor), typeof(EditorRenderer));
                handlers.TryAddCompatibilityRenderer(typeof(Label), typeof(LabelRenderer));
                handlers.TryAddCompatibilityRenderer(typeof(Image), typeof(ImageRenderer));
                handlers.TryAddCompatibilityRenderer(typeof(Button), typeof(ButtonRenderer));
                handlers.TryAddCompatibilityRenderer(typeof(ImageButton), typeof(ImageButtonRenderer));
                handlers.TryAddCompatibilityRenderer(typeof(TableView), typeof(TableViewRenderer));
                handlers.TryAddCompatibilityRenderer(typeof(ListView), typeof(ListViewRenderer));
                handlers.TryAddCompatibilityRenderer(typeof(CollectionView), typeof(CollectionViewRenderer));
                handlers.TryAddCompatibilityRenderer(typeof(CarouselView), typeof(CarouselViewRenderer));
                handlers.TryAddCompatibilityRenderer(typeof(IndicatorView), typeof(IndicatorViewRenderer));
                handlers.TryAddCompatibilityRenderer(typeof(Path), typeof(PathRenderer));
                handlers.TryAddCompatibilityRenderer(typeof(Ellipse), typeof(EllipseRenderer));
                handlers.TryAddCompatibilityRenderer(typeof(Line), typeof(LineRenderer));
                handlers.TryAddCompatibilityRenderer(typeof(Polyline), typeof(PolylineRenderer));
                handlers.TryAddCompatibilityRenderer(typeof(Polygon), typeof(PolygonRenderer));
                handlers.TryAddCompatibilityRenderer(typeof(Shapes.Rectangle), typeof(RectangleRenderer));
                handlers.TryAddCompatibilityRenderer(typeof(RadioButton), typeof(RadioButtonRenderer));
                handlers.TryAddCompatibilityRenderer(typeof(Slider), typeof(SliderRenderer));
                handlers.TryAddCompatibilityRenderer(typeof(WebView), typeof(WebViewRenderer));
                handlers.TryAddCompatibilityRenderer(typeof(SearchBar), typeof(SearchBarRenderer));
                handlers.TryAddCompatibilityRenderer(typeof(Switch), typeof(SwitchRenderer));
                handlers.TryAddCompatibilityRenderer(typeof(SwipeView), typeof(SwipeViewRenderer));
                handlers.TryAddCompatibilityRenderer(typeof(DatePicker), typeof(DatePickerRenderer));
                handlers.TryAddCompatibilityRenderer(typeof(TimePicker), typeof(TimePickerRenderer));
                handlers.TryAddCompatibilityRenderer(typeof(Picker), typeof(PickerRenderer));
                handlers.TryAddCompatibilityRenderer(typeof(Stepper), typeof(StepperRenderer));
                handlers.TryAddCompatibilityRenderer(typeof(ProgressBar), typeof(ProgressBarRenderer));
                handlers.TryAddCompatibilityRenderer(typeof(ScrollView), typeof(ScrollViewRenderer));
                handlers.TryAddCompatibilityRenderer(typeof(ActivityIndicator), typeof(ActivityIndicatorRenderer));
                handlers.TryAddCompatibilityRenderer(typeof(CheckBox), typeof(CheckBoxRenderer));
                handlers.TryAddCompatibilityRenderer(typeof(TabbedPage), typeof(TabbedPageRenderer));
#if !WINDOWS
                handlers.TryAddCompatibilityRenderer(typeof(Shell), typeof(ShellRenderer));
                handlers.TryAddCompatibilityRenderer(typeof(OpenGLView), typeof(OpenGLViewRenderer));
#else
                handlers.TryAddCompatibilityRenderer(typeof(Layout), typeof(LayoutRenderer));
#endif
                handlers.TryAddCompatibilityRenderer(typeof(NavigationPage), typeof(NavigationPageRenderer));
                handlers.TryAddCompatibilityRenderer(typeof(CarouselPage), typeof(CarouselPageRenderer));
                handlers.TryAddCompatibilityRenderer(typeof(Page), typeof(PageRenderer));
                handlers.TryAddCompatibilityRenderer(typeof(FlyoutPage), typeof(FlyoutPageRenderer));
                handlers.TryAddCompatibilityRenderer(typeof(RefreshView), typeof(RefreshViewRenderer));
                handlers.TryAddCompatibilityRenderer(typeof(NativeViewWrapper), typeof(NativeViewWrapperRenderer));
                handlers.TryAddCompatibilityRenderer(typeof(Cell), typeof(CellRenderer));
                handlers.TryAddCompatibilityRenderer(typeof(ImageCell), typeof(ImageCellRenderer));
                handlers.TryAddCompatibilityRenderer(typeof(EntryCell), typeof(EntryCellRenderer));
                handlers.TryAddCompatibilityRenderer(typeof(TextCell), typeof(TextCellRenderer));
                handlers.TryAddCompatibilityRenderer(typeof(ViewCell), typeof(ViewCellRenderer));
                handlers.TryAddCompatibilityRenderer(typeof(SwitchCell), typeof(SwitchCellRenderer));

                // This is for Layouts that currently don't work when assigned to LayoutHandler

                DependencyService.Register <Xaml.ResourcesLoader>();
                DependencyService.Register <NativeBindingService>();
                DependencyService.Register <NativeValueConverterService>();
                DependencyService.Register <Deserializer>();
                DependencyService.Register <ResourcesProvider>();
                DependencyService.Register <Xaml.ValueConverterProvider>();

                // Shimmed renderers go directly to the registrar to load Image Handlers
                Internals.Registrar.Registered.Register(typeof(FileImageSource), typeof(FileImageSourceHandler));
                Internals.Registrar.Registered.Register(typeof(StreamImageSource), typeof(StreamImagesourceHandler));
                Internals.Registrar.Registered.Register(typeof(UriImageSource), typeof(ImageLoaderSourceHandler));
                Internals.Registrar.Registered.Register(typeof(FontImageSource), typeof(FontImageSourceHandler));


                Internals.Registrar.Registered.Register(typeof(Microsoft.Maui.EmbeddedFont), typeof(Microsoft.Maui.EmbeddedFontLoader));
#endif

#if __IOS__ || MACCATALYST
                Internals.Registrar.RegisterEffect("Xamarin", "ShadowEffect", typeof(ShadowEffect));
#endif

                // Update the mappings for IView/View to work specifically for Controls
                VisualElement.RemapForControls();
                Label.RemapForControls();
                Button.RemapForControls();
            });

            builder.AddMauiCompat();

            return(builder);
        }