Skip to content

Commit

Permalink
migrate to bob, use @types/react-navigation until react-navigation is…
Browse files Browse the repository at this point in the history
… fully typed
  • Loading branch information
slorber committed Jul 13, 2019
1 parent 80d48ea commit bb114e3
Show file tree
Hide file tree
Showing 6 changed files with 604 additions and 86 deletions.
29 changes: 23 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
{
"name": "react-navigation-hooks",
"version": "1.0.1",
"versin": "1.0.1",
"description": "React hooks for convenient react-navigation use",
"main": "dist/Hooks.js",
"types": "dist/Hooks.d.ts",
"main": "dist/commonjs/Hooks.js",
"module": "dist/module/Hooks.js",
"react-native": "dist/module/Hooks.js",
"types": "dist/typescript/Hooks.d.ts",
"files": [
"dist/",
"src/",
Expand All @@ -14,7 +16,7 @@
"test": "jest",
"lint": "tslint --project tsconfig.json",
"build": "tsc --project tsconfig-build.json",
"prepare": "yarn build",
"prepare": "bob build",
"release": "release-it",
"precommit": "lint-staged"
},
Expand All @@ -31,12 +33,28 @@
"url": "https://github.com/react-navigation/react-navigation-hooks/issues"
},
"homepage": "https://github.com/react-navigation/react-navigation-hooks#readme",
"@react-native-community/bob": {
"source": "src",
"output": "dist",
"targets": [
[
"commonjs",
{
"flow": true
}
],
"module",
"typescript"
]
},
"devDependencies": {
"@react-native-community/bob": "^0.6.1",
"@react-navigation/core": "^3.0.0",
"@react-navigation/native": "^3.0.2",
"@types/jest": "^23.3.9",
"@types/react": "^16.7.7",
"@types/react-native": "^0.57.14",
"@types/react-navigation": "^3.0.7",
"@types/react-test-renderer": "^16.0.3",
"conventional-changelog-cli": "^2.0.5",
"husky": "^0.14.3",
Expand All @@ -46,7 +64,6 @@
"pretty-quick": "^1.8.0",
"react": "^16.7.0-alpha.2",
"react-native": "^0.57.7",
"react-navigation-types-only": "bySabi/react-navigation#patch-1",
"react-test-renderer": "^16.7.0-alpha.2",
"release-it": "^7.6.1",
"ts-jest": "^23.10.5",
Expand All @@ -58,7 +75,7 @@
},
"peerDependencies": {
"@react-navigation/core": "^3.0.0",
"react": "^16.7.0-alpha.2",
"react": "^16.8.0",
"react-native": "*"
},
"lint-staged": {
Expand Down
7 changes: 3 additions & 4 deletions src/Hooks.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import { useState, useContext, useEffect } from 'react';
import { NavigationContext } from '@react-navigation/core';
// TODO: move to "react-navigation" when https://github.com/react-navigation/react-navigation/pull/5276
// get merged

import {
NavigationContext,
NavigationScreenProp,
NavigationRoute,
NavigationParams,
NavigationEventCallback,
NavigationEventPayload,
EventType,
} from 'react-navigation-types-only';
} from 'react-navigation';

export function useNavigation<S>(): NavigationScreenProp<S & NavigationRoute> {
return useContext(NavigationContext as any);
Expand Down
19 changes: 10 additions & 9 deletions src/__tests__/Hooks-test.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { default as React, useState } from 'react';
import * as renderer from 'react-test-renderer';
// @ts-ignore
import { createSwitchNavigator } from '@react-navigation/core';

import {
createSwitchNavigator,
createAppContainer,
NavigationEventPayload,
NavigationActions,
} from '@react-navigation/core';
import { createAppContainer } from '@react-navigation/native';
// TODO: move to "react-navigation" when https://github.com/react-navigation/react-navigation/pull/5276
// get merged
import { NavigationEventPayload } from 'react-navigation-types-only';
} from 'react-navigation';

import {
useNavigation,
Expand All @@ -16,7 +16,8 @@ import {
useNavigationKey,
useNavigationEvents,
useFocusState,
} from '../../dist/Hooks';
// @ts-ignore
} from '../../dist/module/Hooks';

const HomeScreen = () => {
const { navigate } = useNavigation();
Expand All @@ -40,7 +41,7 @@ const KeyScreen = () => {

const EventScreen = () => {
const [events, setEvents] = useState([] as NavigationEventPayload[]);
useNavigationEvents((evt) => {
useNavigationEvents((evt: any) => {
// latest state on evt.state
// prev state on evt.lastState
// triggering navigation action on evt.action
Expand Down Expand Up @@ -92,7 +93,7 @@ describe('AppNavigator1 Stack', () => {
});

it('useNavigation: Navigating to "DetailsScreen"', () => {
const instance = navigationContainer.getInstance()
const instance = navigationContainer.getInstance();
expect(instance.state.nav).toMatchObject({ index: 1 });
});

Expand Down
8 changes: 0 additions & 8 deletions tsconfig-build.json

This file was deleted.

37 changes: 20 additions & 17 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"lib": ["es7"],
"allowUnreachableCode": false,
"allowUnusedLabels": false,
"alwaysStrict": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"jsx": "react",
"sourceMap": true,
"lib": ["esnext"],
"module": "esnext",
"moduleResolution": "node",
"rootDir": "src",
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"noImplicitAny": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noImplicitAny": false,
"strictNullChecks": true,
"suppressImplicitAnyIndexErrors": true,
"noImplicitUseStrict": false,
"noStrictGenericChecks": false,
"noUnusedLocals": true,
"declaration": true,
"pretty": true,
"noEmitHelpers": true,
"importHelpers": true,
"noUnusedParameters": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"strict": true,
"outDir": "dist",
"allowSyntheticDefaultImports": true,
"esModuleInterop": true
"target": "esnext",
"plugins": [{ "name": "typescript-tslint-plugin" }]
},
"exclude": ["dist", ".jest", "node_modules"]
"typeAcquisition": {
"enable": true,
"include": ["react", "react-native"]
}
}
Loading

0 comments on commit bb114e3

Please sign in to comment.