diff --git a/README.md b/README.md index ca2c390d..1a5befb3 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,8 @@ https://github.com/user-attachments/assets/09e96ac3-827d-4ac0-add0-e7b88ee9197c | **tvOS** | | | **macOS** | | +> **Note:** This library uses native platform primitives which are not available on web. For web support, see the [Web Platform Support guide](https://oss.callstack.com/react-native-bottom-tabs/docs/guides/web-platform-support) in the documentation. + ## Package Versions | Name | Latest Version | diff --git a/docs/docs/docs/getting-started/introduction.mdx b/docs/docs/docs/getting-started/introduction.mdx index c42dadb8..94d757ee 100644 --- a/docs/docs/docs/getting-started/introduction.mdx +++ b/docs/docs/docs/getting-started/introduction.mdx @@ -10,3 +10,9 @@ React Native Bottom Tabs is a library that provides a native bottom tabs experie - visionOS - tvOS - macOS + +:::note + +For **web** platform support, native tabs are not available. See the [Web Platform Support](/docs/guides/web-platform-support) guide for JavaScript-based alternatives. + +::: diff --git a/docs/docs/docs/guides/_meta.json b/docs/docs/docs/guides/_meta.json index 23e1a0c2..fa7dd987 100644 --- a/docs/docs/docs/guides/_meta.json +++ b/docs/docs/docs/guides/_meta.json @@ -1 +1 @@ -["usage-with-react-navigation", "usage-with-expo-router", "usage-with-one", "standalone-usage", {"type": "divider"}, "handling-scrollview-insets", "usage-with-vector-icons", {"type": "divider"}, "android-native-styling", "edge-to-edge-support"] +["usage-with-react-navigation", "usage-with-expo-router", "usage-with-one", "standalone-usage", {"type": "divider"}, "web-platform-support", "handling-scrollview-insets", "usage-with-vector-icons", {"type": "divider"}, "android-native-styling", "edge-to-edge-support"] diff --git a/docs/docs/docs/guides/web-platform-support.md b/docs/docs/docs/guides/web-platform-support.md new file mode 100644 index 00000000..37f3337a --- /dev/null +++ b/docs/docs/docs/guides/web-platform-support.md @@ -0,0 +1,115 @@ +# Web Platform Support + +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. + +## How It Works + +React Native's Metro bundler automatically resolves platform-specific files. You can create separate implementations for native platforms and web. + +### File Structure + +``` +src/ +├── navigation/ +│ ├── TabNavigator.native.tsx # Used on iOS/Android +│ └── TabNavigator.web.tsx # Used on web +``` + +### Native Implementation + +```tsx title="TabNavigator.native.tsx" +import { createNativeBottomTabNavigator } from '@bottom-tabs/react-navigation'; +import { Platform } from 'react-native'; +import { HomeScreen } from '../screens/HomeScreen'; +import { SettingsScreen } from '../screens/SettingsScreen'; + +const Tabs = createNativeBottomTabNavigator(); + +export function TabNavigator() { + return ( + + + Platform.OS === 'ios' + ? { sfSymbol: 'house' } + : require('../assets/icons/home.png'), + }} + /> + + Platform.OS === 'ios' + ? { sfSymbol: 'gear' } + : require('../assets/icons/settings.png'), + }} + /> + + ); +} +``` + +### Web Implementation + +For web, install `@react-navigation/bottom-tabs` which provides a JavaScript-based implementation: + +```bash +npm install @react-navigation/bottom-tabs +``` + +```tsx title="TabNavigator.web.tsx" +import { createBottomTabNavigator } from '@react-navigation/bottom-tabs'; +import { HomeScreen } from '../screens/HomeScreen'; +import { SettingsScreen } from '../screens/SettingsScreen'; + +const Tab = createBottomTabNavigator(); + +export function TabNavigator() { + return ( + + require('../assets/icons/home.png'), + }} + /> + require('../assets/icons/settings.png'), + }} + /> + + ); +} +``` + +### Using in Your App + +Import the component normally - React Native will automatically use the correct file: + +```tsx title="App.tsx" +import { NavigationContainer } from '@react-navigation/native'; +import { TabNavigator } from './navigation/TabNavigator'; + +export default function App() { + return ( + + + + ); +} +``` + + +## Additional Resources + +- [React Navigation Bottom Tabs](https://reactnavigation.org/docs/bottom-tab-navigator/) +- [React Native Web Documentation](https://necolas.github.io/react-native-web/) +- [Metro Bundler Platform-Specific Extensions](https://reactnative.dev/docs/platform-specific-code#platform-specific-extensions)