mirror of
https://github.com/zhigang1992/react-navigation.git
synced 2026-04-30 13:22:13 +08:00
feat: upgrade project and add example
BREAKING CHANGE: Migrate to React Navigation 4.x
This commit is contained in:
@@ -1,22 +1,3 @@
|
|||||||
{
|
{
|
||||||
"extends": "eslint-config-satya164",
|
"extends": "eslint-config-satya164"
|
||||||
|
|
||||||
"plugins": ["react-native-globals"],
|
|
||||||
|
|
||||||
"settings": {
|
|
||||||
"react": {
|
|
||||||
"version": "detect"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
"env": {
|
|
||||||
"es6": true,
|
|
||||||
"react-native-globals/all": true
|
|
||||||
},
|
|
||||||
|
|
||||||
"rules": {
|
|
||||||
"import/no-unresolved": "off",
|
|
||||||
"react/sort-comp": "off",
|
|
||||||
"jest/no-disabled-tests": "off"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
/* eslint-disable import/no-commonjs */
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
extends: ['@commitlint/config-conventional'],
|
extends: ['@commitlint/config-conventional'],
|
||||||
};
|
};
|
||||||
|
|||||||
BIN
packages/animated-switch/example/.DS_Store
vendored
Normal file
BIN
packages/animated-switch/example/.DS_Store
vendored
Normal file
Binary file not shown.
7
packages/animated-switch/example/.eslintrc
Normal file
7
packages/animated-switch/example/.eslintrc
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"extends": "../.eslintrc",
|
||||||
|
|
||||||
|
"settings": {
|
||||||
|
"import/core-modules": [ "react-navigation-animated-switch" ]
|
||||||
|
}
|
||||||
|
}
|
||||||
3
packages/animated-switch/example/.gitignore
vendored
Normal file
3
packages/animated-switch/example/.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# XDE
|
||||||
|
#
|
||||||
|
.expo/
|
||||||
1
packages/animated-switch/example/App.js
Normal file
1
packages/animated-switch/example/App.js
Normal file
@@ -0,0 +1 @@
|
|||||||
|
export { default } from './src/index.tsx';
|
||||||
27
packages/animated-switch/example/app.json
Normal file
27
packages/animated-switch/example/app.json
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
{
|
||||||
|
"expo": {
|
||||||
|
"name": "React Navigation Animated Switch Example",
|
||||||
|
"description": "Demonstrates the various capabilities of react-navigation-animated-switch",
|
||||||
|
"slug": "react-navigation-animated-switch-drawer-demo",
|
||||||
|
"privacy": "public",
|
||||||
|
"sdkVersion": "36.0.0",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"orientation": "default",
|
||||||
|
"primaryColor": "#cccccc",
|
||||||
|
"notification": {
|
||||||
|
"icon": "https://s3.amazonaws.com/exp-us-standard/placeholder-push-icon-blue-circle.png",
|
||||||
|
"color": "#000000"
|
||||||
|
},
|
||||||
|
"packagerOpts": {
|
||||||
|
"assetExts": [
|
||||||
|
"ttf"
|
||||||
|
],
|
||||||
|
"config": "./metro.config.js",
|
||||||
|
"projectRoots": ""
|
||||||
|
},
|
||||||
|
"platforms": [
|
||||||
|
"android",
|
||||||
|
"ios"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
13
packages/animated-switch/example/babel.config.js
Normal file
13
packages/animated-switch/example/babel.config.js
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
module.exports = {
|
||||||
|
presets: ['expo'],
|
||||||
|
plugins: [
|
||||||
|
[
|
||||||
|
'module-resolver',
|
||||||
|
{
|
||||||
|
alias: {
|
||||||
|
'react-navigation-animated-switch': '../src/index',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
],
|
||||||
|
};
|
||||||
46
packages/animated-switch/example/metro.config.js
Normal file
46
packages/animated-switch/example/metro.config.js
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
// /* eslint-disable import/no-commonjs */
|
||||||
|
|
||||||
|
const path = require('path');
|
||||||
|
const fs = require('fs');
|
||||||
|
// eslint-disable-next-line import/no-extraneous-dependencies
|
||||||
|
const blacklist = require('metro-config/src/defaults/blacklist');
|
||||||
|
const escape = require('escape-string-regexp');
|
||||||
|
|
||||||
|
const root = path.resolve(__dirname, '..');
|
||||||
|
const pak = JSON.parse(
|
||||||
|
fs.readFileSync(path.join(root, 'package.json'), 'utf8')
|
||||||
|
);
|
||||||
|
|
||||||
|
const modules = [
|
||||||
|
'@babel/runtime',
|
||||||
|
'@expo/vector-icons',
|
||||||
|
...Object.keys({
|
||||||
|
...pak.dependencies,
|
||||||
|
...pak.peerDependencies,
|
||||||
|
}),
|
||||||
|
];
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
projectRoot: __dirname,
|
||||||
|
watchFolders: [root],
|
||||||
|
|
||||||
|
resolver: {
|
||||||
|
blacklistRE: blacklist([
|
||||||
|
new RegExp(`^${escape(path.join(root, 'node_modules'))}\\/.*$`),
|
||||||
|
]),
|
||||||
|
|
||||||
|
extraNodeModules: modules.reduce((acc, name) => {
|
||||||
|
acc[name] = path.join(__dirname, 'node_modules', name);
|
||||||
|
return acc;
|
||||||
|
}, {}),
|
||||||
|
},
|
||||||
|
|
||||||
|
transformer: {
|
||||||
|
getTransformOptions: async () => ({
|
||||||
|
transform: {
|
||||||
|
experimentalImportSupport: false,
|
||||||
|
inlineRequires: true,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
};
|
||||||
31
packages/animated-switch/example/package.json
Normal file
31
packages/animated-switch/example/package.json
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
{
|
||||||
|
"name": "reanimated-switch-example",
|
||||||
|
"version": "0.0.1",
|
||||||
|
"description": "Example for Reanimated Switch Navigator",
|
||||||
|
"author": "",
|
||||||
|
"private": true,
|
||||||
|
"scripts": {
|
||||||
|
"start": "expo start",
|
||||||
|
"android": "expo android",
|
||||||
|
"ios": "expo ios"
|
||||||
|
},
|
||||||
|
"main": "node_modules/expo/AppEntry.js",
|
||||||
|
"dependencies": {
|
||||||
|
"expo": "^36.0.0",
|
||||||
|
"expo-keep-awake": "~8.0.0",
|
||||||
|
"react": "16.9.0",
|
||||||
|
"react-native": "https://github.com/expo/react-native/archive/sdk-36.0.0.tar.gz",
|
||||||
|
"react-native-gesture-handler": "~1.5.0",
|
||||||
|
"react-native-reanimated": "~1.4.0",
|
||||||
|
"react-navigation": "^4.0.10"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"babel-plugin-module-resolver": "^4.0.0",
|
||||||
|
"babel-preset-expo": "^8.0.0",
|
||||||
|
"escape-string-regexp": "^2.0.0",
|
||||||
|
"expo-cli": "^3.11.1"
|
||||||
|
},
|
||||||
|
"resolutions": {
|
||||||
|
"**/react": "16.9.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
61
packages/animated-switch/example/src/index.tsx
Normal file
61
packages/animated-switch/example/src/index.tsx
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
import * as React from 'react';
|
||||||
|
import { Text, View, Button, StyleSheet } from 'react-native';
|
||||||
|
import { createAppContainer } from 'react-navigation';
|
||||||
|
import createAnimatedSwitchNavigator, {
|
||||||
|
NavigationAnimatedSwitchProp,
|
||||||
|
} from 'react-navigation-animated-switch';
|
||||||
|
import { Transition } from 'react-native-reanimated';
|
||||||
|
|
||||||
|
function Home({ navigation }: { navigation: NavigationAnimatedSwitchProp }) {
|
||||||
|
return (
|
||||||
|
<View style={styles.content}>
|
||||||
|
<Text>Home screen</Text>
|
||||||
|
<Button
|
||||||
|
title="Go to settings"
|
||||||
|
onPress={() => navigation.navigate('Settings')}
|
||||||
|
/>
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function Settings({
|
||||||
|
navigation,
|
||||||
|
}: {
|
||||||
|
navigation: NavigationAnimatedSwitchProp;
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<View style={styles.content}>
|
||||||
|
<Text>Settings screen</Text>
|
||||||
|
<Button title="Go to home" onPress={() => navigation.navigate('Home')} />
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const MySwitch = createAnimatedSwitchNavigator(
|
||||||
|
{
|
||||||
|
Home,
|
||||||
|
Settings,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
transition: (
|
||||||
|
<Transition.Together>
|
||||||
|
<Transition.Out
|
||||||
|
type="slide-bottom"
|
||||||
|
durationMs={400}
|
||||||
|
interpolation="easeIn"
|
||||||
|
/>
|
||||||
|
<Transition.In type="fade" durationMs={500} />
|
||||||
|
</Transition.Together>
|
||||||
|
),
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
const styles = StyleSheet.create({
|
||||||
|
content: {
|
||||||
|
flex: 1,
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export default createAppContainer(MySwitch);
|
||||||
13066
packages/animated-switch/example/yarn.lock
Normal file
13066
packages/animated-switch/example/yarn.lock
Normal file
File diff suppressed because it is too large
Load Diff
@@ -16,34 +16,36 @@
|
|||||||
"lint": "eslint --ext .js,.ts,.tsx .",
|
"lint": "eslint --ext .js,.ts,.tsx .",
|
||||||
"prepare": "bob build",
|
"prepare": "bob build",
|
||||||
"release": "release-it",
|
"release": "release-it",
|
||||||
"typescript": "tsc --noEmit"
|
"typescript": "tsc --noEmit",
|
||||||
|
"example": "yarn --cwd example",
|
||||||
|
"bootstrap": "yarn example && yarn"
|
||||||
|
},
|
||||||
|
"publishConfig": {
|
||||||
|
"registry": "https://registry.npmjs.org/"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@commitlint/config-conventional": "8.1.0",
|
"@commitlint/config-conventional": "8.2.0",
|
||||||
"@react-native-community/bob": "0.6.1",
|
"@react-native-community/bob": "0.7.0",
|
||||||
"@react-navigation/core": "3.4.2",
|
|
||||||
"@release-it/conventional-changelog": "1.1.0",
|
"@release-it/conventional-changelog": "1.1.0",
|
||||||
"@types/react": "16.8.24",
|
"@types/react": "16.9.16",
|
||||||
"@types/react-native": "0.60.3",
|
"@types/react-native": "0.60.25",
|
||||||
"commitlint": "8.1.0",
|
"commitlint": "8.2.0",
|
||||||
"eslint": "6.1.0",
|
"eslint": "^6.7.2",
|
||||||
"eslint-config-satya164": "2.4.1",
|
"eslint-config-satya164": "^3.1.2",
|
||||||
"eslint-plugin-react-native-globals": "0.1.2",
|
"husky": "3.1.0",
|
||||||
"husky": "3.0.2",
|
"prettier": "^1.19.1",
|
||||||
"prettier": "1.18.2",
|
"react": "~16.9.0",
|
||||||
"react": "16.8.6",
|
"react-native": "~0.61.5",
|
||||||
"react-native": "0.60.4",
|
"react-native-reanimated": "~1.4.0",
|
||||||
"react-native-reanimated": "1.1.0",
|
"react-navigation": "^4.0.10",
|
||||||
"react-navigation": "3.11.1",
|
"release-it": "12.4.3",
|
||||||
"release-it": "12.3.5",
|
"typescript": "3.7.3"
|
||||||
"typescript": "3.5.3"
|
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"@react-navigation/core": "^3.0.0",
|
"react-navigation": "^4.0.0",
|
||||||
"react": "*",
|
"react": "*",
|
||||||
"react-native": "*",
|
"react-native": "*",
|
||||||
"react-native-reanimated": "^1.0.0",
|
"react-native-reanimated": "^1.0.0"
|
||||||
"react-navigation": "^3.0.0"
|
|
||||||
},
|
},
|
||||||
"prettier": {
|
"prettier": {
|
||||||
"trailingComma": "es5",
|
"trailingComma": "es5",
|
||||||
|
|||||||
@@ -1,19 +1,22 @@
|
|||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import { StyleSheet, ViewStyle } from 'react-native';
|
import { StyleSheet, ViewStyle } from 'react-native';
|
||||||
import {
|
|
||||||
NavigationProp,
|
|
||||||
NavigationDescriptor,
|
|
||||||
NavigationState,
|
|
||||||
NavigationRouteConfigMap,
|
|
||||||
ScreenProps,
|
|
||||||
NavigationContainer,
|
|
||||||
SwitchNavigatorConfig,
|
|
||||||
} from 'react-navigation';
|
|
||||||
import {
|
import {
|
||||||
createNavigator,
|
createNavigator,
|
||||||
|
CreateNavigatorConfig,
|
||||||
|
NavigationDescriptor,
|
||||||
|
NavigationParams,
|
||||||
|
NavigationProp,
|
||||||
|
NavigationRoute,
|
||||||
|
NavigationRouteConfigMap,
|
||||||
|
NavigationScreenProp,
|
||||||
|
NavigationState,
|
||||||
|
NavigationSwitchProp,
|
||||||
|
NavigationSwitchRouterConfig,
|
||||||
SceneView,
|
SceneView,
|
||||||
SwitchRouter,
|
SwitchRouter,
|
||||||
} from '@react-navigation/core';
|
SupportedThemes,
|
||||||
|
NavigationScreenConfig,
|
||||||
|
} from 'react-navigation';
|
||||||
import {
|
import {
|
||||||
TransitioningView,
|
TransitioningView,
|
||||||
Transitioning,
|
Transitioning,
|
||||||
@@ -27,19 +30,20 @@ const DEFAULT_TRANSITION = (
|
|||||||
</Transition.Together>
|
</Transition.Together>
|
||||||
);
|
);
|
||||||
|
|
||||||
interface Props {
|
type Props = {
|
||||||
navigationConfig: {
|
navigationConfig: NavigationAnimatedSwitchConfig;
|
||||||
transition?: React.ReactNode;
|
|
||||||
transitionViewStyle?: ViewStyle;
|
|
||||||
};
|
|
||||||
navigation: NavigationProp<NavigationState>;
|
navigation: NavigationProp<NavigationState>;
|
||||||
descriptors: { [key: string]: NavigationDescriptor };
|
descriptors: {
|
||||||
screenProps?: ScreenProps;
|
[key: string]: NavigationDescriptor<
|
||||||
}
|
NavigationParams,
|
||||||
|
NavigationAnimatedSwitchOptions,
|
||||||
class AnimatedSwitchView extends React.Component<Props, {}> {
|
NavigationSwitchProp<NavigationRoute, any>
|
||||||
containerRef = React.createRef<TransitioningView>();
|
>;
|
||||||
|
};
|
||||||
|
screenProps?: unknown;
|
||||||
|
};
|
||||||
|
|
||||||
|
class AnimatedSwitchView extends React.Component<Props> {
|
||||||
componentDidUpdate(prevProps: Props) {
|
componentDidUpdate(prevProps: Props) {
|
||||||
const { state: prevState } = prevProps.navigation;
|
const { state: prevState } = prevProps.navigation;
|
||||||
const prevActiveKey = prevState.routes[prevState.index].key;
|
const prevActiveKey = prevState.routes[prevState.index].key;
|
||||||
@@ -51,8 +55,10 @@ class AnimatedSwitchView extends React.Component<Props, {}> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private containerRef = React.createRef<TransitioningView>();
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { navigationConfig } = this.props;
|
const { navigationConfig, screenProps } = this.props;
|
||||||
const { state } = this.props.navigation;
|
const { state } = this.props.navigation;
|
||||||
const activeKey = state.routes[state.index].key;
|
const activeKey = state.routes[state.index].key;
|
||||||
const descriptor = this.props.descriptors[activeKey];
|
const descriptor = this.props.descriptors[activeKey];
|
||||||
@@ -72,25 +78,62 @@ class AnimatedSwitchView extends React.Component<Props, {}> {
|
|||||||
<SceneView
|
<SceneView
|
||||||
component={ChildComponent}
|
component={ChildComponent}
|
||||||
navigation={descriptor.navigation}
|
navigation={descriptor.navigation}
|
||||||
screenProps={this.props.screenProps}
|
screenProps={screenProps}
|
||||||
/>
|
/>
|
||||||
</Transitioning.View>
|
</Transitioning.View>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface AnimatedSwitchNavigatorConfig extends SwitchNavigatorConfig {
|
export type NavigationAnimatedSwitchConfig = NavigationSwitchRouterConfig & {
|
||||||
transition?: React.ReactNode;
|
transition?: React.ReactNode;
|
||||||
transitionViewStyle?: ViewStyle;
|
transitionViewStyle?: ViewStyle;
|
||||||
}
|
};
|
||||||
|
|
||||||
|
export type NavigationAnimatedSwitchOptions = {};
|
||||||
|
|
||||||
|
export type NavigationAnimatedSwitchProp<
|
||||||
|
State = NavigationRoute,
|
||||||
|
Params = NavigationParams
|
||||||
|
> = NavigationScreenProp<State, Params> & {
|
||||||
|
jumpTo: (routeName: string, key?: string) => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type NavigationAnimatedSwitchScreenProps<
|
||||||
|
Params = NavigationParams,
|
||||||
|
ScreenProps = unknown
|
||||||
|
> = {
|
||||||
|
theme: SupportedThemes;
|
||||||
|
navigation: NavigationAnimatedSwitchProp<NavigationRoute, Params>;
|
||||||
|
screenProps: ScreenProps;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type NavigationAnimatedSwitchScreenComponent<
|
||||||
|
Params = NavigationParams,
|
||||||
|
ScreenProps = unknown
|
||||||
|
> = React.ComponentType<
|
||||||
|
NavigationAnimatedSwitchScreenProps<Params, ScreenProps>
|
||||||
|
> & {
|
||||||
|
navigationOptions?: NavigationScreenConfig<
|
||||||
|
NavigationAnimatedSwitchOptions,
|
||||||
|
NavigationAnimatedSwitchProp<NavigationRoute, Params>,
|
||||||
|
ScreenProps
|
||||||
|
>;
|
||||||
|
};
|
||||||
|
|
||||||
export default function createAnimatedSwitchNavigator(
|
export default function createAnimatedSwitchNavigator(
|
||||||
routeConfigMap: NavigationRouteConfigMap,
|
routeConfigMap: NavigationRouteConfigMap<{}, NavigationAnimatedSwitchProp>,
|
||||||
switchConfig: SwitchNavigatorConfig & {
|
switchConfig: CreateNavigatorConfig<
|
||||||
transition?: React.ReactNode;
|
NavigationAnimatedSwitchConfig,
|
||||||
}
|
NavigationSwitchRouterConfig,
|
||||||
): NavigationContainer {
|
NavigationAnimatedSwitchOptions,
|
||||||
|
NavigationAnimatedSwitchProp<NavigationRoute, any>
|
||||||
|
> = {}
|
||||||
|
) {
|
||||||
const router = SwitchRouter(routeConfigMap, switchConfig);
|
const router = SwitchRouter(routeConfigMap, switchConfig);
|
||||||
|
|
||||||
|
// TODO: don't have time to fix it right now
|
||||||
|
// @ts-ignore
|
||||||
const Navigator = createNavigator(AnimatedSwitchView, router, switchConfig);
|
const Navigator = createNavigator(AnimatedSwitchView, router, switchConfig);
|
||||||
|
|
||||||
return Navigator;
|
return Navigator;
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
{
|
{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
|
"baseUrl": ".",
|
||||||
|
"paths": {
|
||||||
|
"react-navigation-animated-switch": ["./src/index"]
|
||||||
|
},
|
||||||
"allowUnreachableCode": false,
|
"allowUnreachableCode": false,
|
||||||
"allowUnusedLabels": false,
|
"allowUnusedLabels": false,
|
||||||
"alwaysStrict": true,
|
"alwaysStrict": true,
|
||||||
@@ -20,8 +24,7 @@
|
|||||||
"resolveJsonModule": true,
|
"resolveJsonModule": true,
|
||||||
"skipLibCheck": true,
|
"skipLibCheck": true,
|
||||||
"strict": true,
|
"strict": true,
|
||||||
"target": "esnext",
|
"target": "esnext"
|
||||||
"plugins": [{ "name": "typescript-tslint-plugin" }]
|
|
||||||
},
|
},
|
||||||
"typeAcquisition": {
|
"typeAcquisition": {
|
||||||
"enable": true,
|
"enable": true,
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user