Skip to content

Commit ec0ebe8

Browse files
authored
re-aligning the back button on android and iOS when using icon background logic (#8236)
* re-aligning the back button on android and iOS when using icon background logic * snapshot test updated * snapshot update for android * update logic android * test update * reverting changes to iOS because they weren't really needed and there is too much chance for a messup
1 parent 5a29a75 commit ec0ebe8

3 files changed

Lines changed: 21 additions & 18 deletions

File tree

android/src/main/java/com/reactnativenavigation/views/stack/topbar/titlebar/IconBackgroundDrawable.kt

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ import com.reactnativenavigation.options.params.DensityPixel
88

99

1010
class IconBackgroundDrawable(
11-
private val wrapped: Drawable,
12-
private val cornerRadius: DensityPixel,
13-
private val backgroundWidth: Int,
14-
private val backgroundHeight: Int,
15-
private val iconColor: Int?,
16-
val backgroundColor: Int?
11+
private val wrapped: Drawable,
12+
private val cornerRadius: DensityPixel,
13+
private val backgroundWidth: Int,
14+
private val backgroundHeight: Int,
15+
private val iconColor: Int?,
16+
val backgroundColor: Int?
1717
) : Drawable() {
1818
private val path: Path = Path()
1919
private val bitmapPaint = Paint().apply {
@@ -56,28 +56,31 @@ class IconBackgroundDrawable(
5656
canvas.drawBitmap(wrapped.toBitmap(), null, bitmapRect, bitmapPaint)
5757
}
5858

59+
override fun getIntrinsicWidth(): Int = backgroundWidth
60+
override fun getIntrinsicHeight(): Int = backgroundHeight
61+
5962
override fun setBounds(l: Int, t: Int, r: Int, b: Int) {
60-
updatePath(RectF(l.toFloat(), t.toFloat(), backgroundWidth.toFloat(), backgroundHeight.toFloat()))
61-
super.setBounds(l, t, backgroundWidth, backgroundHeight)
63+
updatePath(RectF(0f, 0f, backgroundWidth.toFloat(), backgroundHeight.toFloat()))
64+
super.setBounds(l, t, l + backgroundWidth, t + backgroundHeight)
6265
}
6366

6467
override fun setBounds(r: Rect) {
65-
r.right = backgroundWidth
66-
r.bottom = backgroundHeight
67-
updatePath(RectF(r))
68+
r.right = r.left + backgroundWidth
69+
r.bottom = r.top + backgroundHeight
70+
updatePath(RectF(0f, 0f, backgroundWidth.toFloat(), backgroundHeight.toFloat()))
6871
super.setBounds(r)
6972
}
7073

7174
override fun onBoundsChange(bounds: Rect) {
7275
if (bounds != null) {
7376
backgroundRect = Rect((bounds.width() - backgroundWidth) / 2,
74-
(bounds.height() - backgroundHeight) / 2,
75-
bounds.width() - (bounds.width() - backgroundWidth) / 2,
76-
bounds.height() - (bounds.height() - backgroundHeight) / 2)
77+
(bounds.height() - backgroundHeight) / 2,
78+
bounds.width() - (bounds.width() - backgroundWidth) / 2,
79+
bounds.height() - (bounds.height() - backgroundHeight) / 2)
7780
bitmapRect = Rect((bounds.width() - bitmapWidth) / 2,
78-
(bounds.height() - bitmapHeight) / 2,
79-
bounds.width() - (bounds.width() - bitmapWidth) / 2,
80-
bounds.height() - (bounds.height() - bitmapHeight) / 2)
81+
(bounds.height() - bitmapHeight) / 2,
82+
bounds.width() - (bounds.width() - bitmapWidth) / 2,
83+
bounds.height() - (bounds.height() - bitmapHeight) / 2)
8184
}
8285
super.onBoundsChange(bounds)
8386
}

playground/e2e/BackButton.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ describe('Back Button', () => {
6565
await expect(elementByLabel('navigationButtonPressed | RNN.hardwareBackButton')).toBeVisible();
6666
});
6767

68-
it.e2e('should render back button with iconBackground', async () => {
68+
it.e2e(':ios: should render back button with iconBackground', async () => {
6969
await elementById(TestIDs.PUSH_BACK_BUTTON_ICON_BACKGROUND).tap();
7070
// eslint-disable-next-line no-undef
7171
const snapshottedImagePath = `./e2e/assets/back_button_icon_background.${device.getPlatform()}.png`;
-409 Bytes
Loading

0 commit comments

Comments
 (0)