Skip to content

Commit 03c59ce

Browse files
authored
fix: make more tab work (#110)
1 parent 8375b1f commit 03c59ce

File tree

2 files changed

+64
-23
lines changed

2 files changed

+64
-23
lines changed

example/src/App.tsx

Lines changed: 51 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
Button,
1212
Alert,
1313
useColorScheme,
14+
Platform,
1415
} from 'react-native';
1516
import {
1617
DarkTheme,
@@ -47,6 +48,10 @@ const FourTabsTransparentScrollEdgeAppearance = () => {
4748
return <FourTabs scrollEdgeAppearance="transparent" />;
4849
};
4950

51+
const FourTabsOpaqueScrollEdgeAppearance = () => {
52+
return <FourTabs scrollEdgeAppearance="opaque" />;
53+
};
54+
5055
const FourTabsWithBarTintColor = () => {
5156
return <FourTabs barTintColor={'#87CEEB'} />;
5257
};
@@ -63,20 +68,32 @@ const examples = [
6368
{ component: ThreeTabs, name: 'Three Tabs' },
6469
{ component: FourTabs, name: 'Four Tabs' },
6570
{ component: SFSymbols, name: 'SF Symbols' },
66-
{ component: LabeledTabs, name: 'Labeled Tabs' },
71+
{ component: LabeledTabs, name: 'Labeled Tabs', platform: 'android' },
6772
{
6873
component: FourTabsIgnoreSafeArea,
6974
name: 'Four Tabs - No header',
75+
platform: 'ios',
7076
screenOptions: { headerShown: false },
7177
},
7278
{
7379
component: FourTabsRippleColor,
7480
name: 'Four Tabs with ripple Color',
81+
platform: 'android',
82+
},
83+
{
84+
component: FourTabsNoAnimations,
85+
name: 'Four Tabs - no animations',
86+
platform: 'ios',
7587
},
76-
{ component: FourTabsNoAnimations, name: 'Four Tabs - no animations' },
7788
{
7889
component: FourTabsTransparentScrollEdgeAppearance,
7990
name: 'Four Tabs - Transparent scroll edge appearance',
91+
platform: 'ios',
92+
},
93+
{
94+
component: FourTabsOpaqueScrollEdgeAppearance,
95+
name: 'Four Tabs - Opaque scroll edge appearance',
96+
platform: 'ios',
8097
},
8198
{
8299
component: FourTabsWithBarTintColor,
@@ -85,6 +102,7 @@ const examples = [
85102
{
86103
component: FourTabsTranslucent,
87104
name: 'Four Tabs - Translucent tab bar',
105+
platform: 'android',
88106
},
89107
{
90108
component: FourTabsActiveIndicatorColor,
@@ -109,19 +127,23 @@ function App() {
109127
const navigation = useNavigation();
110128
return (
111129
<ScrollView>
112-
{examples.map((example) => (
113-
<TouchableOpacity
114-
key={example.name}
115-
testID={example.name}
116-
style={styles.exampleTouchable}
117-
onPress={() => {
118-
//@ts-ignore
119-
navigation.navigate(example.name);
120-
}}
121-
>
122-
<Text style={styles.exampleText}>{example.name}</Text>
123-
</TouchableOpacity>
124-
))}
130+
{examples
131+
.filter((example) =>
132+
'platform' in example ? example?.platform === Platform.OS : example
133+
)
134+
.map((example) => (
135+
<TouchableOpacity
136+
key={example.name}
137+
testID={example.name}
138+
style={styles.exampleTouchable}
139+
onPress={() => {
140+
//@ts-ignore
141+
navigation.navigate(example.name);
142+
}}
143+
>
144+
<Text style={styles.exampleText}>{example.name}</Text>
145+
</TouchableOpacity>
146+
))}
125147
</ScrollView>
126148
);
127149
}
@@ -169,14 +191,20 @@ export default function Navigation() {
169191
),
170192
}}
171193
/>
172-
{examples.map((example, index) => (
173-
<NavigationStack.Screen
174-
key={index}
175-
name={example.name}
176-
component={example.component}
177-
options={example.screenOptions}
178-
/>
179-
))}
194+
{examples
195+
.filter((example) =>
196+
'platform' in example
197+
? example?.platform === Platform.OS
198+
: example
199+
)
200+
.map((example, index) => (
201+
<NavigationStack.Screen
202+
key={index}
203+
name={example.name}
204+
component={example.component}
205+
options={example.screenOptions}
206+
/>
207+
))}
180208
</NavigationStack.Navigator>
181209
</NavigationContainer>
182210
</SafeAreaProvider>

ios/TabViewImpl.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,19 @@ struct TabViewImpl: View {
7575
}
7676
.tag(tabData?.key)
7777
.tabBadge(tabData?.badge)
78+
#if os(iOS)
79+
.onAppear {
80+
// SwiftUI doesn't change `selection` when clicked on items from the "More" list.
81+
// More tab is visible only if we have more than 5 items.
82+
// This is a workaround that fixes the "More" feature.
83+
if index < 4 {
84+
return
85+
}
86+
if let key = tabData?.key, props.selectedPage != key {
87+
onSelect(key)
88+
}
89+
}
90+
#endif
7891
}
7992

8093
}

0 commit comments

Comments
 (0)