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

Commit bb114e3

Browse files
committed
migrate to bob, use @types/react-navigation until react-navigation is fully typed
1 parent 80d48ea commit bb114e3

File tree

6 files changed

+604
-86
lines changed

6 files changed

+604
-86
lines changed

package.json

Lines changed: 23 additions & 6 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+
"versin": "1.0.1",
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/",
@@ -14,7 +16,7 @@
1416
"test": "jest",
1517
"lint": "tslint --project tsconfig.json",
1618
"build": "tsc --project tsconfig-build.json",
17-
"prepare": "yarn build",
19+
"prepare": "bob build",
1820
"release": "release-it",
1921
"precommit": "lint-staged"
2022
},
@@ -31,12 +33,28 @@
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+
[
41+
"commonjs",
42+
{
43+
"flow": true
44+
}
45+
],
46+
"module",
47+
"typescript"
48+
]
49+
},
3450
"devDependencies": {
51+
"@react-native-community/bob": "^0.6.1",
3552
"@react-navigation/core": "^3.0.0",
3653
"@react-navigation/native": "^3.0.2",
3754
"@types/jest": "^23.3.9",
3855
"@types/react": "^16.7.7",
3956
"@types/react-native": "^0.57.14",
57+
"@types/react-navigation": "^3.0.7",
4058
"@types/react-test-renderer": "^16.0.3",
4159
"conventional-changelog-cli": "^2.0.5",
4260
"husky": "^0.14.3",
@@ -46,7 +64,6 @@
4664
"pretty-quick": "^1.8.0",
4765
"react": "^16.7.0-alpha.2",
4866
"react-native": "^0.57.7",
49-
"react-navigation-types-only": "bySabi/react-navigation#patch-1",
5067
"react-test-renderer": "^16.7.0-alpha.2",
5168
"release-it": "^7.6.1",
5269
"ts-jest": "^23.10.5",
@@ -58,7 +75,7 @@
5875
},
5976
"peerDependencies": {
6077
"@react-navigation/core": "^3.0.0",
61-
"react": "^16.7.0-alpha.2",
78+
"react": "^16.8.0",
6279
"react-native": "*"
6380
},
6481
"lint-staged": {

src/Hooks.ts

Lines changed: 3 additions & 4 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);

src/__tests__/Hooks-test.tsx

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { default as React, useState } from 'react';
22
import * as renderer from 'react-test-renderer';
3+
// @ts-ignore
4+
import { createSwitchNavigator } from '@react-navigation/core';
5+
36
import {
4-
createSwitchNavigator,
7+
createAppContainer,
8+
NavigationEventPayload,
59
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';
10+
} from 'react-navigation';
1111

1212
import {
1313
useNavigation,
@@ -16,7 +16,8 @@ import {
1616
useNavigationKey,
1717
useNavigationEvents,
1818
useFocusState,
19-
} from '../../dist/Hooks';
19+
// @ts-ignore
20+
} from '../../dist/module/Hooks';
2021

2122
const HomeScreen = () => {
2223
const { navigate } = useNavigation();
@@ -40,7 +41,7 @@ const KeyScreen = () => {
4041

4142
const EventScreen = () => {
4243
const [events, setEvents] = useState([] as NavigationEventPayload[]);
43-
useNavigationEvents((evt) => {
44+
useNavigationEvents((evt: any) => {
4445
// latest state on evt.state
4546
// prev state on evt.lastState
4647
// triggering navigation action on evt.action
@@ -92,7 +93,7 @@ describe('AppNavigator1 Stack', () => {
9293
});
9394

9495
it('useNavigation: Navigating to "DetailsScreen"', () => {
95-
const instance = navigationContainer.getInstance()
96+
const instance = navigationContainer.getInstance();
9697
expect(instance.state.nav).toMatchObject({ index: 1 });
9798
});
9899

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
}

0 commit comments

Comments
 (0)