Skip to content
This repository was archived by the owner on Dec 3, 2022. It is now read-only.

Commit d766f74

Browse files
authored
Merge pull request #27 from react-navigation/feature/bob
Feature/bob
2 parents 80d48ea + bb57c89 commit d766f74

File tree

9 files changed

+2399
-1644
lines changed

9 files changed

+2399
-1644
lines changed

jest-setup.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// nothing

jest.config.js

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,15 @@
1-
const { defaults: tsjPreset } = require('ts-jest/presets');
2-
31
module.exports = {
4-
...tsjPreset,
52
preset: 'react-native',
6-
transform: {
7-
...tsjPreset.transform,
8-
'\\.js$': '<rootDir>/node_modules/react-native/jest/preprocessor.js',
9-
},
10-
globals: {
11-
'ts-jest': {
12-
babelConfig: true,
13-
},
14-
},
15-
testPathIgnorePatterns: [
16-
"\\.snap$",
17-
"<rootDir>/node_modules/",
18-
"<rootDir>/dist/"
19-
],
3+
setupFiles: ['<rootDir>/jest-setup.js'],
4+
coveragePathIgnorePatterns: ['jest-setup.js'],
5+
modulePathIgnorePatterns: ['<rootDir>/example/'],
206
transformIgnorePatterns: [
21-
"<rootDir>/node_modules/(?!react-native)/"
7+
'node_modules/(?!(jest-)?react-native|react-clone-referenced-element|react-navigation-deprecated-tab-navigator|@react-navigation/core|@react-navigation/native)',
228
],
23-
cacheDirectory: '.jest/cache',
9+
testPathIgnorePatterns: ['/node_modules/', '/dist/'],
10+
testRegex: '/__tests__/.*\\.(test|spec)\\.(js|tsx?)$',
11+
testEnvironment: 'node',
12+
transform: {
13+
'^.+\\.(js|ts|tsx)$': 'babel-jest',
14+
},
2415
};

package.json

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
{
22
"name": "react-navigation-hooks",
3-
"version": "1.0.1",
3+
"version": "1.0.2-alpha.0",
44
"description": "React hooks for convenient react-navigation use",
5-
"main": "dist/Hooks.js",
6-
"types": "dist/Hooks.d.ts",
5+
"main": "dist/commonjs/Hooks.js",
6+
"module": "dist/module/Hooks.js",
7+
"react-native": "dist/module/Hooks.js",
8+
"types": "dist/typescript/Hooks.d.ts",
79
"files": [
810
"dist/",
911
"src/",
@@ -13,7 +15,7 @@
1315
"scripts": {
1416
"test": "jest",
1517
"lint": "tslint --project tsconfig.json",
16-
"build": "tsc --project tsconfig-build.json",
18+
"build": "bob build",
1719
"prepare": "yarn build",
1820
"release": "release-it",
1921
"precommit": "lint-staged"
@@ -31,34 +33,44 @@
3133
"url": "https://github.com/react-navigation/react-navigation-hooks/issues"
3234
},
3335
"homepage": "https://github.com/react-navigation/react-navigation-hooks#readme",
36+
"@react-native-community/bob": {
37+
"source": "src",
38+
"output": "dist",
39+
"targets": [
40+
"commonjs",
41+
"module",
42+
"typescript"
43+
]
44+
},
3445
"devDependencies": {
46+
"@react-native-community/bob": "^0.6.1",
3547
"@react-navigation/core": "^3.0.0",
3648
"@react-navigation/native": "^3.0.2",
3749
"@types/jest": "^23.3.9",
3850
"@types/react": "^16.7.7",
3951
"@types/react-native": "^0.57.14",
4052
"@types/react-test-renderer": "^16.0.3",
53+
"babel-jest": "^24.7.1",
4154
"conventional-changelog-cli": "^2.0.5",
4255
"husky": "^0.14.3",
43-
"jest": "^23.6.0",
56+
"jest": "^24.7.1",
4457
"lint-staged": "^8.1.0",
4558
"prettier": "^1.8.2",
4659
"pretty-quick": "^1.8.0",
47-
"react": "^16.7.0-alpha.2",
60+
"react": "^16.8.0",
4861
"react-native": "^0.57.7",
49-
"react-navigation-types-only": "bySabi/react-navigation#patch-1",
50-
"react-test-renderer": "^16.7.0-alpha.2",
62+
"react-navigation": "^3.11.1",
63+
"react-test-renderer": "^16.8.0",
5164
"release-it": "^7.6.1",
52-
"ts-jest": "^23.10.5",
5365
"tslint": "^5.11.0",
5466
"tslint-config-airbnb": "^5.11.1",
5567
"tslint-config-prettier": "^1.16.0",
5668
"tslint-react": "^3.6.0",
57-
"typescript": "^3.1.6"
69+
"typescript": "^3.5.3"
5870
},
5971
"peerDependencies": {
6072
"@react-navigation/core": "^3.0.0",
61-
"react": "^16.7.0-alpha.2",
73+
"react": "^16.8.0",
6274
"react-native": "*"
6375
},
6476
"lint-staged": {

src/Hooks.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
import { useState, useContext, useEffect } from 'react';
2-
import { NavigationContext } from '@react-navigation/core';
3-
// TODO: move to "react-navigation" when https://github.com/react-navigation/react-navigation/pull/5276
4-
// get merged
2+
53
import {
4+
NavigationContext,
65
NavigationScreenProp,
76
NavigationRoute,
87
NavigationParams,
98
NavigationEventCallback,
109
NavigationEventPayload,
1110
EventType,
12-
} from 'react-navigation-types-only';
11+
} from 'react-navigation';
1312

1413
export function useNavigation<S>(): NavigationScreenProp<S & NavigationRoute> {
1514
return useContext(NavigationContext as any);
@@ -33,7 +32,9 @@ export function useNavigationEvents(handleEvt: NavigationEventCallback) {
3332
const navigation = useNavigation();
3433
useEffect(
3534
() => {
36-
const subsA = navigation.addListener('action', handleEvt);
35+
const subsA = navigation.addListener(
36+
'action' as any // TODO should we remove it? it's not in the published typedefs
37+
, handleEvt);
3738
const subsWF = navigation.addListener('willFocus', handleEvt);
3839
const subsDF = navigation.addListener('didFocus', handleEvt);
3940
const subsWB = navigation.addListener('willBlur', handleEvt);

src/__tests__/Hooks-test.tsx renamed to src/__tests__/Hooks.test.tsx

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import { default as React, useState } from 'react';
22
import * as renderer from 'react-test-renderer';
3+
34
import {
45
createSwitchNavigator,
6+
createAppContainer,
7+
NavigationEventPayload,
58
NavigationActions,
6-
} from '@react-navigation/core';
7-
import { createAppContainer } from '@react-navigation/native';
8-
// TODO: move to "react-navigation" when https://github.com/react-navigation/react-navigation/pull/5276
9-
// get merged
10-
import { NavigationEventPayload } from 'react-navigation-types-only';
9+
} from 'react-navigation';
1110

1211
import {
1312
useNavigation,
@@ -16,11 +15,16 @@ import {
1615
useNavigationKey,
1716
useNavigationEvents,
1817
useFocusState,
19-
} from '../../dist/Hooks';
18+
} from '../Hooks';
19+
20+
interface DetailsScreenParams {
21+
from: string;
22+
}
2023

2124
const HomeScreen = () => {
2225
const { navigate } = useNavigation();
23-
return navigate('Details', { from: 'Home' });
26+
const params: DetailsScreenParams = { from: 'Home' };
27+
return navigate('Details', params);
2428
};
2529

2630
const DetailsScreen = () => {
@@ -40,7 +44,7 @@ const KeyScreen = () => {
4044

4145
const EventScreen = () => {
4246
const [events, setEvents] = useState([] as NavigationEventPayload[]);
43-
useNavigationEvents((evt) => {
47+
useNavigationEvents(evt => {
4448
// latest state on evt.state
4549
// prev state on evt.lastState
4650
// triggering navigation action on evt.action
@@ -92,7 +96,7 @@ describe('AppNavigator1 Stack', () => {
9296
});
9397

9498
it('useNavigation: Navigating to "DetailsScreen"', () => {
95-
const instance = navigationContainer.getInstance()
99+
const instance = navigationContainer.getInstance();
96100
expect(instance.state.nav).toMatchObject({ index: 1 });
97101
});
98102

tsconfig-build.json

Lines changed: 0 additions & 8 deletions
This file was deleted.

tsconfig.json

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,30 @@
11
{
22
"compilerOptions": {
3-
"target": "es5",
4-
"module": "commonjs",
5-
"lib": ["es7"],
3+
"allowUnreachableCode": false,
4+
"allowUnusedLabels": false,
5+
"alwaysStrict": true,
6+
"esModuleInterop": true,
7+
"forceConsistentCasingInFileNames": true,
68
"jsx": "react",
7-
"sourceMap": true,
9+
"lib": ["esnext"],
10+
"module": "esnext",
811
"moduleResolution": "node",
9-
"rootDir": "src",
10-
"forceConsistentCasingInFileNames": true,
12+
"noFallthroughCasesInSwitch": true,
13+
"noImplicitAny": true,
1114
"noImplicitReturns": true,
1215
"noImplicitThis": true,
13-
"noImplicitAny": false,
14-
"strictNullChecks": true,
15-
"suppressImplicitAnyIndexErrors": true,
16+
"noImplicitUseStrict": false,
17+
"noStrictGenericChecks": false,
1618
"noUnusedLocals": true,
17-
"declaration": true,
18-
"pretty": true,
19-
"noEmitHelpers": true,
20-
"importHelpers": true,
19+
"noUnusedParameters": true,
20+
"resolveJsonModule": true,
21+
"skipLibCheck": true,
2122
"strict": true,
22-
"outDir": "dist",
23-
"allowSyntheticDefaultImports": true,
24-
"esModuleInterop": true
23+
"target": "esnext",
24+
"plugins": [{ "name": "typescript-tslint-plugin" }]
2525
},
26-
"exclude": ["dist", ".jest", "node_modules"]
26+
"typeAcquisition": {
27+
"enable": true,
28+
"include": ["react", "react-native"]
29+
}
2730
}

tslint.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"quotemark": [true, "single", "jsx-double"],
1212
"ordered-imports": false,
1313
"object-literal-sort-keys": false,
14-
"arrow-parens": false,
14+
"arrow-parens": [true, "ban-single-arg-parens"],
15+
"ter-arrow-parens": false,
1516
"no-console": [false],
1617
"no-unused-expression": [true, "allow-fast-null-checks"],
1718
"comment-format": false,

0 commit comments

Comments
 (0)