Skip to content

Commit 922b9c3

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

21 files changed

+150
-449
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: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import TintColorsExample from './Examples/TintColors';
2727
import NativeBottomTabsEmbeddedStacks from './Examples/NativeBottomTabsEmbeddedStacks';
2828
import NativeBottomTabsSVGs from './Examples/NativeBottomTabsSVGs';
2929
import NativeBottomTabsRemoteIcons from './Examples/NativeBottomTabsRemoteIcons';
30+
import NativeBottomTabsUnmounting from './Examples/NativeBottomTabsUnmounting';
3031

3132
const FourTabsIgnoreSafeArea = () => {
3233
return <FourTabs ignoresTopSafeArea />;
@@ -95,7 +96,6 @@ const examples = [
9596
{
9697
component: FourTabsNoAnimations,
9798
name: 'Four Tabs - no animations',
98-
platform: 'ios',
9999
},
100100
{
101101
component: FourTabsTransparentScrollEdgeAppearance,
@@ -128,6 +128,10 @@ const examples = [
128128
component: NativeBottomTabsSVGs,
129129
name: 'Native Bottom Tabs with SVG Icons',
130130
},
131+
{
132+
component: NativeBottomTabsUnmounting,
133+
name: 'Native Bottom Tabs unmounting',
134+
},
131135
{
132136
component: NativeBottomTabsRemoteIcons,
133137
name: 'Native Bottom Tabs with SVG Remote Icons',
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import { Article } from '../Screens/Article';
2+
import { Albums } from '../Screens/Albums';
3+
import { Contacts } from '../Screens/Contacts';
4+
import { Chat } from '../Screens/Chat';
5+
import { createNativeBottomTabNavigator } from '@bottom-tabs/react-navigation';
6+
import React from 'react';
7+
import { Alert } from 'react-native';
8+
9+
const Tab = createNativeBottomTabNavigator();
10+
11+
function NativeBottomTabsUnmounting() {
12+
const [isTabMounted, setIsTabMounted] = React.useState(true);
13+
14+
React.useEffect(() => {
15+
const id = setTimeout(() => {
16+
setIsTabMounted(false);
17+
Alert.alert('Tab is unmounted');
18+
}, 1000);
19+
20+
return () => clearTimeout(id);
21+
}, []);
22+
return (
23+
<Tab.Navigator initialRouteName="Chat" labeled={true}>
24+
<Tab.Screen
25+
name="Article"
26+
component={Article}
27+
options={{
28+
tabBarButtonTestID: 'articleTestID',
29+
tabBarBadge: '10',
30+
tabBarIcon: ({ focused }) =>
31+
focused
32+
? require('../../assets/icons/person_dark.png')
33+
: require('../../assets/icons/article_dark.png'),
34+
}}
35+
/>
36+
<Tab.Screen
37+
name="Albums"
38+
component={Albums}
39+
options={{
40+
tabBarIcon: () => require('../../assets/icons/grid_dark.png'),
41+
}}
42+
/>
43+
<Tab.Screen
44+
name="Contacts"
45+
component={Contacts}
46+
options={{
47+
tabBarIcon: () => require('../../assets/icons/person_dark.png'),
48+
}}
49+
/>
50+
{isTabMounted && (
51+
<Tab.Screen
52+
name="Chat"
53+
component={Chat}
54+
options={{
55+
tabBarIcon: () => require('../../assets/icons/chat_dark.png'),
56+
}}
57+
/>
58+
)}
59+
</Tab.Navigator>
60+
);
61+
}
62+
63+
export default NativeBottomTabsUnmounting;

packages/react-native-bottom-tabs/android/build.gradle

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@ buildscript {
1414
}
1515
}
1616

17-
def reactNativeArchitectures() {
18-
def value = rootProject.getProperties().get("reactNativeArchitectures")
19-
return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
20-
}
21-
2217
def isNewArchitectureEnabled() {
2318
return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
2419
}

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

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class ReactBottomNavigationView(context: ReactContext) : FrameLayout(context) {
4444
var onTabLongPressedListener: ((key: String) -> Unit)? = null
4545
var onNativeLayoutListener: ((width: Double, height: Double) -> Unit)? = null
4646
var disablePageTransitions = false
47-
var items: MutableList<TabInfo>? = null
47+
var items: MutableList<TabInfo> = mutableListOf()
4848

4949
private var selectedItem: String? = null
5050
private val iconSources: MutableMap<Int, ImageSource> = mutableMapOf()
@@ -106,17 +106,15 @@ class ReactBottomNavigationView(context: ReactContext) : FrameLayout(context) {
106106

107107
fun setSelectedItem(value: String) {
108108
selectedItem = value
109-
items?.indexOfFirst { it.key == value }?.let {
110-
setSelectedIndex(it)
111-
}
109+
setSelectedIndex(items.indexOfFirst { it.key == value })
112110
}
113111

114112
override fun addView(child: View, index: Int, params: ViewGroup.LayoutParams?) {
115113
if (child === viewPager || child === bottomNavigation) {
116114
super.addView(child, index, params)
117115
} else {
118116
viewPagerAdapter.addChild(child, index)
119-
val itemKey = items?.get(index)?.key
117+
val itemKey = items[index].key
120118
if (selectedItem == itemKey) {
121119
setSelectedIndex(index)
122120
}
@@ -157,22 +155,26 @@ class ReactBottomNavigationView(context: ReactContext) : FrameLayout(context) {
157155
}
158156

159157
private fun onTabSelected(item: MenuItem) {
160-
val selectedItem = items?.first { it.title == item.title }
161-
selectedItem?.let {
158+
val selectedItem = items.first { it.title == item.title }
159+
selectedItem.let {
162160
onTabSelectedListener?.invoke(selectedItem.key)
163161
emitHapticFeedback(HapticFeedbackConstants.CONTEXT_CLICK)
164162
}
165163
}
166164

167165
private fun onTabLongPressed(item: MenuItem) {
168-
val longPressedItem = items?.firstOrNull { it.title == item.title }
166+
val longPressedItem = items.firstOrNull { it.title == item.title }
169167
longPressedItem?.let {
170168
onTabLongPressedListener?.invoke(longPressedItem.key)
171169
emitHapticFeedback(HapticFeedbackConstants.LONG_PRESS)
172170
}
173171
}
174172

175173
fun updateItems(items: MutableList<TabInfo>) {
174+
// If an item got removed, let's re-add all items
175+
if (items.size < this.items.size) {
176+
bottomNavigation.menu.clear()
177+
}
176178
this.items = items
177179
items.forEachIndexed { index, item ->
178180
val menuItem = getOrCreateItem(index, item.title)
@@ -248,11 +250,9 @@ class ReactBottomNavigationView(context: ReactContext) : FrameLayout(context) {
248250
false -> {
249251
LABEL_VISIBILITY_UNLABELED
250252
}
251-
252253
true -> {
253254
LABEL_VISIBILITY_LABELED
254255
}
255-
256256
else -> {
257257
LABEL_VISIBILITY_AUTO
258258
}
@@ -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?) {
@@ -359,7 +361,7 @@ class ReactBottomNavigationView(context: ReactContext) : FrameLayout(context) {
359361

360362
private fun updateTintColors(item: MenuItem? = null) {
361363
// First let's check current item color.
362-
val currentItemTintColor = items?.find { it.title == item?.title }?.activeTintColor
364+
val currentItemTintColor = items.find { it.title == item?.title }?.activeTintColor
363365

364366
// getDefaultColor will always return a valid color but to satisfy the compiler we need to check for null
365367
val colorPrimary = currentItemTintColor ?: activeTintColor ?: Utils.getDefaultColorFor(
@@ -380,6 +382,9 @@ 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+
}
388+
imageLoader.shutdown()
384389
}
385390
}

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

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,27 +24,24 @@ class RCTTabViewImpl {
2424
fun setItems(view: ReactBottomNavigationView, items: ReadableArray) {
2525
val itemsArray = mutableListOf<TabInfo>()
2626
for (i in 0 until items.size()) {
27-
items.getMap(i).let { item ->
28-
itemsArray.add(
29-
TabInfo(
30-
key = item.getString("key") ?: "",
31-
title = item.getString("title") ?: "",
32-
badge = item.getString("badge") ?: "",
33-
activeTintColor = if (item.hasKey("activeTintColor")) item.getInt("activeTintColor") else null,
34-
hidden = if (item.hasKey("hidden")) item.getBoolean("hidden") else false,
35-
testID = item.getString("testID")
27+
items.getMap(i)?.let { item ->
28+
itemsArray.add(
29+
TabInfo(
30+
key = item.getString("key") ?: "",
31+
title = item.getString("title") ?: "",
32+
badge = item.getString("badge") ?: "",
33+
activeTintColor = if (item.hasKey("activeTintColor")) item.getInt("activeTintColor") else null,
34+
hidden = if (item.hasKey("hidden")) item.getBoolean("hidden") else false,
35+
testID = item.getString("testID")
36+
)
3637
)
37-
)
3838
}
3939
}
4040
view.updateItems(itemsArray)
4141
}
4242

4343
fun setSelectedPage(view: ReactBottomNavigationView, key: String) {
4444
view.setSelectedItem(key)
45-
// view.items?.indexOfFirst { it.key == key }?.let {
46-
// view.setSelectedItemId(it)
47-
// }
4845
}
4946

5047
fun setLabeled(view: ReactBottomNavigationView, flag: Boolean?) {

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.

0 commit comments

Comments
 (0)