-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create One Stop Shop UseMauiControls #1157
Merged
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
9ba1d0a
Create One Stop UseMauiControls
PureWeen 782e2f4
- cleanup
PureWeen 24ec5b8
- add graphics view
PureWeen 5fe06ed
- add ios
PureWeen 83d8d6e
- winui fixes
PureWeen 50a0cbe
- make public
PureWeen 110ae0b
- enable shell handler on winui
PureWeen ef14c37
- shell winui
PureWeen 725f569
- clean up
PureWeen 28a67ff
Update DependencyService.cs
PureWeen 784bd53
- fix unit test
PureWeen bd4784d
Update Device.cs
PureWeen bf7f965
- fix xaml tests
PureWeen e83065d
- fix xaml reference for net6
PureWeen e9e236d
- fix tests
PureWeen 19ccdfd
- fix test and register current stubs
PureWeen 872cbc5
- fix startup
PureWeen 3c7c938
- fix namespace
PureWeen 329f0f7
Update HostBuilderAppTests.cs
PureWeen f2d3b7e
Update HostBuilderHandlerTests.cs
PureWeen a2d6a80
- change back to UseMauiApp
PureWeen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
151 changes: 151 additions & 0 deletions
151
src/Compatibility/Core/src/AppHostBuilderExtensions.Controls.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
#nullable enable | ||
using System; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Hosting; | ||
using Microsoft.Maui.Controls.Compatibility; | ||
|
||
#if __ANDROID__ | ||
using Microsoft.Maui.Controls.Compatibility.Platform.Android; | ||
using Microsoft.Maui.Controls.Compatibility.Platform.Android.AppCompat; | ||
using FrameRenderer = Microsoft.Maui.Controls.Compatibility.Platform.Android.FastRenderers.FrameRenderer; | ||
using LabelRenderer = Microsoft.Maui.Controls.Compatibility.Platform.Android.FastRenderers.LabelRenderer; | ||
using ImageRenderer = Microsoft.Maui.Controls.Compatibility.Platform.Android.FastRenderers.ImageRenderer; | ||
using ButtonRenderer = Microsoft.Maui.Controls.Compatibility.Platform.Android.FastRenderers.ButtonRenderer; | ||
#elif WINDOWS | ||
using Microsoft.Maui.Controls.Compatibility.Platform.UWP; | ||
using BoxRenderer = Microsoft.Maui.Controls.Compatibility.Platform.UWP.BoxViewBorderRenderer; | ||
using CellRenderer = Microsoft.Maui.Controls.Compatibility.Platform.UWP.TextCellRenderer; | ||
using Deserializer = Microsoft.Maui.Controls.Compatibility.Platform.UWP.WindowsSerializer; | ||
using ResourcesProvider = Microsoft.Maui.Controls.Compatibility.Platform.UWP.WindowsResourcesProvider; | ||
#elif __IOS__ | ||
using Microsoft.Maui.Controls.Compatibility.Platform.iOS; | ||
using WebViewRenderer = Microsoft.Maui.Controls.Compatibility.Platform.iOS.WkWebViewRenderer; | ||
using NavigationPageRenderer = Microsoft.Maui.Controls.Compatibility.Platform.iOS.NavigationRenderer; | ||
using TabbedPageRenderer = Microsoft.Maui.Controls.Compatibility.Platform.iOS.TabbedRenderer; | ||
using FlyoutPageRenderer = Microsoft.Maui.Controls.Compatibility.Platform.iOS.PhoneFlyoutPageRenderer; | ||
using RadioButtonRenderer = Microsoft.Maui.Controls.Compatibility.Platform.iOS.Platform.DefaultRenderer; | ||
#endif | ||
|
||
using Microsoft.Maui.Hosting; | ||
using Microsoft.Maui.Controls.Shapes; | ||
|
||
namespace Microsoft.Maui.Controls.Hosting | ||
{ | ||
public static class AppHostBuilderExtensions | ||
{ | ||
public static IAppHostBuilder UseMauiApp<TApp>(this IAppHostBuilder builder) | ||
where TApp : class, IApplication | ||
{ | ||
builder.ConfigureServices((context, collection) => | ||
{ | ||
collection.AddSingleton<IApplication, TApp>(); | ||
}); | ||
|
||
builder.SetupDefaults(); | ||
return builder; | ||
} | ||
|
||
public static IAppHostBuilder UseMauiApp<TApp>(this IAppHostBuilder builder, Func<IServiceProvider, TApp> implementationFactory) | ||
where TApp : class, IApplication | ||
{ | ||
builder.ConfigureServices((context, collection) => | ||
{ | ||
collection.AddSingleton<IApplication>(implementationFactory); | ||
}); | ||
|
||
builder.SetupDefaults(); | ||
return builder; | ||
} | ||
|
||
static IAppHostBuilder SetupDefaults(this IAppHostBuilder builder) | ||
{ | ||
builder | ||
.ConfigureMauiHandlers(handlers => | ||
{ | ||
handlers.AddMauiControlsHandlers(); | ||
DependencyService.SetToInitialized(); | ||
|
||
#if __ANDROID__ || __IOS__ || WINDOWS || MACCATALYST | ||
|
||
Forms.RenderersRegistered(); | ||
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(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(Frame), typeof(FrameRenderer)); | ||
handlers.TryAddCompatibilityRenderer(typeof(CheckBox), typeof(CheckBoxRenderer)); | ||
#if !WINDOWS | ||
handlers.TryAddCompatibilityRenderer(typeof(TabbedPage), typeof(TabbedPageRenderer)); | ||
handlers.TryAddCompatibilityRenderer(typeof(Shell), typeof(ShellRenderer)); | ||
handlers.TryAddCompatibilityRenderer(typeof(OpenGLView), typeof(OpenGLViewRenderer)); | ||
#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)); | ||
DependencyService.Register<Xaml.ResourcesLoader>(); | ||
DependencyService.Register<NativeBindingService>(); | ||
DependencyService.Register<NativeValueConverterService>(); | ||
DependencyService.Register<Deserializer>(); | ||
DependencyService.Register<ResourcesProvider>(); | ||
DependencyService.Register<Xaml.ValueConverterProvider>(); | ||
#endif | ||
|
||
#if __IOS__ || MACCATALYST | ||
Internals.Registrar.RegisterEffect("Xamarin", "ShadowEffect", typeof(ShadowEffect)); | ||
#endif | ||
}) | ||
.ConfigureServices(ConfigureNativeServices); | ||
|
||
|
||
return builder; | ||
} | ||
|
||
static void ConfigureNativeServices(HostBuilderContext arg1, IServiceCollection arg2) | ||
{ | ||
#if WINDOWS | ||
if (!UI.Xaml.Application.Current.Resources.ContainsKey("MauiControlsPageControlStyle")) | ||
{ | ||
var myResourceDictionary = new Microsoft.UI.Xaml.ResourceDictionary(); | ||
myResourceDictionary.Source = new Uri("ms-appx:///Microsoft.Maui.Controls/Platform/Windows/Styles/Resources.xbf"); | ||
Microsoft.UI.Xaml.Application.Current.Resources.MergedDictionaries.Add(myResourceDictionary); | ||
} | ||
#endif | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be using FormsCompatBuilder?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had this initially using FormsCompatBuilder and it wasn't working because FormsCompatBuilder only runs through and registers the
PendingRenderers
if you callUseFormsCompat
but I changed all this code so we're no longer calling 'UseFormsCompat' anymoreI don't totally understand the whole use case for
FormsCompatBuilder
and why it needs the wholePendingRenderers
thing though