maui icon indicating copy to clipboard operation
maui copied to clipboard

Auto theme change doesn't behave as expected on .NET 7 whereas the same works fine on .NET 6

Open egvijayanand opened this issue 2 years ago • 1 comments

Description

The styling in the default .NET MAUI app project template is loaded with AppThemeBinding constructs to detect theme change and behave accordingly like updating the back color, text color, and so on ...

This works fine on .NET 6 whereas, on .NET 7, it doesn't work as expected. The theme change is not honored.,

Note: Have selected Unknown/Other as the Version with the bug since .NET 7 (7.0.49) is not appearing in that list.

Have selected Unknown/Other as the Last version that worked well since SR7 (6.0.547) is not appearing in that list.

Steps to Reproduce

  1. Create two app instances (one with a target framework as .NET 6 and the other with .NET 7) from the default app template
  2. Build the app and launch it on Android/Windows (I haven't tried it on other platforms)
  3. Update the OS theme so that the app responds to that change (Light -> Dark or vice versa)
  4. App responds to this scenario fine on .NET 6 whereas the same fails on .NET 7

Link to public reproduction project repository

The default template itself is sufficient.

Version with bug

Unknown/Other (please specify)

.NET 7 GA (7.0.49)

Last version that worked well

Unknown/Other

.NET 6 SR7 (6.0.547)

Affected platforms

Android, Windows, I was not able test on other platforms

Affected platform versions

Android 33.0, Windows SDK 10.0.19041

Did you find any workaround?

So far none, need to explore further.

Relevant log output

No response

egvijayanand avatar Nov 11 '22 22:11 egvijayanand

On an additional note, even on .NET 6, the auto theme change works only once. Then it doesn't respond.

egvijayanand avatar Nov 11 '22 23:11 egvijayanand

Hi @egvijayanand. We have added the "s/needs-repro" label to this issue, which indicates that we require steps and sample code to reproduce the issue before we can take further action. Please try to create a minimal sample project/solution or code samples which reproduce the issue, ideally as a GitHub repo that we can clone. See more details about creating repros here: https://github.com/dotnet/maui/blob/main/.github/repro.md

This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

ghost avatar Nov 15 '22 19:11 ghost

Could be fixed by https://github.com/dotnet/maui/pull/11200

jsuarezruiz avatar Nov 15 '22 19:11 jsuarezruiz

This issue is getting simulated with the default template itself, without requiring any changes.

dotnet new maui -f net7.0
dotnet new maui -f net6.0

egvijayanand avatar Nov 15 '22 19:11 egvijayanand

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

ghost avatar Nov 23 '22 19:11 ghost

@davidortinau Moving critical issues like this to the backlog defeats the whole purpose of reporting issues and the stability of the product becomes questionable.

egvijayanand avatar Nov 23 '22 19:11 egvijayanand

Yeah, I'm puzzled how this was overlooked in the release, I have been pounding my head against the wall for several days being sure it is something with my code, until I realized that even with a fresh template 6 works while 7 does not...

jaredrsowers avatar Dec 03 '22 15:12 jaredrsowers

Confirmed the AppThemeBinding is working also inconsistently on iOS. Sample project either the new 7.0 template or https://github.com/dotnet-presentations/dotnet-maui-workshop/tree/main/Finish.

I have to close and restart the app to get some colors to update, and at runtime some views update while others on the same screen do not.

https://user-images.githubusercontent.com/41873/205763031-a740b51e-3663-4362-81a8-29a6cd75a309.mp4

davidortinau avatar Dec 05 '22 23:12 davidortinau

I have this issue too. I think it solved in #11200 but still not migrated yet.

mostafagamal68 avatar Dec 07 '22 13:12 mostafagamal68

@davidortinau Moving critical issues like this to the backlog defeats the whole purpose of reporting issues and the stability of the product becomes questionable.

Totally, 100% agree. Our business has gone all in on Xamarin in the last 4-5 years with two heavily used apps in production today (40k active installs) and Microsoft has us scared out of our skin with stuff like this! We're trying to port some of our internal libraries to MAUI as a test to see the viability of migrating from Xamarin due to the sorry state of Xamarin's support and on day 1 I've noticed that themed bindings nor the app theme callback is not being fired at all on the default template?! This is basic, basic stuff which should work out of the box in V1. Xamarin has been a mess for a while now, but the excuse in the last year or so has been lack of support due to MAUI, but obviously that excuse doesn't wash with MAUI itself.

We're just barely clinging on to Xamarin/MAUI due to the fact that we have so much existing code invested in the ecosystem and our developers love C#, but it seems that with each month that goes by the scales tip a little further towards us biting the bullet, dumping the lot and taking the proverbial "life boat" to another framework with more stable functionality and support.

This is coming from a business where we are 100% a Microsoft shop (except for React/Redux on web).

I'm probably just shouting into the wind, but please don't treat this as badly as Xamarin!!

RobTF avatar Dec 10 '22 10:12 RobTF

The marked answer from this thread can still be used in MAUI: How to Check For Dark Mode in Xamarin.Forms

borrmann avatar Jan 30 '23 14:01 borrmann

Any updates?

scriptBoris avatar Feb 27 '23 15:02 scriptBoris

I tried adding some code to manually switch the UserAppTheme. What I noticed was that the control colors were not correctly updating. The only way for all the colors to update correctly was to kill the app and launch it again.

Cybrosys avatar Feb 27 '23 21:02 Cybrosys

Looks these were both fixed by https://github.com/dotnet/maui/pull/11200 as @mostafagamal68 mentioned! From running the sample project inside main of Maui, I get the below recordings.

@jsuarezruiz can you approve?

https://user-images.githubusercontent.com/50846373/228677154-a47861db-cd82-45bd-85c8-ae416afc9004.mov

https://user-images.githubusercontent.com/50846373/228677161-43613ab7-b1a8-4968-8d04-17ccdddcc6d3.mov

tj-devel709 avatar Mar 29 '23 22:03 tj-devel709

Yes, must be fixed by https://github.com/dotnet/maui/pull/11200 ios-appareance

Closing for now this issue, but let us know if find any detail and can reopen it etc.

jsuarezruiz avatar Apr 03 '23 10:04 jsuarezruiz

@jsuarezruiz / @samhouts - this problem still persists on latest windows 11, .net with latest stable visual studio and latest maui workloads under android 33. The event is still only being fired once and a whole bunch of controls do not react to the changes at all.

grafik

grafik

https://user-images.githubusercontent.com/2254304/231768963-47f44410-fd93-45aa-a803-6a9414c5de76.mp4

EDIT: This also affects latest iOS builds - the event is not executed correctly and some elements still do not react correctly to theme changes. The on resume behaviour might also be broken, but hasn't been tested by me yet

UkeHa avatar Apr 13 '23 13:04 UkeHa

@jsuarezruiz / @samhouts will this issue be resolved in one of the coming releases and if so, will it be backported to .net7?

UkeHa avatar Apr 25 '23 13:04 UkeHa

I am unable to reproduce this using the default maui template with .NET MAUI 7.0.81

VS Info: https://gist.github.com/mattleibow/c59cd29ca1e7a164e65f463fb91a8b8e

https://user-images.githubusercontent.com/1096616/235800130-1b183ecb-9608-4544-82b7-d74b8fb6ac84.mp4

https://user-images.githubusercontent.com/1096616/235800156-97e47254-8055-421b-a4f0-112b51768557.mp4

https://user-images.githubusercontent.com/1096616/235800166-c88c195d-71c8-450e-ab9c-b586c56307aa.mp4

I think if this is still happening, there is something else that is going wrong. Can you attach a sample that you have (even if it is just the default project) and then a binlog that was used to build it: https://github.com/xamarin/xamarin-macios/wiki/Diagnosis

Other info that will help is the android device/simulator, API version and anything else that you can see.

I think I used the same emulator as you as my VS just updated to the latest stable and this was the default emulator that came with the wizard.

mattleibow avatar May 02 '23 22:05 mattleibow

Hi @egvijayanand @UkeHa. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

ghost avatar May 02 '23 22:05 ghost

@mattleibow as of the latest VS (17.5.5) i am no longer able to reproduce it. Both in the sample project as well as in our production software. Therefore this issue can be closed.

UkeHa avatar May 05 '23 07:05 UkeHa