|
| 1 | +# Web Platform Support |
| 2 | + |
| 3 | +React Native Bottom Tabs uses native platform primitives (SwiftUI on iOS and Material Design on Android) which are not available on web. For web applications, you'll need to use JavaScript-based tab implementations as a fallback. |
| 4 | + |
| 5 | +## How It Works |
| 6 | + |
| 7 | +React Native's Metro bundler automatically resolves platform-specific files. You can create separate implementations for native platforms and web. |
| 8 | + |
| 9 | +### File Structure |
| 10 | + |
| 11 | +``` |
| 12 | +src/ |
| 13 | +├── navigation/ |
| 14 | +│ ├── TabNavigator.native.tsx # Used on iOS/Android |
| 15 | +│ └── TabNavigator.web.tsx # Used on web |
| 16 | +``` |
| 17 | + |
| 18 | +### Native Implementation |
| 19 | + |
| 20 | +```tsx title="TabNavigator.native.tsx" |
| 21 | +import { createNativeBottomTabNavigator } from '@bottom-tabs/react-navigation'; |
| 22 | +import { Platform } from 'react-native'; |
| 23 | +import { HomeScreen } from '../screens/HomeScreen'; |
| 24 | +import { SettingsScreen } from '../screens/SettingsScreen'; |
| 25 | + |
| 26 | +const Tabs = createNativeBottomTabNavigator(); |
| 27 | + |
| 28 | +export function TabNavigator() { |
| 29 | + return ( |
| 30 | + <Tabs.Navigator> |
| 31 | + <Tabs.Screen |
| 32 | + name="Home" |
| 33 | + component={HomeScreen} |
| 34 | + options={{ |
| 35 | + tabBarIcon: () => |
| 36 | + Platform.OS === 'ios' |
| 37 | + ? { sfSymbol: 'house' } |
| 38 | + : require('../assets/icons/home.png'), |
| 39 | + }} |
| 40 | + /> |
| 41 | + <Tabs.Screen |
| 42 | + name="Settings" |
| 43 | + component={SettingsScreen} |
| 44 | + options={{ |
| 45 | + tabBarIcon: () => |
| 46 | + Platform.OS === 'ios' |
| 47 | + ? { sfSymbol: 'gear' } |
| 48 | + : require('../assets/icons/settings.png'), |
| 49 | + }} |
| 50 | + /> |
| 51 | + </Tabs.Navigator> |
| 52 | + ); |
| 53 | +} |
| 54 | +``` |
| 55 | + |
| 56 | +### Web Implementation |
| 57 | + |
| 58 | +For web, install `@react-navigation/bottom-tabs` which provides a JavaScript-based implementation: |
| 59 | + |
| 60 | +```bash |
| 61 | +npm install @react-navigation/bottom-tabs |
| 62 | +``` |
| 63 | + |
| 64 | +```tsx title="TabNavigator.web.tsx" |
| 65 | +import { createBottomTabNavigator } from '@react-navigation/bottom-tabs'; |
| 66 | +import { HomeScreen } from '../screens/HomeScreen'; |
| 67 | +import { SettingsScreen } from '../screens/SettingsScreen'; |
| 68 | + |
| 69 | +const Tab = createBottomTabNavigator(); |
| 70 | + |
| 71 | +export function TabNavigator() { |
| 72 | + return ( |
| 73 | + <Tab.Navigator> |
| 74 | + <Tab.Screen |
| 75 | + name="Home" |
| 76 | + component={HomeScreen} |
| 77 | + options={{ |
| 78 | + tabBarIcon: () => require('../assets/icons/home.png'), |
| 79 | + }} |
| 80 | + /> |
| 81 | + <Tab.Screen |
| 82 | + name="Settings" |
| 83 | + component={SettingsScreen} |
| 84 | + options={{ |
| 85 | + tabBarIcon: () => require('../assets/icons/settings.png'), |
| 86 | + }} |
| 87 | + /> |
| 88 | + </Tab.Navigator> |
| 89 | + ); |
| 90 | +} |
| 91 | +``` |
| 92 | + |
| 93 | +### Using in Your App |
| 94 | + |
| 95 | +Import the component normally - React Native will automatically use the correct file: |
| 96 | + |
| 97 | +```tsx title="App.tsx" |
| 98 | +import { NavigationContainer } from '@react-navigation/native'; |
| 99 | +import { TabNavigator } from './navigation/TabNavigator'; |
| 100 | + |
| 101 | +export default function App() { |
| 102 | + return ( |
| 103 | + <NavigationContainer> |
| 104 | + <TabNavigator /> |
| 105 | + </NavigationContainer> |
| 106 | + ); |
| 107 | +} |
| 108 | +``` |
| 109 | + |
| 110 | + |
| 111 | +## Additional Resources |
| 112 | + |
| 113 | +- [React Navigation Bottom Tabs](https://reactnavigation.org/docs/bottom-tab-navigator/) |
| 114 | +- [React Native Web Documentation](https://necolas.github.io/react-native-web/) |
| 115 | +- [Metro Bundler Platform-Specific Extensions](https://reactnative.dev/docs/platform-specific-code#platform-specific-extensions) |
0 commit comments