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

Feature/bob #27

Merged
merged 17 commits into from
Jul 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions jest-setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// nothing
29 changes: 10 additions & 19 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,15 @@
const { defaults: tsjPreset } = require('ts-jest/presets');

module.exports = {
...tsjPreset,
preset: 'react-native',
transform: {
...tsjPreset.transform,
'\\.js$': '<rootDir>/node_modules/react-native/jest/preprocessor.js',
},
globals: {
'ts-jest': {
babelConfig: true,
},
},
testPathIgnorePatterns: [
"\\.snap$",
"<rootDir>/node_modules/",
"<rootDir>/dist/"
],
setupFiles: ['<rootDir>/jest-setup.js'],
coveragePathIgnorePatterns: ['jest-setup.js'],
modulePathIgnorePatterns: ['<rootDir>/example/'],
transformIgnorePatterns: [
"<rootDir>/node_modules/(?!react-native)/"
'node_modules/(?!(jest-)?react-native|react-clone-referenced-element|react-navigation-deprecated-tab-navigator|@react-navigation/core|@react-navigation/native)',
],
cacheDirectory: '.jest/cache',
testPathIgnorePatterns: ['/node_modules/', '/dist/'],
testRegex: '/__tests__/.*\\.(test|spec)\\.(js|tsx?)$',
testEnvironment: 'node',
transform: {
'^.+\\.(js|ts|tsx)$': 'babel-jest',
},
};
34 changes: 23 additions & 11 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",
"version": "1.0.2-alpha.0",
"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 @@ -13,7 +15,7 @@
"scripts": {
"test": "jest",
"lint": "tslint --project tsconfig.json",
"build": "tsc --project tsconfig-build.json",
"build": "bob build",
"prepare": "yarn build",
"release": "release-it",
"precommit": "lint-staged"
Expand All @@ -31,34 +33,44 @@
"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",
"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-test-renderer": "^16.0.3",
"babel-jest": "^24.7.1",
"conventional-changelog-cli": "^2.0.5",
"husky": "^0.14.3",
"jest": "^23.6.0",
"jest": "^24.7.1",
"lint-staged": "^8.1.0",
"prettier": "^1.8.2",
"pretty-quick": "^1.8.0",
"react": "^16.7.0-alpha.2",
"react": "^16.8.0",
"react-native": "^0.57.7",
"react-navigation-types-only": "bySabi/react-navigation#patch-1",
"react-test-renderer": "^16.7.0-alpha.2",
"react-navigation": "^3.11.1",
"react-test-renderer": "^16.8.0",
"release-it": "^7.6.1",
"ts-jest": "^23.10.5",
"tslint": "^5.11.0",
"tslint-config-airbnb": "^5.11.1",
"tslint-config-prettier": "^1.16.0",
"tslint-react": "^3.6.0",
"typescript": "^3.1.6"
"typescript": "^3.5.3"
},
"peerDependencies": {
"@react-navigation/core": "^3.0.0",
"react": "^16.7.0-alpha.2",
"react": "^16.8.0",
"react-native": "*"
},
"lint-staged": {
Expand Down
11 changes: 6 additions & 5 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 All @@ -33,7 +32,9 @@ export function useNavigationEvents(handleEvt: NavigationEventCallback) {
const navigation = useNavigation();
useEffect(
() => {
const subsA = navigation.addListener('action', handleEvt);
const subsA = navigation.addListener(
'action' as any // TODO should we remove it? it's not in the published typedefs
, handleEvt);
const subsWF = navigation.addListener('willFocus', handleEvt);
const subsDF = navigation.addListener('didFocus', handleEvt);
const subsWB = navigation.addListener('willBlur', handleEvt);
Expand Down
22 changes: 13 additions & 9 deletions src/__tests__/Hooks-test.tsx → src/__tests__/Hooks.test.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { default as React, useState } from 'react';
import * as renderer from 'react-test-renderer';

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,11 +15,16 @@ import {
useNavigationKey,
useNavigationEvents,
useFocusState,
} from '../../dist/Hooks';
} from '../Hooks';

interface DetailsScreenParams {
from: string;
}

const HomeScreen = () => {
const { navigate } = useNavigation();
return navigate('Details', { from: 'Home' });
const params: DetailsScreenParams = { from: 'Home' };
return navigate('Details', params);
};

const DetailsScreen = () => {
Expand All @@ -40,7 +44,7 @@ const KeyScreen = () => {

const EventScreen = () => {
const [events, setEvents] = useState([] as NavigationEventPayload[]);
useNavigationEvents((evt) => {
useNavigationEvents(evt => {
// latest state on evt.state
// prev state on evt.lastState
// triggering navigation action on evt.action
Expand Down Expand Up @@ -92,7 +96,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"]
}
}
3 changes: 2 additions & 1 deletion tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"quotemark": [true, "single", "jsx-double"],
"ordered-imports": false,
"object-literal-sort-keys": false,
"arrow-parens": false,
"arrow-parens": [true, "ban-single-arg-parens"],
"ter-arrow-parens": false,
"no-console": [false],
"no-unused-expression": [true, "allow-fast-null-checks"],
"comment-format": false,
Expand Down
Loading