Skip to content
This repository was archived by the owner on Feb 25, 2020. It is now read-only.

Commit cd5032c

Browse files
committed
chore: reuse the stack code from react navigation 5
The code for the stack is almost the same as v5, with the only differences being the types and the navigation object. To avoid making same changes in 2 places which error-prone, I decided to reuse the same code. Due to the differences, it's not possible to just use it as a dependency, so I followed this approach: - Copy the source files on post install and apply patches to make it work with React Navigation 4 - When we need to make changes, we can make them in v5 repo and update the version here, most of the time it wouldn't need any extra work - If we need to make v4 specific changes, we can change the code in vendor/ and then re-generate the patch with `yarn patch`
1 parent 1bd09d7 commit cd5032c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+4112
-6753
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
node_modules/
22
coverage/
33
lib/
4+
vendor/

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ android/keystores/debug.keystore
5151
# Build
5252
dist/
5353
generated/
54+
vendor/
5455

5556
# generated by bob
5657
lib/

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ While developing, you can run the example app with [Expo](https://expo.io/) to t
4747
yarn example start
4848
```
4949

50+
The code in this repo uses the source from [`@react-navigation/stack`](https://github.com/react-navigation/navigation-ex/tree/master/packages/stack) and patches it to make it usable in React Navigation 4. If you need to make changes, please send a pull request there.
51+
52+
If the change is specifically related to React Navigation 4 integration, change the files in `src/vendor` and then run `yarn patch` to update the patch file with the latest changes.
53+
5054
Make sure your code passes TypeScript and ESLint. Run the following to verify:
5155

5256
```sh

example/app.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,18 @@
33
"name": "React Navigation Stack Example",
44
"description": "Demonstrates the various capabilities of react-navigation-stack",
55
"slug": "react-navigation-stack-demo",
6-
"sdkVersion": "35.0.0",
6+
"sdkVersion": "36.0.0",
77
"version": "1.0.0",
88
"primaryColor": "#2196f3",
99
"packagerOpts": {
1010
"config": "./metro.config.js",
1111
"projectRoots": ""
1212
},
13-
"entryPoint": "node_modules/expo/AppEntry.js"
13+
"entryPoint": "node_modules/expo/AppEntry.js",
14+
"platforms": [
15+
"android",
16+
"ios"
17+
]
1418
},
1519
"displayName": "React Navigation Stack Example",
1620
"name": "StackExample"

example/metro.config.js

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,43 @@
11
/* eslint-disable import/no-extraneous-dependencies */
22

33
const path = require('path');
4-
const blacklist = require('metro-config/src/defaults/blacklist');
5-
const project = require('../package.json');
4+
const fs = require('fs');
65
const escape = require('escape-string-regexp');
6+
const blacklist = require('metro-config/src/defaults/blacklist');
7+
8+
const root = path.resolve(__dirname, '..');
9+
const pak = JSON.parse(
10+
fs.readFileSync(path.join(root, 'package.json'), 'utf8')
11+
);
712

8-
const projectDependencies = Object.keys({
9-
...project.dependencies,
10-
...project.peerDependencies,
11-
});
13+
const modules = [
14+
'@babel/runtime',
15+
'@expo/vector-icons',
16+
...Object.keys(pak.dependencies || {}),
17+
...Object.keys(pak.peerDependencies || {}),
18+
];
1219

1320
module.exports = {
1421
projectRoot: __dirname,
15-
watchFolders: [path.resolve(__dirname, '..')],
22+
watchFolders: [root],
1623

1724
resolver: {
1825
blacklistRE: blacklist([
19-
new RegExp(
20-
`^${escape(
21-
path.resolve(__dirname, 'node_modules', project.name)
22-
)}\\/.*$`
23-
),
24-
new RegExp(
25-
`^${escape(path.resolve(__dirname, '..', 'node_modules'))}\\/.*$`
26-
),
26+
new RegExp(`^${escape(path.join(root, 'node_modules'))}\\/.*$`),
2727
]),
2828

29-
providesModuleNodeModules: [
30-
'@expo/vector-icons',
31-
'react-native-safe-area-context',
32-
'@babel/runtime',
33-
'react-navigation',
34-
...projectDependencies,
35-
],
29+
extraNodeModules: modules.reduce((acc, name) => {
30+
acc[name] = path.join(__dirname, 'node_modules', name);
31+
return acc;
32+
}, {}),
33+
},
34+
35+
transformer: {
36+
getTransformOptions: async () => ({
37+
transform: {
38+
experimentalImportSupport: false,
39+
inlineRequires: true,
40+
},
41+
}),
3642
},
3743
};

example/package.json

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,23 @@
99
"ios": "react-native run-ios"
1010
},
1111
"dependencies": {
12-
"@react-native-community/masked-view": "^0.1.1",
13-
"expo": "^35.0.0",
14-
"expo-asset": "~7.0.0",
15-
"expo-barcode-scanner": "~7.0.0",
16-
"expo-constants": "~7.0.0",
12+
"@react-native-community/masked-view": "0.1.5",
13+
"expo": "^36.0.0",
14+
"expo-asset": "~8.0.0",
15+
"expo-barcode-scanner": "~8.0.0",
16+
"expo-constants": "~8.0.0",
1717
"hoist-non-react-statics": "^3.3.0",
18-
"react": "~16.8.3",
19-
"react-dom": "~16.8.3",
20-
"react-native": "~0.59.10",
21-
"react-native-gesture-handler": "~1.3.0",
22-
"react-native-maps": "~0.25.0",
18+
"react": "16.9.0",
19+
"react-dom": "16.9.0",
20+
"react-native": "0.61.4",
21+
"react-native-gesture-handler": "~1.5.0",
22+
"react-native-maps": "0.26.1",
2323
"react-native-paper": "^2.15.2",
24-
"react-native-reanimated": "~1.2.0",
25-
"react-native-safe-area-context": "^0.3.6",
24+
"react-native-reanimated": "~1.4.0",
25+
"react-native-safe-area-context": "0.6.0",
2626
"react-native-unimodules": "^0.7.0-rc.1",
2727
"react-native-web": "^0.11.4",
28-
"react-native-webview": "7.0.5",
28+
"react-native-webview": "7.4.3",
2929
"react-navigation": "^4.0.7",
3030
"react-navigation-drawer": "^2.2.2",
3131
"react-navigation-tabs": "^2.5.5"

example/src/ModalStack.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
createStackNavigator,
1212
CardStyleInterpolators,
1313
NavigationStackScreenProps,
14-
CardStyleInterpolator,
14+
StackCardStyleInterpolator,
1515
} from 'react-navigation-stack';
1616
import Animated from 'react-native-reanimated';
1717

@@ -21,7 +21,7 @@ const gestureResponseDistance = {
2121
vertical: Dimensions.get('window').height,
2222
};
2323

24-
const forVerticalInvertedIOS: CardStyleInterpolator = ({
24+
const forVerticalInvertedIOS: StackCardStyleInterpolator = ({
2525
current: { progress },
2626
layouts: { screen },
2727
}) => {

0 commit comments

Comments
 (0)