Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(web): add web-compatible linking and titling in react-navigation #38

Merged
merged 3 commits into from
Dec 4, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion template/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,14 @@

import appJson from './app.json';
import React from 'react';
import {ScrollView, StyleSheet, Text, useColorScheme, View} from 'react-native';
import {
Button,
ScrollView,
StyleSheet,
Text,
useColorScheme,
View,
} from 'react-native';
import {
Colors,
DebugInstructions,
Expand All @@ -23,6 +30,7 @@ import {
SafeAreaProvider,
useSafeAreaInsets,
} from 'react-native-safe-area-context';
import {useLinkTo} from '@react-navigation/native';
import {createMaterialTopTabNavigator} from '@react-navigation/material-top-tabs';
import Icon from 'react-native-vector-icons/FontAwesome';

Expand Down Expand Up @@ -105,6 +113,9 @@ const TopTabNavigator = () => {
// Used for status bar layout in react-navigation
const insets = useSafeAreaInsets();

// Allows us to use web-compatible navigation
const linkTo = useLinkTo();

// Dark mode theming items
const isDarkMode = useColorScheme() === 'dark';
const accentColor = isDarkMode ? Colors.ligher : Colors.darker;
Expand All @@ -125,6 +136,13 @@ const TopTabNavigator = () => {
</Text>
</View>
);
const LinkingExample = () => {
return (
<View style={[backgroundStyle, styles.detailsContainer]}>
<Button title="Link to Details" onPress={() => linkTo('/details')} />
</View>
);
};

const screenOptions = {
tabBarStyle: {
Expand All @@ -139,6 +157,7 @@ const TopTabNavigator = () => {
<Tab.Navigator initialRouteName="Home" screenOptions={screenOptions}>
<Tab.Screen component={App} key={'Home'} name={'Home'} />
<Tab.Screen component={DetailsTab} key={'Details'} name={'Details'} />
<Tab.Screen component={LinkingExample} key={'Linking'} name={'Linking'} />
</Tab.Navigator>
);
};
Expand All @@ -147,6 +166,16 @@ const TabbedApp = () => {
return (
<SafeAreaProvider>
<NavigationContainer
linking={{
prefixes: ['plaut-ro.github.io/luna', 'localhost'],
LunatiqueCoder marked this conversation as resolved.
Show resolved Hide resolved
config: {
screens: {
Details: 'details',
Linking: 'linking',
Home: '*', // Fall back to if no routes match
},
},
}}
documentTitle={{
formatter: (options, route) =>
`${appJson.displayName} - ${options?.title ?? route?.name}`,
Expand Down