Compare commits
43 Commits
@react-nav
...
@react-nav
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
31565d5576 | ||
|
|
2c31d1705c | ||
|
|
8f9a250958 | ||
|
|
87d28ca430 | ||
|
|
fa4411a14d | ||
|
|
77b757091c | ||
|
|
6b9b999c5b | ||
|
|
8c5f84094f | ||
|
|
21709f7674 | ||
|
|
22742e4a7f | ||
|
|
3cd1aedcf4 | ||
|
|
797d3a798e | ||
|
|
59803f54d6 | ||
|
|
935659899f | ||
|
|
ef0f5d6567 | ||
|
|
499f66dba4 | ||
|
|
2ef2f1a86f | ||
|
|
0252bdc222 | ||
|
|
282f62c258 | ||
|
|
f462d67270 | ||
|
|
873afec9fe | ||
|
|
878297e52f | ||
|
|
1ea9b4524d | ||
|
|
c52a8c46a8 | ||
|
|
0635365483 | ||
|
|
9843b92e05 | ||
|
|
ebd145a09d | ||
|
|
9fc1af02c2 | ||
|
|
68a334cc93 | ||
|
|
c110570d4c | ||
|
|
d57226fd8b | ||
|
|
c3d3748143 | ||
|
|
8002d51795 | ||
|
|
31cf19912b | ||
|
|
d0e4e1f6fb | ||
|
|
00fc616de0 | ||
|
|
703edb3569 | ||
|
|
38a38b021a | ||
|
|
42bc37d2ff | ||
|
|
75ad2aaae5 | ||
|
|
eef17a801e | ||
|
|
7b8277dae5 | ||
|
|
6cddb5238c |
@@ -35,7 +35,7 @@ Navigators bundle a router and a view which takes the navigation state and decid
|
|||||||
A simple navigator could look like this:
|
A simple navigator could look like this:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
import { createNavigatorFactory } from '@react-navigation/core';
|
import { createNavigatorFactory } from '@react-navigation/native';
|
||||||
|
|
||||||
function StackNavigator({ initialRouteName, children, ...rest }) {
|
function StackNavigator({ initialRouteName, children, ...rest }) {
|
||||||
// The `navigation` object contains the navigation state and some helpers (e.g. push, pop)
|
// The `navigation` object contains the navigation state and some helpers (e.g. push, pop)
|
||||||
@@ -256,7 +256,7 @@ Sometimes we want to run side-effects when a screen is focused. A side effect ma
|
|||||||
To make this easier, the library exports a `useFocusEffect` hook:
|
To make this easier, the library exports a `useFocusEffect` hook:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
import { useFocusEffect } from '@react-navigation/core';
|
import { useFocusEffect } from '@react-navigation/native';
|
||||||
|
|
||||||
function Profile({ userId }) {
|
function Profile({ userId }) {
|
||||||
const [user, setUser] = React.useState(null);
|
const [user, setUser] = React.useState(null);
|
||||||
@@ -285,7 +285,7 @@ The `useFocusEffect` is analogous to React's `useEffect` hook. The only differen
|
|||||||
We might want to render different content based on the current focus state of the screen. The library exports a `useIsFocused` hook to make this easier:
|
We might want to render different content based on the current focus state of the screen. The library exports a `useIsFocused` hook to make this easier:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
import { useIsFocused } from '@react-navigation/core';
|
import { useIsFocused } from '@react-navigation/native';
|
||||||
|
|
||||||
// ...
|
// ...
|
||||||
|
|
||||||
|
|||||||
@@ -13,5 +13,8 @@ module.exports = {
|
|||||||
'@babel/preset-react',
|
'@babel/preset-react',
|
||||||
'@babel/preset-typescript',
|
'@babel/preset-typescript',
|
||||||
],
|
],
|
||||||
plugins: ['@babel/plugin-proposal-class-properties'],
|
plugins: [
|
||||||
|
'@babel/plugin-proposal-class-properties',
|
||||||
|
'@babel/plugin-proposal-optional-chaining',
|
||||||
|
],
|
||||||
};
|
};
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 29 KiB After Width: | Height: | Size: 28 KiB |
|
Before Width: | Height: | Size: 21 KiB After Width: | Height: | Size: 20 KiB |
|
Before Width: | Height: | Size: 28 KiB After Width: | Height: | Size: 27 KiB |
|
Before Width: | Height: | Size: 35 KiB After Width: | Height: | Size: 33 KiB |
|
Before Width: | Height: | Size: 22 KiB After Width: | Height: | Size: 22 KiB |
|
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 10 KiB |
|
Before Width: | Height: | Size: 21 KiB After Width: | Height: | Size: 21 KiB |
|
Before Width: | Height: | Size: 3.3 KiB After Width: | Height: | Size: 2.4 KiB |
|
Before Width: | Height: | Size: 2.3 KiB After Width: | Height: | Size: 1.7 KiB |
|
Before Width: | Height: | Size: 98 KiB After Width: | Height: | Size: 94 KiB |
|
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 900 B |
@@ -54,6 +54,23 @@ module.exports = {
|
|||||||
}, {}),
|
}, {}),
|
||||||
},
|
},
|
||||||
|
|
||||||
|
server: {
|
||||||
|
enhanceMiddleware: middleware => {
|
||||||
|
return (req, res, next) => {
|
||||||
|
const assets = '/packages/stack/src/views/assets';
|
||||||
|
|
||||||
|
if (req.url.startsWith(assets)) {
|
||||||
|
req.url = req.url.replace(
|
||||||
|
assets,
|
||||||
|
'/assets/../packages/stack/src/views/assets'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return middleware(req, res, next);
|
||||||
|
};
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
transformer: {
|
transformer: {
|
||||||
getTransformOptions: async () => ({
|
getTransformOptions: async () => ({
|
||||||
transform: {
|
transform: {
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@expo/vector-icons": "^10.0.0",
|
"@expo/vector-icons": "^10.0.0",
|
||||||
"@react-native-community/masked-view": "0.1.5",
|
"@react-native-community/masked-view": "0.1.5",
|
||||||
|
"color": "^3.1.2",
|
||||||
"expo": "^36.0.0",
|
"expo": "^36.0.0",
|
||||||
"expo-asset": "~8.0.0",
|
"expo-asset": "~8.0.0",
|
||||||
"query-string": "^6.9.0",
|
"query-string": "^6.9.0",
|
||||||
@@ -27,24 +28,25 @@
|
|||||||
"react-dom": "~16.9.0",
|
"react-dom": "~16.9.0",
|
||||||
"react-native": "~0.61.5",
|
"react-native": "~0.61.5",
|
||||||
"react-native-gesture-handler": "~1.5.0",
|
"react-native-gesture-handler": "~1.5.0",
|
||||||
"react-native-paper": "^3.2.1",
|
"react-native-iphone-x-helper": "^1.2.1",
|
||||||
|
"react-native-paper": "^3.3.0",
|
||||||
"react-native-reanimated": "^1.4.0",
|
"react-native-reanimated": "^1.4.0",
|
||||||
"react-native-safe-area-context": "^0.6.0",
|
"react-native-safe-area-context": "^0.6.0",
|
||||||
"react-native-screens": "^2.0.0-alpha.12",
|
"react-native-screens": "^2.0.0-alpha.19",
|
||||||
"react-native-tab-view": "2.11.0",
|
"react-native-tab-view": "2.11.0",
|
||||||
"react-native-unimodules": "^0.6.0",
|
"react-native-unimodules": "^0.7.0",
|
||||||
"react-native-web": "^0.11.7",
|
"react-native-web": "^0.11.7",
|
||||||
"scheduler": "^0.18.0",
|
"scheduler": "^0.18.0",
|
||||||
"shortid": "^2.2.15",
|
"shortid": "^2.2.15",
|
||||||
"use-subscription": "^1.3.0"
|
"use-subscription": "^1.3.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/core": "^7.7.2",
|
"@babel/core": "^7.7.5",
|
||||||
"@expo/webpack-config": "^0.10.1",
|
"@expo/webpack-config": "^0.10.6",
|
||||||
"@types/react": "^16.9.11",
|
"@types/react": "^16.9.16",
|
||||||
"@types/react-native": "^0.60.22",
|
"@types/react-native": "^0.60.25",
|
||||||
"babel-preset-expo": "^7.1.0",
|
"babel-preset-expo": "^8.0.0",
|
||||||
"expo-cli": "^3.8.0",
|
"expo-cli": "^3.11.1",
|
||||||
"typescript": "^3.7.2"
|
"typescript": "^3.7.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import { View, TextInput, ActivityIndicator, StyleSheet } from 'react-native';
|
import { View, TextInput, ActivityIndicator, StyleSheet } from 'react-native';
|
||||||
import { Title, Button } from 'react-native-paper';
|
import { Title, Button } from 'react-native-paper';
|
||||||
import { ParamListBase } from '@react-navigation/core';
|
import { ParamListBase } from '@react-navigation/native';
|
||||||
import {
|
import {
|
||||||
createStackNavigator,
|
createStackNavigator,
|
||||||
HeaderBackButton,
|
HeaderBackButton,
|
||||||
@@ -9,11 +9,27 @@ import {
|
|||||||
} from '@react-navigation/stack';
|
} from '@react-navigation/stack';
|
||||||
|
|
||||||
type AuthStackParams = {
|
type AuthStackParams = {
|
||||||
splash: undefined;
|
Splash: undefined;
|
||||||
home: undefined;
|
Home: undefined;
|
||||||
'sign-in': undefined;
|
SignIn: undefined;
|
||||||
|
PostSignOut: undefined;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const AUTH_CONTEXT_ERROR =
|
||||||
|
'Authentication context not found. Have your wrapped your components with AuthContext.Consumer?';
|
||||||
|
|
||||||
|
const AuthContext = React.createContext<{
|
||||||
|
signIn: () => void;
|
||||||
|
signOut: () => void;
|
||||||
|
}>({
|
||||||
|
signIn: () => {
|
||||||
|
throw new Error(AUTH_CONTEXT_ERROR);
|
||||||
|
},
|
||||||
|
signOut: () => {
|
||||||
|
throw new Error(AUTH_CONTEXT_ERROR);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
const SplashScreen = () => {
|
const SplashScreen = () => {
|
||||||
return (
|
return (
|
||||||
<View style={styles.content}>
|
<View style={styles.content}>
|
||||||
@@ -22,27 +38,27 @@ const SplashScreen = () => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const SignInScreen = ({ onSignIn }: { onSignIn: (token: string) => void }) => {
|
const SignInScreen = () => {
|
||||||
|
const { signIn } = React.useContext(AuthContext);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={styles.content}>
|
<View style={styles.content}>
|
||||||
<TextInput placeholder="Username" style={styles.input} />
|
<TextInput placeholder="Username" style={styles.input} />
|
||||||
<TextInput placeholder="Password" secureTextEntry style={styles.input} />
|
<TextInput placeholder="Password" secureTextEntry style={styles.input} />
|
||||||
<Button
|
<Button mode="contained" onPress={signIn} style={styles.button}>
|
||||||
mode="contained"
|
|
||||||
onPress={() => onSignIn('token')}
|
|
||||||
style={styles.button}
|
|
||||||
>
|
|
||||||
Sign in
|
Sign in
|
||||||
</Button>
|
</Button>
|
||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const HomeScreen = ({ onSignOut }: { onSignOut: () => void }) => {
|
const HomeScreen = () => {
|
||||||
|
const { signOut } = React.useContext(AuthContext);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={styles.content}>
|
<View style={styles.content}>
|
||||||
<Title style={styles.text}>Signed in successfully 🎉</Title>
|
<Title style={styles.text}>Signed in successfully 🎉</Title>
|
||||||
<Button onPress={onSignOut} style={styles.button}>
|
<Button onPress={signOut} style={styles.button}>
|
||||||
Sign out
|
Sign out
|
||||||
</Button>
|
</Button>
|
||||||
</View>
|
</View>
|
||||||
@@ -105,7 +121,16 @@ export default function SimpleStackScreen({ navigation }: Props) {
|
|||||||
headerShown: false,
|
headerShown: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const authContext = React.useMemo(
|
||||||
|
() => ({
|
||||||
|
signIn: () => dispatch({ type: 'SIGN_IN', token: 'dummy-auth-token' }),
|
||||||
|
signOut: () => dispatch({ type: 'SIGN_OUT' }),
|
||||||
|
}),
|
||||||
|
[]
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
<AuthContext.Provider value={authContext}>
|
||||||
<SimpleStack.Navigator
|
<SimpleStack.Navigator
|
||||||
screenOptions={{
|
screenOptions={{
|
||||||
headerLeft: () => (
|
headerLeft: () => (
|
||||||
@@ -115,26 +140,25 @@ export default function SimpleStackScreen({ navigation }: Props) {
|
|||||||
>
|
>
|
||||||
{state.isLoading ? (
|
{state.isLoading ? (
|
||||||
<SimpleStack.Screen
|
<SimpleStack.Screen
|
||||||
name="splash"
|
name="Splash"
|
||||||
component={SplashScreen}
|
component={SplashScreen}
|
||||||
options={{ title: `Auth Flow` }}
|
options={{ title: 'Auth Flow' }}
|
||||||
/>
|
/>
|
||||||
) : state.userToken === undefined ? (
|
) : state.userToken === undefined ? (
|
||||||
<SimpleStack.Screen name="sign-in" options={{ title: `Sign in` }}>
|
<SimpleStack.Screen
|
||||||
{() => (
|
name="SignIn"
|
||||||
<SignInScreen
|
options={{ title: 'Sign in' }}
|
||||||
onSignIn={token => dispatch({ type: 'SIGN_IN', token })}
|
component={SignInScreen}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<SimpleStack.Screen
|
||||||
|
name="Home"
|
||||||
|
options={{ title: 'Home' }}
|
||||||
|
component={HomeScreen}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</SimpleStack.Screen>
|
|
||||||
) : (
|
|
||||||
<SimpleStack.Screen name="home" options={{ title: 'Home' }}>
|
|
||||||
{() => (
|
|
||||||
<HomeScreen onSignOut={() => dispatch({ type: 'SIGN_OUT' })} />
|
|
||||||
)}
|
|
||||||
</SimpleStack.Screen>
|
|
||||||
)}
|
|
||||||
</SimpleStack.Navigator>
|
</SimpleStack.Navigator>
|
||||||
|
</AuthContext.Provider>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,10 +16,10 @@ const getTabBarIcon = (name: string) => ({
|
|||||||
}) => <MaterialCommunityIcons name={name} color={color} size={size} />;
|
}) => <MaterialCommunityIcons name={name} color={color} size={size} />;
|
||||||
|
|
||||||
type BottomTabParams = {
|
type BottomTabParams = {
|
||||||
article: undefined;
|
Article: undefined;
|
||||||
albums: undefined;
|
Albums: undefined;
|
||||||
contacts: undefined;
|
Contacts: undefined;
|
||||||
chat: undefined;
|
Chat: undefined;
|
||||||
};
|
};
|
||||||
|
|
||||||
const BottomTabs = createBottomTabNavigator<BottomTabParams>();
|
const BottomTabs = createBottomTabNavigator<BottomTabParams>();
|
||||||
@@ -32,7 +32,7 @@ export default function BottomTabsScreen() {
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<BottomTabs.Screen
|
<BottomTabs.Screen
|
||||||
name="article"
|
name="Article"
|
||||||
options={{
|
options={{
|
||||||
title: 'Article',
|
title: 'Article',
|
||||||
tabBarIcon: getTabBarIcon('file-document-box'),
|
tabBarIcon: getTabBarIcon('file-document-box'),
|
||||||
@@ -41,7 +41,7 @@ export default function BottomTabsScreen() {
|
|||||||
{props => <SimpleStackScreen {...props} headerMode="none" />}
|
{props => <SimpleStackScreen {...props} headerMode="none" />}
|
||||||
</BottomTabs.Screen>
|
</BottomTabs.Screen>
|
||||||
<BottomTabs.Screen
|
<BottomTabs.Screen
|
||||||
name="chat"
|
name="Chat"
|
||||||
component={Chat}
|
component={Chat}
|
||||||
options={{
|
options={{
|
||||||
tabBarLabel: 'Chat',
|
tabBarLabel: 'Chat',
|
||||||
@@ -49,7 +49,7 @@ export default function BottomTabsScreen() {
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<BottomTabs.Screen
|
<BottomTabs.Screen
|
||||||
name="contacts"
|
name="Contacts"
|
||||||
component={Contacts}
|
component={Contacts}
|
||||||
options={{
|
options={{
|
||||||
title: 'Contacts',
|
title: 'Contacts',
|
||||||
@@ -57,7 +57,7 @@ export default function BottomTabsScreen() {
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<BottomTabs.Screen
|
<BottomTabs.Screen
|
||||||
name="albums"
|
name="Albums"
|
||||||
component={Albums}
|
component={Albums}
|
||||||
options={{
|
options={{
|
||||||
title: 'Albums',
|
title: 'Albums',
|
||||||
|
|||||||
@@ -7,10 +7,10 @@ import Chat from '../Shared/Chat';
|
|||||||
import SimpleStackScreen from './SimpleStack';
|
import SimpleStackScreen from './SimpleStack';
|
||||||
|
|
||||||
type MaterialBottomTabParams = {
|
type MaterialBottomTabParams = {
|
||||||
article: undefined;
|
Article: undefined;
|
||||||
albums: undefined;
|
Albums: undefined;
|
||||||
contacts: undefined;
|
Contacts: undefined;
|
||||||
chat: undefined;
|
Chat: undefined;
|
||||||
};
|
};
|
||||||
|
|
||||||
const MaterialBottomTabs = createMaterialBottomTabNavigator<
|
const MaterialBottomTabs = createMaterialBottomTabNavigator<
|
||||||
@@ -21,7 +21,7 @@ export default function MaterialBottomTabsScreen() {
|
|||||||
return (
|
return (
|
||||||
<MaterialBottomTabs.Navigator barStyle={styles.tabBar}>
|
<MaterialBottomTabs.Navigator barStyle={styles.tabBar}>
|
||||||
<MaterialBottomTabs.Screen
|
<MaterialBottomTabs.Screen
|
||||||
name="article"
|
name="Article"
|
||||||
options={{
|
options={{
|
||||||
tabBarLabel: 'Article',
|
tabBarLabel: 'Article',
|
||||||
tabBarIcon: 'file-document-box',
|
tabBarIcon: 'file-document-box',
|
||||||
@@ -31,7 +31,7 @@ export default function MaterialBottomTabsScreen() {
|
|||||||
{props => <SimpleStackScreen {...props} headerMode="none" />}
|
{props => <SimpleStackScreen {...props} headerMode="none" />}
|
||||||
</MaterialBottomTabs.Screen>
|
</MaterialBottomTabs.Screen>
|
||||||
<MaterialBottomTabs.Screen
|
<MaterialBottomTabs.Screen
|
||||||
name="chat"
|
name="Chat"
|
||||||
component={Chat}
|
component={Chat}
|
||||||
options={{
|
options={{
|
||||||
tabBarLabel: 'Chat',
|
tabBarLabel: 'Chat',
|
||||||
@@ -41,7 +41,7 @@ export default function MaterialBottomTabsScreen() {
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<MaterialBottomTabs.Screen
|
<MaterialBottomTabs.Screen
|
||||||
name="contacts"
|
name="Contacts"
|
||||||
component={Contacts}
|
component={Contacts}
|
||||||
options={{
|
options={{
|
||||||
tabBarLabel: 'Contacts',
|
tabBarLabel: 'Contacts',
|
||||||
@@ -50,7 +50,7 @@ export default function MaterialBottomTabsScreen() {
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<MaterialBottomTabs.Screen
|
<MaterialBottomTabs.Screen
|
||||||
name="albums"
|
name="Albums"
|
||||||
component={Albums}
|
component={Albums}
|
||||||
options={{
|
options={{
|
||||||
tabBarLabel: 'Albums',
|
tabBarLabel: 'Albums',
|
||||||
|
|||||||
@@ -1,54 +1,35 @@
|
|||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import { StyleSheet } from 'react-native';
|
|
||||||
import { createMaterialTopTabNavigator } from '@react-navigation/material-top-tabs';
|
import { createMaterialTopTabNavigator } from '@react-navigation/material-top-tabs';
|
||||||
import Albums from '../Shared/Albums';
|
import Albums from '../Shared/Albums';
|
||||||
import Contacts from '../Shared/Contacts';
|
import Contacts from '../Shared/Contacts';
|
||||||
import Chat from '../Shared/Chat';
|
import Chat from '../Shared/Chat';
|
||||||
|
|
||||||
type MaterialTopTabParams = {
|
type MaterialTopTabParams = {
|
||||||
albums: undefined;
|
Albums: undefined;
|
||||||
contacts: undefined;
|
Contacts: undefined;
|
||||||
chat: undefined;
|
Chat: undefined;
|
||||||
};
|
};
|
||||||
|
|
||||||
const MaterialTopTabs = createMaterialTopTabNavigator<MaterialTopTabParams>();
|
const MaterialTopTabs = createMaterialTopTabNavigator<MaterialTopTabParams>();
|
||||||
|
|
||||||
export default function MaterialTopTabsScreen() {
|
export default function MaterialTopTabsScreen() {
|
||||||
return (
|
return (
|
||||||
<MaterialTopTabs.Navigator
|
<MaterialTopTabs.Navigator>
|
||||||
tabBarOptions={{
|
|
||||||
style: styles.tabBar,
|
|
||||||
labelStyle: styles.tabLabel,
|
|
||||||
indicatorStyle: styles.tabIndicator,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<MaterialTopTabs.Screen
|
<MaterialTopTabs.Screen
|
||||||
name="chat"
|
name="Chat"
|
||||||
component={Chat}
|
component={Chat}
|
||||||
options={{ title: 'Chat' }}
|
options={{ title: 'Chat' }}
|
||||||
/>
|
/>
|
||||||
<MaterialTopTabs.Screen
|
<MaterialTopTabs.Screen
|
||||||
name="contacts"
|
name="Contacts"
|
||||||
component={Contacts}
|
component={Contacts}
|
||||||
options={{ title: 'Contacts' }}
|
options={{ title: 'Contacts' }}
|
||||||
/>
|
/>
|
||||||
<MaterialTopTabs.Screen
|
<MaterialTopTabs.Screen
|
||||||
name="albums"
|
name="Albums"
|
||||||
component={Albums}
|
component={Albums}
|
||||||
options={{ title: 'Albums' }}
|
options={{ title: 'Albums' }}
|
||||||
/>
|
/>
|
||||||
</MaterialTopTabs.Navigator>
|
</MaterialTopTabs.Navigator>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
|
||||||
tabBar: {
|
|
||||||
backgroundColor: 'white',
|
|
||||||
},
|
|
||||||
tabLabel: {
|
|
||||||
color: 'black',
|
|
||||||
},
|
|
||||||
tabIndicator: {
|
|
||||||
backgroundColor: 'tomato',
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import * as React from 'react';
|
|||||||
import { View, StyleSheet } from 'react-native';
|
import { View, StyleSheet } from 'react-native';
|
||||||
import { Button } from 'react-native-paper';
|
import { Button } from 'react-native-paper';
|
||||||
import { useSafeArea } from 'react-native-safe-area-context';
|
import { useSafeArea } from 'react-native-safe-area-context';
|
||||||
import { RouteProp, ParamListBase } from '@react-navigation/core';
|
import { RouteProp, ParamListBase } from '@react-navigation/native';
|
||||||
import {
|
import {
|
||||||
createStackNavigator,
|
createStackNavigator,
|
||||||
StackNavigationProp,
|
StackNavigationProp,
|
||||||
@@ -11,19 +11,19 @@ import {
|
|||||||
import Article from '../Shared/Article';
|
import Article from '../Shared/Article';
|
||||||
import Albums from '../Shared/Albums';
|
import Albums from '../Shared/Albums';
|
||||||
|
|
||||||
type SimpleStackParams = {
|
type ModalStackParams = {
|
||||||
article: { author: string };
|
Article: { author: string };
|
||||||
album: undefined;
|
Album: undefined;
|
||||||
};
|
};
|
||||||
|
|
||||||
type SimpleStackNavigation = StackNavigationProp<SimpleStackParams>;
|
type ModalStackNavigation = StackNavigationProp<ModalStackParams>;
|
||||||
|
|
||||||
const ArticleScreen = ({
|
const ArticleScreen = ({
|
||||||
navigation,
|
navigation,
|
||||||
route,
|
route,
|
||||||
}: {
|
}: {
|
||||||
navigation: SimpleStackNavigation;
|
navigation: ModalStackNavigation;
|
||||||
route: RouteProp<SimpleStackParams, 'article'>;
|
route: RouteProp<ModalStackParams, 'Article'>;
|
||||||
}) => {
|
}) => {
|
||||||
const insets = useSafeArea();
|
const insets = useSafeArea();
|
||||||
|
|
||||||
@@ -32,7 +32,7 @@ const ArticleScreen = ({
|
|||||||
<View style={[styles.buttons, { marginTop: insets.top }]}>
|
<View style={[styles.buttons, { marginTop: insets.top }]}>
|
||||||
<Button
|
<Button
|
||||||
mode="contained"
|
mode="contained"
|
||||||
onPress={() => navigation.push('album')}
|
onPress={() => navigation.push('Album')}
|
||||||
style={styles.button}
|
style={styles.button}
|
||||||
>
|
>
|
||||||
Push album
|
Push album
|
||||||
@@ -50,11 +50,7 @@ const ArticleScreen = ({
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const AlbumsScreen = ({
|
const AlbumsScreen = ({ navigation }: { navigation: ModalStackNavigation }) => {
|
||||||
navigation,
|
|
||||||
}: {
|
|
||||||
navigation: SimpleStackNavigation;
|
|
||||||
}) => {
|
|
||||||
const insets = useSafeArea();
|
const insets = useSafeArea();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -62,7 +58,7 @@ const AlbumsScreen = ({
|
|||||||
<View style={[styles.buttons, { marginTop: insets.top }]}>
|
<View style={[styles.buttons, { marginTop: insets.top }]}>
|
||||||
<Button
|
<Button
|
||||||
mode="contained"
|
mode="contained"
|
||||||
onPress={() => navigation.push('article', { author: 'Babel fish' })}
|
onPress={() => navigation.push('Article', { author: 'Babel fish' })}
|
||||||
style={styles.button}
|
style={styles.button}
|
||||||
>
|
>
|
||||||
Push article
|
Push article
|
||||||
@@ -80,7 +76,7 @@ const AlbumsScreen = ({
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const ModalPresentationStack = createStackNavigator<SimpleStackParams>();
|
const ModalPresentationStack = createStackNavigator<ModalStackParams>();
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
options?: React.ComponentProps<typeof ModalPresentationStack.Navigator>;
|
options?: React.ComponentProps<typeof ModalPresentationStack.Navigator>;
|
||||||
@@ -104,7 +100,7 @@ export default function SimpleStackScreen({ navigation, options }: Props) {
|
|||||||
{...options}
|
{...options}
|
||||||
>
|
>
|
||||||
<ModalPresentationStack.Screen
|
<ModalPresentationStack.Screen
|
||||||
name="article"
|
name="Article"
|
||||||
component={ArticleScreen}
|
component={ArticleScreen}
|
||||||
options={({ route }) => ({
|
options={({ route }) => ({
|
||||||
title: `Article by ${route.params.author}`,
|
title: `Article by ${route.params.author}`,
|
||||||
@@ -112,7 +108,7 @@ export default function SimpleStackScreen({ navigation, options }: Props) {
|
|||||||
initialParams={{ author: 'Gandalf' }}
|
initialParams={{ author: 'Gandalf' }}
|
||||||
/>
|
/>
|
||||||
<ModalPresentationStack.Screen
|
<ModalPresentationStack.Screen
|
||||||
name="album"
|
name="Album"
|
||||||
component={AlbumsScreen}
|
component={AlbumsScreen}
|
||||||
options={{ title: 'Album' }}
|
options={{ title: 'Album' }}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -7,7 +7,8 @@ import {
|
|||||||
RouteProp,
|
RouteProp,
|
||||||
ParamListBase,
|
ParamListBase,
|
||||||
useFocusEffect,
|
useFocusEffect,
|
||||||
} from '@react-navigation/core';
|
useTheme,
|
||||||
|
} from '@react-navigation/native';
|
||||||
import { DrawerNavigationProp } from '@react-navigation/drawer';
|
import { DrawerNavigationProp } from '@react-navigation/drawer';
|
||||||
import { StackNavigationProp } from '@react-navigation/stack';
|
import { StackNavigationProp } from '@react-navigation/stack';
|
||||||
import {
|
import {
|
||||||
@@ -17,23 +18,43 @@ import {
|
|||||||
import Albums from '../Shared/Albums';
|
import Albums from '../Shared/Albums';
|
||||||
|
|
||||||
type NativeStackParams = {
|
type NativeStackParams = {
|
||||||
article: { author: string };
|
Article: { author: string };
|
||||||
album: undefined;
|
Album: undefined;
|
||||||
};
|
};
|
||||||
|
|
||||||
type NativeStackNavigation = NativeStackNavigationProp<NativeStackParams>;
|
type NativeStackNavigation = NativeStackNavigationProp<NativeStackParams>;
|
||||||
|
|
||||||
|
const Title = ({ children }: { children: React.ReactNode }) => {
|
||||||
|
const { colors } = useTheme();
|
||||||
|
|
||||||
|
return <Text style={[styles.title, { color: colors.text }]}>{children}</Text>;
|
||||||
|
};
|
||||||
|
|
||||||
|
const Paragraph = ({ children }: { children: React.ReactNode }) => {
|
||||||
|
const { colors } = useTheme();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Text style={[styles.paragraph, { color: colors.text }]}>{children}</Text>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
const ArticleScreen = ({
|
const ArticleScreen = ({
|
||||||
navigation,
|
navigation,
|
||||||
}: {
|
}: {
|
||||||
navigation: NativeStackNavigation;
|
navigation: NativeStackNavigation;
|
||||||
route: RouteProp<NativeStackParams, 'article'>;
|
route: RouteProp<NativeStackParams, 'Article'>;
|
||||||
}) => (
|
}) => {
|
||||||
<ScrollView style={styles.container} contentContainerStyle={styles.content}>
|
const { colors } = useTheme();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ScrollView
|
||||||
|
style={{ backgroundColor: colors.card }}
|
||||||
|
contentContainerStyle={styles.content}
|
||||||
|
>
|
||||||
<View style={styles.buttons}>
|
<View style={styles.buttons}>
|
||||||
<Button
|
<Button
|
||||||
mode="contained"
|
mode="contained"
|
||||||
onPress={() => navigation.push('album')}
|
onPress={() => navigation.push('Album')}
|
||||||
style={styles.button}
|
style={styles.button}
|
||||||
>
|
>
|
||||||
Push album
|
Push album
|
||||||
@@ -46,67 +67,70 @@ const ArticleScreen = ({
|
|||||||
Go back
|
Go back
|
||||||
</Button>
|
</Button>
|
||||||
</View>
|
</View>
|
||||||
<Text style={styles.title}>What is Lorem Ipsum?</Text>
|
<Title>What is Lorem Ipsum?</Title>
|
||||||
<Text style={styles.paragraph}>
|
<Paragraph>
|
||||||
Lorem Ipsum is simply dummy text of the printing and typesetting industry.
|
Lorem Ipsum is simply dummy text of the printing and typesetting
|
||||||
Lorem Ipsum has been the industry's standard dummy text ever since
|
industry. Lorem Ipsum has been the industry's standard dummy text
|
||||||
the 1500s, when an unknown printer took a galley of type and scrambled it
|
ever since the 1500s, when an unknown printer took a galley of type and
|
||||||
to make a type specimen book. It has survived not only five centuries, but
|
scrambled it to make a type specimen book. It has survived not only five
|
||||||
also the leap into electronic typesetting, remaining essentially
|
centuries, but also the leap into electronic typesetting, remaining
|
||||||
unchanged. It was popularised in the 1960s with the release of Letraset
|
essentially unchanged. It was popularised in the 1960s with the release
|
||||||
sheets containing Lorem Ipsum passages, and more recently with desktop
|
of Letraset sheets containing Lorem Ipsum passages, and more recently
|
||||||
publishing software like Aldus PageMaker including versions of Lorem
|
with desktop publishing software like Aldus PageMaker including versions
|
||||||
Ipsum.
|
of Lorem Ipsum.
|
||||||
</Text>
|
</Paragraph>
|
||||||
<Text style={styles.title}>Where does it come from?</Text>
|
<Title>Where does it come from?</Title>
|
||||||
<Text style={styles.paragraph}>
|
<Paragraph>
|
||||||
Contrary to popular belief, Lorem Ipsum is not simply random text. It has
|
Contrary to popular belief, Lorem Ipsum is not simply random text. It
|
||||||
roots in a piece of classical Latin literature from 45 BC, making it over
|
has roots in a piece of classical Latin literature from 45 BC, making it
|
||||||
2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney
|
over 2000 years old. Richard McClintock, a Latin professor at
|
||||||
College in Virginia, looked up one of the more obscure Latin words,
|
Hampden-Sydney College in Virginia, looked up one of the more obscure
|
||||||
consectetur, from a Lorem Ipsum passage, and going through the cites of
|
Latin words, consectetur, from a Lorem Ipsum passage, and going through
|
||||||
the word in classical literature, discovered the undoubtable source. Lorem
|
the cites of the word in classical literature, discovered the
|
||||||
Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum
|
undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33
|
||||||
et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45
|
of "de Finibus Bonorum et Malorum" (The Extremes of Good and
|
||||||
BC. This book is a treatise on the theory of ethics, very popular during
|
Evil) by Cicero, written in 45 BC. This book is a treatise on the theory
|
||||||
the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor
|
of ethics, very popular during the Renaissance. The first line of Lorem
|
||||||
sit amet..", comes from a line in section 1.10.32.
|
Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in
|
||||||
</Text>
|
section 1.10.32.
|
||||||
<Text style={styles.paragraph}>
|
</Paragraph>
|
||||||
The standard chunk of Lorem Ipsum used since the 1500s is reproduced below
|
<Paragraph>
|
||||||
for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus
|
The standard chunk of Lorem Ipsum used since the 1500s is reproduced
|
||||||
Bonorum et Malorum" by Cicero are also reproduced in their exact
|
below for those interested. Sections 1.10.32 and 1.10.33 from "de
|
||||||
original form, accompanied by English versions from the 1914 translation
|
Finibus Bonorum et Malorum" by Cicero are also reproduced in their
|
||||||
by H. Rackham.
|
exact original form, accompanied by English versions from the 1914
|
||||||
</Text>
|
translation by H. Rackham.
|
||||||
<Text style={styles.title}>Why do we use it?</Text>
|
</Paragraph>
|
||||||
<Text style={styles.paragraph}>
|
<Title>Why do we use it?</Title>
|
||||||
|
<Paragraph>
|
||||||
It is a long established fact that a reader will be distracted by the
|
It is a long established fact that a reader will be distracted by the
|
||||||
readable content of a page when looking at its layout. The point of using
|
readable content of a page when looking at its layout. The point of
|
||||||
Lorem Ipsum is that it has a more-or-less normal distribution of letters,
|
using Lorem Ipsum is that it has a more-or-less normal distribution of
|
||||||
as opposed to using "Content here, content here", making it look
|
letters, as opposed to using "Content here, content here",
|
||||||
like readable English. Many desktop publishing packages and web page
|
making it look like readable English. Many desktop publishing packages
|
||||||
editors now use Lorem Ipsum as their default model text, and a search for
|
and web page editors now use Lorem Ipsum as their default model text,
|
||||||
"lorem ipsum" will uncover many web sites still in their
|
and a search for "lorem ipsum" will uncover many web sites
|
||||||
infancy. Various versions have evolved over the years, sometimes by
|
still in their infancy. Various versions have evolved over the years,
|
||||||
accident, sometimes on purpose (injected humour and the like).
|
sometimes by accident, sometimes on purpose (injected humour and the
|
||||||
</Text>
|
like).
|
||||||
<Text style={styles.title}>Where can I get some?</Text>
|
</Paragraph>
|
||||||
<Text style={styles.paragraph}>
|
<Title>Where can I get some?</Title>
|
||||||
|
<Paragraph>
|
||||||
There are many variations of passages of Lorem Ipsum available, but the
|
There are many variations of passages of Lorem Ipsum available, but the
|
||||||
majority have suffered alteration in some form, by injected humour, or
|
majority have suffered alteration in some form, by injected humour, or
|
||||||
randomised words which don't look even slightly believable. If you
|
randomised words which don't look even slightly believable. If you
|
||||||
are going to use a passage of Lorem Ipsum, you need to be sure there
|
are going to use a passage of Lorem Ipsum, you need to be sure there
|
||||||
isn't anything embarrassing hidden in the middle of text. All the
|
isn't anything embarrassing hidden in the middle of text. All the
|
||||||
Lorem Ipsum generators on the Internet tend to repeat predefined chunks as
|
Lorem Ipsum generators on the Internet tend to repeat predefined chunks
|
||||||
necessary, making this the first true generator on the Internet. It uses a
|
as necessary, making this the first true generator on the Internet. It
|
||||||
dictionary of over 200 Latin words, combined with a handful of model
|
uses a dictionary of over 200 Latin words, combined with a handful of
|
||||||
sentence structures, to generate Lorem Ipsum which looks reasonable. The
|
model sentence structures, to generate Lorem Ipsum which looks
|
||||||
generated Lorem Ipsum is therefore always free from repetition, injected
|
reasonable. The generated Lorem Ipsum is therefore always free from
|
||||||
humour, or non-characteristic words etc.
|
repetition, injected humour, or non-characteristic words etc.
|
||||||
</Text>
|
</Paragraph>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
);
|
);
|
||||||
|
};
|
||||||
|
|
||||||
const AlbumsScreen = ({
|
const AlbumsScreen = ({
|
||||||
navigation,
|
navigation,
|
||||||
@@ -117,7 +141,7 @@ const AlbumsScreen = ({
|
|||||||
<View style={styles.buttons}>
|
<View style={styles.buttons}>
|
||||||
<Button
|
<Button
|
||||||
mode="contained"
|
mode="contained"
|
||||||
onPress={() => navigation.push('article', { author: 'Babel fish' })}
|
onPress={() => navigation.push('Article', { author: 'Babel fish' })}
|
||||||
style={styles.button}
|
style={styles.button}
|
||||||
>
|
>
|
||||||
Push article
|
Push article
|
||||||
@@ -164,7 +188,7 @@ export default function NativeStackScreen({ navigation }: Props) {
|
|||||||
return (
|
return (
|
||||||
<NativeStack.Navigator>
|
<NativeStack.Navigator>
|
||||||
<NativeStack.Screen
|
<NativeStack.Screen
|
||||||
name="article"
|
name="Article"
|
||||||
component={ArticleScreen}
|
component={ArticleScreen}
|
||||||
options={{
|
options={{
|
||||||
title: 'Lorem Ipsum',
|
title: 'Lorem Ipsum',
|
||||||
@@ -173,7 +197,7 @@ export default function NativeStackScreen({ navigation }: Props) {
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<NativeStack.Screen
|
<NativeStack.Screen
|
||||||
name="album"
|
name="Album"
|
||||||
component={AlbumsScreen}
|
component={AlbumsScreen}
|
||||||
options={{ title: 'Album' }}
|
options={{ title: 'Album' }}
|
||||||
/>
|
/>
|
||||||
@@ -191,21 +215,16 @@ const styles = StyleSheet.create({
|
|||||||
button: {
|
button: {
|
||||||
margin: 8,
|
margin: 8,
|
||||||
},
|
},
|
||||||
container: {
|
|
||||||
backgroundColor: 'white',
|
|
||||||
},
|
|
||||||
content: {
|
content: {
|
||||||
paddingVertical: 16,
|
paddingVertical: 16,
|
||||||
},
|
},
|
||||||
title: {
|
title: {
|
||||||
color: '#000',
|
|
||||||
fontWeight: 'bold',
|
fontWeight: 'bold',
|
||||||
fontSize: 24,
|
fontSize: 24,
|
||||||
marginVertical: 8,
|
marginVertical: 8,
|
||||||
marginHorizontal: 16,
|
marginHorizontal: 16,
|
||||||
},
|
},
|
||||||
paragraph: {
|
paragraph: {
|
||||||
color: '#000',
|
|
||||||
fontSize: 16,
|
fontSize: 16,
|
||||||
lineHeight: 24,
|
lineHeight: 24,
|
||||||
marginVertical: 8,
|
marginVertical: 8,
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import { View, StyleSheet } from 'react-native';
|
import { View, StyleSheet } from 'react-native';
|
||||||
import { Button } from 'react-native-paper';
|
import { Button } from 'react-native-paper';
|
||||||
import { RouteProp, ParamListBase } from '@react-navigation/core';
|
import { RouteProp, ParamListBase } from '@react-navigation/native';
|
||||||
import {
|
import {
|
||||||
createStackNavigator,
|
createStackNavigator,
|
||||||
StackNavigationProp,
|
StackNavigationProp,
|
||||||
@@ -10,8 +10,8 @@ import Article from '../Shared/Article';
|
|||||||
import Albums from '../Shared/Albums';
|
import Albums from '../Shared/Albums';
|
||||||
|
|
||||||
type SimpleStackParams = {
|
type SimpleStackParams = {
|
||||||
article: { author: string };
|
Article: { author: string };
|
||||||
album: undefined;
|
Album: undefined;
|
||||||
};
|
};
|
||||||
|
|
||||||
type SimpleStackNavigation = StackNavigationProp<SimpleStackParams>;
|
type SimpleStackNavigation = StackNavigationProp<SimpleStackParams>;
|
||||||
@@ -21,14 +21,14 @@ const ArticleScreen = ({
|
|||||||
route,
|
route,
|
||||||
}: {
|
}: {
|
||||||
navigation: SimpleStackNavigation;
|
navigation: SimpleStackNavigation;
|
||||||
route: RouteProp<SimpleStackParams, 'article'>;
|
route: RouteProp<SimpleStackParams, 'Article'>;
|
||||||
}) => {
|
}) => {
|
||||||
return (
|
return (
|
||||||
<React.Fragment>
|
<React.Fragment>
|
||||||
<View style={styles.buttons}>
|
<View style={styles.buttons}>
|
||||||
<Button
|
<Button
|
||||||
mode="contained"
|
mode="contained"
|
||||||
onPress={() => navigation.push('album')}
|
onPress={() => navigation.push('Album')}
|
||||||
style={styles.button}
|
style={styles.button}
|
||||||
>
|
>
|
||||||
Push album
|
Push album
|
||||||
@@ -56,7 +56,7 @@ const AlbumsScreen = ({
|
|||||||
<View style={styles.buttons}>
|
<View style={styles.buttons}>
|
||||||
<Button
|
<Button
|
||||||
mode="contained"
|
mode="contained"
|
||||||
onPress={() => navigation.push('article', { author: 'Babel fish' })}
|
onPress={() => navigation.push('Article', { author: 'Babel fish' })}
|
||||||
style={styles.button}
|
style={styles.button}
|
||||||
>
|
>
|
||||||
Push article
|
Push article
|
||||||
@@ -88,7 +88,7 @@ export default function SimpleStackScreen({ navigation, ...rest }: Props) {
|
|||||||
return (
|
return (
|
||||||
<SimpleStack.Navigator {...rest}>
|
<SimpleStack.Navigator {...rest}>
|
||||||
<SimpleStack.Screen
|
<SimpleStack.Screen
|
||||||
name="article"
|
name="Article"
|
||||||
component={ArticleScreen}
|
component={ArticleScreen}
|
||||||
options={({ route }) => ({
|
options={({ route }) => ({
|
||||||
title: `Article by ${route.params.author}`,
|
title: `Article by ${route.params.author}`,
|
||||||
@@ -96,7 +96,7 @@ export default function SimpleStackScreen({ navigation, ...rest }: Props) {
|
|||||||
initialParams={{ author: 'Gandalf' }}
|
initialParams={{ author: 'Gandalf' }}
|
||||||
/>
|
/>
|
||||||
<SimpleStack.Screen
|
<SimpleStack.Screen
|
||||||
name="album"
|
name="Album"
|
||||||
component={AlbumsScreen}
|
component={AlbumsScreen}
|
||||||
options={{ title: 'Album' }}
|
options={{ title: 'Album' }}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
/* eslint-disable import/no-commonjs */
|
||||||
|
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import { Image, Dimensions, ScrollView, StyleSheet } from 'react-native';
|
import { Image, Dimensions, ScrollView, StyleSheet } from 'react-native';
|
||||||
import { useScrollToTop } from '@react-navigation/native';
|
import { useScrollToTop } from '@react-navigation/native';
|
||||||
@@ -38,7 +40,7 @@ export default function Albums() {
|
|||||||
|
|
||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
||||||
container: {
|
container: {
|
||||||
backgroundColor: '#343C46',
|
backgroundColor: '#000',
|
||||||
},
|
},
|
||||||
content: {
|
content: {
|
||||||
flexDirection: 'row',
|
flexDirection: 'row',
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import { View, Text, Image, ScrollView, StyleSheet } from 'react-native';
|
import { View, Text, Image, ScrollView, StyleSheet } from 'react-native';
|
||||||
import { useScrollToTop } from '@react-navigation/native';
|
import { useScrollToTop, useTheme } from '@react-navigation/native';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
date?: string;
|
date?: string;
|
||||||
@@ -19,10 +19,12 @@ export default function Article({
|
|||||||
|
|
||||||
useScrollToTop(ref);
|
useScrollToTop(ref);
|
||||||
|
|
||||||
|
const { colors } = useTheme();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ScrollView
|
<ScrollView
|
||||||
ref={ref}
|
ref={ref}
|
||||||
style={styles.container}
|
style={{ backgroundColor: colors.card }}
|
||||||
contentContainerStyle={styles.content}
|
contentContainerStyle={styles.content}
|
||||||
>
|
>
|
||||||
<View style={styles.author}>
|
<View style={styles.author}>
|
||||||
@@ -31,24 +33,26 @@ export default function Article({
|
|||||||
source={require('../../assets/avatar-1.png')}
|
source={require('../../assets/avatar-1.png')}
|
||||||
/>
|
/>
|
||||||
<View style={styles.meta}>
|
<View style={styles.meta}>
|
||||||
<Text style={styles.name}>{author.name}</Text>
|
<Text style={[styles.name, { color: colors.text }]}>
|
||||||
<Text style={styles.timestamp}>{date}</Text>
|
{author.name}
|
||||||
|
</Text>
|
||||||
|
<Text style={[styles.timestamp, { color: colors.text }]}>{date}</Text>
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
<Text style={styles.title}>Lorem Ipsum</Text>
|
<Text style={[styles.title, { color: colors.text }]}>Lorem Ipsum</Text>
|
||||||
<Text style={styles.paragraph}>
|
<Text style={[styles.paragraph, { color: colors.text }]}>
|
||||||
Contrary to popular belief, Lorem Ipsum is not simply random text. It
|
Contrary to popular belief, Lorem Ipsum is not simply random text. It
|
||||||
has roots in a piece of classical Latin literature from 45 BC, making it
|
has roots in a piece of classical Latin literature from 45 BC, making it
|
||||||
over 2000 years old.
|
over 2000 years old.
|
||||||
</Text>
|
</Text>
|
||||||
<Image style={styles.image} source={require('../../assets/book.jpg')} />
|
<Image style={styles.image} source={require('../../assets/book.jpg')} />
|
||||||
<Text style={styles.paragraph}>
|
<Text style={[styles.paragraph, { color: colors.text }]}>
|
||||||
Richard McClintock, a Latin professor at Hampden-Sydney College in
|
Richard McClintock, a Latin professor at Hampden-Sydney College in
|
||||||
Virginia, looked up one of the more obscure Latin words, consectetur,
|
Virginia, looked up one of the more obscure Latin words, consectetur,
|
||||||
from a Lorem Ipsum passage, and going through the cites of the word in
|
from a Lorem Ipsum passage, and going through the cites of the word in
|
||||||
classical literature, discovered the undoubtable source.
|
classical literature, discovered the undoubtable source.
|
||||||
</Text>
|
</Text>
|
||||||
<Text style={styles.paragraph}>
|
<Text style={[styles.paragraph, { color: colors.text }]}>
|
||||||
Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus
|
Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus
|
||||||
Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero,
|
Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero,
|
||||||
written in 45 BC. This book is a treatise on the theory of ethics, very
|
written in 45 BC. This book is a treatise on the theory of ethics, very
|
||||||
@@ -61,9 +65,6 @@ export default function Article({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
||||||
container: {
|
|
||||||
backgroundColor: 'white',
|
|
||||||
},
|
|
||||||
content: {
|
content: {
|
||||||
paddingVertical: 16,
|
paddingVertical: 16,
|
||||||
},
|
},
|
||||||
@@ -77,13 +78,12 @@ const styles = StyleSheet.create({
|
|||||||
justifyContent: 'center',
|
justifyContent: 'center',
|
||||||
},
|
},
|
||||||
name: {
|
name: {
|
||||||
color: '#000',
|
|
||||||
fontWeight: 'bold',
|
fontWeight: 'bold',
|
||||||
fontSize: 16,
|
fontSize: 16,
|
||||||
lineHeight: 24,
|
lineHeight: 24,
|
||||||
},
|
},
|
||||||
timestamp: {
|
timestamp: {
|
||||||
color: '#999',
|
opacity: 0.5,
|
||||||
fontSize: 14,
|
fontSize: 14,
|
||||||
lineHeight: 21,
|
lineHeight: 21,
|
||||||
},
|
},
|
||||||
@@ -93,14 +93,12 @@ const styles = StyleSheet.create({
|
|||||||
borderRadius: 24,
|
borderRadius: 24,
|
||||||
},
|
},
|
||||||
title: {
|
title: {
|
||||||
color: '#000',
|
|
||||||
fontWeight: 'bold',
|
fontWeight: 'bold',
|
||||||
fontSize: 36,
|
fontSize: 36,
|
||||||
marginVertical: 8,
|
marginVertical: 8,
|
||||||
marginHorizontal: 16,
|
marginHorizontal: 16,
|
||||||
},
|
},
|
||||||
paragraph: {
|
paragraph: {
|
||||||
color: '#000',
|
|
||||||
fontSize: 16,
|
fontSize: 16,
|
||||||
lineHeight: 24,
|
lineHeight: 24,
|
||||||
marginVertical: 8,
|
marginVertical: 8,
|
||||||
|
|||||||
@@ -7,7 +7,8 @@ import {
|
|||||||
ScrollView,
|
ScrollView,
|
||||||
StyleSheet,
|
StyleSheet,
|
||||||
} from 'react-native';
|
} from 'react-native';
|
||||||
import { useScrollToTop } from '@react-navigation/native';
|
import { useScrollToTop, useTheme } from '@react-navigation/native';
|
||||||
|
import Color from 'color';
|
||||||
|
|
||||||
const MESSAGES = [
|
const MESSAGES = [
|
||||||
'okay',
|
'okay',
|
||||||
@@ -21,6 +22,8 @@ export default function Chat() {
|
|||||||
|
|
||||||
useScrollToTop(ref);
|
useScrollToTop(ref);
|
||||||
|
|
||||||
|
const { colors } = useTheme();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={styles.container}>
|
<View style={styles.container}>
|
||||||
<ScrollView
|
<ScrollView
|
||||||
@@ -45,9 +48,12 @@ export default function Chat() {
|
|||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
<View
|
<View
|
||||||
style={[styles.bubble, odd ? styles.received : styles.sent]}
|
style={[
|
||||||
|
styles.bubble,
|
||||||
|
{ backgroundColor: odd ? colors.primary : colors.card },
|
||||||
|
]}
|
||||||
>
|
>
|
||||||
<Text style={odd ? styles.receivedText : styles.sentText}>
|
<Text style={{ color: odd ? 'white' : colors.text }}>
|
||||||
{text}
|
{text}
|
||||||
</Text>
|
</Text>
|
||||||
</View>
|
</View>
|
||||||
@@ -56,7 +62,14 @@ export default function Chat() {
|
|||||||
})}
|
})}
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
<TextInput
|
<TextInput
|
||||||
style={styles.input}
|
style={[
|
||||||
|
styles.input,
|
||||||
|
{ backgroundColor: colors.card, color: colors.text },
|
||||||
|
]}
|
||||||
|
placeholderTextColor={Color(colors.text)
|
||||||
|
.alpha(0.5)
|
||||||
|
.rgb()
|
||||||
|
.string()}
|
||||||
placeholder="Write a message"
|
placeholder="Write a message"
|
||||||
underlineColorAndroid="transparent"
|
underlineColorAndroid="transparent"
|
||||||
/>
|
/>
|
||||||
@@ -67,7 +80,6 @@ export default function Chat() {
|
|||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
||||||
container: {
|
container: {
|
||||||
flex: 1,
|
flex: 1,
|
||||||
backgroundColor: '#eceff1',
|
|
||||||
},
|
},
|
||||||
inverted: {
|
inverted: {
|
||||||
transform: [{ scaleY: -1 }],
|
transform: [{ scaleY: -1 }],
|
||||||
@@ -97,22 +109,9 @@ const styles = StyleSheet.create({
|
|||||||
paddingHorizontal: 16,
|
paddingHorizontal: 16,
|
||||||
borderRadius: 20,
|
borderRadius: 20,
|
||||||
},
|
},
|
||||||
sent: {
|
|
||||||
backgroundColor: '#cfd8dc',
|
|
||||||
},
|
|
||||||
received: {
|
|
||||||
backgroundColor: '#2196F3',
|
|
||||||
},
|
|
||||||
sentText: {
|
|
||||||
color: 'black',
|
|
||||||
},
|
|
||||||
receivedText: {
|
|
||||||
color: 'white',
|
|
||||||
},
|
|
||||||
input: {
|
input: {
|
||||||
height: 48,
|
height: 48,
|
||||||
paddingVertical: 12,
|
paddingVertical: 12,
|
||||||
paddingHorizontal: 24,
|
paddingHorizontal: 24,
|
||||||
backgroundColor: 'white',
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import { View, Text, FlatList, StyleSheet } from 'react-native';
|
import { View, Text, FlatList, StyleSheet } from 'react-native';
|
||||||
import { useScrollToTop } from '@react-navigation/native';
|
import { useScrollToTop, useTheme } from '@react-navigation/native';
|
||||||
|
|
||||||
type Item = { name: string; number: number };
|
type Item = { name: string; number: number };
|
||||||
|
|
||||||
@@ -57,27 +57,35 @@ const CONTACTS: Item[] = [
|
|||||||
{ name: 'Vincent Sandoval', number: 2606111495 },
|
{ name: 'Vincent Sandoval', number: 2606111495 },
|
||||||
];
|
];
|
||||||
|
|
||||||
class ContactItem extends React.PureComponent<{
|
const ContactItem = React.memo(
|
||||||
item: { name: string; number: number };
|
({ item }: { item: { name: string; number: number } }) => {
|
||||||
}> {
|
const { colors } = useTheme();
|
||||||
render() {
|
|
||||||
const { item } = this.props;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={styles.item}>
|
<View style={[styles.item, { backgroundColor: colors.card }]}>
|
||||||
<View style={styles.avatar}>
|
<View style={styles.avatar}>
|
||||||
<Text style={styles.letter}>
|
<Text style={styles.letter}>
|
||||||
{item.name.slice(0, 1).toUpperCase()}
|
{item.name.slice(0, 1).toUpperCase()}
|
||||||
</Text>
|
</Text>
|
||||||
</View>
|
</View>
|
||||||
<View style={styles.details}>
|
<View style={styles.details}>
|
||||||
<Text style={styles.name}>{item.name}</Text>
|
<Text style={[styles.name, { color: colors.text }]}>{item.name}</Text>
|
||||||
<Text style={styles.number}>{item.number}</Text>
|
<Text style={[styles.number, { color: colors.text, opacity: 0.5 }]}>
|
||||||
|
{item.number}
|
||||||
|
</Text>
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
);
|
||||||
|
|
||||||
|
const ItemSeparator = () => {
|
||||||
|
const { colors } = useTheme();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<View style={[styles.separator, { backgroundColor: colors.border }]} />
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
export default function Contacts() {
|
export default function Contacts() {
|
||||||
const ref = React.useRef<FlatList<Item>>(null);
|
const ref = React.useRef<FlatList<Item>>(null);
|
||||||
@@ -86,8 +94,6 @@ export default function Contacts() {
|
|||||||
|
|
||||||
const renderItem = ({ item }: { item: Item }) => <ContactItem item={item} />;
|
const renderItem = ({ item }: { item: Item }) => <ContactItem item={item} />;
|
||||||
|
|
||||||
const ItemSeparator = () => <View style={styles.separator} />;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<FlatList
|
<FlatList
|
||||||
ref={ref}
|
ref={ref}
|
||||||
@@ -101,7 +107,6 @@ export default function Contacts() {
|
|||||||
|
|
||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
||||||
item: {
|
item: {
|
||||||
backgroundColor: 'white',
|
|
||||||
flexDirection: 'row',
|
flexDirection: 'row',
|
||||||
alignItems: 'center',
|
alignItems: 'center',
|
||||||
padding: 8,
|
padding: 8,
|
||||||
@@ -124,14 +129,11 @@ const styles = StyleSheet.create({
|
|||||||
name: {
|
name: {
|
||||||
fontWeight: 'bold',
|
fontWeight: 'bold',
|
||||||
fontSize: 14,
|
fontSize: 14,
|
||||||
color: 'black',
|
|
||||||
},
|
},
|
||||||
number: {
|
number: {
|
||||||
fontSize: 12,
|
fontSize: 12,
|
||||||
color: '#999',
|
|
||||||
},
|
},
|
||||||
separator: {
|
separator: {
|
||||||
height: StyleSheet.hairlineWidth,
|
height: StyleSheet.hairlineWidth,
|
||||||
backgroundColor: 'rgba(0, 0, 0, .08)',
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,16 +1,31 @@
|
|||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import { ScrollView, AsyncStorage, YellowBox } from 'react-native';
|
import {
|
||||||
|
View,
|
||||||
|
ScrollView,
|
||||||
|
AsyncStorage,
|
||||||
|
YellowBox,
|
||||||
|
Platform,
|
||||||
|
StatusBar,
|
||||||
|
} from 'react-native';
|
||||||
import { MaterialIcons } from '@expo/vector-icons';
|
import { MaterialIcons } from '@expo/vector-icons';
|
||||||
import { Appbar, List } from 'react-native-paper';
|
import {
|
||||||
|
Provider as PaperProvider,
|
||||||
|
DefaultTheme as PaperLightTheme,
|
||||||
|
DarkTheme as PaperDarkTheme,
|
||||||
|
Subheading,
|
||||||
|
Appbar,
|
||||||
|
List,
|
||||||
|
Switch,
|
||||||
|
Divider,
|
||||||
|
} from 'react-native-paper';
|
||||||
import { Asset } from 'expo-asset';
|
import { Asset } from 'expo-asset';
|
||||||
import {
|
import {
|
||||||
InitialState,
|
InitialState,
|
||||||
getStateFromPath,
|
|
||||||
NavigationContainerRef,
|
|
||||||
} from '@react-navigation/core';
|
|
||||||
import {
|
|
||||||
useLinking,
|
useLinking,
|
||||||
|
NavigationContainerRef,
|
||||||
NavigationNativeContainer,
|
NavigationNativeContainer,
|
||||||
|
DefaultTheme,
|
||||||
|
DarkTheme,
|
||||||
} from '@react-navigation/native';
|
} from '@react-navigation/native';
|
||||||
import {
|
import {
|
||||||
createDrawerNavigator,
|
createDrawerNavigator,
|
||||||
@@ -74,7 +89,8 @@ const SCREENS = {
|
|||||||
const Drawer = createDrawerNavigator<RootDrawerParamList>();
|
const Drawer = createDrawerNavigator<RootDrawerParamList>();
|
||||||
const Stack = createStackNavigator<RootStackParamList>();
|
const Stack = createStackNavigator<RootStackParamList>();
|
||||||
|
|
||||||
const PERSISTENCE_KEY = 'NAVIGATION_STATE';
|
const NAVIGATION_PERSISTENCE_KEY = 'NAVIGATION_STATE';
|
||||||
|
const THEME_PERSISTENCE_KEY = 'THEME_TYPE';
|
||||||
|
|
||||||
Asset.loadAsync(StackAssets);
|
Asset.loadAsync(StackAssets);
|
||||||
|
|
||||||
@@ -87,23 +103,24 @@ export default function App() {
|
|||||||
// The first segment of the link is the the scheme + host (returned by `Linking.makeUrl`)
|
// The first segment of the link is the the scheme + host (returned by `Linking.makeUrl`)
|
||||||
const { getInitialState } = useLinking(containerRef, {
|
const { getInitialState } = useLinking(containerRef, {
|
||||||
prefixes: LinkingPrefixes,
|
prefixes: LinkingPrefixes,
|
||||||
getStateFromPath: path => {
|
config: {
|
||||||
const state = getStateFromPath(path);
|
Root: Object.keys(SCREENS).reduce<{ [key: string]: string }>(
|
||||||
|
(acc, name) => {
|
||||||
|
// Convert screen names such as SimpleStack to kebab case (simple-stack)
|
||||||
|
acc[name] = name
|
||||||
|
.replace(/([A-Z]+)/g, '-$1')
|
||||||
|
.replace(/^-/, '')
|
||||||
|
.toLowerCase();
|
||||||
|
|
||||||
return {
|
return acc;
|
||||||
routes: [
|
|
||||||
{
|
|
||||||
name: 'root',
|
|
||||||
state: {
|
|
||||||
...state,
|
|
||||||
routes: [{ name: 'home' }, ...(state ? state.routes : [])],
|
|
||||||
},
|
},
|
||||||
},
|
{}
|
||||||
],
|
),
|
||||||
};
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const [theme, setTheme] = React.useState(DefaultTheme);
|
||||||
|
|
||||||
const [isReady, setIsReady] = React.useState(false);
|
const [isReady, setIsReady] = React.useState(false);
|
||||||
const [initialState, setInitialState] = React.useState<
|
const [initialState, setInitialState] = React.useState<
|
||||||
InitialState | undefined
|
InitialState | undefined
|
||||||
@@ -115,7 +132,9 @@ export default function App() {
|
|||||||
let state = await getInitialState();
|
let state = await getInitialState();
|
||||||
|
|
||||||
if (state === undefined) {
|
if (state === undefined) {
|
||||||
const savedState = await AsyncStorage.getItem(PERSISTENCE_KEY);
|
const savedState = await AsyncStorage.getItem(
|
||||||
|
NAVIGATION_PERSISTENCE_KEY
|
||||||
|
);
|
||||||
state = savedState ? JSON.parse(savedState) : undefined;
|
state = savedState ? JSON.parse(savedState) : undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -123,6 +142,14 @@ export default function App() {
|
|||||||
setInitialState(state);
|
setInitialState(state);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
|
try {
|
||||||
|
const themeName = await AsyncStorage.getItem(THEME_PERSISTENCE_KEY);
|
||||||
|
|
||||||
|
setTheme(themeName === 'dark' ? DarkTheme : DefaultTheme);
|
||||||
|
} catch (e) {
|
||||||
|
// Ignore
|
||||||
|
}
|
||||||
|
|
||||||
setIsReady(true);
|
setIsReady(true);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -130,17 +157,39 @@ export default function App() {
|
|||||||
restoreState();
|
restoreState();
|
||||||
}, [getInitialState]);
|
}, [getInitialState]);
|
||||||
|
|
||||||
|
const paperTheme = React.useMemo(() => {
|
||||||
|
const t = theme.dark ? PaperDarkTheme : PaperLightTheme;
|
||||||
|
|
||||||
|
return {
|
||||||
|
...t,
|
||||||
|
colors: {
|
||||||
|
...t.colors,
|
||||||
|
...theme.colors,
|
||||||
|
surface: theme.colors.card,
|
||||||
|
accent: theme.dark ? 'rgb(255, 55, 95)' : 'rgb(255, 45, 85)',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}, [theme.colors, theme.dark]);
|
||||||
|
|
||||||
if (!isReady) {
|
if (!isReady) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
<PaperProvider theme={paperTheme}>
|
||||||
|
{Platform.OS === 'ios' && (
|
||||||
|
<StatusBar barStyle={theme.dark ? 'light-content' : 'dark-content'} />
|
||||||
|
)}
|
||||||
<NavigationNativeContainer
|
<NavigationNativeContainer
|
||||||
ref={containerRef}
|
ref={containerRef}
|
||||||
initialState={initialState}
|
initialState={initialState}
|
||||||
onStateChange={state =>
|
onStateChange={state =>
|
||||||
AsyncStorage.setItem(PERSISTENCE_KEY, JSON.stringify(state))
|
AsyncStorage.setItem(
|
||||||
|
NAVIGATION_PERSISTENCE_KEY,
|
||||||
|
JSON.stringify(state)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
theme={theme}
|
||||||
>
|
>
|
||||||
<Drawer.Navigator>
|
<Drawer.Navigator>
|
||||||
<Drawer.Screen
|
<Drawer.Screen
|
||||||
@@ -164,6 +213,7 @@ export default function App() {
|
|||||||
title: 'Examples',
|
title: 'Examples',
|
||||||
headerLeft: () => (
|
headerLeft: () => (
|
||||||
<Appbar.Action
|
<Appbar.Action
|
||||||
|
color={theme.colors.text}
|
||||||
icon="menu"
|
icon="menu"
|
||||||
onPress={() => navigation.toggleDrawer()}
|
onPress={() => navigation.toggleDrawer()}
|
||||||
/>
|
/>
|
||||||
@@ -175,8 +225,32 @@ export default function App() {
|
|||||||
}: {
|
}: {
|
||||||
navigation: StackNavigationProp<RootStackParamList>;
|
navigation: StackNavigationProp<RootStackParamList>;
|
||||||
}) => (
|
}) => (
|
||||||
<ScrollView>
|
<ScrollView
|
||||||
{(Object.keys(SCREENS) as Array<keyof typeof SCREENS>).map(
|
style={{ backgroundColor: theme.colors.background }}
|
||||||
|
>
|
||||||
|
<View
|
||||||
|
style={{
|
||||||
|
flexDirection: 'row',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'space-between',
|
||||||
|
padding: 16,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Subheading>Dark theme</Subheading>
|
||||||
|
<Switch
|
||||||
|
value={theme.dark}
|
||||||
|
onValueChange={() => {
|
||||||
|
AsyncStorage.setItem(
|
||||||
|
THEME_PERSISTENCE_KEY,
|
||||||
|
theme.dark ? 'light' : 'dark'
|
||||||
|
);
|
||||||
|
|
||||||
|
setTheme(t => (t.dark ? DefaultTheme : DarkTheme));
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</View>
|
||||||
|
<Divider />
|
||||||
|
{(Object.keys(SCREENS) as (keyof typeof SCREENS)[]).map(
|
||||||
name => (
|
name => (
|
||||||
<List.Item
|
<List.Item
|
||||||
key={name}
|
key={name}
|
||||||
@@ -188,7 +262,7 @@ export default function App() {
|
|||||||
</ScrollView>
|
</ScrollView>
|
||||||
)}
|
)}
|
||||||
</Stack.Screen>
|
</Stack.Screen>
|
||||||
{(Object.keys(SCREENS) as Array<keyof typeof SCREENS>).map(
|
{(Object.keys(SCREENS) as (keyof typeof SCREENS)[]).map(
|
||||||
name => (
|
name => (
|
||||||
<Stack.Screen
|
<Stack.Screen
|
||||||
key={name}
|
key={name}
|
||||||
@@ -203,5 +277,6 @@ export default function App() {
|
|||||||
</Drawer.Screen>
|
</Drawer.Screen>
|
||||||
</Drawer.Navigator>
|
</Drawer.Navigator>
|
||||||
</NavigationNativeContainer>
|
</NavigationNativeContainer>
|
||||||
|
</PaperProvider>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ const error = console.error;
|
|||||||
|
|
||||||
console.error = (...args) =>
|
console.error = (...args) =>
|
||||||
// Supress error messages regarding error boundary in tests
|
// Supress error messages regarding error boundary in tests
|
||||||
/Consider adding an error boundary to your tree to customize error handling behavior/m.test(
|
/(Consider adding an error boundary to your tree to customize error handling behavior|React will try to recreate this component tree from scratch using the error boundary you provided|Error boundaries should implement getDerivedStateFromError)/m.test(
|
||||||
args[0]
|
args[0]
|
||||||
)
|
)
|
||||||
? void 0
|
? void 0
|
||||||
|
|||||||
13
package.json
@@ -24,22 +24,23 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/plugin-proposal-class-properties": "^7.7.0",
|
"@babel/plugin-proposal-class-properties": "^7.7.0",
|
||||||
"@babel/preset-env": "^7.7.1",
|
"@babel/plugin-proposal-optional-chaining": "^7.7.5",
|
||||||
|
"@babel/preset-env": "^7.7.6",
|
||||||
"@babel/preset-react": "^7.7.0",
|
"@babel/preset-react": "^7.7.0",
|
||||||
"@babel/preset-typescript": "^7.7.2",
|
"@babel/preset-typescript": "^7.7.2",
|
||||||
"@babel/runtime": "^7.7.2",
|
"@babel/runtime": "^7.7.6",
|
||||||
"@commitlint/config-conventional": "^8.2.0",
|
"@commitlint/config-conventional": "^8.2.0",
|
||||||
"@types/jest": "^24.0.23",
|
"@types/jest": "^24.0.23",
|
||||||
"codecov": "^3.6.1",
|
"codecov": "^3.6.1",
|
||||||
"commitlint": "^8.2.0",
|
"commitlint": "^8.2.0",
|
||||||
"core-js": "^3.4.1",
|
"core-js": "^3.5.0",
|
||||||
"eslint": "^6.6.0",
|
"eslint": "^6.7.2",
|
||||||
"eslint-config-satya164": "^3.1.2",
|
"eslint-config-satya164": "^3.1.5",
|
||||||
"husky": "^3.0.9",
|
"husky": "^3.0.9",
|
||||||
"jest": "^24.8.0",
|
"jest": "^24.8.0",
|
||||||
"lerna": "^3.18.4",
|
"lerna": "^3.18.4",
|
||||||
"prettier": "^1.19.1",
|
"prettier": "^1.19.1",
|
||||||
"typescript": "^3.7.2"
|
"typescript": "^3.7.3"
|
||||||
},
|
},
|
||||||
"resolutions": {
|
"resolutions": {
|
||||||
"react": "~16.9.0",
|
"react": "~16.9.0",
|
||||||
|
|||||||
@@ -3,6 +3,68 @@
|
|||||||
All notable changes to this project will be documented in this file.
|
All notable changes to this project will be documented in this file.
|
||||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||||
|
|
||||||
|
# [5.0.0-alpha.31](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/bottom-tabs@5.0.0-alpha.30...@react-navigation/bottom-tabs@5.0.0-alpha.31) (2020-01-03)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* provide initial values for safe area to prevent blank screen ([#238](https://github.com/react-navigation/navigation-ex/issues/238)) ([77b7570](https://github.com/react-navigation/navigation-ex/commit/77b757091c0451e20bca01138629669c7da544a8))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [5.0.0-alpha.30](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/bottom-tabs@5.0.0-alpha.29...@react-navigation/bottom-tabs@5.0.0-alpha.30) (2020-01-03)
|
||||||
|
|
||||||
|
**Note:** Version bump only for package @react-navigation/bottom-tabs
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [5.0.0-alpha.29](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/bottom-tabs@5.0.0-alpha.28...@react-navigation/bottom-tabs@5.0.0-alpha.29) (2020-01-01)
|
||||||
|
|
||||||
|
**Note:** Version bump only for package @react-navigation/bottom-tabs
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [5.0.0-alpha.28](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/bottom-tabs@5.0.0-alpha.27...@react-navigation/bottom-tabs@5.0.0-alpha.28) (2019-12-19)
|
||||||
|
|
||||||
|
**Note:** Version bump only for package @react-navigation/bottom-tabs
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [5.0.0-alpha.27](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/bottom-tabs@5.0.0-alpha.26...@react-navigation/bottom-tabs@5.0.0-alpha.27) (2019-12-16)
|
||||||
|
|
||||||
|
**Note:** Version bump only for package @react-navigation/bottom-tabs
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [5.0.0-alpha.26](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/bottom-tabs@5.0.0-alpha.25...@react-navigation/bottom-tabs@5.0.0-alpha.26) (2019-12-14)
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* add custom theme support ([#211](https://github.com/react-navigation/navigation-ex/issues/211)) ([00fc616](https://github.com/react-navigation/navigation-ex/commit/00fc616de0572bade8aa85052cdc8290360b1d7f))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [5.0.0-alpha.25](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/bottom-tabs@5.0.0-alpha.24...@react-navigation/bottom-tabs@5.0.0-alpha.25) (2019-12-11)
|
||||||
|
|
||||||
|
**Note:** Version bump only for package @react-navigation/bottom-tabs
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# [5.0.0-alpha.24](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/bottom-tabs@5.0.0-alpha.23...@react-navigation/bottom-tabs@5.0.0-alpha.24) (2019-12-10)
|
# [5.0.0-alpha.24](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/bottom-tabs@5.0.0-alpha.23...@react-navigation/bottom-tabs@5.0.0-alpha.24) (2019-12-10)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ Bottom tab navigator for React Navigation following iOS design guidelines.
|
|||||||
Open a Terminal in your project's folder and run,
|
Open a Terminal in your project's folder and run,
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
yarn add @react-navigation/core @react-navigation/bottom-tabs
|
yarn add @react-navigation/native @react-navigation/bottom-tabs
|
||||||
```
|
```
|
||||||
|
|
||||||
Now we need to install [`react-native-safe-area-context`](https://github.com/th3rdwave/react-native-safe-area-context).
|
Now we need to install [`react-native-safe-area-context`](https://github.com/th3rdwave/react-native-safe-area-context).
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
"android",
|
"android",
|
||||||
"tab"
|
"tab"
|
||||||
],
|
],
|
||||||
"version": "5.0.0-alpha.24",
|
"version": "5.0.0-alpha.31",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@@ -33,23 +33,26 @@
|
|||||||
"clean": "del lib"
|
"clean": "del lib"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@react-navigation/routers": "^5.0.0-alpha.15"
|
"@react-navigation/routers": "^5.0.0-alpha.19",
|
||||||
|
"color": "^3.1.2",
|
||||||
|
"react-native-iphone-x-helper": "^1.2.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@react-native-community/bob": "^0.7.0",
|
"@react-native-community/bob": "^0.7.0",
|
||||||
"@types/react": "^16.9.11",
|
"@types/color": "^3.0.0",
|
||||||
"@types/react-native": "^0.60.22",
|
"@types/react": "^16.9.16",
|
||||||
|
"@types/react-native": "^0.60.25",
|
||||||
"del-cli": "^3.0.0",
|
"del-cli": "^3.0.0",
|
||||||
"react": "~16.9.0",
|
"react": "~16.9.0",
|
||||||
"react-native": "~0.61.5",
|
"react-native": "~0.61.5",
|
||||||
"react-native-safe-area-context": "^0.6.0",
|
"react-native-safe-area-context": "^0.6.0",
|
||||||
"typescript": "^3.7.2"
|
"typescript": "^3.7.3"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"@react-navigation/core": "^5.0.0-alpha.0",
|
"@react-navigation/native": "^5.0.0-alpha.0",
|
||||||
"react": "*",
|
"react": "*",
|
||||||
"react-native": "*",
|
"react-native": "*",
|
||||||
"react-native-safe-area-context": "^0.3.6"
|
"react-native-safe-area-context": "^0.6.0"
|
||||||
},
|
},
|
||||||
"@react-native-community/bob": {
|
"@react-native-community/bob": {
|
||||||
"source": "src",
|
"source": "src",
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import {
|
|||||||
useNavigationBuilder,
|
useNavigationBuilder,
|
||||||
createNavigatorFactory,
|
createNavigatorFactory,
|
||||||
DefaultNavigatorOptions,
|
DefaultNavigatorOptions,
|
||||||
} from '@react-navigation/core';
|
} from '@react-navigation/native';
|
||||||
import {
|
import {
|
||||||
TabRouter,
|
TabRouter,
|
||||||
TabRouterOptions,
|
TabRouterOptions,
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import {
|
|||||||
NavigationProp,
|
NavigationProp,
|
||||||
ParamListBase,
|
ParamListBase,
|
||||||
Descriptor,
|
Descriptor,
|
||||||
} from '@react-navigation/core';
|
} from '@react-navigation/native';
|
||||||
import { TabNavigationState } from '@react-navigation/routers';
|
import { TabNavigationState } from '@react-navigation/routers';
|
||||||
|
|
||||||
export type BottomTabNavigationEventMap = {
|
export type BottomTabNavigationEventMap = {
|
||||||
|
|||||||
@@ -10,22 +10,15 @@ import {
|
|||||||
Dimensions,
|
Dimensions,
|
||||||
} from 'react-native';
|
} from 'react-native';
|
||||||
import {
|
import {
|
||||||
Route,
|
|
||||||
NavigationContext,
|
NavigationContext,
|
||||||
CommonActions,
|
CommonActions,
|
||||||
} from '@react-navigation/core';
|
useTheme,
|
||||||
|
} from '@react-navigation/native';
|
||||||
import { SafeAreaConsumer } from 'react-native-safe-area-context';
|
import { SafeAreaConsumer } from 'react-native-safe-area-context';
|
||||||
|
|
||||||
import BottomTabItem from './BottomTabItem';
|
import BottomTabItem from './BottomTabItem';
|
||||||
import { BottomTabBarProps } from '../types';
|
import { BottomTabBarProps } from '../types';
|
||||||
|
|
||||||
type State = {
|
|
||||||
dimensions: { height: number; width: number };
|
|
||||||
layout: { height: number; width: number };
|
|
||||||
keyboard: boolean;
|
|
||||||
visible: Animated.Value;
|
|
||||||
};
|
|
||||||
|
|
||||||
type Props = BottomTabBarProps & {
|
type Props = BottomTabBarProps & {
|
||||||
activeTintColor?: string;
|
activeTintColor?: string;
|
||||||
inactiveTintColor?: string;
|
inactiveTintColor?: string;
|
||||||
@@ -34,97 +27,101 @@ type Props = BottomTabBarProps & {
|
|||||||
const DEFAULT_TABBAR_HEIGHT = 50;
|
const DEFAULT_TABBAR_HEIGHT = 50;
|
||||||
const DEFAULT_MAX_TAB_ITEM_WIDTH = 125;
|
const DEFAULT_MAX_TAB_ITEM_WIDTH = 125;
|
||||||
|
|
||||||
export default class BottomTabBar extends React.Component<Props, State> {
|
export default function BottomTabBar({
|
||||||
static defaultProps = {
|
state,
|
||||||
keyboardHidesTabBar: false,
|
navigation,
|
||||||
adaptive: true,
|
descriptors,
|
||||||
};
|
activeBackgroundColor,
|
||||||
|
activeTintColor,
|
||||||
|
adaptive = true,
|
||||||
|
allowFontScaling,
|
||||||
|
inactiveBackgroundColor,
|
||||||
|
inactiveTintColor,
|
||||||
|
keyboardHidesTabBar = false,
|
||||||
|
labelPosition,
|
||||||
|
labelStyle,
|
||||||
|
showIcon,
|
||||||
|
showLabel,
|
||||||
|
style,
|
||||||
|
tabStyle,
|
||||||
|
}: Props) {
|
||||||
|
const { colors } = useTheme();
|
||||||
|
|
||||||
state = {
|
const [dimensions, setDimensions] = React.useState(Dimensions.get('window'));
|
||||||
dimensions: Dimensions.get('window'),
|
const [layout, setLayout] = React.useState({ height: 0, width: 0 });
|
||||||
layout: { height: 0, width: 0 },
|
const [keyboardShown, setKeyboardShown] = React.useState(false);
|
||||||
keyboard: false,
|
|
||||||
visible: new Animated.Value(1),
|
|
||||||
};
|
|
||||||
|
|
||||||
componentDidMount() {
|
const [visible] = React.useState(() => new Animated.Value(0));
|
||||||
Dimensions.addEventListener('change', this.handleOrientationChange);
|
|
||||||
|
|
||||||
if (Platform.OS === 'ios') {
|
const { routes } = state;
|
||||||
Keyboard.addListener('keyboardWillShow', this.handleKeyboardShow);
|
|
||||||
Keyboard.addListener('keyboardWillHide', this.handleKeyboardHide);
|
|
||||||
} else {
|
|
||||||
Keyboard.addListener('keyboardDidShow', this.handleKeyboardShow);
|
|
||||||
Keyboard.addListener('keyboardDidHide', this.handleKeyboardHide);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
componentWillUnmount() {
|
React.useEffect(() => {
|
||||||
Dimensions.removeEventListener('change', this.handleOrientationChange);
|
if (keyboardShown) {
|
||||||
|
Animated.timing(visible, {
|
||||||
if (Platform.OS === 'ios') {
|
|
||||||
Keyboard.removeListener('keyboardWillShow', this.handleKeyboardShow);
|
|
||||||
Keyboard.removeListener('keyboardWillHide', this.handleKeyboardHide);
|
|
||||||
} else {
|
|
||||||
Keyboard.removeListener('keyboardDidShow', this.handleKeyboardShow);
|
|
||||||
Keyboard.removeListener('keyboardDidHide', this.handleKeyboardHide);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private handleOrientationChange = ({ window }: { window: ScaledSize }) => {
|
|
||||||
this.setState({ dimensions: window });
|
|
||||||
};
|
|
||||||
|
|
||||||
private handleKeyboardShow = () =>
|
|
||||||
this.setState({ keyboard: true }, () =>
|
|
||||||
Animated.timing(this.state.visible, {
|
|
||||||
toValue: 0,
|
toValue: 0,
|
||||||
duration: 200,
|
duration: 200,
|
||||||
useNativeDriver: true,
|
useNativeDriver: true,
|
||||||
}).start()
|
}).start();
|
||||||
);
|
}
|
||||||
|
}, [keyboardShown, visible]);
|
||||||
|
|
||||||
private handleKeyboardHide = () =>
|
React.useEffect(() => {
|
||||||
Animated.timing(this.state.visible, {
|
const handleOrientationChange = ({ window }: { window: ScaledSize }) => {
|
||||||
|
setDimensions(window);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleKeyboardShow = () => setKeyboardShown(true);
|
||||||
|
|
||||||
|
const handleKeyboardHide = () =>
|
||||||
|
Animated.timing(visible, {
|
||||||
toValue: 1,
|
toValue: 1,
|
||||||
duration: 250,
|
duration: 250,
|
||||||
useNativeDriver: true,
|
useNativeDriver: true,
|
||||||
}).start(({ finished }) => {
|
}).start(({ finished }) => {
|
||||||
if (finished) {
|
if (finished) {
|
||||||
this.setState({ keyboard: false });
|
setKeyboardShown(false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
private handleLayout = (e: LayoutChangeEvent) => {
|
Dimensions.addEventListener('change', handleOrientationChange);
|
||||||
const { layout } = this.state;
|
|
||||||
|
if (Platform.OS === 'ios') {
|
||||||
|
Keyboard.addListener('keyboardWillShow', handleKeyboardShow);
|
||||||
|
Keyboard.addListener('keyboardWillHide', handleKeyboardHide);
|
||||||
|
} else {
|
||||||
|
Keyboard.addListener('keyboardDidShow', handleKeyboardShow);
|
||||||
|
Keyboard.addListener('keyboardDidHide', handleKeyboardHide);
|
||||||
|
}
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
Dimensions.removeEventListener('change', handleOrientationChange);
|
||||||
|
|
||||||
|
if (Platform.OS === 'ios') {
|
||||||
|
Keyboard.removeListener('keyboardWillShow', handleKeyboardShow);
|
||||||
|
Keyboard.removeListener('keyboardWillHide', handleKeyboardHide);
|
||||||
|
} else {
|
||||||
|
Keyboard.removeListener('keyboardDidShow', handleKeyboardShow);
|
||||||
|
Keyboard.removeListener('keyboardDidHide', handleKeyboardHide);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}, [visible]);
|
||||||
|
|
||||||
|
const handleLayout = (e: LayoutChangeEvent) => {
|
||||||
const { height, width } = e.nativeEvent.layout;
|
const { height, width } = e.nativeEvent.layout;
|
||||||
|
|
||||||
|
setLayout(layout => {
|
||||||
if (height === layout.height && width === layout.width) {
|
if (height === layout.height && width === layout.width) {
|
||||||
return;
|
return layout;
|
||||||
}
|
} else {
|
||||||
|
return {
|
||||||
this.setState({
|
|
||||||
layout: {
|
|
||||||
height,
|
height,
|
||||||
width,
|
width,
|
||||||
},
|
};
|
||||||
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
private getLabelText = ({ route }: { route: Route<string> }) => {
|
const shouldUseHorizontalLabels = () => {
|
||||||
const { options } = this.props.descriptors[route.key];
|
|
||||||
|
|
||||||
return options.tabBarLabel !== undefined
|
|
||||||
? options.tabBarLabel
|
|
||||||
: options.title !== undefined
|
|
||||||
? options.title
|
|
||||||
: route.name;
|
|
||||||
};
|
|
||||||
|
|
||||||
private shouldUseHorizontalLabels = () => {
|
|
||||||
const { state, adaptive, tabStyle, labelPosition } = this.props;
|
|
||||||
const { dimensions } = this.state;
|
|
||||||
const { routes } = state;
|
|
||||||
const isLandscape = dimensions.width > dimensions.height;
|
const isLandscape = dimensions.width > dimensions.height;
|
||||||
|
|
||||||
if (labelPosition) {
|
if (labelPosition) {
|
||||||
@@ -165,45 +162,30 @@ export default class BottomTabBar extends React.Component<Props, State> {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
|
||||||
const {
|
|
||||||
state,
|
|
||||||
navigation,
|
|
||||||
descriptors,
|
|
||||||
keyboardHidesTabBar,
|
|
||||||
activeTintColor,
|
|
||||||
inactiveTintColor,
|
|
||||||
activeBackgroundColor,
|
|
||||||
inactiveBackgroundColor,
|
|
||||||
labelStyle,
|
|
||||||
showIcon,
|
|
||||||
showLabel,
|
|
||||||
allowFontScaling,
|
|
||||||
style,
|
|
||||||
tabStyle,
|
|
||||||
} = this.props;
|
|
||||||
const { routes } = state;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SafeAreaConsumer>
|
<SafeAreaConsumer>
|
||||||
{insets => (
|
{insets => (
|
||||||
<Animated.View
|
<Animated.View
|
||||||
style={[
|
style={[
|
||||||
styles.tabBar,
|
styles.tabBar,
|
||||||
|
{
|
||||||
|
backgroundColor: colors.card,
|
||||||
|
borderTopColor: colors.border,
|
||||||
|
},
|
||||||
keyboardHidesTabBar
|
keyboardHidesTabBar
|
||||||
? {
|
? {
|
||||||
// When the keyboard is shown, slide down the tab bar
|
// When the keyboard is shown, slide down the tab bar
|
||||||
transform: [
|
transform: [
|
||||||
{
|
{
|
||||||
translateY: this.state.visible.interpolate({
|
translateY: visible.interpolate({
|
||||||
inputRange: [0, 1],
|
inputRange: [0, 1],
|
||||||
outputRange: [this.state.layout.height, 0],
|
outputRange: [layout.height, 0],
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
// Absolutely position the tab bar so that the content is below it
|
// Absolutely position the tab bar so that the content is below it
|
||||||
// This is needed to avoid gap at bottom when the tab bar is hidden
|
// This is needed to avoid gap at bottom when the tab bar is hidden
|
||||||
position: this.state.keyboard ? 'absolute' : null,
|
position: keyboardShown ? 'absolute' : null,
|
||||||
}
|
}
|
||||||
: null,
|
: null,
|
||||||
{
|
{
|
||||||
@@ -212,11 +194,9 @@ export default class BottomTabBar extends React.Component<Props, State> {
|
|||||||
},
|
},
|
||||||
style,
|
style,
|
||||||
]}
|
]}
|
||||||
pointerEvents={
|
pointerEvents={keyboardHidesTabBar && keyboardShown ? 'none' : 'auto'}
|
||||||
keyboardHidesTabBar && this.state.keyboard ? 'none' : 'auto'
|
|
||||||
}
|
|
||||||
>
|
>
|
||||||
<View style={styles.content} onLayout={this.handleLayout}>
|
<View style={styles.content} onLayout={handleLayout}>
|
||||||
{routes.map((route, index) => {
|
{routes.map((route, index) => {
|
||||||
const focused = index === state.index;
|
const focused = index === state.index;
|
||||||
const { options } = descriptors[route.key];
|
const { options } = descriptors[route.key];
|
||||||
@@ -242,7 +222,13 @@ export default class BottomTabBar extends React.Component<Props, State> {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const label = this.getLabelText({ route });
|
const label =
|
||||||
|
options.tabBarLabel !== undefined
|
||||||
|
? options.tabBarLabel
|
||||||
|
: options.title !== undefined
|
||||||
|
? options.title
|
||||||
|
: route.name;
|
||||||
|
|
||||||
const accessibilityLabel =
|
const accessibilityLabel =
|
||||||
options.tabBarAccessibilityLabel !== undefined
|
options.tabBarAccessibilityLabel !== undefined
|
||||||
? options.tabBarAccessibilityLabel
|
? options.tabBarAccessibilityLabel
|
||||||
@@ -258,7 +244,7 @@ export default class BottomTabBar extends React.Component<Props, State> {
|
|||||||
<BottomTabItem
|
<BottomTabItem
|
||||||
route={route}
|
route={route}
|
||||||
focused={focused}
|
focused={focused}
|
||||||
horizontal={this.shouldUseHorizontalLabels()}
|
horizontal={shouldUseHorizontalLabels()}
|
||||||
onPress={onPress}
|
onPress={onPress}
|
||||||
onLongPress={onLongPress}
|
onLongPress={onLongPress}
|
||||||
accessibilityLabel={accessibilityLabel}
|
accessibilityLabel={accessibilityLabel}
|
||||||
@@ -284,7 +270,6 @@ export default class BottomTabBar extends React.Component<Props, State> {
|
|||||||
)}
|
)}
|
||||||
</SafeAreaConsumer>
|
</SafeAreaConsumer>
|
||||||
);
|
);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
||||||
@@ -292,9 +277,7 @@ const styles = StyleSheet.create({
|
|||||||
left: 0,
|
left: 0,
|
||||||
right: 0,
|
right: 0,
|
||||||
bottom: 0,
|
bottom: 0,
|
||||||
backgroundColor: '#fff',
|
|
||||||
borderTopWidth: StyleSheet.hairlineWidth,
|
borderTopWidth: StyleSheet.hairlineWidth,
|
||||||
borderTopColor: 'rgba(0, 0, 0, .3)',
|
|
||||||
elevation: 8,
|
elevation: 8,
|
||||||
},
|
},
|
||||||
content: {
|
content: {
|
||||||
|
|||||||
@@ -8,7 +8,8 @@ import {
|
|||||||
ViewStyle,
|
ViewStyle,
|
||||||
TextStyle,
|
TextStyle,
|
||||||
} from 'react-native';
|
} from 'react-native';
|
||||||
import { Route } from '@react-navigation/core';
|
import { Route, useTheme } from '@react-navigation/native';
|
||||||
|
import Color from 'color';
|
||||||
|
|
||||||
import TabBarIcon from './TabBarIcon';
|
import TabBarIcon from './TabBarIcon';
|
||||||
import { BottomTabBarButtonProps } from '../types';
|
import { BottomTabBarButtonProps } from '../types';
|
||||||
@@ -113,8 +114,8 @@ export default function BottomTabBarItem({
|
|||||||
onPress,
|
onPress,
|
||||||
onLongPress,
|
onLongPress,
|
||||||
horizontal,
|
horizontal,
|
||||||
activeTintColor = '#007AFF',
|
activeTintColor: customActiveTintColor,
|
||||||
inactiveTintColor = '#8E8E93',
|
inactiveTintColor: customInactiveTintColor,
|
||||||
activeBackgroundColor = 'transparent',
|
activeBackgroundColor = 'transparent',
|
||||||
inactiveBackgroundColor = 'transparent',
|
inactiveBackgroundColor = 'transparent',
|
||||||
showLabel = true,
|
showLabel = true,
|
||||||
@@ -123,6 +124,20 @@ export default function BottomTabBarItem({
|
|||||||
labelStyle,
|
labelStyle,
|
||||||
style,
|
style,
|
||||||
}: Props) {
|
}: Props) {
|
||||||
|
const { colors } = useTheme();
|
||||||
|
|
||||||
|
const activeTintColor =
|
||||||
|
customActiveTintColor === undefined
|
||||||
|
? colors.primary
|
||||||
|
: customActiveTintColor;
|
||||||
|
|
||||||
|
const inactiveTintColor =
|
||||||
|
customInactiveTintColor === undefined
|
||||||
|
? Color(colors.text)
|
||||||
|
.mix(Color(colors.card), 0.5)
|
||||||
|
.hex()
|
||||||
|
: customInactiveTintColor;
|
||||||
|
|
||||||
const renderLabel = ({ focused }: { focused: boolean }) => {
|
const renderLabel = ({ focused }: { focused: boolean }) => {
|
||||||
if (showLabel === false) {
|
if (showLabel === false) {
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import * as React from 'react';
|
|||||||
import { View, StyleSheet } from 'react-native';
|
import { View, StyleSheet } from 'react-native';
|
||||||
|
|
||||||
import { TabNavigationState } from '@react-navigation/routers';
|
import { TabNavigationState } from '@react-navigation/routers';
|
||||||
|
import { useTheme } from '@react-navigation/native';
|
||||||
// eslint-disable-next-line import/no-unresolved
|
// eslint-disable-next-line import/no-unresolved
|
||||||
import { ScreenContainer } from 'react-native-screens';
|
import { ScreenContainer } from 'react-native-screens';
|
||||||
|
|
||||||
@@ -25,6 +26,26 @@ type State = {
|
|||||||
loaded: number[];
|
loaded: number[];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function SceneContent({
|
||||||
|
isFocused,
|
||||||
|
children,
|
||||||
|
}: {
|
||||||
|
isFocused: boolean;
|
||||||
|
children: React.ReactNode;
|
||||||
|
}) {
|
||||||
|
const { colors } = useTheme();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<View
|
||||||
|
accessibilityElementsHidden={!isFocused}
|
||||||
|
importantForAccessibility={isFocused ? 'auto' : 'no-hide-descendants'}
|
||||||
|
style={[styles.content, { backgroundColor: colors.background }]}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
export default class BottomTabView extends React.Component<Props, State> {
|
export default class BottomTabView extends React.Component<Props, State> {
|
||||||
static defaultProps = {
|
static defaultProps = {
|
||||||
lazy: true,
|
lazy: true,
|
||||||
@@ -97,15 +118,9 @@ export default class BottomTabView extends React.Component<Props, State> {
|
|||||||
style={StyleSheet.absoluteFill}
|
style={StyleSheet.absoluteFill}
|
||||||
isVisible={isFocused}
|
isVisible={isFocused}
|
||||||
>
|
>
|
||||||
<View
|
<SceneContent isFocused={isFocused}>
|
||||||
accessibilityElementsHidden={!isFocused}
|
|
||||||
importantForAccessibility={
|
|
||||||
isFocused ? 'auto' : 'no-hide-descendants'
|
|
||||||
}
|
|
||||||
style={styles.content}
|
|
||||||
>
|
|
||||||
{descriptors[route.key].render()}
|
{descriptors[route.key].render()}
|
||||||
</View>
|
</SceneContent>
|
||||||
</ResourceSavingScene>
|
</ResourceSavingScene>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ const FAR_FAR_AWAY = 3000; // this should be big enough to move the whole view o
|
|||||||
|
|
||||||
export default class ResourceSavingScene extends React.Component<Props> {
|
export default class ResourceSavingScene extends React.Component<Props> {
|
||||||
render() {
|
render() {
|
||||||
if (screensEnabled && screensEnabled()) {
|
if (screensEnabled?.()) {
|
||||||
const { isVisible, ...rest } = this.props;
|
const { isVisible, ...rest } = this.props;
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
return <Screen active={isVisible ? 1 : 0} {...rest} />;
|
return <Screen active={isVisible ? 1 : 0} {...rest} />;
|
||||||
|
|||||||
@@ -3,6 +3,17 @@ import {
|
|||||||
SafeAreaProvider,
|
SafeAreaProvider,
|
||||||
SafeAreaConsumer,
|
SafeAreaConsumer,
|
||||||
} from 'react-native-safe-area-context';
|
} from 'react-native-safe-area-context';
|
||||||
|
import {
|
||||||
|
getStatusBarHeight,
|
||||||
|
getBottomSpace,
|
||||||
|
} from 'react-native-iphone-x-helper';
|
||||||
|
|
||||||
|
const initialSafeAreaInsets = {
|
||||||
|
top: getStatusBarHeight(true),
|
||||||
|
bottom: getBottomSpace(),
|
||||||
|
right: 0,
|
||||||
|
left: 0,
|
||||||
|
};
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
@@ -19,7 +30,11 @@ export default function SafeAreaProviderCompat({ children }: Props) {
|
|||||||
return children;
|
return children;
|
||||||
}
|
}
|
||||||
|
|
||||||
return <SafeAreaProvider>{children}</SafeAreaProvider>;
|
return (
|
||||||
|
<SafeAreaProvider initialSafeAreaInsets={initialSafeAreaInsets}>
|
||||||
|
{children}
|
||||||
|
</SafeAreaProvider>
|
||||||
|
);
|
||||||
}}
|
}}
|
||||||
</SafeAreaConsumer>
|
</SafeAreaConsumer>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { View, StyleSheet, StyleProp, ViewStyle } from 'react-native';
|
import { View, StyleSheet, StyleProp, ViewStyle } from 'react-native';
|
||||||
import { Route } from '@react-navigation/core';
|
import { Route } from '@react-navigation/native';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
route: Route<string>;
|
route: Route<string>;
|
||||||
|
|||||||
@@ -3,6 +3,38 @@
|
|||||||
All notable changes to this project will be documented in this file.
|
All notable changes to this project will be documented in this file.
|
||||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||||
|
|
||||||
|
# [5.0.0-alpha.20](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/compat@5.0.0-alpha.19...@react-navigation/compat@5.0.0-alpha.20) (2020-01-01)
|
||||||
|
|
||||||
|
**Note:** Version bump only for package @react-navigation/compat
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [5.0.0-alpha.19](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/compat@5.0.0-alpha.18...@react-navigation/compat@5.0.0-alpha.19) (2019-12-19)
|
||||||
|
|
||||||
|
**Note:** Version bump only for package @react-navigation/compat
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [5.0.0-alpha.18](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/compat@5.0.0-alpha.17...@react-navigation/compat@5.0.0-alpha.18) (2019-12-16)
|
||||||
|
|
||||||
|
**Note:** Version bump only for package @react-navigation/compat
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [5.0.0-alpha.17](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/compat@5.0.0-alpha.16...@react-navigation/compat@5.0.0-alpha.17) (2019-12-11)
|
||||||
|
|
||||||
|
**Note:** Version bump only for package @react-navigation/compat
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# [5.0.0-alpha.16](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/compat@5.0.0-alpha.15...@react-navigation/compat@5.0.0-alpha.16) (2019-12-10)
|
# [5.0.0-alpha.16](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/compat@5.0.0-alpha.15...@react-navigation/compat@5.0.0-alpha.16) (2019-12-10)
|
||||||
|
|
||||||
**Note:** Version bump only for package @react-navigation/compat
|
**Note:** Version bump only for package @react-navigation/compat
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ Compatibility layer to write navigator definitions in static configuration forma
|
|||||||
Open a Terminal in your project's folder and run,
|
Open a Terminal in your project's folder and run,
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
yarn add @react-navigation/core @react-navigation/compat
|
yarn add @react-navigation/native @react-navigation/compat
|
||||||
```
|
```
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@react-navigation/compat",
|
"name": "@react-navigation/compat",
|
||||||
"description": "Compatibility layer to write navigator definitions in static configuration format",
|
"description": "Compatibility layer to write navigator definitions in static configuration format",
|
||||||
"version": "5.0.0-alpha.16",
|
"version": "5.0.0-alpha.20",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@@ -24,15 +24,15 @@
|
|||||||
"clean": "del lib"
|
"clean": "del lib"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@react-navigation/routers": "^5.0.0-alpha.15"
|
"@react-navigation/routers": "^5.0.0-alpha.19"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/react": "^16.9.11",
|
"@types/react": "^16.9.16",
|
||||||
"react": "~16.9.0",
|
"react": "~16.9.0",
|
||||||
"typescript": "^3.7.2"
|
"typescript": "^3.7.3"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"@react-navigation/core": "^5.0.0-alpha.0",
|
"@react-navigation/native": "^5.0.0-alpha.0",
|
||||||
"react": "~16.9.0"
|
"react": "~16.9.0"
|
||||||
},
|
},
|
||||||
"@react-native-community/bob": {
|
"@react-native-community/bob": {
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import {
|
|||||||
NavigationProp,
|
NavigationProp,
|
||||||
ParamListBase,
|
ParamListBase,
|
||||||
RouteProp,
|
RouteProp,
|
||||||
} from '@react-navigation/core';
|
} from '@react-navigation/native';
|
||||||
import ScreenPropsContext from './ScreenPropsContext';
|
import ScreenPropsContext from './ScreenPropsContext';
|
||||||
import createCompatNavigationProp from './createCompatNavigationProp';
|
import createCompatNavigationProp from './createCompatNavigationProp';
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { CommonActions, NavigationState } from '@react-navigation/core';
|
import { CommonActions, NavigationState } from '@react-navigation/native';
|
||||||
|
|
||||||
export function navigate({
|
export function navigate({
|
||||||
routeName,
|
routeName,
|
||||||
@@ -25,7 +25,7 @@ export function navigate({
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function back(options?: { key?: null | string }) {
|
export function back(options?: { key?: null | string }) {
|
||||||
return options && options.key != null
|
return options?.key != null
|
||||||
? (state: NavigationState) => ({
|
? (state: NavigationState) => ({
|
||||||
...CommonActions.goBack(),
|
...CommonActions.goBack(),
|
||||||
source: options.key,
|
source: options.key,
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { CommonActions } from '@react-navigation/core';
|
import { CommonActions } from '@react-navigation/native';
|
||||||
import { StackActions, StackActionType } from '@react-navigation/routers';
|
import { StackActions, StackActionType } from '@react-navigation/routers';
|
||||||
|
|
||||||
export function reset(): CommonActions.Action {
|
export function reset(): CommonActions.Action {
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import {
|
|||||||
ParamListBase,
|
ParamListBase,
|
||||||
NavigationProp,
|
NavigationProp,
|
||||||
RouteProp,
|
RouteProp,
|
||||||
} from '@react-navigation/core';
|
} from '@react-navigation/native';
|
||||||
import * as helpers from './helpers';
|
import * as helpers from './helpers';
|
||||||
import { CompatNavigationProp } from './types';
|
import { CompatNavigationProp } from './types';
|
||||||
|
|
||||||
@@ -109,17 +109,17 @@ export default function createCompatNavigationProp<
|
|||||||
break;
|
break;
|
||||||
case 'didFocus': {
|
case 'didFocus': {
|
||||||
const unsubscribe = focusSubscriptions.get(callback);
|
const unsubscribe = focusSubscriptions.get(callback);
|
||||||
unsubscribe && unsubscribe();
|
unsubscribe?.();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'didBlur': {
|
case 'didBlur': {
|
||||||
const unsubscribe = blurSubscriptions.get(callback);
|
const unsubscribe = blurSubscriptions.get(callback);
|
||||||
unsubscribe && unsubscribe();
|
unsubscribe?.();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'refocus': {
|
case 'refocus': {
|
||||||
const unsubscribe = refocusSubscriptions.get(callback);
|
const unsubscribe = refocusSubscriptions.get(callback);
|
||||||
unsubscribe && unsubscribe();
|
unsubscribe?.();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import {
|
|||||||
TypedNavigator,
|
TypedNavigator,
|
||||||
NavigationProp,
|
NavigationProp,
|
||||||
RouteProp,
|
RouteProp,
|
||||||
} from '@react-navigation/core';
|
} from '@react-navigation/native';
|
||||||
import CompatScreen from './CompatScreen';
|
import CompatScreen from './CompatScreen';
|
||||||
import ScreenPropsContext from './ScreenPropsContext';
|
import ScreenPropsContext from './ScreenPropsContext';
|
||||||
import createCompatNavigationProp from './createCompatNavigationProp';
|
import createCompatNavigationProp from './createCompatNavigationProp';
|
||||||
@@ -47,7 +47,7 @@ export default function createCompatNavigatorFactory<
|
|||||||
>(
|
>(
|
||||||
routeConfig: CompatRouteConfig<NavigationPropType>,
|
routeConfig: CompatRouteConfig<NavigationPropType>,
|
||||||
navigationConfig: Partial<Omit<NavigationConfig, 'screenOptions'>> & {
|
navigationConfig: Partial<Omit<NavigationConfig, 'screenOptions'>> & {
|
||||||
order?: Array<Extract<keyof ParamList, string>>;
|
order?: Extract<keyof ParamList, string>[];
|
||||||
defaultNavigationOptions?: ScreenOptions;
|
defaultNavigationOptions?: ScreenOptions;
|
||||||
navigationOptions?: Record<string, any>;
|
navigationOptions?: Record<string, any>;
|
||||||
} = {}
|
} = {}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import {
|
|||||||
useNavigationBuilder,
|
useNavigationBuilder,
|
||||||
createNavigatorFactory,
|
createNavigatorFactory,
|
||||||
DefaultNavigatorOptions,
|
DefaultNavigatorOptions,
|
||||||
} from '@react-navigation/core';
|
} from '@react-navigation/native';
|
||||||
import {
|
import {
|
||||||
TabRouter,
|
TabRouter,
|
||||||
TabRouterOptions,
|
TabRouterOptions,
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { ParamListBase, NavigationProp, Route } from '@react-navigation/core';
|
import { ParamListBase, NavigationProp, Route } from '@react-navigation/native';
|
||||||
import * as helpers from './helpers';
|
import * as helpers from './helpers';
|
||||||
|
|
||||||
export type CompatNavigationProp<
|
export type CompatNavigationProp<
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import {
|
|||||||
useRoute,
|
useRoute,
|
||||||
NavigationProp,
|
NavigationProp,
|
||||||
ParamListBase,
|
ParamListBase,
|
||||||
} from '@react-navigation/core';
|
} from '@react-navigation/native';
|
||||||
import createCompatNavigationProp from './createCompatNavigationProp';
|
import createCompatNavigationProp from './createCompatNavigationProp';
|
||||||
import { CompatNavigationProp } from './types';
|
import { CompatNavigationProp } from './types';
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import { NavigationProp, ParamListBase } from '@react-navigation/core';
|
import { NavigationProp, ParamListBase } from '@react-navigation/native';
|
||||||
import useCompatNavigation from './useCompatNavigation';
|
import useCompatNavigation from './useCompatNavigation';
|
||||||
import { CompatNavigationProp } from './types';
|
import { CompatNavigationProp } from './types';
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import { useIsFocused } from '@react-navigation/core';
|
import { useIsFocused } from '@react-navigation/native';
|
||||||
|
|
||||||
type InjectedProps = {
|
type InjectedProps = {
|
||||||
isFocused: boolean;
|
isFocused: boolean;
|
||||||
|
|||||||
@@ -3,6 +3,42 @@
|
|||||||
All notable changes to this project will be documented in this file.
|
All notable changes to this project will be documented in this file.
|
||||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||||
|
|
||||||
|
# [5.0.0-alpha.30](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/core@5.0.0-alpha.29...@react-navigation/core@5.0.0-alpha.30) (2020-01-01)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* cleanup transaction even if action wasn't handled ([f462d67](https://github.com/react-navigation/navigation-ex/commit/f462d672708cabfb0477c3a48505bd194ea626fd))
|
||||||
|
* show error if an action was not handled ([0252bdc](https://github.com/react-navigation/navigation-ex/commit/0252bdc2222ebe7410a0ed593bf03b2bdf5dc7ca))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [5.0.0-alpha.29](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/core@5.0.0-alpha.28...@react-navigation/core@5.0.0-alpha.29) (2019-12-19)
|
||||||
|
|
||||||
|
**Note:** Version bump only for package @react-navigation/core
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [5.0.0-alpha.28](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/core@5.0.0-alpha.27...@react-navigation/core@5.0.0-alpha.28) (2019-12-16)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* use Partial type for initialParam ([#206](https://github.com/react-navigation/navigation-ex/issues/206)) ([c3d3748](https://github.com/react-navigation/navigation-ex/commit/c3d374814308b0bd6d259099444f0f24593f4d7e))
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* add nested config in deep linking ([#210](https://github.com/react-navigation/navigation-ex/issues/210)) ([8002d51](https://github.com/react-navigation/navigation-ex/commit/8002d5179524a7211c37760a4ed45e8c12af4358)), closes [#154](https://github.com/react-navigation/navigation-ex/issues/154)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# [5.0.0-alpha.27](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/core@5.0.0-alpha.26...@react-navigation/core@5.0.0-alpha.27) (2019-12-10)
|
# [5.0.0-alpha.27](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/core@5.0.0-alpha.26...@react-navigation/core@5.0.0-alpha.27) (2019-12-10)
|
||||||
|
|
||||||
**Note:** Version bump only for package @react-navigation/core
|
**Note:** Version bump only for package @react-navigation/core
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
"react-native",
|
"react-native",
|
||||||
"react-navigation"
|
"react-navigation"
|
||||||
],
|
],
|
||||||
"version": "5.0.0-alpha.27",
|
"version": "5.0.0-alpha.30",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@@ -35,15 +35,15 @@
|
|||||||
"use-subscription": "^1.3.0"
|
"use-subscription": "^1.3.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/core": "^7.7.2",
|
"@babel/core": "^7.7.5",
|
||||||
"@react-native-community/bob": "^0.7.0",
|
"@react-native-community/bob": "^0.7.0",
|
||||||
"@types/react": "^16.9.11",
|
"@types/react": "^16.9.16",
|
||||||
"@types/shortid": "^0.0.29",
|
"@types/shortid": "^0.0.29",
|
||||||
"del-cli": "^3.0.0",
|
"del-cli": "^3.0.0",
|
||||||
"react": "~16.9.0",
|
"react": "~16.9.0",
|
||||||
"react-native-testing-library": "^1.9.1",
|
"react-native-testing-library": "^1.12.0",
|
||||||
"react-test-renderer": "~16.9.0",
|
"react-test-renderer": "~16.9.0",
|
||||||
"typescript": "^3.7.2"
|
"typescript": "^3.7.3"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"react": "~16.9.0"
|
"react": "~16.9.0"
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
// eslint-disable-next-line import/no-cycle
|
|
||||||
import { NavigationState, PartialState } from './types';
|
import { NavigationState, PartialState } from './types';
|
||||||
|
|
||||||
export type Action =
|
export type Action =
|
||||||
|
|||||||
@@ -123,9 +123,11 @@ const Container = React.forwardRef(function NavigationContainer(
|
|||||||
isTransactionActiveRef.current = true;
|
isTransactionActiveRef.current = true;
|
||||||
transactionStateRef.current = navigationState;
|
transactionStateRef.current = navigationState;
|
||||||
|
|
||||||
|
try {
|
||||||
callback();
|
callback();
|
||||||
|
} finally {
|
||||||
isTransactionActiveRef.current = false;
|
isTransactionActiveRef.current = false;
|
||||||
|
}
|
||||||
|
|
||||||
return transactionStateRef.current;
|
return transactionStateRef.current;
|
||||||
});
|
});
|
||||||
@@ -202,7 +204,7 @@ const Container = React.forwardRef(function NavigationContainer(
|
|||||||
}, [getStateForRoute]);
|
}, [getStateForRoute]);
|
||||||
|
|
||||||
React.useImperativeHandle(ref, () => ({
|
React.useImperativeHandle(ref, () => ({
|
||||||
...(Object.keys(CommonActions) as Array<keyof typeof CommonActions>).reduce<
|
...(Object.keys(CommonActions) as (keyof typeof CommonActions)[]).reduce<
|
||||||
any
|
any
|
||||||
>((acc, name) => {
|
>((acc, name) => {
|
||||||
acc[name] = (...args: any[]) =>
|
acc[name] = (...args: any[]) =>
|
||||||
|
|||||||
75
packages/core/src/__tests__/getActionFromState.test.tsx
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
import getActionFromState from '../getActionFromState';
|
||||||
|
|
||||||
|
it('gets navigate action from state', () => {
|
||||||
|
const state = {
|
||||||
|
routes: [
|
||||||
|
{
|
||||||
|
name: 'foo',
|
||||||
|
state: {
|
||||||
|
routes: [
|
||||||
|
{
|
||||||
|
name: 'bar',
|
||||||
|
params: { answer: 42 },
|
||||||
|
state: {
|
||||||
|
routes: [
|
||||||
|
{
|
||||||
|
name: 'qux',
|
||||||
|
params: { author: 'jane' },
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(getActionFromState(state)).toEqual({
|
||||||
|
payload: {
|
||||||
|
name: 'foo',
|
||||||
|
params: {
|
||||||
|
params: {
|
||||||
|
answer: 42,
|
||||||
|
params: {
|
||||||
|
author: 'jane',
|
||||||
|
},
|
||||||
|
screen: 'qux',
|
||||||
|
},
|
||||||
|
screen: 'bar',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
type: 'NAVIGATE',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('gets reset action from state', () => {
|
||||||
|
const state = {
|
||||||
|
routes: [
|
||||||
|
{
|
||||||
|
name: 'foo',
|
||||||
|
state: {
|
||||||
|
routes: [
|
||||||
|
{
|
||||||
|
name: 'bar',
|
||||||
|
state: {
|
||||||
|
routes: [
|
||||||
|
{
|
||||||
|
name: 'qux',
|
||||||
|
params: { author: 'jane' },
|
||||||
|
},
|
||||||
|
{ name: 'quz' },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(getActionFromState(state)).toEqual({
|
||||||
|
payload: state,
|
||||||
|
type: 'RESET_ROOT',
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -127,3 +127,238 @@ it('handles route without param', () => {
|
|||||||
it('returns undefined for invalid path', () => {
|
it('returns undefined for invalid path', () => {
|
||||||
expect(getStateFromPath('//')).toBe(undefined);
|
expect(getStateFromPath('//')).toBe(undefined);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('converts path string to initial state with config with nested screens', () => {
|
||||||
|
expect(
|
||||||
|
getStateFromPath(
|
||||||
|
'/few/bar/sweet/apple/baz/jane?count=10&answer=42&valid=true',
|
||||||
|
{
|
||||||
|
Foo: {
|
||||||
|
Foe: 'few',
|
||||||
|
},
|
||||||
|
Bar: 'bar/:type/:fruit',
|
||||||
|
Baz: {
|
||||||
|
path: 'baz/:author',
|
||||||
|
parse: {
|
||||||
|
author: (author: string) =>
|
||||||
|
author.replace(/^\w/, c => c.toUpperCase()),
|
||||||
|
count: Number,
|
||||||
|
valid: Boolean,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
).toEqual({
|
||||||
|
routes: [
|
||||||
|
{
|
||||||
|
name: 'Foo',
|
||||||
|
state: {
|
||||||
|
routes: [
|
||||||
|
{
|
||||||
|
name: 'Foe',
|
||||||
|
state: {
|
||||||
|
routes: [
|
||||||
|
{
|
||||||
|
name: 'Bar',
|
||||||
|
params: { fruit: 'apple', type: 'sweet' },
|
||||||
|
state: {
|
||||||
|
routes: [
|
||||||
|
{
|
||||||
|
name: 'Baz',
|
||||||
|
params: {
|
||||||
|
author: 'Jane',
|
||||||
|
count: 10,
|
||||||
|
answer: '42',
|
||||||
|
valid: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('converts path string to initial state with config with nested screens and unused configs', () => {
|
||||||
|
expect(
|
||||||
|
getStateFromPath('/few/baz/jane?count=10&answer=42&valid=true', {
|
||||||
|
Foo: {
|
||||||
|
Foe: 'few',
|
||||||
|
},
|
||||||
|
Baz: {
|
||||||
|
path: 'baz/:author',
|
||||||
|
parse: {
|
||||||
|
author: (author: string) =>
|
||||||
|
author.replace(/^\w/, c => c.toUpperCase()),
|
||||||
|
count: Number,
|
||||||
|
valid: Boolean,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
).toEqual({
|
||||||
|
routes: [
|
||||||
|
{
|
||||||
|
name: 'Foo',
|
||||||
|
state: {
|
||||||
|
routes: [
|
||||||
|
{
|
||||||
|
name: 'Foe',
|
||||||
|
state: {
|
||||||
|
routes: [
|
||||||
|
{
|
||||||
|
name: 'Baz',
|
||||||
|
params: {
|
||||||
|
author: 'Jane',
|
||||||
|
count: 10,
|
||||||
|
answer: '42',
|
||||||
|
valid: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('handles parse in nested object with parse in it', () => {
|
||||||
|
expect(
|
||||||
|
getStateFromPath(
|
||||||
|
'/bar/sweet/apple/few/bis/jane?count=10&answer=42&valid=true',
|
||||||
|
{
|
||||||
|
Foo: {
|
||||||
|
Foe: 'few',
|
||||||
|
},
|
||||||
|
Bar: 'bar/:type/:fruit',
|
||||||
|
Baz: {
|
||||||
|
Bis: {
|
||||||
|
path: 'bis/:author',
|
||||||
|
parse: {
|
||||||
|
author: (author: string) =>
|
||||||
|
author.replace(/^\w/, c => c.toUpperCase()),
|
||||||
|
count: Number,
|
||||||
|
valid: Boolean,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
).toEqual({
|
||||||
|
routes: [
|
||||||
|
{
|
||||||
|
name: 'Bar',
|
||||||
|
params: { fruit: 'apple', type: 'sweet' },
|
||||||
|
state: {
|
||||||
|
routes: [
|
||||||
|
{
|
||||||
|
name: 'Foo',
|
||||||
|
state: {
|
||||||
|
routes: [
|
||||||
|
{
|
||||||
|
name: 'Foe',
|
||||||
|
state: {
|
||||||
|
routes: [
|
||||||
|
{
|
||||||
|
name: 'Baz',
|
||||||
|
state: {
|
||||||
|
routes: [
|
||||||
|
{
|
||||||
|
name: 'Bis',
|
||||||
|
params: {
|
||||||
|
author: 'Jane',
|
||||||
|
count: 10,
|
||||||
|
answer: '42',
|
||||||
|
valid: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('handles parse in nested object for second route depth', () => {
|
||||||
|
expect(
|
||||||
|
getStateFromPath('/baz', {
|
||||||
|
Foo: {
|
||||||
|
path: 'foo',
|
||||||
|
Foe: 'foe',
|
||||||
|
Bar: {
|
||||||
|
Baz: 'baz',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
).toEqual({
|
||||||
|
routes: [
|
||||||
|
{
|
||||||
|
name: 'Foo',
|
||||||
|
state: {
|
||||||
|
routes: [
|
||||||
|
{
|
||||||
|
name: 'Bar',
|
||||||
|
state: {
|
||||||
|
routes: [{ name: 'Baz' }],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('handles parse in nested object for second route depth and and path and parse in roots', () => {
|
||||||
|
expect(
|
||||||
|
getStateFromPath('/baz', {
|
||||||
|
Foo: {
|
||||||
|
path: 'foo/:id',
|
||||||
|
parse: {
|
||||||
|
id: Number,
|
||||||
|
},
|
||||||
|
Foe: 'foe',
|
||||||
|
Bar: {
|
||||||
|
path: 'bar/:id',
|
||||||
|
parse: {
|
||||||
|
id: Number,
|
||||||
|
},
|
||||||
|
Baz: 'baz',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
).toEqual({
|
||||||
|
routes: [
|
||||||
|
{
|
||||||
|
name: 'Foo',
|
||||||
|
state: {
|
||||||
|
routes: [
|
||||||
|
{
|
||||||
|
name: 'Bar',
|
||||||
|
state: {
|
||||||
|
routes: [{ name: 'Baz' }],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
@@ -357,6 +357,8 @@ it("doesn't update state if action wasn't handled", () => {
|
|||||||
|
|
||||||
const onStateChange = jest.fn();
|
const onStateChange = jest.fn();
|
||||||
|
|
||||||
|
const spy = jest.spyOn(console, 'error').mockImplementation();
|
||||||
|
|
||||||
render(
|
render(
|
||||||
<NavigationContainer onStateChange={onStateChange}>
|
<NavigationContainer onStateChange={onStateChange}>
|
||||||
<TestNavigator initialRouteName="foo">
|
<TestNavigator initialRouteName="foo">
|
||||||
@@ -367,6 +369,12 @@ it("doesn't update state if action wasn't handled", () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
expect(onStateChange).toBeCalledTimes(0);
|
expect(onStateChange).toBeCalledTimes(0);
|
||||||
|
|
||||||
|
expect(spy.mock.calls[0][0]).toMatch(
|
||||||
|
"The action 'INVALID' with payload 'undefined' was not handled by any navigator."
|
||||||
|
);
|
||||||
|
|
||||||
|
spy.mockRestore();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('cleans up state when the navigator unmounts', () => {
|
it('cleans up state when the navigator unmounts', () => {
|
||||||
|
|||||||
@@ -305,8 +305,7 @@ it("action doesn't bubble if target is specified", () => {
|
|||||||
expect(onStateChange).not.toBeCalled();
|
expect(onStateChange).not.toBeCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
// eslint-disable-next-line jest/expect-expect
|
it('logs error if no navigator handled the action', () => {
|
||||||
it("doesn't crash if no navigator handled the action", () => {
|
|
||||||
const TestRouter = MockRouter;
|
const TestRouter = MockRouter;
|
||||||
|
|
||||||
const TestNavigator = (props: any) => {
|
const TestNavigator = (props: any) => {
|
||||||
@@ -366,5 +365,13 @@ it("doesn't crash if no navigator handled the action", () => {
|
|||||||
</NavigationContainer>
|
</NavigationContainer>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const spy = jest.spyOn(console, 'error').mockImplementation();
|
||||||
|
|
||||||
render(element).update(element);
|
render(element).update(element);
|
||||||
|
|
||||||
|
expect(spy.mock.calls[0][0]).toMatch(
|
||||||
|
"The action 'UNKNOWN' with payload 'undefined' was not handled by any navigator."
|
||||||
|
);
|
||||||
|
|
||||||
|
spy.mockRestore();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ it('gets route prop from context', () => {
|
|||||||
const Test = () => {
|
const Test = () => {
|
||||||
const route = useRoute<RouteProp<{ sample: { x: string } }, 'sample'>>();
|
const route = useRoute<RouteProp<{ sample: { x: string } }, 'sample'>>();
|
||||||
|
|
||||||
expect(route && route.params && route.params.x).toEqual(1);
|
expect(route?.params?.x).toEqual(1);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|||||||
67
packages/core/src/getActionFromState.tsx
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
import { PartialState, NavigationState } from './types';
|
||||||
|
|
||||||
|
type NavigateParams = {
|
||||||
|
screen?: string;
|
||||||
|
params?: NavigateParams;
|
||||||
|
};
|
||||||
|
|
||||||
|
type Action =
|
||||||
|
| {
|
||||||
|
type: 'NAVIGATE';
|
||||||
|
payload: { name: string; params: NavigateParams };
|
||||||
|
}
|
||||||
|
| {
|
||||||
|
type: 'RESET_ROOT';
|
||||||
|
payload: PartialState<NavigationState>;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function getActionFromState(
|
||||||
|
state: PartialState<NavigationState>
|
||||||
|
): Action {
|
||||||
|
let payload: { name: string; params: NavigateParams } | undefined;
|
||||||
|
|
||||||
|
if (state.routes.length === 1) {
|
||||||
|
// Try to construct payload for a `NAVIGATE` action from the state
|
||||||
|
// This lets us preserve the navigation state and not lose it
|
||||||
|
let route = state.routes[0];
|
||||||
|
|
||||||
|
payload = {
|
||||||
|
name: route.name,
|
||||||
|
params: { ...route.params },
|
||||||
|
};
|
||||||
|
|
||||||
|
let current = state.routes[0].state;
|
||||||
|
let params = payload.params;
|
||||||
|
|
||||||
|
while (current) {
|
||||||
|
if (current.routes.length === 1) {
|
||||||
|
route = current.routes[0];
|
||||||
|
params.screen = route.name;
|
||||||
|
|
||||||
|
if (route.state) {
|
||||||
|
params.params = { ...route.params };
|
||||||
|
params = params.params;
|
||||||
|
} else {
|
||||||
|
params.params = route.params;
|
||||||
|
}
|
||||||
|
|
||||||
|
current = route.state;
|
||||||
|
} else {
|
||||||
|
payload = undefined;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (payload) {
|
||||||
|
return {
|
||||||
|
type: 'NAVIGATE',
|
||||||
|
payload,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
type: 'RESET_ROOT',
|
||||||
|
payload: state,
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -60,7 +60,7 @@ export default function getPathFromState(
|
|||||||
Object.entries(route.params).reduce<{
|
Object.entries(route.params).reduce<{
|
||||||
[key: string]: string;
|
[key: string]: string;
|
||||||
}>((acc, [key, value]) => {
|
}>((acc, [key, value]) => {
|
||||||
acc[key] = config && config[key] ? config[key](value) : String(value);
|
acc[key] = config?.[key] ? config[key](value) : String(value);
|
||||||
return acc;
|
return acc;
|
||||||
}, {})
|
}, {})
|
||||||
: undefined;
|
: undefined;
|
||||||
@@ -80,6 +80,7 @@ export default function getPathFromState(
|
|||||||
if (params && name in params && p.startsWith(':')) {
|
if (params && name in params && p.startsWith(':')) {
|
||||||
const value = params[name];
|
const value = params[name];
|
||||||
// Remove the used value from the params object since we'll use the rest for query string
|
// Remove the used value from the params object since we'll use the rest for query string
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
|
||||||
delete params[name];
|
delete params[name];
|
||||||
return encodeURIComponent(value);
|
return encodeURIComponent(value);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,22 @@
|
|||||||
import escape from 'escape-string-regexp';
|
import escape from 'escape-string-regexp';
|
||||||
import queryString from 'query-string';
|
import queryString from 'query-string';
|
||||||
import { NavigationState, PartialState } from './types';
|
import { NavigationState, PartialState, InitialState } from './types';
|
||||||
|
|
||||||
type ParseConfig = Record<string, (value: string) => any>;
|
type ParseConfig = Record<string, (value: string) => any>;
|
||||||
|
|
||||||
type Options = {
|
type Options = {
|
||||||
[routeName: string]: string | { path: string; parse?: ParseConfig };
|
[routeName: string]: string | { path: string; parse?: ParseConfig } | Options;
|
||||||
|
};
|
||||||
|
|
||||||
|
type RouteConfig = {
|
||||||
|
match: RegExp;
|
||||||
|
pattern: string;
|
||||||
|
routeNames: string[];
|
||||||
|
parse: Record<string, (value: string) => any> | undefined;
|
||||||
|
};
|
||||||
|
|
||||||
|
type ResultState = PartialState<NavigationState> & {
|
||||||
|
state?: ResultState;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -30,29 +41,12 @@ type Options = {
|
|||||||
export default function getStateFromPath(
|
export default function getStateFromPath(
|
||||||
path: string,
|
path: string,
|
||||||
options: Options = {}
|
options: Options = {}
|
||||||
): PartialState<NavigationState> | undefined {
|
): ResultState | undefined {
|
||||||
// Create a normalized config array which will be easier to use
|
// Create a normalized configs array which will be easier to use
|
||||||
const routeConfig = Object.keys(options).map(key => {
|
const configs = ([] as RouteConfig[]).concat(
|
||||||
const pattern =
|
...Object.keys(options).map(key => createNormalizedConfigs(key, options))
|
||||||
typeof options[key] === 'string'
|
|
||||||
? (options[key] as string)
|
|
||||||
: (options[key] as { path: string }).path;
|
|
||||||
|
|
||||||
// Create a regex from the provided path pattern
|
|
||||||
// With the pattern, we can match segements containing params and extract them
|
|
||||||
const match = new RegExp(
|
|
||||||
'^' + escape(pattern).replace(/:[a-z0-9]+/gi, '([^/]+)') + '/?'
|
|
||||||
);
|
);
|
||||||
|
|
||||||
return {
|
|
||||||
match,
|
|
||||||
pattern,
|
|
||||||
routeName: key,
|
|
||||||
// @ts-ignore
|
|
||||||
parse: options[key].parse,
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
let result: PartialState<NavigationState> | undefined;
|
let result: PartialState<NavigationState> | undefined;
|
||||||
let current: PartialState<NavigationState> | undefined;
|
let current: PartialState<NavigationState> | undefined;
|
||||||
|
|
||||||
@@ -62,16 +56,16 @@ export default function getStateFromPath(
|
|||||||
.replace(/\?.*/, ''); // Remove query params which we will handle later
|
.replace(/\?.*/, ''); // Remove query params which we will handle later
|
||||||
|
|
||||||
while (remaining) {
|
while (remaining) {
|
||||||
let routeName;
|
let routeNames;
|
||||||
let params;
|
let params;
|
||||||
|
|
||||||
// Go through all configs, and see if the next path segment matches our regex
|
// Go through all configs, and see if the next path segment matches our regex
|
||||||
for (const config of routeConfig) {
|
for (const config of configs) {
|
||||||
const match = remaining.match(config.match);
|
const match = remaining.match(config.match);
|
||||||
|
|
||||||
// If our regex matches, we need to extract params from the path
|
// If our regex matches, we need to extract params from the path
|
||||||
if (match) {
|
if (match) {
|
||||||
routeName = config.routeName;
|
routeNames = config.routeNames;
|
||||||
|
|
||||||
const paramPatterns = config.pattern
|
const paramPatterns = config.pattern
|
||||||
.split('/')
|
.split('/')
|
||||||
@@ -99,20 +93,54 @@ export default function getStateFromPath(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If we hadn't matched any segments earlier, use the path as route name
|
// If we hadn't matched any segments earlier, use the path as route name
|
||||||
if (routeName === undefined) {
|
if (routeNames === undefined) {
|
||||||
const segments = remaining.split('/');
|
const segments = remaining.split('/');
|
||||||
|
|
||||||
routeName = decodeURIComponent(segments[0]);
|
routeNames = [decodeURIComponent(segments[0])];
|
||||||
segments.shift();
|
segments.shift();
|
||||||
remaining = segments.join('/');
|
remaining = segments.join('/');
|
||||||
}
|
}
|
||||||
|
|
||||||
const state = {
|
let state: InitialState;
|
||||||
routes: [{ name: routeName, params }],
|
|
||||||
|
if (routeNames.length === 1) {
|
||||||
|
state = {
|
||||||
|
routes: [
|
||||||
|
{ name: routeNames.shift() as string, ...(params && { params }) },
|
||||||
|
],
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
state = {
|
||||||
|
routes: [{ name: routeNames.shift() as string, state: { routes: [] } }],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let helper = state.routes[0].state as InitialState;
|
||||||
|
let routeName;
|
||||||
|
|
||||||
|
while ((routeName = routeNames.shift())) {
|
||||||
|
if (routeNames.length === 0) {
|
||||||
|
helper.routes.push({
|
||||||
|
name: routeName,
|
||||||
|
...(params && { params }),
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
helper.routes[0] = {
|
||||||
|
name: routeName,
|
||||||
|
state: {
|
||||||
|
routes: [],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
helper = helper.routes[0].state as InitialState;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (current) {
|
if (current) {
|
||||||
// The state should be nested inside the route we parsed before
|
// The state should be nested inside the deepest route we parsed before
|
||||||
|
while (current.routes[0].state) {
|
||||||
|
current = current.routes[0].state;
|
||||||
|
}
|
||||||
|
|
||||||
current.routes[0].state = state;
|
current.routes[0].state = state;
|
||||||
} else {
|
} else {
|
||||||
result = state;
|
result = state;
|
||||||
@@ -128,17 +156,20 @@ export default function getStateFromPath(
|
|||||||
const query = path.split('?')[1];
|
const query = path.split('?')[1];
|
||||||
|
|
||||||
if (query) {
|
if (query) {
|
||||||
|
while (current.routes[0].state) {
|
||||||
|
// The query params apply to the deepest route
|
||||||
|
current = current.routes[0].state;
|
||||||
|
}
|
||||||
|
|
||||||
const route = current.routes[0];
|
const route = current.routes[0];
|
||||||
|
|
||||||
const params = queryString.parse(query);
|
const params = queryString.parse(query);
|
||||||
const config = options[route.name]
|
const parseFunction = findParseConfigForRoute(route.name, options);
|
||||||
? (options[route.name] as { parse?: ParseConfig }).parse
|
|
||||||
: undefined;
|
|
||||||
|
|
||||||
if (config) {
|
if (parseFunction) {
|
||||||
Object.keys(params).forEach(name => {
|
Object.keys(params).forEach(name => {
|
||||||
if (config[name] && typeof params[name] === 'string') {
|
if (parseFunction[name] && typeof params[name] === 'string') {
|
||||||
params[name] = config[name](params[name] as string);
|
params[name] = parseFunction[name](params[name] as string);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -148,3 +179,89 @@ export default function getStateFromPath(
|
|||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function createNormalizedConfigs(
|
||||||
|
key: string,
|
||||||
|
routeConfig: Options,
|
||||||
|
routeNames: string[] = []
|
||||||
|
): RouteConfig[] {
|
||||||
|
const configs = [];
|
||||||
|
|
||||||
|
routeNames.push(key);
|
||||||
|
|
||||||
|
const value = routeConfig[key];
|
||||||
|
|
||||||
|
if (typeof value === 'string') {
|
||||||
|
// If a string is specified as the value of the key(e.g. Foo: '/path'), use it as the pattern
|
||||||
|
configs.push(createConfigItem(routeNames, value));
|
||||||
|
} else if (typeof value === 'object') {
|
||||||
|
// if an object is specified as the value (e.g. Foo: { ... }),
|
||||||
|
// it could have config object and optionally nested config
|
||||||
|
Object.keys(value).forEach(nestedKey => {
|
||||||
|
if (nestedKey === 'path') {
|
||||||
|
configs.push(
|
||||||
|
createConfigItem(
|
||||||
|
routeNames,
|
||||||
|
value[nestedKey] as string,
|
||||||
|
value.parse ? (value.parse as ParseConfig) : undefined
|
||||||
|
)
|
||||||
|
);
|
||||||
|
} else if (nestedKey === 'parse') {
|
||||||
|
// We handle custom parse function when a `path` is specified (in nestedKey === path)
|
||||||
|
} else {
|
||||||
|
// If the name of the key is not `path` or `parse`, it's a nested config for route
|
||||||
|
// So we need to traverse into it and collect the configs
|
||||||
|
const result = createNormalizedConfigs(
|
||||||
|
nestedKey,
|
||||||
|
routeConfig[key] as Options,
|
||||||
|
routeNames
|
||||||
|
);
|
||||||
|
|
||||||
|
configs.push(...result);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
routeNames.pop();
|
||||||
|
|
||||||
|
return configs;
|
||||||
|
}
|
||||||
|
|
||||||
|
function createConfigItem(
|
||||||
|
routeNames: string[],
|
||||||
|
pattern: string,
|
||||||
|
parse?: ParseConfig
|
||||||
|
): RouteConfig {
|
||||||
|
const match = new RegExp(
|
||||||
|
'^' + escape(pattern).replace(/:[a-z0-9]+/gi, '([^/]+)') + '/?'
|
||||||
|
);
|
||||||
|
|
||||||
|
return {
|
||||||
|
match,
|
||||||
|
pattern,
|
||||||
|
// The routeNames array is mutated, so copy it to keep the current state
|
||||||
|
routeNames: [...routeNames],
|
||||||
|
parse,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function findParseConfigForRoute(
|
||||||
|
routeName: string,
|
||||||
|
config: Options
|
||||||
|
): ParseConfig | undefined {
|
||||||
|
if (config[routeName]) {
|
||||||
|
return (config[routeName] as { parse?: ParseConfig }).parse;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const name in config) {
|
||||||
|
if (typeof config[name] === 'object') {
|
||||||
|
const parse = findParseConfigForRoute(routeName, config[name] as Options);
|
||||||
|
|
||||||
|
if (parse) {
|
||||||
|
return parse;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|||||||
@@ -17,5 +17,6 @@ export { default as useIsFocused } from './useIsFocused';
|
|||||||
|
|
||||||
export { default as getStateFromPath } from './getStateFromPath';
|
export { default as getStateFromPath } from './getStateFromPath';
|
||||||
export { default as getPathFromState } from './getPathFromState';
|
export { default as getPathFromState } from './getPathFromState';
|
||||||
|
export { default as getActionFromState } from './getActionFromState';
|
||||||
|
|
||||||
export * from './types';
|
export * from './types';
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
// eslint-disable-next-line import/no-cycle
|
|
||||||
import * as CommonActions from './CommonActions';
|
import * as CommonActions from './CommonActions';
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
|
|
||||||
@@ -20,9 +19,9 @@ export type NavigationState = {
|
|||||||
/**
|
/**
|
||||||
* List of rendered routes.
|
* List of rendered routes.
|
||||||
*/
|
*/
|
||||||
routes: Array<
|
routes: (Route<string> & {
|
||||||
Route<string> & { state?: NavigationState | PartialState<NavigationState> }
|
state?: NavigationState | PartialState<NavigationState>;
|
||||||
>;
|
})[];
|
||||||
/**
|
/**
|
||||||
* Custom type for the state, whether it's for tab, stack, drawer etc.
|
* Custom type for the state, whether it's for tab, stack, drawer etc.
|
||||||
* During rehydration, the state will be discarded if type doesn't match with router type.
|
* During rehydration, the state will be discarded if type doesn't match with router type.
|
||||||
@@ -38,7 +37,7 @@ export type NavigationState = {
|
|||||||
export type InitialState = Partial<
|
export type InitialState = Partial<
|
||||||
Omit<NavigationState, 'stale' | 'routes'>
|
Omit<NavigationState, 'stale' | 'routes'>
|
||||||
> & {
|
> & {
|
||||||
routes: Array<Omit<Route<string>, 'key'> & { state?: InitialState }>;
|
routes: (Omit<Route<string>, 'key'> & { state?: InitialState })[];
|
||||||
};
|
};
|
||||||
|
|
||||||
export type PartialState<State extends NavigationState> = Partial<
|
export type PartialState<State extends NavigationState> = Partial<
|
||||||
@@ -46,9 +45,10 @@ export type PartialState<State extends NavigationState> = Partial<
|
|||||||
> & {
|
> & {
|
||||||
stale?: true;
|
stale?: true;
|
||||||
type?: string;
|
type?: string;
|
||||||
routes: Array<
|
routes: (Omit<Route<string>, 'key'> & {
|
||||||
Omit<Route<string>, 'key'> & { key?: string; state?: InitialState }
|
key?: string;
|
||||||
>;
|
state?: InitialState;
|
||||||
|
})[];
|
||||||
};
|
};
|
||||||
|
|
||||||
export type Route<RouteName extends string> = {
|
export type Route<RouteName extends string> = {
|
||||||
@@ -71,6 +71,10 @@ export type NavigationAction = {
|
|||||||
* Type of the action (e.g. `NAVIGATE`)
|
* Type of the action (e.g. `NAVIGATE`)
|
||||||
*/
|
*/
|
||||||
type: string;
|
type: string;
|
||||||
|
/**
|
||||||
|
* Additional data for the action
|
||||||
|
*/
|
||||||
|
payload?: object;
|
||||||
/**
|
/**
|
||||||
* Key of the route which dispatched this action.
|
* Key of the route which dispatched this action.
|
||||||
*/
|
*/
|
||||||
@@ -533,7 +537,7 @@ export type RouteConfig<
|
|||||||
/**
|
/**
|
||||||
* Initial params object for the route.
|
* Initial params object for the route.
|
||||||
*/
|
*/
|
||||||
initialParams?: ParamList[RouteName];
|
initialParams?: Partial<ParamList[RouteName]>;
|
||||||
} & (
|
} & (
|
||||||
| {
|
| {
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -44,16 +44,15 @@ export default function useDevTools({ name, reset, state }: Options) {
|
|||||||
|
|
||||||
const devTools = devToolsRef.current;
|
const devTools = devToolsRef.current;
|
||||||
const lastStateRef = React.useRef<State>(state);
|
const lastStateRef = React.useRef<State>(state);
|
||||||
const actions = React.useRef<Array<NavigationAction | string>>([]);
|
const actions = React.useRef<(NavigationAction | string)[]>([]);
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
devTools && devTools.init(lastStateRef.current);
|
devTools?.init(lastStateRef.current);
|
||||||
}, [devTools]);
|
}, [devTools]);
|
||||||
|
|
||||||
React.useEffect(
|
React.useEffect(
|
||||||
() =>
|
() =>
|
||||||
devTools &&
|
devTools?.subscribe(message => {
|
||||||
devTools.subscribe(message => {
|
|
||||||
if (message.type === 'DISPATCH' && message.state) {
|
if (message.type === 'DISPATCH' && message.state) {
|
||||||
reset(JSON.parse(message.state));
|
reset(JSON.parse(message.state));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ export type NavigationEventEmitter = EventEmitter<Record<string, any>> & {
|
|||||||
create: (target: string) => EventConsumer<Record<string, any>>;
|
create: (target: string) => EventConsumer<Record<string, any>>;
|
||||||
};
|
};
|
||||||
|
|
||||||
type Listeners = Array<(data: any) => void>;
|
type Listeners = ((data: any) => void)[];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hook to manage the event system used by the navigator to notify screens of various events.
|
* Hook to manage the event system used by the navigator to notify screens of various events.
|
||||||
@@ -69,7 +69,7 @@ export default function useEventEmitter(): NavigationEventEmitter {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
callbacks && callbacks.forEach(cb => cb(event));
|
callbacks?.forEach(cb => cb(event));
|
||||||
|
|
||||||
return event;
|
return event;
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import useNavigation from './useNavigation';
|
import useNavigation from './useNavigation';
|
||||||
|
|
||||||
type EffectCallback = (() => void) | (() => () => void);
|
type EffectCallback = (() => undefined) | (() => () => void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hook to run an effect in a focused screen, similar to `React.useEffect`.
|
* Hook to run an effect in a focused screen, similar to `React.useEffect`.
|
||||||
@@ -15,7 +15,7 @@ export default function useFocusEffect(callback: EffectCallback) {
|
|||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
let isFocused = false;
|
let isFocused = false;
|
||||||
let cleanup: (() => void) | void;
|
let cleanup: (() => void) | undefined;
|
||||||
|
|
||||||
// We need to run the effect on intial render/dep changes if the screen is focused
|
// We need to run the effect on intial render/dep changes if the screen is focused
|
||||||
if (navigation.isFocused()) {
|
if (navigation.isFocused()) {
|
||||||
@@ -30,19 +30,19 @@ export default function useFocusEffect(callback: EffectCallback) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanup && cleanup();
|
cleanup?.();
|
||||||
cleanup = callback();
|
cleanup = callback();
|
||||||
isFocused = true;
|
isFocused = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
const unsubscribeBlur = navigation.addListener('blur', () => {
|
const unsubscribeBlur = navigation.addListener('blur', () => {
|
||||||
cleanup && cleanup();
|
cleanup?.();
|
||||||
cleanup = undefined;
|
cleanup = undefined;
|
||||||
isFocused = false;
|
isFocused = false;
|
||||||
});
|
});
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
cleanup && cleanup();
|
cleanup?.();
|
||||||
unsubscribeFocus();
|
unsubscribeFocus();
|
||||||
unsubscribeBlur();
|
unsubscribeBlur();
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -21,8 +21,7 @@ export default function useFocusEvents({ state, emitter }: Options) {
|
|||||||
// Coz the child screen can't be focused if the parent screen is out of fcous
|
// Coz the child screen can't be focused if the parent screen is out of fcous
|
||||||
React.useEffect(
|
React.useEffect(
|
||||||
() =>
|
() =>
|
||||||
navigation &&
|
navigation?.addListener('focus', () =>
|
||||||
navigation.addListener('focus', () =>
|
|
||||||
emitter.emit({ type: 'focus', target: currentFocusedKey })
|
emitter.emit({ type: 'focus', target: currentFocusedKey })
|
||||||
),
|
),
|
||||||
[currentFocusedKey, emitter, navigation]
|
[currentFocusedKey, emitter, navigation]
|
||||||
@@ -30,8 +29,7 @@ export default function useFocusEvents({ state, emitter }: Options) {
|
|||||||
|
|
||||||
React.useEffect(
|
React.useEffect(
|
||||||
() =>
|
() =>
|
||||||
navigation &&
|
navigation?.addListener('blur', () =>
|
||||||
navigation.addListener('blur', () =>
|
|
||||||
emitter.emit({ type: 'blur', target: currentFocusedKey })
|
emitter.emit({ type: 'blur', target: currentFocusedKey })
|
||||||
),
|
),
|
||||||
[currentFocusedKey, emitter, navigation]
|
[currentFocusedKey, emitter, navigation]
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ export default function useFocusedListenersChildrenAdapter({
|
|||||||
[focusedListeners, navigation]
|
[focusedListeners, navigation]
|
||||||
);
|
);
|
||||||
|
|
||||||
React.useEffect(() => addFocusedListener && addFocusedListener(listener), [
|
React.useEffect(() => addFocusedListener?.(listener), [
|
||||||
addFocusedListener,
|
addFocusedListener,
|
||||||
listener,
|
listener,
|
||||||
]);
|
]);
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ export default function useNavigationBuilder<
|
|||||||
const { current: router } = React.useRef<Router<State, any>>(
|
const { current: router } = React.useRef<Router<State, any>>(
|
||||||
createRouter({
|
createRouter({
|
||||||
...((rest as unknown) as RouterOptions),
|
...((rest as unknown) as RouterOptions),
|
||||||
...(route && route.params && typeof route.params.screen === 'string'
|
...(route?.params && typeof route.params.screen === 'string'
|
||||||
? { initialRouteName: route.params.screen }
|
? { initialRouteName: route.params.screen }
|
||||||
: null),
|
: null),
|
||||||
})
|
})
|
||||||
@@ -141,7 +141,7 @@ export default function useNavigationBuilder<
|
|||||||
(acc, curr) => {
|
(acc, curr) => {
|
||||||
const { initialParams } = screens[curr];
|
const { initialParams } = screens[curr];
|
||||||
const initialParamsFromParams =
|
const initialParamsFromParams =
|
||||||
route && route.params && route.params.screen === curr
|
route?.params && route.params.screen === curr
|
||||||
? route.params.params
|
? route.params.params
|
||||||
: undefined;
|
: undefined;
|
||||||
|
|
||||||
|
|||||||
@@ -42,13 +42,22 @@ export default function useNavigationHelpers<
|
|||||||
const { performTransaction } = React.useContext(NavigationStateContext);
|
const { performTransaction } = React.useContext(NavigationStateContext);
|
||||||
|
|
||||||
return React.useMemo(() => {
|
return React.useMemo(() => {
|
||||||
const dispatch = (action: Action | ((state: State) => Action)) =>
|
const dispatch = (action: Action | ((state: State) => Action)) => {
|
||||||
performTransaction(() => {
|
performTransaction(() => {
|
||||||
const payload =
|
const payload =
|
||||||
typeof action === 'function' ? action(getState()) : action;
|
typeof action === 'function' ? action(getState()) : action;
|
||||||
|
|
||||||
onAction(payload);
|
const handled = onAction(payload);
|
||||||
|
|
||||||
|
if (!handled && process.env.NODE_ENV !== 'production') {
|
||||||
|
console.error(
|
||||||
|
`The action '${payload.type}' with payload '${JSON.stringify(
|
||||||
|
payload.payload
|
||||||
|
)}' was not handled by any navigator.`
|
||||||
|
);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
};
|
||||||
|
|
||||||
const actions = {
|
const actions = {
|
||||||
...router.actionCreators,
|
...router.actionCreators,
|
||||||
@@ -81,7 +90,7 @@ export default function useNavigationHelpers<
|
|||||||
routeNames: state.routeNames,
|
routeNames: state.routeNames,
|
||||||
routeParamList: {},
|
routeParamList: {},
|
||||||
}) !== null ||
|
}) !== null ||
|
||||||
(parentNavigationHelpers && parentNavigationHelpers.canGoBack()) ||
|
parentNavigationHelpers?.canGoBack() ||
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -130,10 +130,10 @@ export default function useOnAction({
|
|||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
React.useEffect(
|
React.useEffect(() => addActionListenerParent?.(onAction), [
|
||||||
() => addActionListenerParent && addActionListenerParent(onAction),
|
addActionListenerParent,
|
||||||
[addActionListenerParent, onAction]
|
onAction,
|
||||||
);
|
]);
|
||||||
|
|
||||||
return onAction;
|
return onAction;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,6 @@ export default function useOnGetState({
|
|||||||
}, [getState, getStateForRoute]);
|
}, [getState, getStateForRoute]);
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
return addStateGetter && addStateGetter(key, getRehydratedState);
|
return addStateGetter?.(key, getRehydratedState);
|
||||||
}, [addStateGetter, getRehydratedState, key]);
|
}, [addStateGetter, getRehydratedState, key]);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,79 @@
|
|||||||
All notable changes to this project will be documented in this file.
|
All notable changes to this project will be documented in this file.
|
||||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||||
|
|
||||||
|
# [5.0.0-alpha.33](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/drawer@5.0.0-alpha.32...@react-navigation/drawer@5.0.0-alpha.33) (2020-01-03)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* provide initial values for safe area to prevent blank screen ([#238](https://github.com/react-navigation/navigation-ex/issues/238)) ([77b7570](https://github.com/react-navigation/navigation-ex/commit/77b757091c0451e20bca01138629669c7da544a8))
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* add interaction handle to drawer ([#239](https://github.com/react-navigation/navigation-ex/issues/239)) ([fa4411a](https://github.com/react-navigation/navigation-ex/commit/fa4411a14dc4aae568794e4b884088e3276a2876))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [5.0.0-alpha.32](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/drawer@5.0.0-alpha.31...@react-navigation/drawer@5.0.0-alpha.32) (2020-01-03)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* pass backBehavior to the router in drawer. fixes [#230](https://github.com/react-navigation/navigation-ex/issues/230) ([3cd1aed](https://github.com/react-navigation/navigation-ex/commit/3cd1aedcf490a4c7962b2d36873d714637f3b9b0))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [5.0.0-alpha.31](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/drawer@5.0.0-alpha.30...@react-navigation/drawer@5.0.0-alpha.31) (2020-01-01)
|
||||||
|
|
||||||
|
**Note:** Version bump only for package @react-navigation/drawer
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [5.0.0-alpha.30](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/drawer@5.0.0-alpha.29...@react-navigation/drawer@5.0.0-alpha.30) (2019-12-19)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* set screen background in drawer from theme ([0635365](https://github.com/react-navigation/navigation-ex/commit/0635365483bf5ac38e75191b4ba8f52cf6d73896))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [5.0.0-alpha.29](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/drawer@5.0.0-alpha.28...@react-navigation/drawer@5.0.0-alpha.29) (2019-12-16)
|
||||||
|
|
||||||
|
**Note:** Version bump only for package @react-navigation/drawer
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [5.0.0-alpha.28](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/drawer@5.0.0-alpha.27...@react-navigation/drawer@5.0.0-alpha.28) (2019-12-14)
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* add custom theme support ([#211](https://github.com/react-navigation/navigation-ex/issues/211)) ([00fc616](https://github.com/react-navigation/navigation-ex/commit/00fc616de0572bade8aa85052cdc8290360b1d7f))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [5.0.0-alpha.27](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/drawer@5.0.0-alpha.26...@react-navigation/drawer@5.0.0-alpha.27) (2019-12-11)
|
||||||
|
|
||||||
|
**Note:** Version bump only for package @react-navigation/drawer
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# [5.0.0-alpha.26](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/drawer@5.0.0-alpha.25...@react-navigation/drawer@5.0.0-alpha.26) (2019-12-10)
|
# [5.0.0-alpha.26](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/drawer@5.0.0-alpha.25...@react-navigation/drawer@5.0.0-alpha.26) (2019-12-10)
|
||||||
|
|
||||||
**Note:** Version bump only for package @react-navigation/drawer
|
**Note:** Version bump only for package @react-navigation/drawer
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ Bottom tab navigator for React Navigation following iOS design guidelines.
|
|||||||
Open a Terminal in your project's folder and run,
|
Open a Terminal in your project's folder and run,
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
yarn add @react-navigation/core @react-navigation/drawer
|
yarn add @react-navigation/native @react-navigation/drawer
|
||||||
```
|
```
|
||||||
|
|
||||||
Now we need to install [`react-native-gesture-handler`](https://github.com/kmagiera/react-native-gesture-handler), [`react-native-reanimated`](https://github.com/kmagiera/react-native-reanimated) and [`react-native-safe-area-context`](https://github.com/th3rdwave/react-native-safe-area-context).
|
Now we need to install [`react-native-gesture-handler`](https://github.com/kmagiera/react-native-gesture-handler), [`react-native-reanimated`](https://github.com/kmagiera/react-native-reanimated) and [`react-native-safe-area-context`](https://github.com/th3rdwave/react-native-safe-area-context).
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
"material",
|
"material",
|
||||||
"drawer"
|
"drawer"
|
||||||
],
|
],
|
||||||
"version": "5.0.0-alpha.26",
|
"version": "5.0.0-alpha.33",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@@ -34,28 +34,30 @@
|
|||||||
"clean": "del lib"
|
"clean": "del lib"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@react-navigation/routers": "^5.0.0-alpha.15"
|
"@react-navigation/routers": "^5.0.0-alpha.19",
|
||||||
|
"color": "^3.1.2",
|
||||||
|
"react-native-iphone-x-helper": "^1.2.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@react-native-community/bob": "^0.7.0",
|
"@react-native-community/bob": "^0.7.0",
|
||||||
"@types/react": "^16.9.11",
|
"@types/react": "^16.9.16",
|
||||||
"@types/react-native": "^0.60.22",
|
"@types/react-native": "^0.60.25",
|
||||||
"del-cli": "^3.0.0",
|
"del-cli": "^3.0.0",
|
||||||
"react": "~16.9.0",
|
"react": "~16.9.0",
|
||||||
"react-native": "~0.61.5",
|
"react-native": "~0.61.5",
|
||||||
"react-native-gesture-handler": "^1.5.0",
|
"react-native-gesture-handler": "^1.5.0",
|
||||||
"react-native-reanimated": "^1.4.0",
|
"react-native-reanimated": "^1.4.0",
|
||||||
"react-native-safe-area-context": "^0.6.0",
|
"react-native-safe-area-context": "^0.6.0",
|
||||||
"react-native-screens": "^2.0.0-alpha.11",
|
"react-native-screens": "^2.0.0-alpha.19",
|
||||||
"typescript": "^3.7.2"
|
"typescript": "^3.7.3"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"@react-navigation/core": "^5.0.0-alpha.0",
|
"@react-navigation/native": "^5.0.0-alpha.0",
|
||||||
"react": "*",
|
"react": "*",
|
||||||
"react-native": "*",
|
"react-native": "*",
|
||||||
"react-native-gesture-handler": "^1.0.0",
|
"react-native-gesture-handler": "^1.0.0",
|
||||||
"react-native-reanimated": "^1.0.0",
|
"react-native-reanimated": "^1.0.0",
|
||||||
"react-native-safe-area-context": "^0.3.6",
|
"react-native-safe-area-context": "^0.6.0",
|
||||||
"react-native-screens": "^1.0.0-alpha.0 || ^2.0.0-alpha.0"
|
"react-native-screens": "^1.0.0-alpha.0 || ^2.0.0-alpha.0"
|
||||||
},
|
},
|
||||||
"@react-native-community/bob": {
|
"@react-native-community/bob": {
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ export { default as DrawerView } from './views/DrawerView';
|
|||||||
export { default as DrawerItem } from './views/DrawerItem';
|
export { default as DrawerItem } from './views/DrawerItem';
|
||||||
export { default as DrawerItemList } from './views/DrawerItemList';
|
export { default as DrawerItemList } from './views/DrawerItemList';
|
||||||
export { default as DrawerContent } from './views/DrawerContent';
|
export { default as DrawerContent } from './views/DrawerContent';
|
||||||
|
export { default as DrawerContentScrollView } from './views/DrawerContentScrollView';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utilities
|
* Utilities
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import {
|
|||||||
createNavigatorFactory,
|
createNavigatorFactory,
|
||||||
useNavigationBuilder,
|
useNavigationBuilder,
|
||||||
DefaultNavigatorOptions,
|
DefaultNavigatorOptions,
|
||||||
} from '@react-navigation/core';
|
} from '@react-navigation/native';
|
||||||
import {
|
import {
|
||||||
DrawerNavigationState,
|
DrawerNavigationState,
|
||||||
DrawerRouterOptions,
|
DrawerRouterOptions,
|
||||||
@@ -19,10 +19,11 @@ import {
|
|||||||
|
|
||||||
type Props = DefaultNavigatorOptions<DrawerNavigationOptions> &
|
type Props = DefaultNavigatorOptions<DrawerNavigationOptions> &
|
||||||
DrawerRouterOptions &
|
DrawerRouterOptions &
|
||||||
Partial<DrawerNavigationConfig>;
|
DrawerNavigationConfig;
|
||||||
|
|
||||||
function DrawerNavigator({
|
function DrawerNavigator({
|
||||||
initialRouteName,
|
initialRouteName,
|
||||||
|
backBehavior,
|
||||||
children,
|
children,
|
||||||
screenOptions,
|
screenOptions,
|
||||||
...rest
|
...rest
|
||||||
@@ -34,6 +35,7 @@ function DrawerNavigator({
|
|||||||
DrawerNavigationEventMap
|
DrawerNavigationEventMap
|
||||||
>(DrawerRouter, {
|
>(DrawerRouter, {
|
||||||
initialRouteName,
|
initialRouteName,
|
||||||
|
backBehavior,
|
||||||
children,
|
children,
|
||||||
screenOptions,
|
screenOptions,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import {
|
|||||||
NavigationProp,
|
NavigationProp,
|
||||||
Descriptor,
|
Descriptor,
|
||||||
NavigationHelpers,
|
NavigationHelpers,
|
||||||
} from '@react-navigation/core';
|
} from '@react-navigation/native';
|
||||||
import { DrawerNavigationState } from '@react-navigation/routers';
|
import { DrawerNavigationState } from '@react-navigation/routers';
|
||||||
import { PanGestureHandler } from 'react-native-gesture-handler';
|
import { PanGestureHandler } from 'react-native-gesture-handler';
|
||||||
|
|
||||||
@@ -20,14 +20,14 @@ export type DrawerNavigationConfig<T = DrawerContentOptions> = {
|
|||||||
/**
|
/**
|
||||||
* Position of the drawer on the screen. Defaults to `left`.
|
* Position of the drawer on the screen. Defaults to `left`.
|
||||||
*/
|
*/
|
||||||
drawerPosition: 'left' | 'right';
|
drawerPosition?: 'left' | 'right';
|
||||||
/**
|
/**
|
||||||
* Type of the drawer. It determines how the drawer looks and animates.
|
* Type of the drawer. It determines how the drawer looks and animates.
|
||||||
* - `front`: Traditional drawer which covers the screen with a overlay behind it.
|
* - `front`: Traditional drawer which covers the screen with a overlay behind it.
|
||||||
* - `back`: The drawer is revealed behind the screen on swipe.
|
* - `back`: The drawer is revealed behind the screen on swipe.
|
||||||
* - `slide`: Both the screen and the drawer slide on swipe to reveal the drawer.
|
* - `slide`: Both the screen and the drawer slide on swipe to reveal the drawer.
|
||||||
*/
|
*/
|
||||||
drawerType: 'front' | 'back' | 'slide';
|
drawerType?: 'front' | 'back' | 'slide';
|
||||||
/**
|
/**
|
||||||
* How far from the edge of the screen the swipe gesture should activate.
|
* How far from the edge of the screen the swipe gesture should activate.
|
||||||
*/
|
*/
|
||||||
@@ -35,12 +35,12 @@ export type DrawerNavigationConfig<T = DrawerContentOptions> = {
|
|||||||
/**
|
/**
|
||||||
* Whether the statusbar should be hidden when the drawer is pulled or opens,
|
* Whether the statusbar should be hidden when the drawer is pulled or opens,
|
||||||
*/
|
*/
|
||||||
hideStatusBar: boolean;
|
hideStatusBar?: boolean;
|
||||||
/**
|
/**
|
||||||
* Whether the keyboard should be dismissed when the swipe gesture begins.
|
* Whether the keyboard should be dismissed when the swipe gesture begins.
|
||||||
* Defaults to `'on-drag'`. Set to `'none'` to disable keyboard handling.
|
* Defaults to `'on-drag'`. Set to `'none'` to disable keyboard handling.
|
||||||
*/
|
*/
|
||||||
keyboardDismissMode: 'on-drag' | 'none';
|
keyboardDismissMode?: 'on-drag' | 'none';
|
||||||
/**
|
/**
|
||||||
* Minimum swipe distance threshold that should activate opening the drawer.
|
* Minimum swipe distance threshold that should activate opening the drawer.
|
||||||
*/
|
*/
|
||||||
@@ -53,7 +53,7 @@ export type DrawerNavigationConfig<T = DrawerContentOptions> = {
|
|||||||
/**
|
/**
|
||||||
* Animation of the statusbar when hiding it. use in combination with `hideStatusBar`.
|
* Animation of the statusbar when hiding it. use in combination with `hideStatusBar`.
|
||||||
*/
|
*/
|
||||||
statusBarAnimation: 'slide' | 'none' | 'fade';
|
statusBarAnimation?: 'slide' | 'none' | 'fade';
|
||||||
/**
|
/**
|
||||||
* Props to pass to the underlying pan gesture handler.
|
* Props to pass to the underlying pan gesture handler.
|
||||||
*/
|
*/
|
||||||
@@ -62,7 +62,7 @@ export type DrawerNavigationConfig<T = DrawerContentOptions> = {
|
|||||||
* Whether the screens should render the first time they are accessed. Defaults to `true`.
|
* Whether the screens should render the first time they are accessed. Defaults to `true`.
|
||||||
* Set it to `false` if you want to render all screens on initial render.
|
* Set it to `false` if you want to render all screens on initial render.
|
||||||
*/
|
*/
|
||||||
lazy: boolean;
|
lazy?: boolean;
|
||||||
/**
|
/**
|
||||||
* Whether a screen should be unmounted when navigating away from it.
|
* Whether a screen should be unmounted when navigating away from it.
|
||||||
* Defaults to `false`.
|
* Defaults to `false`.
|
||||||
@@ -72,7 +72,7 @@ export type DrawerNavigationConfig<T = DrawerContentOptions> = {
|
|||||||
* Function that returns React element to render as the content of the drawer, for example, navigation items.
|
* Function that returns React element to render as the content of the drawer, for example, navigation items.
|
||||||
* Defaults to `DrawerContent`.
|
* Defaults to `DrawerContent`.
|
||||||
*/
|
*/
|
||||||
drawerContent: (props: DrawerContentComponentProps<T>) => React.ReactNode;
|
drawerContent?: (props: DrawerContentComponentProps<T>) => React.ReactNode;
|
||||||
/**
|
/**
|
||||||
* Options for the content component which will be passed as props.
|
* Options for the content component which will be passed as props.
|
||||||
*/
|
*/
|
||||||
@@ -121,7 +121,7 @@ export type DrawerNavigationOptions = {
|
|||||||
|
|
||||||
export type DrawerContentComponentProps<T = DrawerContentOptions> = T & {
|
export type DrawerContentComponentProps<T = DrawerContentOptions> = T & {
|
||||||
state: DrawerNavigationState;
|
state: DrawerNavigationState;
|
||||||
navigation: NavigationHelpers<ParamListBase>;
|
navigation: DrawerNavigationHelpers;
|
||||||
descriptors: DrawerDescriptorMap;
|
descriptors: DrawerDescriptorMap;
|
||||||
/**
|
/**
|
||||||
* Animated node which represents the current progress of the drawer's open state.
|
* Animated node which represents the current progress of the drawer's open state.
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import {
|
|||||||
StatusBar,
|
StatusBar,
|
||||||
StyleProp,
|
StyleProp,
|
||||||
View,
|
View,
|
||||||
|
InteractionManager,
|
||||||
} from 'react-native';
|
} from 'react-native';
|
||||||
import {
|
import {
|
||||||
PanGestureHandler,
|
PanGestureHandler,
|
||||||
@@ -161,9 +162,24 @@ export default class DrawerView extends React.PureComponent<Props> {
|
|||||||
|
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
this.toggleStatusBar(false);
|
this.toggleStatusBar(false);
|
||||||
|
this.handleEndInteraction();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private handleEndInteraction = () => {
|
||||||
|
if (this.interactionHandle !== undefined) {
|
||||||
|
InteractionManager.clearInteractionHandle(this.interactionHandle);
|
||||||
|
this.interactionHandle = undefined;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
private handleStartInteraction = () => {
|
||||||
|
if (this.interactionHandle === undefined) {
|
||||||
|
this.interactionHandle = InteractionManager.createInteractionHandle();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
private clock = new Clock();
|
private clock = new Clock();
|
||||||
|
private interactionHandle: number | undefined;
|
||||||
|
|
||||||
private isDrawerTypeFront = new Value<Binary>(
|
private isDrawerTypeFront = new Value<Binary>(
|
||||||
this.props.drawerType === 'front' ? TRUE : FALSE
|
this.props.drawerType === 'front' ? TRUE : FALSE
|
||||||
@@ -277,6 +293,7 @@ export default class DrawerView extends React.PureComponent<Props> {
|
|||||||
set(state.velocity, this.velocityX),
|
set(state.velocity, this.velocityX),
|
||||||
set(this.isOpen, isOpen),
|
set(this.isOpen, isOpen),
|
||||||
startClock(this.clock),
|
startClock(this.clock),
|
||||||
|
call([], this.handleStartInteraction),
|
||||||
set(this.manuallyTriggerSpring, FALSE),
|
set(this.manuallyTriggerSpring, FALSE),
|
||||||
]),
|
]),
|
||||||
spring(this.clock, state, { ...SPRING_CONFIG, toValue }),
|
spring(this.clock, state, { ...SPRING_CONFIG, toValue }),
|
||||||
@@ -288,8 +305,9 @@ export default class DrawerView extends React.PureComponent<Props> {
|
|||||||
set(this.offsetX, 0),
|
set(this.offsetX, 0),
|
||||||
// When the animation finishes, stop the clock
|
// When the animation finishes, stop the clock
|
||||||
stopClock(this.clock),
|
stopClock(this.clock),
|
||||||
call([this.isOpen], ([value]: ReadonlyArray<Binary>) => {
|
call([this.isOpen], ([value]: readonly Binary[]) => {
|
||||||
const open = Boolean(value);
|
const open = Boolean(value);
|
||||||
|
this.handleEndInteraction();
|
||||||
|
|
||||||
if (open !== this.props.open) {
|
if (open !== this.props.open) {
|
||||||
// Sync drawer's state after animation finished
|
// Sync drawer's state after animation finished
|
||||||
@@ -304,7 +322,7 @@ export default class DrawerView extends React.PureComponent<Props> {
|
|||||||
private dragX = block([
|
private dragX = block([
|
||||||
onChange(
|
onChange(
|
||||||
this.isOpen,
|
this.isOpen,
|
||||||
call([this.isOpen], ([value]: ReadonlyArray<Binary>) => {
|
call([this.isOpen], ([value]: readonly Binary[]) => {
|
||||||
const open = Boolean(value);
|
const open = Boolean(value);
|
||||||
|
|
||||||
this.currentOpenValue = open;
|
this.currentOpenValue = open;
|
||||||
@@ -344,7 +362,7 @@ export default class DrawerView extends React.PureComponent<Props> {
|
|||||||
// Listen to updates for this value only when it changes
|
// Listen to updates for this value only when it changes
|
||||||
// Without `onChange`, this will fire even if the value didn't change
|
// Without `onChange`, this will fire even if the value didn't change
|
||||||
// We don't want to call the listeners if the value didn't change
|
// We don't want to call the listeners if the value didn't change
|
||||||
call([this.isSwiping], ([value]: ReadonlyArray<Binary>) => {
|
call([this.isSwiping], ([value]: readonly Binary[]) => {
|
||||||
const { keyboardDismissMode } = this.props;
|
const { keyboardDismissMode } = this.props;
|
||||||
|
|
||||||
if (value === TRUE) {
|
if (value === TRUE) {
|
||||||
@@ -358,6 +376,13 @@ export default class DrawerView extends React.PureComponent<Props> {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
),
|
),
|
||||||
|
onChange(
|
||||||
|
this.gestureState,
|
||||||
|
cond(
|
||||||
|
eq(this.gestureState, State.ACTIVE),
|
||||||
|
call([], this.handleStartInteraction)
|
||||||
|
)
|
||||||
|
),
|
||||||
cond(
|
cond(
|
||||||
eq(this.gestureState, State.ACTIVE),
|
eq(this.gestureState, State.ACTIVE),
|
||||||
[
|
[
|
||||||
|
|||||||
@@ -1,36 +1,12 @@
|
|||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import { ScrollView, StyleSheet } from 'react-native';
|
|
||||||
import { useSafeArea } from 'react-native-safe-area-context';
|
|
||||||
import DrawerItemList from './DrawerItemList';
|
import DrawerItemList from './DrawerItemList';
|
||||||
import { DrawerContentComponentProps } from '../types';
|
import { DrawerContentComponentProps } from '../types';
|
||||||
|
import DrawerContentScrollView from './DrawerContentScrollView';
|
||||||
|
|
||||||
export default function DrawerContent({
|
export default function DrawerContent(props: DrawerContentComponentProps) {
|
||||||
contentContainerStyle,
|
|
||||||
style,
|
|
||||||
drawerPosition,
|
|
||||||
...rest
|
|
||||||
}: DrawerContentComponentProps) {
|
|
||||||
const insets = useSafeArea();
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ScrollView
|
<DrawerContentScrollView {...props}>
|
||||||
contentContainerStyle={[
|
<DrawerItemList {...props} />
|
||||||
{
|
</DrawerContentScrollView>
|
||||||
paddingTop: insets.top + 4,
|
|
||||||
paddingLeft: drawerPosition === 'left' ? insets.left : 0,
|
|
||||||
paddingRight: drawerPosition === 'right' ? insets.right : 0,
|
|
||||||
},
|
|
||||||
contentContainerStyle,
|
|
||||||
]}
|
|
||||||
style={[styles.container, style]}
|
|
||||||
>
|
|
||||||
<DrawerItemList {...rest} />
|
|
||||||
</ScrollView>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
|
||||||
container: {
|
|
||||||
flex: 1,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|||||||
41
packages/drawer/src/views/DrawerContentScrollView.tsx
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
import * as React from 'react';
|
||||||
|
import { ScrollView, StyleSheet, ScrollViewProps } from 'react-native';
|
||||||
|
import { useSafeArea } from 'react-native-safe-area-context';
|
||||||
|
|
||||||
|
type Props = ScrollViewProps & {
|
||||||
|
drawerPosition: 'left' | 'right';
|
||||||
|
children: React.ReactNode;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function DrawerContentScrollView({
|
||||||
|
contentContainerStyle,
|
||||||
|
style,
|
||||||
|
drawerPosition,
|
||||||
|
children,
|
||||||
|
...rest
|
||||||
|
}: Props) {
|
||||||
|
const insets = useSafeArea();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ScrollView
|
||||||
|
{...rest}
|
||||||
|
contentContainerStyle={[
|
||||||
|
{
|
||||||
|
paddingTop: insets.top + 4,
|
||||||
|
paddingLeft: drawerPosition === 'left' ? insets.left : 0,
|
||||||
|
paddingRight: drawerPosition === 'right' ? insets.right : 0,
|
||||||
|
},
|
||||||
|
contentContainerStyle,
|
||||||
|
]}
|
||||||
|
style={[styles.container, style]}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</ScrollView>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const styles = StyleSheet.create({
|
||||||
|
container: {
|
||||||
|
flex: 1,
|
||||||
|
},
|
||||||
|
});
|
||||||
@@ -7,6 +7,8 @@ import {
|
|||||||
ViewStyle,
|
ViewStyle,
|
||||||
TextStyle,
|
TextStyle,
|
||||||
} from 'react-native';
|
} from 'react-native';
|
||||||
|
import { useTheme } from '@react-navigation/native';
|
||||||
|
import Color from 'color';
|
||||||
import TouchableItem from './TouchableItem';
|
import TouchableItem from './TouchableItem';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
@@ -61,19 +63,29 @@ type Props = {
|
|||||||
/**
|
/**
|
||||||
* A component used to show an action item with an icon and a label in a navigation drawer.
|
* A component used to show an action item with an icon and a label in a navigation drawer.
|
||||||
*/
|
*/
|
||||||
export default function DrawerItem({
|
export default function DrawerItem(props: Props) {
|
||||||
|
const { colors } = useTheme();
|
||||||
|
|
||||||
|
const {
|
||||||
icon,
|
icon,
|
||||||
label,
|
label,
|
||||||
labelStyle,
|
labelStyle,
|
||||||
focused = false,
|
focused = false,
|
||||||
activeTintColor = '#6200ee',
|
activeTintColor = colors.primary,
|
||||||
inactiveTintColor = 'rgba(0, 0, 0, .68)',
|
inactiveTintColor = Color(colors.text)
|
||||||
activeBackgroundColor = 'rgba(98, 0, 238, 0.12)',
|
.alpha(0.68)
|
||||||
|
.rgb()
|
||||||
|
.string(),
|
||||||
|
activeBackgroundColor = Color(activeTintColor)
|
||||||
|
.alpha(0.12)
|
||||||
|
.rgb()
|
||||||
|
.string(),
|
||||||
inactiveBackgroundColor = 'transparent',
|
inactiveBackgroundColor = 'transparent',
|
||||||
style,
|
style,
|
||||||
onPress,
|
onPress,
|
||||||
...rest
|
...rest
|
||||||
}: Props) {
|
} = props;
|
||||||
|
|
||||||
const { borderRadius = 4 } = StyleSheet.flatten(style || {});
|
const { borderRadius = 4 } = StyleSheet.flatten(style || {});
|
||||||
const color = focused ? activeTintColor : inactiveTintColor;
|
const color = focused ? activeTintColor : inactiveTintColor;
|
||||||
const backgroundColor = focused
|
const backgroundColor = focused
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import { CommonActions } from '@react-navigation/core';
|
import { CommonActions } from '@react-navigation/native';
|
||||||
import {
|
import {
|
||||||
DrawerActions,
|
DrawerActions,
|
||||||
DrawerNavigationState,
|
DrawerNavigationState,
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import {
|
|||||||
DrawerNavigationState,
|
DrawerNavigationState,
|
||||||
DrawerActions,
|
DrawerActions,
|
||||||
} from '@react-navigation/routers';
|
} from '@react-navigation/routers';
|
||||||
|
import { useTheme } from '@react-navigation/native';
|
||||||
|
|
||||||
import DrawerGestureContext from '../utils/DrawerGestureContext';
|
import DrawerGestureContext from '../utils/DrawerGestureContext';
|
||||||
import SafeAreaProviderCompat from './SafeAreaProviderCompat';
|
import SafeAreaProviderCompat from './SafeAreaProviderCompat';
|
||||||
@@ -26,16 +27,10 @@ import {
|
|||||||
DrawerContentComponentProps,
|
DrawerContentComponentProps,
|
||||||
} from '../types';
|
} from '../types';
|
||||||
|
|
||||||
type Props = Omit<DrawerNavigationConfig, 'overlayColor'> & {
|
type Props = DrawerNavigationConfig & {
|
||||||
state: DrawerNavigationState;
|
state: DrawerNavigationState;
|
||||||
navigation: DrawerNavigationHelpers;
|
navigation: DrawerNavigationHelpers;
|
||||||
descriptors: DrawerDescriptorMap;
|
descriptors: DrawerDescriptorMap;
|
||||||
overlayColor: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
type State = {
|
|
||||||
loaded: number[];
|
|
||||||
drawerWidth: number;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const getDefaultDrawerWidth = ({
|
const getDefaultDrawerWidth = ({
|
||||||
@@ -62,49 +57,52 @@ const getDefaultDrawerWidth = ({
|
|||||||
/**
|
/**
|
||||||
* Component that renders the drawer.
|
* Component that renders the drawer.
|
||||||
*/
|
*/
|
||||||
export default class DrawerView extends React.PureComponent<Props, State> {
|
export default function DrawerView({
|
||||||
static defaultProps = {
|
state,
|
||||||
lazy: true,
|
navigation,
|
||||||
drawerContent: (props: DrawerContentComponentProps) => (
|
descriptors,
|
||||||
|
lazy = true,
|
||||||
|
drawerContent = (props: DrawerContentComponentProps) => (
|
||||||
<DrawerContent {...props} />
|
<DrawerContent {...props} />
|
||||||
),
|
),
|
||||||
drawerPosition: I18nManager.isRTL ? 'right' : 'left',
|
drawerPosition = I18nManager.isRTL ? 'right' : 'left',
|
||||||
keyboardDismissMode: 'on-drag',
|
keyboardDismissMode = 'on-drag',
|
||||||
overlayColor: 'rgba(0, 0, 0, 0.5)',
|
overlayColor = 'rgba(0, 0, 0, 0.5)',
|
||||||
drawerType: 'front',
|
drawerType = 'front',
|
||||||
hideStatusBar: false,
|
hideStatusBar = false,
|
||||||
statusBarAnimation: 'slide',
|
statusBarAnimation = 'slide',
|
||||||
|
drawerContentOptions,
|
||||||
|
drawerStyle,
|
||||||
|
edgeWidth,
|
||||||
|
gestureHandlerProps,
|
||||||
|
minSwipeDistance,
|
||||||
|
sceneContainerStyle,
|
||||||
|
unmountInactiveScreens,
|
||||||
|
}: Props) {
|
||||||
|
const [loaded, setLoaded] = React.useState([state.index]);
|
||||||
|
const [drawerWidth, setDrawerWidth] = React.useState(() =>
|
||||||
|
getDefaultDrawerWidth(Dimensions.get('window'))
|
||||||
|
);
|
||||||
|
|
||||||
|
const drawerGestureRef = React.useRef<PanGestureHandler>(null);
|
||||||
|
|
||||||
|
const { colors } = useTheme();
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
const updateWidth = ({ window }: { window: ScaledSize }) => {
|
||||||
|
setDrawerWidth(getDefaultDrawerWidth(window));
|
||||||
};
|
};
|
||||||
|
|
||||||
static getDerivedStateFromProps(nextProps: Props, prevState: State) {
|
Dimensions.addEventListener('change', updateWidth);
|
||||||
const { index } = nextProps.state;
|
|
||||||
|
|
||||||
return {
|
return () => Dimensions.removeEventListener('change', updateWidth);
|
||||||
// Set the current tab to be loaded if it was not loaded before
|
}, []);
|
||||||
loaded: prevState.loaded.includes(index)
|
|
||||||
? prevState.loaded
|
if (!loaded.includes(state.index)) {
|
||||||
: [...prevState.loaded, index],
|
setLoaded([...loaded, state.index]);
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
state: State = {
|
const handleDrawerOpen = () => {
|
||||||
loaded: [this.props.state.index],
|
|
||||||
drawerWidth: getDefaultDrawerWidth(Dimensions.get('window')),
|
|
||||||
};
|
|
||||||
|
|
||||||
componentDidMount() {
|
|
||||||
Dimensions.addEventListener('change', this.updateWidth);
|
|
||||||
}
|
|
||||||
|
|
||||||
componentWillUnmount() {
|
|
||||||
Dimensions.removeEventListener('change', this.updateWidth);
|
|
||||||
}
|
|
||||||
|
|
||||||
private drawerGestureRef = React.createRef<PanGestureHandler>();
|
|
||||||
|
|
||||||
private handleDrawerOpen = () => {
|
|
||||||
const { state, navigation } = this.props;
|
|
||||||
|
|
||||||
navigation.dispatch({
|
navigation.dispatch({
|
||||||
...DrawerActions.openDrawer(),
|
...DrawerActions.openDrawer(),
|
||||||
target: state.key,
|
target: state.key,
|
||||||
@@ -113,9 +111,7 @@ export default class DrawerView extends React.PureComponent<Props, State> {
|
|||||||
navigation.emit({ type: 'drawerOpen' });
|
navigation.emit({ type: 'drawerOpen' });
|
||||||
};
|
};
|
||||||
|
|
||||||
private handleDrawerClose = () => {
|
const handleDrawerClose = () => {
|
||||||
const { state, navigation } = this.props;
|
|
||||||
|
|
||||||
navigation.dispatch({
|
navigation.dispatch({
|
||||||
...DrawerActions.closeDrawer(),
|
...DrawerActions.closeDrawer(),
|
||||||
target: state.key,
|
target: state.key,
|
||||||
@@ -124,24 +120,7 @@ export default class DrawerView extends React.PureComponent<Props, State> {
|
|||||||
navigation.emit({ type: 'drawerClose' });
|
navigation.emit({ type: 'drawerClose' });
|
||||||
};
|
};
|
||||||
|
|
||||||
private updateWidth = ({ window }: { window: ScaledSize }) => {
|
const renderNavigationView = ({ progress }: any) => {
|
||||||
const drawerWidth = getDefaultDrawerWidth(window);
|
|
||||||
|
|
||||||
if (this.state.drawerWidth !== drawerWidth) {
|
|
||||||
this.setState({ drawerWidth });
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private renderNavigationView = ({ progress }: any) => {
|
|
||||||
const {
|
|
||||||
state,
|
|
||||||
navigation,
|
|
||||||
descriptors,
|
|
||||||
drawerPosition,
|
|
||||||
drawerContent,
|
|
||||||
drawerContentOptions,
|
|
||||||
} = this.props;
|
|
||||||
|
|
||||||
return drawerContent({
|
return drawerContent({
|
||||||
...drawerContentOptions,
|
...drawerContentOptions,
|
||||||
progress: progress,
|
progress: progress,
|
||||||
@@ -152,11 +131,7 @@ export default class DrawerView extends React.PureComponent<Props, State> {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
private renderContent = () => {
|
const renderContent = () => {
|
||||||
let { lazy, state, descriptors, unmountInactiveScreens } = this.props;
|
|
||||||
|
|
||||||
const { loaded } = this.state;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ScreenContainer style={styles.content}>
|
<ScreenContainer style={styles.content}>
|
||||||
{state.routes.map((route, index) => {
|
{state.routes.map((route, index) => {
|
||||||
@@ -164,7 +139,7 @@ export default class DrawerView extends React.PureComponent<Props, State> {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lazy && !loaded.includes(index)) {
|
if (lazy && !loaded.includes(index) && index !== state.index) {
|
||||||
// Don't render a screen if we've never navigated to it
|
// Don't render a screen if we've never navigated to it
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -186,58 +161,45 @@ export default class DrawerView extends React.PureComponent<Props, State> {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
private setDrawerGestureRef = (ref: PanGestureHandler | null) => {
|
|
||||||
// @ts-ignore
|
|
||||||
this.drawerGestureRef.current = ref;
|
|
||||||
};
|
|
||||||
|
|
||||||
render() {
|
|
||||||
const {
|
|
||||||
state,
|
|
||||||
descriptors,
|
|
||||||
drawerType,
|
|
||||||
drawerPosition,
|
|
||||||
overlayColor,
|
|
||||||
sceneContainerStyle,
|
|
||||||
drawerStyle,
|
|
||||||
edgeWidth,
|
|
||||||
minSwipeDistance,
|
|
||||||
hideStatusBar,
|
|
||||||
statusBarAnimation,
|
|
||||||
gestureHandlerProps,
|
|
||||||
} = this.props;
|
|
||||||
|
|
||||||
const { drawerWidth } = this.state;
|
|
||||||
|
|
||||||
const activeKey = state.routes[state.index].key;
|
const activeKey = state.routes[state.index].key;
|
||||||
const { gestureEnabled } = descriptors[activeKey].options;
|
const { gestureEnabled } = descriptors[activeKey].options;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SafeAreaProviderCompat>
|
<SafeAreaProviderCompat>
|
||||||
<DrawerGestureContext.Provider value={this.drawerGestureRef}>
|
<DrawerGestureContext.Provider value={drawerGestureRef}>
|
||||||
<Drawer
|
<Drawer
|
||||||
open={state.isDrawerOpen}
|
open={state.isDrawerOpen}
|
||||||
gestureEnabled={gestureEnabled !== false}
|
gestureEnabled={gestureEnabled !== false}
|
||||||
onOpen={this.handleDrawerOpen}
|
onOpen={handleDrawerOpen}
|
||||||
onClose={this.handleDrawerClose}
|
onClose={handleDrawerClose}
|
||||||
onGestureRef={this.setDrawerGestureRef}
|
onGestureRef={ref => {
|
||||||
|
// @ts-ignore
|
||||||
|
drawerGestureRef.current = ref;
|
||||||
|
}}
|
||||||
gestureHandlerProps={gestureHandlerProps}
|
gestureHandlerProps={gestureHandlerProps}
|
||||||
drawerType={drawerType}
|
drawerType={drawerType}
|
||||||
drawerPosition={drawerPosition}
|
drawerPosition={drawerPosition}
|
||||||
sceneContainerStyle={sceneContainerStyle}
|
sceneContainerStyle={[
|
||||||
drawerStyle={[{ width: drawerWidth }, drawerStyle]}
|
{ backgroundColor: colors.background },
|
||||||
|
sceneContainerStyle,
|
||||||
|
]}
|
||||||
|
drawerStyle={[
|
||||||
|
{ width: drawerWidth, backgroundColor: colors.card },
|
||||||
|
drawerStyle,
|
||||||
|
]}
|
||||||
overlayStyle={{ backgroundColor: overlayColor }}
|
overlayStyle={{ backgroundColor: overlayColor }}
|
||||||
swipeEdgeWidth={edgeWidth}
|
swipeEdgeWidth={edgeWidth}
|
||||||
swipeDistanceThreshold={minSwipeDistance}
|
swipeDistanceThreshold={minSwipeDistance}
|
||||||
hideStatusBar={hideStatusBar}
|
hideStatusBar={hideStatusBar}
|
||||||
statusBarAnimation={statusBarAnimation}
|
statusBarAnimation={statusBarAnimation}
|
||||||
renderDrawerContent={this.renderNavigationView}
|
renderDrawerContent={renderNavigationView}
|
||||||
renderSceneContent={this.renderContent}
|
renderSceneContent={renderContent}
|
||||||
|
keyboardDismissMode={keyboardDismissMode}
|
||||||
|
drawerPostion={drawerPosition}
|
||||||
/>
|
/>
|
||||||
</DrawerGestureContext.Provider>
|
</DrawerGestureContext.Provider>
|
||||||
</SafeAreaProviderCompat>
|
</SafeAreaProviderCompat>
|
||||||
);
|
);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ const FAR_FAR_AWAY = 3000; // this should be big enough to move the whole view o
|
|||||||
|
|
||||||
export default class ResourceSavingScene extends React.Component<Props> {
|
export default class ResourceSavingScene extends React.Component<Props> {
|
||||||
render() {
|
render() {
|
||||||
if (screensEnabled && screensEnabled()) {
|
if (screensEnabled?.()) {
|
||||||
const { isVisible, ...rest } = this.props;
|
const { isVisible, ...rest } = this.props;
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
|
|||||||
@@ -3,6 +3,17 @@ import {
|
|||||||
SafeAreaProvider,
|
SafeAreaProvider,
|
||||||
SafeAreaConsumer,
|
SafeAreaConsumer,
|
||||||
} from 'react-native-safe-area-context';
|
} from 'react-native-safe-area-context';
|
||||||
|
import {
|
||||||
|
getStatusBarHeight,
|
||||||
|
getBottomSpace,
|
||||||
|
} from 'react-native-iphone-x-helper';
|
||||||
|
|
||||||
|
const initialSafeAreaInsets = {
|
||||||
|
top: getStatusBarHeight(true),
|
||||||
|
bottom: getBottomSpace(),
|
||||||
|
right: 0,
|
||||||
|
left: 0,
|
||||||
|
};
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
@@ -19,7 +30,11 @@ export default function SafeAreaProviderCompat({ children }: Props) {
|
|||||||
return children;
|
return children;
|
||||||
}
|
}
|
||||||
|
|
||||||
return <SafeAreaProvider>{children}</SafeAreaProvider>;
|
return (
|
||||||
|
<SafeAreaProvider initialSafeAreaInsets={initialSafeAreaInsets}>
|
||||||
|
{children}
|
||||||
|
</SafeAreaProvider>
|
||||||
|
);
|
||||||
}}
|
}}
|
||||||
</SafeAreaConsumer>
|
</SafeAreaConsumer>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -3,6 +3,49 @@
|
|||||||
All notable changes to this project will be documented in this file.
|
All notable changes to this project will be documented in this file.
|
||||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||||
|
|
||||||
|
# [5.0.0-alpha.28](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/material-bottom-tabs@5.0.0-alpha.27...@react-navigation/material-bottom-tabs@5.0.0-alpha.28) (2020-01-01)
|
||||||
|
|
||||||
|
**Note:** Version bump only for package @react-navigation/material-bottom-tabs
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [5.0.0-alpha.27](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/material-bottom-tabs@5.0.0-alpha.26...@react-navigation/material-bottom-tabs@5.0.0-alpha.27) (2019-12-19)
|
||||||
|
|
||||||
|
**Note:** Version bump only for package @react-navigation/material-bottom-tabs
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [5.0.0-alpha.26](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/material-bottom-tabs@5.0.0-alpha.25...@react-navigation/material-bottom-tabs@5.0.0-alpha.26) (2019-12-16)
|
||||||
|
|
||||||
|
**Note:** Version bump only for package @react-navigation/material-bottom-tabs
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [5.0.0-alpha.25](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/material-bottom-tabs@5.0.0-alpha.24...@react-navigation/material-bottom-tabs@5.0.0-alpha.25) (2019-12-14)
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* add custom theme support ([#211](https://github.com/react-navigation/navigation-ex/issues/211)) ([00fc616](https://github.com/react-navigation/navigation-ex/commit/00fc616de0572bade8aa85052cdc8290360b1d7f))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [5.0.0-alpha.24](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/material-bottom-tabs@5.0.0-alpha.23...@react-navigation/material-bottom-tabs@5.0.0-alpha.24) (2019-12-11)
|
||||||
|
|
||||||
|
**Note:** Version bump only for package @react-navigation/material-bottom-tabs
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# [5.0.0-alpha.23](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/material-bottom-tabs@5.0.0-alpha.22...@react-navigation/material-bottom-tabs@5.0.0-alpha.23) (2019-12-10)
|
# [5.0.0-alpha.23](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/material-bottom-tabs@5.0.0-alpha.22...@react-navigation/material-bottom-tabs@5.0.0-alpha.23) (2019-12-10)
|
||||||
|
|
||||||
**Note:** Version bump only for package @react-navigation/material-bottom-tabs
|
**Note:** Version bump only for package @react-navigation/material-bottom-tabs
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ React Navigation integration for [bottom navigation](https://material.io/design/
|
|||||||
Open a Terminal in your project's folder and run,
|
Open a Terminal in your project's folder and run,
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
yarn add @react-navigation/core @react-navigation/material-bottom-tabs
|
yarn add @react-navigation/native @react-navigation/material-bottom-tabs
|
||||||
```
|
```
|
||||||
|
|
||||||
Setup `react-native-paper` following the [Getting Started guide](https://callstack.github.io/react-native-paper/getting-started.html).
|
Setup `react-native-paper` following the [Getting Started guide](https://callstack.github.io/react-native-paper/getting-started.html).
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
"material",
|
"material",
|
||||||
"tab"
|
"tab"
|
||||||
],
|
],
|
||||||
"version": "5.0.0-alpha.23",
|
"version": "5.0.0-alpha.28",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@@ -34,22 +34,22 @@
|
|||||||
"clean": "del lib"
|
"clean": "del lib"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@react-navigation/routers": "^5.0.0-alpha.15"
|
"@react-navigation/routers": "^5.0.0-alpha.19"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@react-native-community/bob": "^0.7.0",
|
"@react-native-community/bob": "^0.7.0",
|
||||||
"@types/react": "^16.9.11",
|
"@types/react": "^16.9.16",
|
||||||
"@types/react-native": "^0.60.22",
|
"@types/react-native": "^0.60.25",
|
||||||
"@types/react-native-vector-icons": "^6.4.4",
|
"@types/react-native-vector-icons": "^6.4.4",
|
||||||
"del-cli": "^3.0.0",
|
"del-cli": "^3.0.0",
|
||||||
"react": "~16.9.0",
|
"react": "~16.9.0",
|
||||||
"react-native": "~0.61.5",
|
"react-native": "~0.61.5",
|
||||||
"react-native-paper": "^3.2.1",
|
"react-native-paper": "^3.3.0",
|
||||||
"react-native-vector-icons": "^6.6.0",
|
"react-native-vector-icons": "^6.6.0",
|
||||||
"typescript": "^3.7.2"
|
"typescript": "^3.7.3"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"@react-navigation/core": "^5.0.0-alpha.0",
|
"@react-navigation/native": "^5.0.0-alpha.0",
|
||||||
"react": "*",
|
"react": "*",
|
||||||
"react-native": "*",
|
"react-native": "*",
|
||||||
"react-native-paper": "^3.0.0",
|
"react-native-paper": "^3.0.0",
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import {
|
|||||||
useNavigationBuilder,
|
useNavigationBuilder,
|
||||||
createNavigatorFactory,
|
createNavigatorFactory,
|
||||||
DefaultNavigatorOptions,
|
DefaultNavigatorOptions,
|
||||||
} from '@react-navigation/core';
|
} from '@react-navigation/native';
|
||||||
import {
|
import {
|
||||||
TabRouter,
|
TabRouter,
|
||||||
TabRouterOptions,
|
TabRouterOptions,
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import {
|
|||||||
Descriptor,
|
Descriptor,
|
||||||
NavigationProp,
|
NavigationProp,
|
||||||
NavigationHelpers,
|
NavigationHelpers,
|
||||||
} from '@react-navigation/core';
|
} from '@react-navigation/native';
|
||||||
import { TabNavigationState } from '@react-navigation/routers';
|
import { TabNavigationState } from '@react-navigation/routers';
|
||||||
|
|
||||||
export type MaterialBottomTabNavigationEventMap = {
|
export type MaterialBottomTabNavigationEventMap = {
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import { StyleSheet } from 'react-native';
|
import { StyleSheet } from 'react-native';
|
||||||
import { BottomNavigation } from 'react-native-paper';
|
import { BottomNavigation, DefaultTheme, DarkTheme } from 'react-native-paper';
|
||||||
import MaterialCommunityIcons from 'react-native-vector-icons/MaterialCommunityIcons';
|
import MaterialCommunityIcons from 'react-native-vector-icons/MaterialCommunityIcons';
|
||||||
import { Route } from '@react-navigation/core';
|
import { Route, useTheme } from '@react-navigation/native';
|
||||||
import { TabNavigationState, TabActions } from '@react-navigation/routers';
|
import { TabNavigationState, TabActions } from '@react-navigation/routers';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@@ -25,9 +25,25 @@ export default function MaterialBottomTabView({
|
|||||||
descriptors,
|
descriptors,
|
||||||
...rest
|
...rest
|
||||||
}: Props) {
|
}: Props) {
|
||||||
|
const { dark, colors } = useTheme();
|
||||||
|
|
||||||
|
const theme = React.useMemo(() => {
|
||||||
|
const t = dark ? DarkTheme : DefaultTheme;
|
||||||
|
|
||||||
|
return {
|
||||||
|
...t,
|
||||||
|
colors: {
|
||||||
|
...t.colors,
|
||||||
|
...colors,
|
||||||
|
surface: colors.card,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}, [colors, dark]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<BottomNavigation
|
<BottomNavigation
|
||||||
{...rest}
|
{...rest}
|
||||||
|
theme={theme}
|
||||||
navigationState={state}
|
navigationState={state}
|
||||||
onIndexChange={(index: number) =>
|
onIndexChange={(index: number) =>
|
||||||
navigation.dispatch({
|
navigation.dispatch({
|
||||||
|
|||||||
@@ -3,6 +3,52 @@
|
|||||||
All notable changes to this project will be documented in this file.
|
All notable changes to this project will be documented in this file.
|
||||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||||
|
|
||||||
|
# [5.0.0-alpha.26](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/material-top-tabs@5.0.0-alpha.25...@react-navigation/material-top-tabs@5.0.0-alpha.26) (2020-01-01)
|
||||||
|
|
||||||
|
**Note:** Version bump only for package @react-navigation/material-top-tabs
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [5.0.0-alpha.25](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/material-top-tabs@5.0.0-alpha.24...@react-navigation/material-top-tabs@5.0.0-alpha.25) (2019-12-19)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* fix backgroundColor in sceneContainerStyle overriden by theme ([ebd145a](https://github.com/react-navigation/navigation-ex/commit/ebd145a09d80f119070a14a8d4940b5757b5e7fb)), closes [#215](https://github.com/react-navigation/navigation-ex/issues/215)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [5.0.0-alpha.24](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/material-top-tabs@5.0.0-alpha.23...@react-navigation/material-top-tabs@5.0.0-alpha.24) (2019-12-16)
|
||||||
|
|
||||||
|
**Note:** Version bump only for package @react-navigation/material-top-tabs
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [5.0.0-alpha.23](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/material-top-tabs@5.0.0-alpha.22...@react-navigation/material-top-tabs@5.0.0-alpha.23) (2019-12-14)
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* add custom theme support ([#211](https://github.com/react-navigation/navigation-ex/issues/211)) ([00fc616](https://github.com/react-navigation/navigation-ex/commit/00fc616de0572bade8aa85052cdc8290360b1d7f))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [5.0.0-alpha.22](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/material-top-tabs@5.0.0-alpha.21...@react-navigation/material-top-tabs@5.0.0-alpha.22) (2019-12-11)
|
||||||
|
|
||||||
|
**Note:** Version bump only for package @react-navigation/material-top-tabs
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# [5.0.0-alpha.21](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/material-top-tabs@5.0.0-alpha.20...@react-navigation/material-top-tabs@5.0.0-alpha.21) (2019-12-10)
|
# [5.0.0-alpha.21](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/material-top-tabs@5.0.0-alpha.20...@react-navigation/material-top-tabs@5.0.0-alpha.21) (2019-12-10)
|
||||||
|
|
||||||
**Note:** Version bump only for package @react-navigation/material-top-tabs
|
**Note:** Version bump only for package @react-navigation/material-top-tabs
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ React Navigation integration for animated tab view component from [`react-native
|
|||||||
Open a Terminal in your project's folder and run,
|
Open a Terminal in your project's folder and run,
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
yarn add @react-navigation/core @react-navigation/material-top-tabs react-native-tab-view
|
yarn add @react-navigation/native @react-navigation/material-top-tabs react-native-tab-view
|
||||||
```
|
```
|
||||||
|
|
||||||
Now we need to install [`react-native-gesture-handler`](https://github.com/kmagiera/react-native-gesture-handler) and [`react-native-reanimated`](https://github.com/kmagiera/react-native-reanimated)..
|
Now we need to install [`react-native-gesture-handler`](https://github.com/kmagiera/react-native-gesture-handler) and [`react-native-reanimated`](https://github.com/kmagiera/react-native-reanimated)..
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
"material",
|
"material",
|
||||||
"tab"
|
"tab"
|
||||||
],
|
],
|
||||||
"version": "5.0.0-alpha.21",
|
"version": "5.0.0-alpha.26",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@@ -34,22 +34,23 @@
|
|||||||
"clean": "del lib"
|
"clean": "del lib"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@react-navigation/routers": "^5.0.0-alpha.15"
|
"@react-navigation/routers": "^5.0.0-alpha.19",
|
||||||
|
"color": "^3.1.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@react-native-community/bob": "^0.7.0",
|
"@react-native-community/bob": "^0.7.0",
|
||||||
"@types/react": "^16.9.11",
|
"@types/react": "^16.9.16",
|
||||||
"@types/react-native": "^0.60.22",
|
"@types/react-native": "^0.60.25",
|
||||||
"del-cli": "^3.0.0",
|
"del-cli": "^3.0.0",
|
||||||
"react": "~16.9.0",
|
"react": "~16.9.0",
|
||||||
"react-native": "~0.61.5",
|
"react-native": "~0.61.5",
|
||||||
"react-native-gesture-handler": "^1.5.0",
|
"react-native-gesture-handler": "^1.5.0",
|
||||||
"react-native-reanimated": "^1.4.0",
|
"react-native-reanimated": "^1.4.0",
|
||||||
"react-native-tab-view": "^2.11.0",
|
"react-native-tab-view": "^2.11.0",
|
||||||
"typescript": "^3.7.2"
|
"typescript": "^3.7.3"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"@react-navigation/core": "^5.0.0-alpha.0",
|
"@react-navigation/native": "^5.0.0-alpha.0",
|
||||||
"react": "*",
|
"react": "*",
|
||||||
"react-native": "*",
|
"react-native": "*",
|
||||||
"react-native-gesture-handler": "^1.0.0",
|
"react-native-gesture-handler": "^1.0.0",
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import {
|
|||||||
useNavigationBuilder,
|
useNavigationBuilder,
|
||||||
createNavigatorFactory,
|
createNavigatorFactory,
|
||||||
DefaultNavigatorOptions,
|
DefaultNavigatorOptions,
|
||||||
} from '@react-navigation/core';
|
} from '@react-navigation/native';
|
||||||
import {
|
import {
|
||||||
TabRouter,
|
TabRouter,
|
||||||
TabRouterOptions,
|
TabRouterOptions,
|
||||||
|
|||||||