Remove MAUI internal API usage#3251
Conversation
|
Follow-up verification after cross-checking #3097 item-by-item:
|
There was a problem hiding this comment.
Pull request overview
Removes .NET MAUI internal API / implementation-detail dependencies across CommunityToolkit.Maui so MAUI can drop InternalsVisibleTo for the toolkit in .NET 11, using public MAUI APIs or toolkit-owned replacements instead.
Changes:
- Reworks AppTheme binding/resource resolution and adds a toolkit dispatcher helper to avoid internal XAML/dispatcher APIs.
- Migrates multiple controls/behaviors (e.g., AvatarView, Touch/ImageTouch, IconTintColor, SemanticOrderView, Keyboard helpers) off internal MAUI interfaces/properties.
- Updates MediaElement iOS/macOS controller discovery to avoid internal handler/controller access; adjusts and expands unit tests accordingly.
Reviewed changes
Copilot reviewed 33 out of 33 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
| src/CommunityToolkit.Maui/Views/WrapperControl.windows.cs | Removes internal handler access for Windows wrapper layout invalidation. |
| src/CommunityToolkit.Maui/Views/Expander/Expander.shared.cs | Safer header/content replacement (casts/removes only when old value is an IView). |
| src/CommunityToolkit.Maui/Views/AvatarView.shared.cs | Replaces internal element-backed bindables/interfaces with toolkit-defined bindable properties. |
| src/CommunityToolkit.Maui/Primitives/BindablePropertySourceGeneratorPrimitives/AttachedBindablePropertyAttribute.shared.cs | Doc comment updated to avoid referencing a long API signature. |
| src/CommunityToolkit.Maui/Layouts/StateContainer/StateContainer.shared.cs | Replaces internal helper usage in animation sequencing logic. |
| src/CommunityToolkit.Maui/ImageSources/GravatarImageSource.shared.cs | Removes reliance on MAUI-internal cancellation token source; adds local CTS coordination. |
| src/CommunityToolkit.Maui/Extensions/HttpClientExtensions.shared.cs | Replaces MAUI-internal StreamWrapper usage with HttpClient + response-owned stream wrapper. |
| src/CommunityToolkit.Maui/Extensions/DispatcherExtensions.shared.cs | Adds toolkit-owned dispatcher helpers to replace internal dispatcher extensions. |
| src/CommunityToolkit.Maui/Extensions/AppThemeResourceExtension.shared.cs | Replaces internal resources provider/source APIs; adds target-property-aware binding selection. |
| src/CommunityToolkit.Maui/Extensions/AppThemeObjectExtensions.shared.cs | Uses target-property-aware AppTheme binding to preserve dynamic resources where possible. |
| src/CommunityToolkit.Maui/Essentials/AppTheme/AppThemeObject.shared.cs | Reimplements AppTheme binding using public Binding/MultiBinding + converter logic. |
| src/CommunityToolkit.Maui/Behaviors/UserStoppedTypingBehavior.shared.cs | Switches to toolkit dispatcher helper instead of internal dispatcher usage. |
| src/CommunityToolkit.Maui/Behaviors/PlatformBehaviors/Touch/GestureManager.shared.cs | Removes internal ImageElement usage; updates dispatch + animation cancellation handling. |
| src/CommunityToolkit.Maui/Behaviors/PlatformBehaviors/ImageTouch/ImageTouchBehavior.shared.cs | Updates source switching logic to avoid internal image element bindables. |
| src/CommunityToolkit.Maui/Behaviors/PlatformBehaviors/IconTintColor/IconTintColorBehavior.windows.cs | Replaces internal image element source access with public Image/ImageButton source handling. |
| src/CommunityToolkit.Maui/Behaviors/PlatformBehaviors/IconTintColor/IconTintColorBehavior.macios.cs | Avoids internal IImageElement by pattern-matching on Image/ImageButton. |
| src/CommunityToolkit.Maui/Behaviors/EventToCommandBehavior.shared.cs | Replaces internal [Preserve] usage with trimming-friendly [DynamicDependency]. |
| src/CommunityToolkit.Maui/Animations/FadeAnimation.shared.cs | Adds suppression around non-cancellation-aware MAUI animation APIs (public surface only). |
| src/CommunityToolkit.Maui/Alerts/Snackbar/Snackbar.windows.cs | Updates usings to align with toolkit-owned extensions. |
| src/CommunityToolkit.Maui/Alerts/Snackbar/Snackbar.shared.cs | Replaces internal MAUI weak-reference helper usage with toolkit-owned equivalent. |
| src/CommunityToolkit.Maui.UnitTests/Views/AvatarView/AvatarViewInterfaceTests.cs | Removes tests that depended on internal MAUI interfaces. |
| src/CommunityToolkit.Maui.UnitTests/Mocks/MockResourcesProvider.cs | Removes internals-based mock used for system resources provider registration. |
| src/CommunityToolkit.Maui.UnitTests/Mocks/MockApplication.cs | Removes dependency service registration that required MAUI internals. |
| src/CommunityToolkit.Maui.UnitTests/Essentials/AppThemeTests.cs | Adds coverage for AppTheme dynamic-resource preservation behavior. |
| src/CommunityToolkit.Maui.MediaElement/Views/MauiMediaElement.macios.cs | Removes reflection/internal handler usage; finds parent UIViewController via responder chain. |
| src/CommunityToolkit.Maui.MediaElement/Extensions/PageExtensions.shared.cs | Uses public navigation/shell APIs to find the current page. |
| src/CommunityToolkit.Maui.Core/Views/SemanticOrderView/MauiSemanticOrderView.windows.cs | Removes dependency on platform handler interface for TabIndex ordering. |
| src/CommunityToolkit.Maui.Core/Views/SemanticOrderView/MauiSemanticOrderView.tizen.cs | Updates comment after removing internal handler dependency. |
| src/CommunityToolkit.Maui.Core/Views/SemanticOrderView/MauiSemanticOrderView.macios.cs | Removes dependency on platform handler interface for accessibility ordering. |
| src/CommunityToolkit.Maui.Core/Views/SemanticOrderView/MauiSemanticOrderView.android.cs | Removes dependency on platform handler interface for view ordering. |
| src/CommunityToolkit.Maui.Core/Platform/KeyboardExtensions/KeyboardExtensions.shared.cs | Removes platform-handler-interface dependency; relies on public IViewHandler. |
|
Pushed follow-up commit
For James's #3222: I did not pull/cherry-pick that PR into this one because it is a broader MediaElement behavior fix with handler/test/playback-control changes beyond the IVT cleanup. This PR keeps the scoped fallback needed for the review comment. If #3222 lands first we can rebase this PR and drop/resolve the small overlap; if this PR lands first, #3222 can rebase on top. Focused local validation after the commit:
|
25faf1e to
7e83015
Compare
7f7b1a8 to
a16ebcb
Compare
Remove CommunityToolkit.Maui dependencies on MAUI internal APIs and implementation details so MAUI can remove InternalsVisibleTo for the toolkit without breaking supported package builds. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Replace MAUI internal RequireFontManager calls with public MauiContext service resolution. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Fix review findings from the MAUI internals cleanup pass: wait for each StateContainer child animation independently, dispose failed HTTP responses, use full animation durations, restrict ImageTouch to supported image controls, preserve the MediaElement view-controller fallback, and align AvatarView default font size with MAUI semantics. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
35a2b2b to
5ebeab6
Compare
7c70bc6 to
6919f8b
Compare
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
TheCodeTraveler
left a comment
There was a problem hiding this comment.
Thanks Gerald!
Just FYI - I had planned on doing this work alongside our release supporting .NET 11 in November. I can review this PR and mark it as approved, however we'll wait to merge it alongside the Add .NET 11 Support PR I'll be creating in a few months. I'll keep an eye on it to ensure there's no merge conflicts from future PRs.
For this PR, just assume that it is only targeting .NET 11.
Please also remove all of the backwards compatibility to .NET 10, eg #if NET11_0_OR_GREATER. We won't be supporting .NET 10 once we migrate to .NET 11.
It's ok if this PR has failing builds for now because it's targeting .NET 11. I'll fix all that stuff when I do the work to migrate to .NET 11.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Build the source generator benchmark project serially and run it with --no-build to avoid CI file-lock races in shared source-generator outputs. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
@TheCodeTraveler This has been rebased onto the latest main and validated. Could we please prioritize reviewing and merging this sooner rather than later? We expect to merge the corresponding .NET MAUI 11 change that removes the Toolkit InternalsVisibleTo access soon, so landing this first will help ensure Toolkit users can move to .NET MAUI 11 from day one without regressions. |
Use the .NET 11 cancellation-aware MAUI animation overloads directly and remove the conditional/net10 WaitAsync fallback paths from the internals-removal work. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
@TheCodeTraveler Updated per the .NET 11-only direction in |
Description of Change
Removes CommunityToolkit.Maui dependencies on MAUI internal APIs and implementation details so dotnet/maui can remove the
InternalsVisibleToentries for CommunityToolkit.Maui in .NET 11.This migrates the toolkit to public MAUI APIs or toolkit-owned replacements across AvatarView, AppTheme helpers, Image/Touch behaviors, Gravatar image loading, StateContainer, Expander, IconTintColorBehavior, Keyboard/SemanticOrder helpers, WrapperControl, MediaElement controller lookup, and related tests.
This should be safe to merge ahead of .NET 11: the changes do not intentionally use .NET 11-specific APIs, and the package projects were restored/built successfully for
net10.0against the repo default MAUI 10 package version (10.0.60). Getting this merged before .NET 11 lands should let users upgrade from day 1 once dotnet/maui removes the IVTs.Maintainer note: this touches behavior-sensitive areas where the toolkit previously depended on MAUI implementation details. Toolkit maintainers/reviewers should own the final correctness and compatibility validation before merging, especially for platform/runtime behavior that cannot be fully proven from this Windows environment.
Linked Issues
InternalsVisibleTofor the .NET MAUI Toolkits inMicrosoft.Maui.Controls v10.0.40Has BrokenCommunityToolkit.MauiandCommunityToolkit.Maui.Markupdotnet/maui#34048PR Checklist
mainat time of PRAdditional information
Validation performed:
Microsoft.Maui.(Controls.)?Internals,.Internals.,Internals.,AppThemeBindingIElementController,NavigationProxy,IShellSectionController,FontElement,TextElement,ImageElement,StreamWrapper,IResourcesProvider,InvalidateMeasureInternal,InvalidationTrigger,TryGetValueAndSourceGetField(,GetProperty(,GetMethod(,BindingFlagsdotnet restore src\CommunityToolkit.Maui.slnx --no-cachedotnet build src\CommunityToolkit.Maui.slnx --no-restore -v minimaldotnet build src\CommunityToolkit.Maui\CommunityToolkit.Maui.csproj -c Release -f net10.0 --no-restorenet10.0against MAUI10.0.60:CommunityToolkit.Maui.CoreCommunityToolkit.MauiCommunityToolkit.Maui.CameraCommunityToolkit.Maui.MediaElementCommunityToolkit.Maui.MapsAppThemeTestsAvatarViewInterfaceTestsImageTouchBehaviorTestsTouchBehaviorTests11.0.0-ci.pr34070.6.26324.9) passed for feasible package builds on this machine.Environment limitations:
AppThemeObject<T>.GetBinding()targetless overload cannot fully preserveDynamicResourceExtensionvalues using public MAUI APIs because binding converters do not expose the targetBindableProperty. The target-aware toolkit extension methods andAppThemeResourceExtensionpreserve dynamic-resource behavior where the target property is available.