-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Rework use of ObtainStyledAttributes so we can enable AndroidLinkResources
#4912
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
Conversation
254e338
to
48a7fd1
Compare
src/Controls/src/Core/Platform/Android/Extensions/ToolbarExtensions.cs
Outdated
Show resolved
Hide resolved
src/Core/AndroidNative/maui/src/main/java/com/microsoft/maui/ContextHelper.java
Outdated
Show resolved
Hide resolved
src/Core/AndroidNative/maui/src/main/java/com/microsoft/maui/ContextHelper.java
Outdated
Show resolved
Hide resolved
48a7fd1
to
2607b70
Compare
@@ -0,0 +1,3 @@ | |||
<resources> | |||
<string name="maui_empty_unused"></string> |
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.
Yeah, if we have to put one, maybe it's worth putting library_name=.NET MAUI
? I feel like I remember some convention for that.
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.
And a comment, saying we need at least 1 resource.
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.
The problem with using library_name
is that it might be used on other libraries. And depending on the order of import you might override something since the resources will overlay on top of each other.
I would prefer this be unique if possible so we don't trip over any existing resources.
/azp run |
Azure Pipelines successfully started running 2 pipeline(s). |
src/Core/AndroidNative/maui/src/main/java/com/microsoft/maui/PlatformInterop.java
Outdated
Show resolved
Hide resolved
src/Core/AndroidNative/maui/src/main/java/com/microsoft/maui/PlatformInterop.java
Outdated
Show resolved
Hide resolved
/azp run |
Commenter does not have sufficient privileges for PR 4912 in repo dotnet/maui |
/azp run |
Azure Pipelines successfully started running 2 pipeline(s). |
var a = TintTypedArray.ObtainStyledAttributes(nativeToolbar.Context?.GetThemedContext(), null, Resource.Styleable.Toolbar, Resource.Attribute.toolbarStyle, 0); | ||
_defaultTitleTextColor = a.GetColorStateList(Resource.Styleable.Toolbar_titleTextColor); | ||
a.Recycle(); | ||
var context = nativeToolbar.Context?.GetThemedContext (); | ||
_defaultTitleTextColor = PlatformInterop.GetColorStateListForToolbarStyleableAttribute (context, | ||
Resource.Attribute.toolbarStyle, Resource.Styleable.Toolbar_titleTextColor); |
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.
@PureWeen what control should we test for this? Would we just need to test changing the toolbar color in a template using Shell?
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.
This behavior is currently in place for non-shell apps. Non-shell apps only ever have a single Toolbar so the purpose of this code was to reset the toolbar
back to the default if you navigate away to a page that has a color set and then back to one that doesn't.
So the test here would be to use a navigation page and then push to a page that changes toolbar styles and then pop back to the page which is default, or setup navigation pages inside some tabbedpages and switch between the tabs.
d5a2f85
to
3be9874
Compare
…urces Xamarin Android has a build property `AndroidLinkResources` which allows any unused `Resource.designer.cs` code to be removed during the Link process. In order to use this however we need to make sure that we do NOT use any of the `int[]` fields from the `Resource.designer.cs` in our C# code. Currently we are using `Resource.Styleable.Toolbar` when we call `ObtainStyledAttributes`. If we do not change this code the app will crash when using `AndroidLinkResources` because the underlying field `Resource.Styleable.Toolbar` will have been removed. So lets move the code which obtains the `ColorStateList` to java and provide a method which will then be bound as part of the `maui.aar` C# binding. This way we can remove the C# usage of `Resource.Styleable.Toolbar` and turn on `AndroidLinkResources`. As a result we see a small improvement in startup times. | Before | After | Δ | Notes | | ------- | ------- | -------- | ------------------------------------ | | 469.850 | 468.550 | -0.28% ✓ | defaults; 32-bit build | | 478.650 | 466.500 | -2.54% ✓ | defaults; profiled AOT; 32-bit build | | 490.450 | 480.450 | -2.04% ✓ | defaults; full AOT; 32-bit build | | 484.650 | 476.650 | -1.65% ✓ | defaults; 64-bit build | | 480.450 | 468.250 | -2.54% ✓ | defaults; profiled AOT; 64-bit build | | 477.800 | 471.550 | -1.31% ✓ | defaults; full AOT; 64-bit build | as well as a small reduction in package size. Size difference in bytes ([*1] apk1 only, [*2] apk2 only): - 52 lib/armeabi-v7a/libaot-Xamarin.Kotlin.StdLib.Common.dll.so - 52 lib/x86/libaot-Xamarin.Kotlin.StdLib.Common.dll.so - 72 lib/arm64-v8a/libaot-Xamarin.Kotlin.StdLib.Common.dll.so - 80 lib/x86_64/libaot-Xamarin.Kotlin.StdLib.Common.dll.so - 4,096 lib/arm64-v8a/libaot-Microsoft.Maui.Controls.dll.so - 4,096 lib/arm64-v8a/libaot-Microsoft.Maui.dll.so - 4,096 lib/armeabi-v7a/libaot-Microsoft.Maui.Controls.dll.so - 4,096 lib/armeabi-v7a/libaot-Microsoft.Maui.dll.so - 4,096 lib/x86/libaot-Microsoft.Maui.Controls.dll.so - 24,576 lib/x86_64/libaot-BasicMauiApp.dll.so - 28,672 lib/arm64-v8a/libaot-BasicMauiApp.dll.so - 28,672 lib/armeabi-v7a/libaot-BasicMauiApp.dll.so - 28,672 lib/x86/libaot-BasicMauiApp.dll.so - 170,446 assemblies/assemblies.blob Summary: - 170,446 Other entries -1.68% (of 10,148,006) + 0 Dalvik executables 0.00% (of 11,463,896) - 131,328 Shared libraries -0.27% (of 47,970,224) - 200,704 Package size difference -0.66% (of 30,356,729)
dab241e
to
90d50e0
Compare
AndroidLinkResources
AndroidLinkResources
/azp run |
Azure Pipelines successfully started running 2 pipeline(s). |
Fixes #4889
Xamarin Android has a build property
AndroidLinkResources
which allowsany unused
Resource.designer.cs
code to be removed during the Linkprocess. In order to use this however we need to make sure that we do
NOT use any of the
int[]
fields from theResource.designer.cs
inour C# code.
Currently we are using
Resource.Styleable.Toolbar
when we callObtainStyledAttributes
. If we do not change this code the app willcrash when using
AndroidLinkResources
because the underlying fieldResource.Styleable.Toolbar
will have been removed.So lets move the code which obtains the
ColorStateList
to java andprovide a method which will then be bound as part of the
maui.aar
C#binding. This way we can remove the C# usage of
Resource.Styleable.Toolbar
and turn on
AndroidLinkResources
.As a result we see a small improvement in startup times.
as well as a small reduction in package size.