Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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()
}