Fix notification background image layouts to render text RTL based on the device's language setting #1474
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
One Line Summary
Fix notification background image layouts to render RTL text based on the device's language setting.
Details
Motivation
Setting a custom background image for notifications is a supported feature only through the REST API, is limited in features, and Android 12 has limited customizability. However OneSignal currently supports this feature and it should remind free of common/high impact bugs.
Scope
Only affects the display of notifications when the following is true:
android_background_layout
in the payload.AndroidManifest.xml
hasandroid:supportsRtl="true"
This PR only affects the text rendering on background image notification layout.
Out of scope:
android:textDirection
was introduced in Android API level 17.What was the bug?
When the notification background image is set and the RTL conditions are meet, the notification text renders on the left side instead of the right side. It also renders over the left safe area (where the app icon is).
NOTE: Background image used in this example isn't the best example, an app icon should be backed into the background image, on left side.
On LTR devices notifications looks like this :
On RTL devices notifications looks like this:
Why the bug was happening?
The text elements on the notification layout had RTL disabled with
tools:ignore="RtlCompat"
, and didn't account for the different padding location.How the bug was fixed?
Added
android:textDirection="locale"
on the layout used for the both the title and body so it's influenced by the language direction. Also corrected title and body padding to support RTL.Testing
Unit testing
N/A, only a visual layout change.
Manual testing
Tested the Example app included in this repo (it has
android:supportsRtl="true"
) and set "Force RTL layout direction" on the device. Also tested w/o "Force RTL layout direction", to make sure it remained working.Test on:
Screenshot after fix
Android 10 Emulator with English with "Force RTL layout direction" enabled:
Affected code checklist
Checklist
Overview
Testing
Final pass
This change is