Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

[Bug] Android configuration updates and window resizing broken when using CreateConfigurationContext #15837

Open
wollac11 opened this issue Nov 16, 2023 · 0 comments
Labels
s/unverified New report that has yet to be verified t/bug 🐛

Comments

@wollac11
Copy link

wollac11 commented Nov 16, 2023

Description

After updating to Xamarin.Forms SR15 or SR16, certain UI elements and dialogs do not properly resize if the application window size changes during runtime. This seems to be because the display size in the Android configuration object is not updated.

I found that this issue only occurs if you call CreateConfigurationContext(Configuration), but this was not an issue on older versions (and it is a fairly common technique to override some Android config values).

I suspect this may be an issue somewhere in Xamarin.Android but I experienced it in a Xamarin.Forms application after upgrading (likely because newer XF versions depend on newer Android binding libs).

Steps to Reproduce

  1. Override AttachBaseContext in your Android MainActivity
  2. Create a new configuration context (using CreateConfigurationContext) and pass it to the base implementation of AttachBaseContext
  3. Run the app and attempt to resize the app window after it has loaded (freeform multi-window and split screen are the best for demonstrating this but even simply rotating will do)
  4. Create some alert dialogs, use size triggers and/or inspect the screen size values from Context.Resources.Configuration or Xamarin.Forms.Device.Info.ScaledScreenSize (comparing before and after resizing)

OR

  1. Download my simple repro app
  2. Extract, build and run the app on an Android device
  3. Resize the app window and watch for the alert dialog (it should trigger automatically on any app configuration change)
  4. Add a breakpoint at the end of OnConfigurationChanged (in MainActivity) and evaluate the screen sizes in newConfig and currentConfig and compare them

Expected Behavior

  • Dialogs are sized to fit the display
  • The Height and Width values in Xamarin.Forms.Device.Info.ScaledScreenSize are updated to match the new window size
  • The ScreenHeightDp and ScreenWidthDp in Context.Resources.Configuration are updated to match the new window size

Actual Behavior

  • Dialogs are cropped if the display is sized significantly smaller than the original size on app startup (or dialogs are too small if the display is widened relative to the startup size)
  • Height and Width values in Xamarin.Forms.Device.Info.ScaledScreenSize do not update
  • ScreenHeightDp and ScreenWidthDp in Context.Resources.Configuration do not update (but the new config object passed on OnConfigurationChanged does hold the correctly updated values).

Basic Information

  • Version with issue: 5.0.02612 / 5.0.02622
  • Last known good version: 5.0.2578
  • Platform Target Frameworks:
    • Android: 33
  • Android Support Library / AndroidX Version: 1.9.0.3 (May affect earlier versions too but that is the minimum version required by these Xamarin.Forms versions)
  • Affected Devices: Galaxy Tab S8, Pixel 7 Pro, Pixel 8 Pro, Pixel Fold, Android Emulator (and likely most modern Android devices)

Screenshots

Screenshot_20231116_180434

Reproduction Link

XamarinSizeBugRepro.zip

Workaround

Nothing yet besides removing the configuration overrides (but sometimes these are needed so this is not a good workaround in most cases).

@wollac11 wollac11 added s/unverified New report that has yet to be verified t/bug 🐛 labels Nov 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
s/unverified New report that has yet to be verified t/bug 🐛
Projects
None yet
Development

No branches or pull requests

1 participant