Skip to content

Commit 1d9ed4d

Browse files
committed
fix: remove custom shadow nodes measurements
1 parent 8dd3a80 commit 1d9ed4d

File tree

15 files changed

+60
-410
lines changed

15 files changed

+60
-410
lines changed

apps/example/android/gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ reactNativeArchitectures=armeabi-v7a,arm64-v8a,x86,x86_64
4040
# to write custom TurboModules/Fabric components OR use libraries that
4141
# are providing them.
4242
# Note that this is incompatible with web debugging.
43-
newArchEnabled=false
43+
newArchEnabled=true
4444
#bridgelessEnabled=true
4545

4646
# Uncomment the line below to build React Native from source.

apps/example/src/App.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ const examples = [
9595
{
9696
component: FourTabsNoAnimations,
9797
name: 'Four Tabs - no animations',
98-
platform: 'ios',
9998
},
10099
{
101100
component: FourTabsTransparentScrollEdgeAppearance,

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,9 @@ class ReactBottomNavigationView(context: ReactContext) : FrameLayout(context) {
291291
bottomNavigation.itemBackground = colorDrawable
292292
backgroundTintList = ColorStateList.valueOf(backgroundColor)
293293
// Set navigationBarColor for edge-to-edge.
294-
reactContext.currentActivity?.window?.navigationBarColor = backgroundColor
294+
if (Utils.isEdgeToEdge()) {
295+
reactContext.currentActivity?.window?.navigationBarColor = backgroundColor
296+
}
295297
}
296298

297299
fun setActiveTintColor(color: Int?) {
@@ -380,6 +382,8 @@ class ReactBottomNavigationView(context: ReactContext) : FrameLayout(context) {
380382

381383
override fun onDetachedFromWindow() {
382384
super.onDetachedFromWindow()
383-
reactContext.currentActivity?.window?.navigationBarColor = Color.TRANSPARENT
385+
if (Utils.isEdgeToEdge()) {
386+
reactContext.currentActivity?.window?.navigationBarColor = Color.TRANSPARENT
387+
}
384388
}
385389
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,13 @@ class Utils {
2727
)
2828
return baseColor.defaultColor
2929
}
30+
31+
// Detect `react-native-edge-to-edge` (https://github.com/zoontek/react-native-edge-to-edge)
32+
fun isEdgeToEdge() = try {
33+
Class.forName("com.zoontek.rnedgetoedge.EdgeToEdgePackage")
34+
true
35+
} catch (exception: ClassNotFoundException) {
36+
false
37+
}
3038
}
3139
}

packages/react-native-bottom-tabs/android/src/main/jni/CMakeLists.txt

Lines changed: 0 additions & 87 deletions
This file was deleted.

packages/react-native-bottom-tabs/android/src/main/jni/RNCTabView.h

Lines changed: 0 additions & 13 deletions
This file was deleted.

packages/react-native-bottom-tabs/android/src/newarch/RCTTabViewManager.kt

Lines changed: 44 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,26 @@
11
package com.rcttabview
22

3-
import android.content.Context
43
import android.view.View
4+
import android.view.ViewGroup
55
import com.facebook.react.bridge.ReactApplicationContext
66
import com.facebook.react.bridge.ReadableArray
7-
import com.facebook.react.bridge.ReadableMap
87
import com.facebook.react.module.annotations.ReactModule
9-
import com.facebook.react.uimanager.PixelUtil.toDIPFromPixel
10-
import com.facebook.react.uimanager.SimpleViewManager
118
import com.facebook.react.uimanager.ThemedReactContext
129
import com.facebook.react.uimanager.UIManagerHelper
10+
import com.facebook.react.uimanager.ViewGroupManager
1311
import com.facebook.react.uimanager.ViewManagerDelegate
1412
import com.facebook.react.viewmanagers.RNCTabViewManagerDelegate
1513
import com.facebook.react.viewmanagers.RNCTabViewManagerInterface
16-
import com.facebook.yoga.YogaMeasureMode
17-
import com.facebook.yoga.YogaMeasureOutput
14+
import com.rcttabview.events.OnNativeLayoutEvent
15+
import com.rcttabview.events.PageSelectedEvent
16+
import com.rcttabview.events.TabLongPressEvent
1817

1918

2019
@ReactModule(name = RCTTabViewImpl.NAME)
2120
class RCTTabViewManager(context: ReactApplicationContext) :
22-
SimpleViewManager<ReactBottomNavigationView>(),
21+
ViewGroupManager<ReactBottomNavigationView>(),
2322
RNCTabViewManagerInterface<ReactBottomNavigationView> {
2423

25-
private val contextInner: ReactApplicationContext = context
2624
private val delegate: RNCTabViewManagerDelegate<ReactBottomNavigationView, RCTTabViewManager> =
2725
RNCTabViewManagerDelegate(this)
2826
private val tabViewImpl: RCTTabViewImpl = RCTTabViewImpl()
@@ -37,6 +35,10 @@ class RCTTabViewManager(context: ReactApplicationContext) :
3735
view.onTabLongPressedListener = { key ->
3836
eventDispatcher?.dispatchEvent(TabLongPressEvent(viewTag = view.id, key))
3937
}
38+
39+
view.onNativeLayoutListener = { width, height ->
40+
eventDispatcher?.dispatchEvent(OnNativeLayoutEvent(viewTag = view.id, width, height))
41+
}
4042
return view
4143

4244
}
@@ -45,6 +47,36 @@ class RCTTabViewManager(context: ReactApplicationContext) :
4547
return tabViewImpl.getName()
4648
}
4749

50+
override fun getChildCount(parent: ReactBottomNavigationView): Int {
51+
return parent.viewPagerAdapter.itemCount ?: 0
52+
}
53+
54+
override fun getChildAt(parent: ReactBottomNavigationView, index: Int): View? {
55+
return parent.viewPagerAdapter.getChildAt(index)
56+
}
57+
58+
override fun removeView(parent: ReactBottomNavigationView, view: View) {
59+
parent.viewPagerAdapter.removeChild(view)
60+
}
61+
62+
override fun removeAllViews(parent: ReactBottomNavigationView) {
63+
parent.viewPagerAdapter.removeAll()
64+
}
65+
66+
override fun removeViewAt(parent: ReactBottomNavigationView, index: Int) {
67+
val child = parent.viewPagerAdapter.getChildAt(index)
68+
69+
if (child.parent != null) {
70+
(child.parent as? ViewGroup)?.removeView(child)
71+
}
72+
73+
parent.viewPagerAdapter.removeChildAt(index)
74+
}
75+
76+
override fun needsCustomLayoutForChildren(): Boolean {
77+
return true
78+
}
79+
4880
override fun setItems(view: ReactBottomNavigationView?, value: ReadableArray?) {
4981
if (view != null && value != null)
5082
tabViewImpl.setItems(view, value)
@@ -99,30 +131,6 @@ class RCTTabViewManager(context: ReactApplicationContext) :
99131
tabViewImpl.setHapticFeedbackEnabled(view, value)
100132
}
101133

102-
public override fun measure(
103-
context: Context?,
104-
localData: ReadableMap?,
105-
props: ReadableMap?,
106-
state: ReadableMap?,
107-
width: Float,
108-
widthMode: YogaMeasureMode?,
109-
height: Float,
110-
heightMode: YogaMeasureMode?,
111-
attachmentsPositions: FloatArray?
112-
): Long {
113-
val view = ReactBottomNavigationView(context ?: contextInner)
114-
val measureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)
115-
view.measure(measureSpec, measureSpec)
116-
117-
val bottomInset = RCTTabViewImpl.getNavigationBarInset(contextInner)
118-
119-
return YogaMeasureOutput.make(
120-
// TabBar should always stretch to the width of the screen.
121-
toDIPFromPixel(width),
122-
toDIPFromPixel(view.measuredHeight.toFloat() + bottomInset)
123-
)
124-
}
125-
126134
override fun setFontFamily(view: ReactBottomNavigationView?, value: String?) {
127135
view?.setFontFamily(value)
128136
}
@@ -135,22 +143,20 @@ class RCTTabViewManager(context: ReactApplicationContext) :
135143
view?.setFontSize(value)
136144
}
137145

138-
// iOS Methods
146+
override fun setDisablePageAnimations(view: ReactBottomNavigationView?, value: Boolean) {
147+
view?.disablePageTransitions = value
148+
}
139149

150+
// iOS Methods
140151
override fun setTranslucent(view: ReactBottomNavigationView?, value: Boolean) {
141152
}
142153

143154
override fun setIgnoresTopSafeArea(view: ReactBottomNavigationView?, value: Boolean) {
144155
}
145156

146-
override fun setDisablePageAnimations(view: ReactBottomNavigationView?, value: Boolean) {
147-
}
148-
149157
override fun setSidebarAdaptable(view: ReactBottomNavigationView?, value: Boolean) {
150158
}
151159

152160
override fun setScrollEdgeAppearance(view: ReactBottomNavigationView?, value: String?) {
153161
}
154-
155-
156162
}

packages/react-native-bottom-tabs/common/cpp/react/renderer/components/RNCTabView/RNCTabViewComponentDescriptor.h

Lines changed: 0 additions & 47 deletions
This file was deleted.

0 commit comments

Comments
 (0)