xamarin / Xamarin.Forms

Xamarin.Forms is no longer supported. Migrate your apps to .NET MAUI.
https://aka.ms/xamarin-upgrade
Other
5.63k stars 1.87k forks source link

[Bug] [iOS] Navigation bar doesn't load correct value if they are set via DynamicResource #9373

Open mduchev opened 4 years ago

mduchev commented 4 years ago

Description

The navigation bar doesn't gets its styles correctly upon start-up of the app if the styles are retrieved via dynamic styles

Steps to Reproduce

  1. Create a demo project
  2. Add 3 dictionary styles - one with default values, one with light- and one with dark-specific styles (colors)
  3. Merge the dictionaries accordingly - both Light & Dark should have merged reference with the default styles
  4. Set the app styles to be by default the Light styles
  5. Create demo wrappers for navigation page and set its styles to be taken dynamically from the appropriate dictionary (light or dark)
  6. Create code for obtaining and setting application's theme depending of the OS one
  7. Start the project with Dark theme enabled

Note: See the attached project. Everything has already been set-up there, for reference.

Expected Behavior

The Navigation bar to be with the styles according to the device theme (if Theme is dark, then the Navigation bar's background color should be black and text color - white and vice-versa)

Actual Behavior

The navigation bar changes its colors if we switch the theme runtime, but on app start-up the styles are incorrect, even though we set the Theme correctly.

Basic Information

Workaround

There is a workaround - if we force the PropertyChanged on BarBackgroundColor & BarTextColor in the code-behind of the navigation page (on the OnAppearing), then it works as expected. See lines 23 & 24 in DemoNavigationPage.xaml.cs from the demo project.

vniehues commented 4 years ago

This has been open for a very long time now and to me it seems like this issue is present in some builds but not in others... It was fixed, i uploaded my app and now after updating the xamarin nuget it's back.

@mduchev Your workaround saved my ass today! Thank you! :)