diff --git a/android/src/main/java/com/reactnativenavigation/customrow/BottomTabsCustomRow.kt b/android/src/main/java/com/reactnativenavigation/customrow/BottomTabsCustomRow.kt index 8764ad4a1a..69113f92ba 100644 --- a/android/src/main/java/com/reactnativenavigation/customrow/BottomTabsCustomRow.kt +++ b/android/src/main/java/com/reactnativenavigation/customrow/BottomTabsCustomRow.kt @@ -69,11 +69,16 @@ class BottomTabsCustomRow( clipChildren = false clipToPadding = false addView(backgroundView, LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)) - BottomTabsCustomRowConfigStore.addListener(configListener) applyOptions(currentOptions) rebuildCells() } + override fun onAttachedToWindow() { + super.onAttachedToWindow() + BottomTabsCustomRowConfigStore.addListener(configListener) + applyOptions(BottomTabsCustomRowConfigStore.get()) + } + override fun onDetachedFromWindow() { super.onDetachedFromWindow() BottomTabsCustomRowConfigStore.removeListener(configListener) diff --git a/android/src/test/java/com/reactnativenavigation/customrow/BottomTabsCustomRowTest.kt b/android/src/test/java/com/reactnativenavigation/customrow/BottomTabsCustomRowTest.kt new file mode 100644 index 0000000000..dad5a54bc0 --- /dev/null +++ b/android/src/test/java/com/reactnativenavigation/customrow/BottomTabsCustomRowTest.kt @@ -0,0 +1,49 @@ +package com.reactnativenavigation.customrow + +import android.content.Context +import android.widget.FrameLayout +import com.reactnativenavigation.BaseTest +import com.reactnativenavigation.views.bottomtabs.BottomTabs +import org.junit.Assert.assertEquals +import org.junit.Test + +class BottomTabsCustomRowTest : BaseTest() { + @Test + fun reattachedRowContinuesReceivingConfigurationUpdates() { + val activity = newActivity() + val container = FrameLayout(activity) + val row = BottomTabsCustomRow(activity, BottomTabs(activity)) + activity.setContentView(container) + + try { + container.addView(row) + BottomTabsCustomRowConfigStore.update( + BottomTabsCustomRowOptions(horizontalMargin = 24f) + ) + idleMainLooper() + assertEquals(dp(activity, 24f), row.effectiveHorizontalMarginPx()) + + container.removeView(row) + BottomTabsCustomRowConfigStore.update( + BottomTabsCustomRowOptions(horizontalMargin = 32f) + ) + idleMainLooper() + assertEquals(dp(activity, 24f), row.effectiveHorizontalMarginPx()) + + container.addView(row) + assertEquals(dp(activity, 32f), row.effectiveHorizontalMarginPx()) + + BottomTabsCustomRowConfigStore.update( + BottomTabsCustomRowOptions(horizontalMargin = 40f) + ) + idleMainLooper() + assertEquals(dp(activity, 40f), row.effectiveHorizontalMarginPx()) + } finally { + container.removeView(row) + BottomTabsCustomRowConfigStore.update(BottomTabsCustomRowOptions()) + } + } + + private fun dp(context: Context, value: Float): Int = + (value * context.resources.displayMetrics.density).toInt() +}