Skip to content

Commit c4b9119

Browse files
committed
feat: use LinearLayout, make measurements better
1 parent 0644e1d commit c4b9119

File tree

1 file changed

+7
-12
lines changed
  • packages/react-native-bottom-tabs/android/src/main/java/com/rcttabview

1 file changed

+7
-12
lines changed

packages/react-native-bottom-tabs/android/src/main/java/com/rcttabview/RCTTabView.kt

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import android.view.MenuItem
1717
import android.view.View
1818
import android.view.ViewGroup
1919
import android.widget.FrameLayout
20+
import android.widget.LinearLayout
2021
import android.widget.TextView
2122
import androidx.viewpager2.widget.ViewPager2
2223
import coil3.ImageLoader
@@ -34,7 +35,7 @@ import com.google.android.material.navigation.NavigationBarView.LABEL_VISIBILITY
3435
import com.google.android.material.navigation.NavigationBarView.LABEL_VISIBILITY_UNLABELED
3536
import com.google.android.material.transition.platform.MaterialFadeThrough
3637

37-
class ReactBottomNavigationView(context: ReactContext) : FrameLayout(context) {
38+
class ReactBottomNavigationView(context: ReactContext) : LinearLayout(context) {
3839
private val reactContext: ReactContext = context
3940
private val bottomNavigation = BottomNavigationView(context)
4041
private val viewPager = ViewPager2(context)
@@ -65,23 +66,21 @@ class ReactBottomNavigationView(context: ReactContext) : FrameLayout(context) {
6566
.build()
6667

6768
init {
69+
orientation = VERTICAL
6870
viewPager.adapter = viewPagerAdapter
6971
viewPager.isUserInputEnabled = false
7072

71-
viewPager.id = View.generateViewId()
7273
addView(
7374
viewPager, LayoutParams(
7475
LayoutParams.MATCH_PARENT,
75-
LayoutParams.MATCH_PARENT
76-
)
76+
0,
77+
).apply { weight = 1f }
7778
)
7879

7980
addView(bottomNavigation, LayoutParams(
8081
LayoutParams.MATCH_PARENT,
8182
LayoutParams.WRAP_CONTENT
82-
).apply {
83-
gravity = Gravity.BOTTOM
84-
})
83+
))
8584

8685
post {
8786
addOnLayoutChangeListener { _, left, top, right, bottom,
@@ -90,12 +89,8 @@ class ReactBottomNavigationView(context: ReactContext) : FrameLayout(context) {
9089
val newHeight = bottom - top
9190

9291
if (newWidth != lastReportedSize?.width || newHeight != lastReportedSize?.height) {
93-
// We subtract bottom navigation height from the screen height
94-
// This should be refactored for adaptive navigation
95-
val availableHeight = viewPager.height - bottomNavigation.height
96-
9792
val dpWidth = Utils.convertPixelsToDp(context, viewPager.width)
98-
val dpHeight = Utils.convertPixelsToDp(context, availableHeight)
93+
val dpHeight = Utils.convertPixelsToDp(context, viewPager.height)
9994

10095
onNativeLayoutListener?.invoke(dpWidth, dpHeight)
10196
lastReportedSize = Size(newWidth, newHeight)

0 commit comments

Comments
 (0)