fix: prevent Expanded Dark Theme inversion on scanner activity#56
Conversation
Adds an AppCompat DayNight theme to `OSBARCScannerActivity` so Android does not treat it as a legacy light-themed app and invert its colors when Expanded Dark Theme is enabled. References: https://outsystemsrd.atlassian.net/browse/RMET-5280
Might be 2.1.0 instead if we bundle with #55; depends on merge order / time.
Not being used these days, might as well comment to see if CI passes
| <?xml version="1.0" encoding="utf-8"?> | ||
| <resources> | ||
| <style name="Theme.BarcodeScannerActivity" | ||
| parent="Theme.AppCompat.DayNight.NoActionBar" /> |
There was a problem hiding this comment.
Random question, does it matter that this theme is Theme.AppCompat.* but the activity is a ComponentActivity (not AppCompatActivity)? Not sure if it's an issue or just a nit, but I think there's also a Theme.Material3.DayNight.NoActionBar that might be a better fit for a Compose activity, right? Worth checking?
There was a problem hiding this comment.
For your first question, doesn't matter that much no, what would happen is that theme brings up additional properties that won't end up being used by this activity because it's not using AppCompat components
For your second question, I didn't use Theme.Material3.DayNight.NoActionBar because it was failing builds for OutSystems, but now that I see it, it's because https://github.com/OutSystems/cordova-outsystems-barcode/blob/main/src/android/com/outsystems/plugins/barcode/build.gradle#L27 has the @aar which means no transitive dependencies come, and so the build failed because it was missing a material library dependency. After adding that, it works fine.
However, when I create an empty compose app, it actually comes with android:Theme.Material.Light.NoActionBar. I thought that would work, but apparently not, still getting color inversion with that theme - This might be due to the native theme configurations of an OutSystems application vs that empty Compose one, didn't exactly figure it out.
But anywho, I'm going with that Theme.Material3.DayNight.NoActionBar that seems to work. Thanks for bringing it up!
There was a problem hiding this comment.
PS: Will need to do similar change for capacitor plugin, but it's fine
There was a problem hiding this comment.
Makes sense, thanks for the clarification 👍
There was a problem hiding this comment.
Actually @OS-ruimoreiramendes I changed my mind 😆 after building an app with and without the google material dependency, it increases the full apk size (debug) by 15 MB and the download size (debug) 1.5 MB. While maybe release builds with R8 would shrink that difference, I don't think it's worth the added size for what is in truth, more of a cosmetic change - So I'm changing back to AppCompat 😅
There was a problem hiding this comment.
Fair enough 😅 15 MB is way too much for a cosmetic win.
Following PR comment #56 (comment)
Description
Adds a AppCompat DayNight theme to
OSBARCScannerActivityso Android does not treat it as a legacy light-themed activity and invert its colors when Expanded Dark Theme is enabled.In this PR I also do a few housekeeping changes like updating PR template and commenting SonarCloud template because it was failing CI and we're not really using it atm.
Consumer Plugins note
Because this library is consumed as @aar in cordova plugin, will need to explicitly add google material dependency there otherwise the app won't build because it won't find Material3 theme.
Same thing for capacitor plugin
Context
Expanded Dark Theme is an accessibility feature added in Android 16.1, that when enabled, was causing the scanning screen to have a white tint, because (without this fix) it was assuming the screen was not in dark mode, therefore (wrongfully) inverting the colors.
Internal jira Reference: https://outsystemsrd.atlassian.net/browse/RMET-5280
Type of changes
Tests
I tested OutSystems Sample apps (O11 with Cordova and ODC with Capacitor). If you'd like to test yourself, refer to the following apk files in this drive folder ("before" for without this PR, "after" for with this PR): https://drive.google.com/drive/folders/1PeI7udQya5Ad4cMBTNXP0jPfUgOpenuF?usp=sharing
Screenshots (if appropriate)
The following are screenshots on a Pixel device with Android 17 and Expanded Dark Theme enabled in device settings.
Checklist