Skip to content

Commit 42cdfaa

Browse files
authored
fix: make pressable items work when switching screens on new arch (#288)
* fix: make pressable items work when switching screens on new arch * chore: add pressable testing examples
1 parent 41f96df commit 42cdfaa

File tree

5 files changed

+19
-15
lines changed

5 files changed

+19
-15
lines changed

.changeset/cold-rabbits-grin.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'react-native-bottom-tabs': patch
3+
---
4+
5+
fix: make pressable items work when switching screens on new arch

apps/example/src/Screens/Chat.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import {
88
Text,
99
TextInput,
1010
View,
11+
Button,
12+
Alert,
1113
} from 'react-native';
1214

1315
const MESSAGES = [
@@ -27,6 +29,7 @@ export function Chat({
2729
behavior={Platform.OS === 'ios' ? 'padding' : 'height'}
2830
style={styles.container}
2931
>
32+
<Button onPress={() => Alert.alert('Hey')} title="Press me" />
3033
<ScrollView
3134
contentInsetAdjustmentBehavior="automatic"
3235
style={styles.inverted}

apps/example/src/Screens/Contacts.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import { useScrollToTop } from '@react-navigation/native';
22
import * as React from 'react';
33
import {
4+
Alert,
45
FlatList,
56
type FlatListProps,
67
Platform,
78
SafeAreaView,
89
StyleSheet,
910
Text,
11+
TouchableOpacity,
1012
View,
1113
} from 'react-native';
1214
import { useBottomTabBarHeight } from 'react-native-bottom-tabs';
@@ -74,7 +76,10 @@ const CONTACTS: Item[] = [
7476
const ContactItem = React.memo(
7577
({ item }: { item: { name: string; number: number } }) => {
7678
return (
77-
<View style={[styles.item, { backgroundColor: '#fff' }]}>
79+
<TouchableOpacity
80+
style={[styles.item, { backgroundColor: '#fff' }]}
81+
onPress={() => Alert.alert(`Pressed: ${item.name}`)}
82+
>
7883
<View style={styles.avatar}>
7984
<Text style={styles.letter}>
8085
{item.name.slice(0, 1).toUpperCase()}
@@ -84,7 +89,7 @@ const ContactItem = React.memo(
8489
<Text style={styles.name}>{item.name}</Text>
8590
<Text style={[styles.number, { opacity: 0.5 }]}>{item.number}</Text>
8691
</View>
87-
</View>
92+
</TouchableOpacity>
8893
);
8994
}
9095
);

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

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import android.view.ViewGroup
1818
import android.widget.FrameLayout
1919
import android.widget.LinearLayout
2020
import android.widget.TextView
21-
import androidx.core.view.children
2221
import androidx.core.view.forEachIndexed
2322
import coil3.ImageLoader
2423
import coil3.asDrawable
@@ -138,7 +137,6 @@ class ReactBottomNavigationView(context: Context) : LinearLayout(context) {
138137
}
139138

140139
val container = createContainer()
141-
child.isEnabled = false
142140
container.addView(child, params)
143141
layoutHolder.addView(container, index)
144142

@@ -155,7 +153,8 @@ class ReactBottomNavigationView(context: Context) : LinearLayout(context) {
155153
FrameLayout.LayoutParams.MATCH_PARENT,
156154
FrameLayout.LayoutParams.MATCH_PARENT
157155
)
158-
visibility = INVISIBLE
156+
isSaveEnabled = false
157+
visibility = GONE
159158
isEnabled = false
160159
}
161160
return container
@@ -183,12 +182,8 @@ class ReactBottomNavigationView(context: Context) : LinearLayout(context) {
183182
private fun toggleViewVisibility(view: View, isVisible: Boolean) {
184183
check(view is ViewGroup) { "Native component tree is corrupted." }
185184

186-
view.visibility = if (isVisible) VISIBLE else INVISIBLE
185+
view.visibility = if (isVisible) VISIBLE else GONE
187186
view.isEnabled = isVisible
188-
189-
// Container has only 1 child, wrapped React Native view.
190-
val reactNativeView = view.children.first()
191-
reactNativeView.isEnabled = isVisible
192187
}
193188

194189
private fun onTabSelected(item: MenuItem) {

packages/react-native-bottom-tabs/src/TabView.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -324,11 +324,7 @@ const TabView = <Route extends BaseRoute>({
324324
importantForAccessibility={
325325
focused ? 'auto' : 'no-hide-descendants'
326326
}
327-
style={
328-
Platform.OS === 'android'
329-
? [measuredDimensions]
330-
: [{ position: 'absolute' }, measuredDimensions]
331-
}
327+
style={[{ position: 'absolute' }, measuredDimensions]}
332328
>
333329
{renderScene({
334330
route,

0 commit comments

Comments
 (0)