Compare commits

..

16 Commits

Author SHA1 Message Date
Satyajit Sahoo
5b7bbbdfd9 chore: publish
- @react-navigation/bottom-tabs@5.0.5
- @react-navigation/compat@5.0.5
- @react-navigation/core@5.1.4
- @react-navigation/drawer@5.0.5
- @react-navigation/material-bottom-tabs@5.0.5
- @react-navigation/material-top-tabs@5.0.5
- @react-navigation/native-stack@5.0.5
- @react-navigation/native@5.0.5
- @react-navigation/stack@5.0.5
2020-02-15 00:18:52 +01:00
Satyajit Sahoo
c5fefc6ee9 chore: tweak versions for peer dependencies 2020-02-15 00:15:01 +01:00
Satyajit Sahoo
aaf01e01e7 fix: return '/' for empty paths 2020-02-14 23:17:29 +01:00
Satyajit Sahoo
ac242fd281 refactor: discard all routes but last when getting action from state 2020-02-14 23:04:09 +01:00
Satyajit Sahoo
c5fcfbd427 fix: link to migration guide on invalid usage 2020-02-14 22:48:04 +01:00
Satyajit Sahoo
424c9469e4 chore: publish
- @react-navigation/bottom-tabs@5.0.4
 - @react-navigation/compat@5.0.4
 - @react-navigation/core@5.1.3
 - @react-navigation/drawer@5.0.4
 - @react-navigation/material-bottom-tabs@5.0.4
 - @react-navigation/material-top-tabs@5.0.4
 - @react-navigation/native-stack@5.0.4
 - @react-navigation/native@5.0.4
 - @react-navigation/stack@5.0.4
2020-02-14 18:50:01 +01:00
Satyajit Sahoo
8f40a98086 fix: hard code header height for animation
closes #6818
2020-02-14 18:44:54 +01:00
Satyajit Sahoo
f964200b0d fix: update links in error messages 2020-02-14 18:32:53 +01:00
Satyajit Sahoo
bd2f008a83 chore: build related changes 2020-02-14 18:32:53 +01:00
Chris
e37d6598ca docs: Update types.tsx (#6849)
Typo :)
2020-02-14 10:43:53 +01:00
Satyajit Sahoo
c8ac5fab61 fix: return false for canGoBack if navigator hasn't finished mounting 2020-02-12 21:28:03 +01:00
Satyajit Sahoo
b6accd03f6 fix: throw a descriptive error if navigation object hasn't initialized 2020-02-12 20:59:58 +01:00
Satyajit Sahoo
0cca1309ec chore: publish
- @react-navigation/bottom-tabs@5.0.3
 - @react-navigation/compat@5.0.3
 - @react-navigation/core@5.1.2
 - @react-navigation/drawer@5.0.3
 - @react-navigation/material-bottom-tabs@5.0.3
 - @react-navigation/material-top-tabs@5.0.3
 - @react-navigation/native-stack@5.0.3
 - @react-navigation/native@5.0.3
 - @react-navigation/stack@5.0.3
2020-02-12 16:58:48 +01:00
Satyajit Sahoo
6c9447a38c fix: check if we can go baack before dispatching pop 2020-02-12 13:17:08 +01:00
Satyajit Sahoo
030c63c89f fix: fix false positives for circular object check
fixes #6827
2020-02-12 11:42:36 +01:00
Abhinandan Ramaprasath
2bf0958502 fix: static container memo check (#6825)
Memo check compared elements of prevProps to nextProps but failed
to take new props into account. Fixed the logic and added a new
test.
2020-02-12 10:56:23 +01:00
39 changed files with 604 additions and 178 deletions

View File

@@ -13,7 +13,7 @@
<content url="file://$MODULE_DIR$"> <content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.gradle" /> <excludeFolder url="file://$MODULE_DIR$/.gradle" />
</content> </content>
<orderEntry type="inheritedJdk" /> <orderEntry type="jdk" jdkName="1.8" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
</component> </component>
</module> </module>

View File

@@ -161,32 +161,33 @@
<orderEntry type="library" name="Gradle: com.facebook.fresco:imagepipeline-okhttp3:2.0.0@aar" level="project" /> <orderEntry type="library" name="Gradle: com.facebook.fresco:imagepipeline-okhttp3:2.0.0@aar" level="project" />
<orderEntry type="library" name="Gradle: io.nlopez.smartlocation:library:3.2.11@aar" level="project" /> <orderEntry type="library" name="Gradle: io.nlopez.smartlocation:library:3.2.11@aar" level="project" />
<orderEntry type="library" name="Gradle: org.webkit:android-jsc:r245459@aar" level="project" /> <orderEntry type="library" name="Gradle: org.webkit:android-jsc:r245459@aar" level="project" />
<orderEntry type="module" module-name="android-expo-permissions" /> <orderEntry type="module" module-name="expo-permissions" />
<orderEntry type="module" module-name="android-expo-constants" /> <orderEntry type="module" module-name="expo-constants" />
<orderEntry type="module" module-name="android-unimodules-image-loader-interface" /> <orderEntry type="module" module-name="unimodules-image-loader-interface" />
<orderEntry type="module" module-name="android-expo-web-browser" /> <orderEntry type="module" module-name="expo-web-browser" />
<orderEntry type="module" module-name="android-unimodules-react-native-adapter" /> <orderEntry type="module" module-name="unimodules-react-native-adapter" />
<orderEntry type="module" module-name="android-expo-file-system" /> <orderEntry type="module" module-name="expo-file-system" />
<orderEntry type="module" module-name="android-expo-location" /> <orderEntry type="module" module-name="expo-location" />
<orderEntry type="module" module-name="android-expo-error-recovery" /> <orderEntry type="module" module-name="expo-error-recovery" />
<orderEntry type="module" module-name="android-unimodules-permissions-interface" /> <orderEntry type="module" module-name="unimodules-permissions-interface" />
<orderEntry type="module" module-name="android-unimodules-core" /> <orderEntry type="module" module-name="unimodules-core" />
<orderEntry type="module" module-name="android-expo-app-loader-provider" /> <orderEntry type="module" module-name="expo-app-loader-provider" />
<orderEntry type="module" module-name="android-expo-font" /> <orderEntry type="module" module-name="expo-font" />
<orderEntry type="module" module-name="android-expo-keep-awake" /> <orderEntry type="module" module-name="expo-keep-awake" />
<orderEntry type="module" module-name="android-expo-linear-gradient" /> <orderEntry type="module" module-name="expo-linear-gradient" />
<orderEntry type="module" module-name="android-expo-sqlite" /> <orderEntry type="module" module-name="expo-sqlite" />
<orderEntry type="module" module-name="android-unimodules-barcode-scanner-interface" /> <orderEntry type="module" module-name="unimodules-barcode-scanner-interface" />
<orderEntry type="module" module-name="android-unimodules-camera-interface" /> <orderEntry type="module" module-name="unimodules-camera-interface" />
<orderEntry type="module" module-name="android-unimodules-constants-interface" /> <orderEntry type="module" module-name="unimodules-constants-interface" />
<orderEntry type="module" module-name="android-unimodules-face-detector-interface" /> <orderEntry type="module" module-name="unimodules-face-detector-interface" />
<orderEntry type="module" module-name="android-unimodules-file-system-interface" /> <orderEntry type="module" module-name="unimodules-file-system-interface" />
<orderEntry type="module" module-name="android-unimodules-font-interface" /> <orderEntry type="module" module-name="unimodules-font-interface" />
<orderEntry type="module" module-name="android-unimodules-sensors-interface" /> <orderEntry type="module" module-name="unimodules-sensors-interface" />
<orderEntry type="module" module-name="android-unimodules-task-manager-interface" /> <orderEntry type="module" module-name="unimodules-task-manager-interface" />
<orderEntry type="module" module-name="android-@react-native-community_masked-view" /> <orderEntry type="module" module-name="@react-native-community_masked-view" />
<orderEntry type="module" module-name="android-react-native-gesture-handler" /> <orderEntry type="module" module-name="react-native-gesture-handler" />
<orderEntry type="module" module-name="android-react-native-reanimated" /> <orderEntry type="module" module-name="react-native-reanimated" />
<orderEntry type="module" module-name="react-native-restart" />
<orderEntry type="module" module-name="react-native-safe-area-context" /> <orderEntry type="module" module-name="react-native-safe-area-context" />
<orderEntry type="module" module-name="react-native-screens" /> <orderEntry type="module" module-name="react-native-screens" />
</component> </component>

View File

@@ -124,7 +124,8 @@ export default function App() {
prefixes: LinkingPrefixes, prefixes: LinkingPrefixes,
config: { config: {
Root: { Root: {
path: 'root', path: '',
initialRouteName: 'Home',
screens: Object.keys(SCREENS).reduce<{ [key: string]: string }>( screens: Object.keys(SCREENS).reduce<{ [key: string]: string }>(
(acc, name) => { (acc, name) => {
// Convert screen names such as SimpleStack to kebab case (simple-stack) // Convert screen names such as SimpleStack to kebab case (simple-stack)
@@ -135,7 +136,7 @@ export default function App() {
return acc; return acc;
}, },
{} { Home: '' }
), ),
}, },
}, },

View File

@@ -3,6 +3,30 @@
All notable changes to this project will be documented in this file. All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [5.0.5](https://github.com/react-navigation/react-navigation/tree/master/packages/bottom-tabs/compare/@react-navigation/bottom-tabs@5.0.4...@react-navigation/bottom-tabs@5.0.5) (2020-02-14)
**Note:** Version bump only for package @react-navigation/bottom-tabs
## [5.0.4](https://github.com/react-navigation/react-navigation/tree/master/packages/bottom-tabs/compare/@react-navigation/bottom-tabs@5.0.3...@react-navigation/bottom-tabs@5.0.4) (2020-02-14)
**Note:** Version bump only for package @react-navigation/bottom-tabs
## [5.0.3](https://github.com/react-navigation/react-navigation/tree/master/packages/bottom-tabs/compare/@react-navigation/bottom-tabs@5.0.2...@react-navigation/bottom-tabs@5.0.3) (2020-02-12)
**Note:** Version bump only for package @react-navigation/bottom-tabs
## [5.0.2](https://github.com/react-navigation/react-navigation/tree/master/packages/bottom-tabs/compare/@react-navigation/bottom-tabs@5.0.1...@react-navigation/bottom-tabs@5.0.2) (2020-02-11) ## [5.0.2](https://github.com/react-navigation/react-navigation/tree/master/packages/bottom-tabs/compare/@react-navigation/bottom-tabs@5.0.1...@react-navigation/bottom-tabs@5.0.2) (2020-02-11)

View File

@@ -10,7 +10,7 @@
"android", "android",
"tab" "tab"
], ],
"version": "5.0.2", "version": "5.0.4",
"license": "MIT", "license": "MIT",
"repository": "https://github.com/react-navigation/react-navigation/tree/master/packages/bottom-tabs", "repository": "https://github.com/react-navigation/react-navigation/tree/master/packages/bottom-tabs",
"main": "lib/commonjs/index.js", "main": "lib/commonjs/index.js",
@@ -35,7 +35,7 @@
}, },
"devDependencies": { "devDependencies": {
"@react-native-community/bob": "^0.9.3", "@react-native-community/bob": "^0.9.3",
"@react-navigation/native": "^5.0.2", "@react-navigation/native": "^5.0.4",
"@types/color": "^3.0.1", "@types/color": "^3.0.1",
"@types/react": "^16.9.19", "@types/react": "^16.9.19",
"@types/react-native": "^0.60.30", "@types/react-native": "^0.60.30",
@@ -49,7 +49,7 @@
"@react-navigation/native": "^5.0.0", "@react-navigation/native": "^5.0.0",
"react": "*", "react": "*",
"react-native": "*", "react-native": "*",
"react-native-safe-area-context": "^0.6.0" "react-native-safe-area-context": ">= 0.6.0"
}, },
"@react-native-community/bob": { "@react-native-community/bob": {
"source": "src", "source": "src",

View File

@@ -176,8 +176,8 @@ export type BottomTabBarOptions = {
*/ */
tabStyle?: StyleProp<ViewStyle>; tabStyle?: StyleProp<ViewStyle>;
/** /**
* Whether the label is renderd below the icon or beside the icon. * Whether the label is rendered below the icon or beside the icon.
* By default, in `vertical` orinetation, label is rendered below and in `horizontal` orientation, it's renderd beside. * By default, in `vertical` orinetation, label is rendered below and in `horizontal` orientation, it's rendered beside.
*/ */
labelPosition?: LabelPosition; labelPosition?: LabelPosition;
/** /**

View File

@@ -3,6 +3,30 @@
All notable changes to this project will be documented in this file. All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [5.0.5](https://github.com/react-navigation/react-navigation/tree/master/packages/compat/compare/@react-navigation/compat@5.0.4...@react-navigation/compat@5.0.5) (2020-02-14)
**Note:** Version bump only for package @react-navigation/compat
## [5.0.4](https://github.com/react-navigation/react-navigation/tree/master/packages/compat/compare/@react-navigation/compat@5.0.3...@react-navigation/compat@5.0.4) (2020-02-14)
**Note:** Version bump only for package @react-navigation/compat
## [5.0.3](https://github.com/react-navigation/react-navigation/tree/master/packages/compat/compare/@react-navigation/compat@5.0.2...@react-navigation/compat@5.0.3) (2020-02-12)
**Note:** Version bump only for package @react-navigation/compat
## [5.0.2](https://github.com/react-navigation/react-navigation/tree/master/packages/compat/compare/@react-navigation/compat@5.0.1...@react-navigation/compat@5.0.2) (2020-02-11) ## [5.0.2](https://github.com/react-navigation/react-navigation/tree/master/packages/compat/compare/@react-navigation/compat@5.0.1...@react-navigation/compat@5.0.2) (2020-02-11)
**Note:** Version bump only for package @react-navigation/compat **Note:** Version bump only for package @react-navigation/compat

View File

@@ -1,7 +1,7 @@
{ {
"name": "@react-navigation/compat", "name": "@react-navigation/compat",
"description": "Compatibility layer to write navigator definitions in static configuration format", "description": "Compatibility layer to write navigator definitions in static configuration format",
"version": "5.0.2", "version": "5.0.4",
"license": "MIT", "license": "MIT",
"repository": "https://github.com/react-navigation/react-navigation/tree/master/packages/compat", "repository": "https://github.com/react-navigation/react-navigation/tree/master/packages/compat",
"bugs": { "bugs": {
@@ -26,14 +26,14 @@
}, },
"devDependencies": { "devDependencies": {
"@react-native-community/bob": "^0.9.3", "@react-native-community/bob": "^0.9.3",
"@react-navigation/native": "^5.0.2", "@react-navigation/native": "^5.0.4",
"@types/react": "^16.9.19", "@types/react": "^16.9.19",
"react": "~16.9.0", "react": "~16.9.0",
"typescript": "^3.7.5" "typescript": "^3.7.5"
}, },
"peerDependencies": { "peerDependencies": {
"@react-navigation/native": "^5.0.0", "@react-navigation/native": "^5.0.0",
"react": "~16.9.0" "react": "*"
}, },
"@react-native-community/bob": { "@react-native-community/bob": {
"source": "src", "source": "src",

View File

@@ -3,6 +3,43 @@
All notable changes to this project will be documented in this file. All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [5.1.4](https://github.com/react-navigation/react-navigation/tree/master/packages/core/compare/@react-navigation/core@5.1.3...@react-navigation/core@5.1.4) (2020-02-14)
### Bug Fixes
* link to migration guide on invalid usage ([c5fcfbd](https://github.com/react-navigation/react-navigation/tree/master/packages/core/commit/c5fcfbd4277541e131acbaa7602a5d7e636afebb))
* return '/' for empty paths ([aaf01e0](https://github.com/react-navigation/react-navigation/tree/master/packages/core/commit/aaf01e01e7b47b375f68aebe6d0effe82878d060))
## [5.1.3](https://github.com/react-navigation/react-navigation/tree/master/packages/core/compare/@react-navigation/core@5.1.2...@react-navigation/core@5.1.3) (2020-02-14)
### Bug Fixes
* return false for canGoBack if navigator hasn't finished mounting ([c8ac5fa](https://github.com/react-navigation/react-navigation/tree/master/packages/core/commit/c8ac5fab61cf127985431075a3c59c1f3dfa42da))
* throw a descriptive error if navigation object hasn't initialized ([b6accd0](https://github.com/react-navigation/react-navigation/tree/master/packages/core/commit/b6accd03f69dd438e595094d8bf8599cc12e71ac))
* update links in error messages ([f964200](https://github.com/react-navigation/react-navigation/tree/master/packages/core/commit/f964200b0dcbc19d5f88ad2dd1eb8e5576973497))
## [5.1.2](https://github.com/react-navigation/react-navigation/tree/master/packages/core/compare/@react-navigation/core@5.1.1...@react-navigation/core@5.1.2) (2020-02-12)
### Bug Fixes
* fix false positives for circular object check ([030c63c](https://github.com/react-navigation/react-navigation/tree/master/packages/core/commit/030c63c89fe447aa484b767831c8f8e26e90431c)), closes [#6827](https://github.com/react-navigation/react-navigation/tree/master/packages/core/issues/6827)
* static container memo check ([#6825](https://github.com/react-navigation/react-navigation/tree/master/packages/core/issues/6825)) ([2bf0958](https://github.com/react-navigation/react-navigation/tree/master/packages/core/commit/2bf09585021470f500d967e9242836840efe970f))
## [5.1.1](https://github.com/react-navigation/react-navigation/tree/master/packages/core/compare/@react-navigation/core@5.1.0...@react-navigation/core@5.1.1) (2020-02-11) ## [5.1.1](https://github.com/react-navigation/react-navigation/tree/master/packages/core/compare/@react-navigation/core@5.1.0...@react-navigation/core@5.1.1) (2020-02-11)

View File

@@ -1,7 +1,7 @@
{ {
"name": "@react-navigation/core", "name": "@react-navigation/core",
"description": "Core utilities for building navigators", "description": "Core utilities for building navigators",
"version": "5.1.1", "version": "5.1.3",
"keywords": [ "keywords": [
"react", "react",
"react-native", "react-native",
@@ -49,7 +49,7 @@
"typescript": "^3.7.5" "typescript": "^3.7.5"
}, },
"peerDependencies": { "peerDependencies": {
"react": "~16.9.0" "react": "*"
}, },
"@react-native-community/bob": { "@react-native-community/bob": {
"source": "src", "source": "src",

View File

@@ -22,6 +22,9 @@ type State = NavigationState | PartialState<NavigationState> | undefined;
const MISSING_CONTEXT_ERROR = const MISSING_CONTEXT_ERROR =
"We couldn't find a navigation context. Have you wrapped your app with 'NavigationContainer'? See https://reactnavigation.org/docs/en/getting-started.html for setup instructions."; "We couldn't find a navigation context. Have you wrapped your app with 'NavigationContainer'? See https://reactnavigation.org/docs/en/getting-started.html for setup instructions.";
const NOT_INITIALIZED_ERROR =
"The 'navigation' object hasn't been initialized yet. This might happen if you don't have a navigator mounted, or if the navigator hasn't finished mounting. You can ensure that all navigators have mounted after the callback to 'useEffect' is called in your root component. See https://reactnavigation.org/docs/en/navigating-without-navigation-prop.html#handling-initialization for more details.";
export const NavigationStateContext = React.createContext<{ export const NavigationStateContext = React.createContext<{
isDefault?: true; isDefault?: true;
state?: NavigationState | PartialState<NavigationState>; state?: NavigationState | PartialState<NavigationState>;
@@ -195,10 +198,18 @@ const BaseNavigationContainer = React.forwardRef(
const dispatch = ( const dispatch = (
action: NavigationAction | ((state: NavigationState) => NavigationAction) action: NavigationAction | ((state: NavigationState) => NavigationAction)
) => { ) => {
if (listeners[0] == null) {
throw new Error(NOT_INITIALIZED_ERROR);
}
listeners[0](navigation => navigation.dispatch(action)); listeners[0](navigation => navigation.dispatch(action));
}; };
const canGoBack = () => { const canGoBack = () => {
if (listeners[0] == null) {
return false;
}
const { result, handled } = listeners[0](navigation => const { result, handled } = listeners[0](navigation =>
navigation.canGoBack() navigation.canGoBack()
); );
@@ -277,7 +288,7 @@ const BaseNavigationContainer = React.forwardRef(
hasWarnedForSerialization = true; hasWarnedForSerialization = true;
console.warn( console.warn(
"We found non-serializable values in the navigation state, which can break usage such as persisting and restoring state. This might happen if you passed non-serializable values such as function, class instances etc. in params. If you need to use components with callbacks in your options, you can use 'navigation.setOptions' instead. See https://reactnavigation.org/docs/en/header-buttons.html#header-interaction-with-its-screen-component for docs." "We found non-serializable values in the navigation state, which can break usage such as persisting and restoring state. This might happen if you passed non-serializable values such as function, class instances etc. in params. If you need to use components with callbacks in your options, you can use 'navigation.setOptions' instead. See https://reactnavigation.org/docs/en/troubleshooting.html#i-get-the-warning-we-found-non-serializable-values-in-the-navigation-state for more details."
); );
} }
} }

View File

@@ -8,12 +8,19 @@ function StaticContainer(props: any) {
} }
export default React.memo(StaticContainer, (prevProps: any, nextProps: any) => { export default React.memo(StaticContainer, (prevProps: any, nextProps: any) => {
for (const prop in prevProps) { const prevPropKeys = Object.keys(prevProps);
if (prop === 'children') { const nextPropKeys = Object.keys(nextProps);
if (prevPropKeys.length !== nextPropKeys.length) {
return false;
}
for (const key of prevPropKeys) {
if (key === 'children') {
continue; continue;
} }
if (prevProps[prop] !== nextProps[prop]) { if (prevProps[key] !== nextProps[key]) {
return false; return false;
} }
} }

View File

@@ -501,3 +501,51 @@ it('emits state events when the state changes', () => {
], ],
}); });
}); });
it('throws if there is no navigator rendered', () => {
expect.assertions(1);
const ref = React.createRef<NavigationContainerRef>();
const element = <BaseNavigationContainer ref={ref} children={null} />;
render(element);
act(() => {
expect(() => ref.current?.dispatch({ type: 'WHATEVER' })).toThrow(
"The 'navigation' object hasn't been initialized yet."
);
});
});
it("throws if the ref hasn't finished initializing", () => {
expect.assertions(1);
const ref = React.createRef<NavigationContainerRef>();
const TestNavigator = (props: any) => {
const { state, descriptors } = useNavigationBuilder(MockRouter, props);
return descriptors[state.routes[state.index].key].render();
};
const TestScreen = () => {
React.useEffect(() => {
expect(() => ref.current?.dispatch({ type: 'WHATEVER' })).toThrow(
"The 'navigation' object hasn't been initialized yet."
);
}, []);
return null;
};
const element = (
<BaseNavigationContainer ref={ref}>
<TestNavigator>
<Screen name="foo" component={TestScreen} />
</TestNavigator>
</BaseNavigationContainer>
);
render(element);
});

View File

@@ -49,3 +49,27 @@ it('updates element if any props changed', () => {
expect(root).toMatchInlineSnapshot(`"second"`); expect(root).toMatchInlineSnapshot(`"second"`);
}); });
it('updates element if any props are added', () => {
expect.assertions(2);
const Test = ({ label }: any) => {
return label;
};
const root = render(
<StaticContainer count={42}>
<Test label="first" />
</StaticContainer>
);
expect(root).toMatchInlineSnapshot(`"first"`);
root.update(
<StaticContainer count={42} moreCounts={12}>
<Test label="second" />
</StaticContainer>
);
expect(root).toMatchInlineSnapshot(`"second"`);
});

View File

@@ -41,6 +41,43 @@ it('gets navigate action from state', () => {
}, },
type: 'NAVIGATE', type: 'NAVIGATE',
}); });
expect(
getActionFromState({
routes: [
{
name: 'foo',
state: {
routes: [
{
name: 'bar',
state: {
routes: [
{
name: 'qux',
params: { author: 'jane' },
},
{ name: 'quz' },
],
},
},
],
},
},
],
})
).toEqual({
payload: {
name: 'foo',
params: {
screen: 'bar',
params: {
screen: 'quz',
},
},
},
type: 'NAVIGATE',
});
}); });
it('gets reset action from state', () => { it('gets reset action from state', () => {
@@ -53,13 +90,7 @@ it('gets reset action from state', () => {
{ {
name: 'bar', name: 'bar',
state: { state: {
routes: [ routes: [],
{
name: 'qux',
params: { author: 'jane' },
},
{ name: 'quz' },
],
}, },
}, },
], ],
@@ -68,8 +99,6 @@ it('gets reset action from state', () => {
], ],
}; };
expect(getActionFromState(state)).toEqual({ expect(getActionFromState(state)).toBe(undefined);
payload: state, expect(getActionFromState({ routes: [] })).toBe(undefined);
type: 'RESET_ROOT',
});
}); });

View File

@@ -489,3 +489,31 @@ it('handles empty path at the end', () => {
expect(getPathFromState(state, config)).toBe(path); expect(getPathFromState(state, config)).toBe(path);
expect(getPathFromState(getStateFromPath(path, config), config)).toBe(path); expect(getPathFromState(getStateFromPath(path, config), config)).toBe(path);
}); });
it('returns "/" for empty path', () => {
const config = {
Foo: {
path: '',
screens: {
Bar: '',
},
},
};
const state = {
routes: [
{
name: 'Foo',
state: {
routes: [
{
name: 'Bar',
},
],
},
},
],
};
expect(getPathFromState(state, config)).toBe('/');
});

View File

@@ -51,20 +51,55 @@ it('returns false for non-serializable object', () => {
}); });
it('returns false for circular references', () => { it('returns false for circular references', () => {
const o = { const x = {
index: 0, a: 1,
key: '7', b: { b1: 1 },
routeNames: ['foo', 'bar'],
routes: [
{
key: 'foo',
name: 'foo',
},
],
}; };
// @ts-ignore // @ts-ignore
o.routes[0].state = o; x.b.b2 = x;
// @ts-ignore
x.c = x.b;
expect(isSerializable(o)).toBe(false); expect(isSerializable(x)).toBe(false);
const y = [
{
label: 'home',
children: [{ label: 'product' }],
},
{ label: 'about', extend: {} },
];
// @ts-ignore
y[0].children[0].parent = y[0];
// @ts-ignore
y[1].extend.home = y[0].children[0];
expect(isSerializable(y)).toBe(false);
const z = {
name: 'sun',
child: [{ name: 'flower' }],
};
// @ts-ignore
z.child[0].parent = z;
expect(isSerializable(z)).toBe(false);
});
it("doesn't fail if same object used multiple times", () => {
const o = { foo: 'bar' };
expect(
isSerializable({
baz: 'bax',
first: o,
second: o,
stuff: {
b: o,
},
})
).toBe(true);
}); });

View File

@@ -21,7 +21,7 @@ export default function createNavigatorFactory<
> { > {
if (arguments[0] !== undefined) { if (arguments[0] !== undefined) {
throw new Error( throw new Error(
"Creating a navigator doesn't take an argument. Maybe you are trying to use React Navigation 4 API with React Navigation 5? See https://reactnavigation.org/docs/en/hello-react-navigation.html for usage guide." "Creating a navigator doesn't take an argument. Maybe you are trying to use React Navigation 4 API with React Navigation 5? See https://reactnavigation.org/docs/en/upgrading-from-4.x.html for migration guide."
); );
} }

View File

@@ -5,63 +5,50 @@ type NavigateParams = {
params?: NavigateParams; params?: NavigateParams;
}; };
type Action = type NavigateAction = {
| { type: 'NAVIGATE';
type: 'NAVIGATE'; payload: { name: string; params: NavigateParams };
payload: { name: string; params: NavigateParams }; };
}
| {
type: 'RESET_ROOT';
payload: PartialState<NavigationState>;
};
export default function getActionFromState( export default function getActionFromState(
state: PartialState<NavigationState> state: PartialState<NavigationState>
): Action { ): NavigateAction | undefined {
let payload: { name: string; params: NavigateParams } | undefined; if (state.routes.length === 0) {
return undefined;
if (state.routes.length === 1) {
// Try to construct payload for a `NAVIGATE` action from the state
// This lets us preserve the navigation state and not lose it
let route = state.routes[0];
payload = {
name: route.name,
params: { ...route.params },
};
let current = state.routes[0].state;
let params = payload.params;
while (current) {
if (current.routes.length === 1) {
route = current.routes[0];
params.screen = route.name;
if (route.state) {
params.params = { ...route.params };
params = params.params;
} else {
params.params = route.params;
}
current = route.state;
} else {
payload = undefined;
break;
}
}
} }
if (payload) { // Try to construct payload for a `NAVIGATE` action from the state
return { // This lets us preserve the navigation state and not lose it
type: 'NAVIGATE', let route = state.routes[state.routes.length - 1];
payload,
}; let payload: { name: string; params: NavigateParams } = {
name: route.name,
params: { ...route.params },
};
let current = route.state;
let params = payload.params;
while (current) {
if (current.routes.length === 0) {
return undefined;
}
route = current.routes[current.routes.length - 1];
params.screen = route.name;
if (route.state) {
params.params = { ...route.params };
params = params.params;
} else {
params.params = route.params;
}
current = route.state;
} }
return { return {
type: 'RESET_ROOT', type: 'NAVIGATE',
payload: state, payload,
}; };
} }

View File

@@ -158,6 +158,10 @@ export default function getPathFromState(
current = route.state; current = route.state;
} }
path = path.slice(path.length - 1) === '/' ? path.slice(0, -1) : path; path =
path !== '/' && path.slice(path.length - 1) === '/'
? path.slice(0, -1)
: path;
return path; return path;
} }

View File

@@ -1,6 +1,6 @@
const isSerializableWithoutCircularReference = ( const isSerializableWithoutCircularReference = (
o: { [key: string]: any }, o: { [key: string]: any },
seen = new Set<any>() seen: Set<any>
): boolean => { ): boolean => {
if ( if (
o === undefined || o === undefined ||
@@ -27,13 +27,13 @@ const isSerializableWithoutCircularReference = (
if (Array.isArray(o)) { if (Array.isArray(o)) {
for (const it of o) { for (const it of o) {
if (!isSerializableWithoutCircularReference(it, seen)) { if (!isSerializableWithoutCircularReference(it, new Set<any>(seen))) {
return false; return false;
} }
} }
} else { } else {
for (const key in o) { for (const key in o) {
if (!isSerializableWithoutCircularReference(o[key], seen)) { if (!isSerializableWithoutCircularReference(o[key], new Set<any>(seen))) {
return false; return false;
} }
} }
@@ -43,5 +43,5 @@ const isSerializableWithoutCircularReference = (
}; };
export default function isSerializable(o: { [key: string]: any }) { export default function isSerializable(o: { [key: string]: any }) {
return isSerializableWithoutCircularReference(o); return isSerializableWithoutCircularReference(o, new Set<any>());
} }

View File

@@ -3,6 +3,30 @@
All notable changes to this project will be documented in this file. All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [5.0.5](https://github.com/react-navigation/react-navigation/tree/master/packages/drawer/compare/@react-navigation/drawer@5.0.4...@react-navigation/drawer@5.0.5) (2020-02-14)
**Note:** Version bump only for package @react-navigation/drawer
## [5.0.4](https://github.com/react-navigation/react-navigation/tree/master/packages/drawer/compare/@react-navigation/drawer@5.0.3...@react-navigation/drawer@5.0.4) (2020-02-14)
**Note:** Version bump only for package @react-navigation/drawer
## [5.0.3](https://github.com/react-navigation/react-navigation/tree/master/packages/drawer/compare/@react-navigation/drawer@5.0.2...@react-navigation/drawer@5.0.3) (2020-02-12)
**Note:** Version bump only for package @react-navigation/drawer
## [5.0.2](https://github.com/react-navigation/react-navigation/tree/master/packages/drawer/compare/@react-navigation/drawer@5.0.1...@react-navigation/drawer@5.0.2) (2020-02-11) ## [5.0.2](https://github.com/react-navigation/react-navigation/tree/master/packages/drawer/compare/@react-navigation/drawer@5.0.1...@react-navigation/drawer@5.0.2) (2020-02-11)

View File

@@ -1,7 +1,7 @@
{ {
"name": "@react-navigation/drawer", "name": "@react-navigation/drawer",
"description": "Drawer navigator component with animated transitions and gesturess", "description": "Drawer navigator component with animated transitions and gesturess",
"version": "5.0.2", "version": "5.0.4",
"keywords": [ "keywords": [
"react-native-component", "react-native-component",
"react-component", "react-component",
@@ -40,7 +40,7 @@
}, },
"devDependencies": { "devDependencies": {
"@react-native-community/bob": "^0.9.3", "@react-native-community/bob": "^0.9.3",
"@react-navigation/native": "^5.0.2", "@react-navigation/native": "^5.0.4",
"@types/react": "^16.9.19", "@types/react": "^16.9.19",
"@types/react-native": "^0.60.30", "@types/react-native": "^0.60.30",
"del-cli": "^3.0.0", "del-cli": "^3.0.0",
@@ -56,10 +56,10 @@
"@react-navigation/native": "^5.0.0", "@react-navigation/native": "^5.0.0",
"react": "*", "react": "*",
"react-native": "*", "react-native": "*",
"react-native-gesture-handler": "^1.0.0", "react-native-gesture-handler": ">= 1.0.0",
"react-native-reanimated": "^1.0.0", "react-native-reanimated": ">= 1.0.0",
"react-native-safe-area-context": "^0.6.0", "react-native-safe-area-context": ">= 0.6.0",
"react-native-screens": "^2.0.0-alpha.33" "react-native-screens": ">= 2.0.0-alpha.0 || >= 2.0.0-beta.0"
}, },
"@react-native-community/bob": { "@react-native-community/bob": {
"source": "src", "source": "src",

View File

@@ -3,6 +3,30 @@
All notable changes to this project will be documented in this file. All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [5.0.5](https://github.com/react-navigation/react-navigation/tree/master/packages/material-bottom-tabs/compare/@react-navigation/material-bottom-tabs@5.0.4...@react-navigation/material-bottom-tabs@5.0.5) (2020-02-14)
**Note:** Version bump only for package @react-navigation/material-bottom-tabs
## [5.0.4](https://github.com/react-navigation/react-navigation/tree/master/packages/material-bottom-tabs/compare/@react-navigation/material-bottom-tabs@5.0.3...@react-navigation/material-bottom-tabs@5.0.4) (2020-02-14)
**Note:** Version bump only for package @react-navigation/material-bottom-tabs
## [5.0.3](https://github.com/react-navigation/react-navigation/tree/master/packages/material-bottom-tabs/compare/@react-navigation/material-bottom-tabs@5.0.2...@react-navigation/material-bottom-tabs@5.0.3) (2020-02-12)
**Note:** Version bump only for package @react-navigation/material-bottom-tabs
## [5.0.2](https://github.com/react-navigation/react-navigation/tree/master/packages/material-bottom-tabs/compare/@react-navigation/material-bottom-tabs@5.0.1...@react-navigation/material-bottom-tabs@5.0.2) (2020-02-11) ## [5.0.2](https://github.com/react-navigation/react-navigation/tree/master/packages/material-bottom-tabs/compare/@react-navigation/material-bottom-tabs@5.0.1...@react-navigation/material-bottom-tabs@5.0.2) (2020-02-11)
**Note:** Version bump only for package @react-navigation/material-bottom-tabs **Note:** Version bump only for package @react-navigation/material-bottom-tabs

View File

@@ -1,7 +1,7 @@
{ {
"name": "@react-navigation/material-bottom-tabs", "name": "@react-navigation/material-bottom-tabs",
"description": "Integration for bottom navigation component from react-native-paper", "description": "Integration for bottom navigation component from react-native-paper",
"version": "5.0.2", "version": "5.0.4",
"keywords": [ "keywords": [
"react-native-component", "react-native-component",
"react-component", "react-component",
@@ -36,7 +36,7 @@
}, },
"devDependencies": { "devDependencies": {
"@react-native-community/bob": "^0.9.3", "@react-native-community/bob": "^0.9.3",
"@react-navigation/native": "^5.0.2", "@react-navigation/native": "^5.0.4",
"@types/react": "^16.9.19", "@types/react": "^16.9.19",
"@types/react-native": "^0.60.30", "@types/react-native": "^0.60.30",
"@types/react-native-vector-icons": "^6.4.5", "@types/react-native-vector-icons": "^6.4.5",
@@ -51,8 +51,8 @@
"@react-navigation/native": "^5.0.0", "@react-navigation/native": "^5.0.0",
"react": "*", "react": "*",
"react-native": "*", "react-native": "*",
"react-native-paper": "^3.5.0", "react-native-paper": ">= 3.0.0",
"react-native-vector-icons": "^6.0.0" "react-native-vector-icons": ">= 6.0.0"
}, },
"@react-native-community/bob": { "@react-native-community/bob": {
"source": "src", "source": "src",

View File

@@ -3,6 +3,30 @@
All notable changes to this project will be documented in this file. All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [5.0.5](https://github.com/react-navigation/react-navigation/tree/master/packages/material-top-tabs/compare/@react-navigation/material-top-tabs@5.0.4...@react-navigation/material-top-tabs@5.0.5) (2020-02-14)
**Note:** Version bump only for package @react-navigation/material-top-tabs
## [5.0.4](https://github.com/react-navigation/react-navigation/tree/master/packages/material-top-tabs/compare/@react-navigation/material-top-tabs@5.0.3...@react-navigation/material-top-tabs@5.0.4) (2020-02-14)
**Note:** Version bump only for package @react-navigation/material-top-tabs
## [5.0.3](https://github.com/react-navigation/react-navigation/tree/master/packages/material-top-tabs/compare/@react-navigation/material-top-tabs@5.0.2...@react-navigation/material-top-tabs@5.0.3) (2020-02-12)
**Note:** Version bump only for package @react-navigation/material-top-tabs
## [5.0.2](https://github.com/react-navigation/react-navigation/tree/master/packages/material-top-tabs/compare/@react-navigation/material-top-tabs@5.0.1...@react-navigation/material-top-tabs@5.0.2) (2020-02-11) ## [5.0.2](https://github.com/react-navigation/react-navigation/tree/master/packages/material-top-tabs/compare/@react-navigation/material-top-tabs@5.0.1...@react-navigation/material-top-tabs@5.0.2) (2020-02-11)
**Note:** Version bump only for package @react-navigation/material-top-tabs **Note:** Version bump only for package @react-navigation/material-top-tabs

View File

@@ -1,7 +1,7 @@
{ {
"name": "@react-navigation/material-top-tabs", "name": "@react-navigation/material-top-tabs",
"description": "Integration for the animated tab view component from react-native-tab-view", "description": "Integration for the animated tab view component from react-native-tab-view",
"version": "5.0.2", "version": "5.0.4",
"keywords": [ "keywords": [
"react-native-component", "react-native-component",
"react-component", "react-component",
@@ -39,7 +39,7 @@
}, },
"devDependencies": { "devDependencies": {
"@react-native-community/bob": "^0.9.3", "@react-native-community/bob": "^0.9.3",
"@react-navigation/native": "^5.0.2", "@react-navigation/native": "^5.0.4",
"@types/react": "^16.9.19", "@types/react": "^16.9.19",
"@types/react-native": "^0.60.30", "@types/react-native": "^0.60.30",
"del-cli": "^3.0.0", "del-cli": "^3.0.0",
@@ -54,9 +54,9 @@
"@react-navigation/native": "^5.0.0", "@react-navigation/native": "^5.0.0",
"react": "*", "react": "*",
"react-native": "*", "react-native": "*",
"react-native-gesture-handler": "^1.0.0", "react-native-gesture-handler": ">= 1.0.0",
"react-native-reanimated": "^1.0.0", "react-native-reanimated": ">= 1.0.0",
"react-native-tab-view": "^2.13.0" "react-native-tab-view": ">= 2.0.0"
}, },
"@react-native-community/bob": { "@react-native-community/bob": {
"source": "src", "source": "src",

View File

@@ -3,6 +3,30 @@
All notable changes to this project will be documented in this file. All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [5.0.5](https://github.com/react-navigation/react-navigation/tree/master/packages/native-stack/compare/@react-navigation/native-stack@5.0.4...@react-navigation/native-stack@5.0.5) (2020-02-14)
**Note:** Version bump only for package @react-navigation/native-stack
## [5.0.4](https://github.com/react-navigation/react-navigation/tree/master/packages/native-stack/compare/@react-navigation/native-stack@5.0.3...@react-navigation/native-stack@5.0.4) (2020-02-14)
**Note:** Version bump only for package @react-navigation/native-stack
## [5.0.3](https://github.com/react-navigation/react-navigation/tree/master/packages/native-stack/compare/@react-navigation/native-stack@5.0.2...@react-navigation/native-stack@5.0.3) (2020-02-12)
**Note:** Version bump only for package @react-navigation/native-stack
## [5.0.2](https://github.com/react-navigation/react-navigation/tree/master/packages/native-stack/compare/@react-navigation/native-stack@5.0.1...@react-navigation/native-stack@5.0.2) (2020-02-11) ## [5.0.2](https://github.com/react-navigation/react-navigation/tree/master/packages/native-stack/compare/@react-navigation/native-stack@5.0.1...@react-navigation/native-stack@5.0.2) (2020-02-11)
**Note:** Version bump only for package @react-navigation/native-stack **Note:** Version bump only for package @react-navigation/native-stack

View File

@@ -1,7 +1,7 @@
{ {
"name": "@react-navigation/native-stack", "name": "@react-navigation/native-stack",
"description": "Native stack navigator component for iOS and Android", "description": "Native stack navigator component for iOS and Android",
"version": "5.0.2", "version": "5.0.4",
"keywords": [ "keywords": [
"react", "react",
"react-native", "react-native",
@@ -31,16 +31,16 @@
}, },
"devDependencies": { "devDependencies": {
"@react-native-community/bob": "^0.9.3", "@react-native-community/bob": "^0.9.3",
"@react-navigation/native": "^5.0.2", "@react-navigation/native": "^5.0.4",
"del-cli": "^3.0.0", "del-cli": "^3.0.0",
"react-native-screens": "^2.0.0-beta.2", "react-native-screens": "^2.0.0-beta.2",
"typescript": "^3.7.5" "typescript": "^3.7.5"
}, },
"peerDependencies": { "peerDependencies": {
"@react-navigation/native": "^5.0.0", "@react-navigation/native": ">= 5.0.0",
"react": "*", "react": "*",
"react-native": "*", "react-native": "*",
"react-native-screens": "^2.0.0-alpha.33" "react-native-screens": ">= 2.0.0-alpha.0 || >= 2.0.0-beta.0"
}, },
"@react-native-community/bob": { "@react-native-community/bob": {
"source": "src", "source": "src",

View File

@@ -3,6 +3,30 @@
All notable changes to this project will be documented in this file. All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [5.0.5](https://github.com/react-navigation/react-navigation/tree/master/packages/native/compare/@react-navigation/native@5.0.4...@react-navigation/native@5.0.5) (2020-02-14)
**Note:** Version bump only for package @react-navigation/native
## [5.0.4](https://github.com/react-navigation/react-navigation/tree/master/packages/native/compare/@react-navigation/native@5.0.3...@react-navigation/native@5.0.4) (2020-02-14)
**Note:** Version bump only for package @react-navigation/native
## [5.0.3](https://github.com/react-navigation/react-navigation/tree/master/packages/native/compare/@react-navigation/native@5.0.2...@react-navigation/native@5.0.3) (2020-02-12)
**Note:** Version bump only for package @react-navigation/native
## [5.0.2](https://github.com/react-navigation/react-navigation/tree/master/packages/native/compare/@react-navigation/native@5.0.1...@react-navigation/native@5.0.2) (2020-02-11) ## [5.0.2](https://github.com/react-navigation/react-navigation/tree/master/packages/native/compare/@react-navigation/native@5.0.1...@react-navigation/native@5.0.2) (2020-02-11)

View File

@@ -1,7 +1,7 @@
{ {
"name": "@react-navigation/native", "name": "@react-navigation/native",
"description": "React Native integration for React Navigation", "description": "React Native integration for React Navigation",
"version": "5.0.2", "version": "5.0.4",
"keywords": [ "keywords": [
"react-native", "react-native",
"react-navigation", "react-navigation",
@@ -31,7 +31,7 @@
"clean": "del lib" "clean": "del lib"
}, },
"dependencies": { "dependencies": {
"@react-navigation/core": "^5.1.1" "@react-navigation/core": "^5.1.3"
}, },
"devDependencies": { "devDependencies": {
"@react-native-community/bob": "^0.9.3", "@react-native-community/bob": "^0.9.3",

View File

@@ -76,10 +76,10 @@ export default function useLinking(
if (state) { if (state) {
const action = getActionFromState(state); const action = getActionFromState(state);
if (action.type === 'RESET_ROOT') { if (action !== undefined) {
navigation.resetRoot(action.payload);
} else {
navigation.dispatch(action); navigation.dispatch(action);
} else {
navigation.resetRoot(state);
} }
} }
} }

View File

@@ -162,10 +162,10 @@ export default function useLinking(
pendingStateUpdateRef.current = true; pendingStateUpdateRef.current = true;
if (action.type === 'RESET_ROOT') { if (action !== undefined) {
navigation.resetRoot(action.payload);
} else {
navigation.dispatch(action); navigation.dispatch(action);
} else {
navigation.resetRoot(state);
} }
} }
} }

View File

@@ -3,6 +3,36 @@
All notable changes to this project will be documented in this file. All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [5.0.5](https://github.com/react-navigation/react-navigation/tree/master/packages/stack/compare/@react-navigation/stack@5.0.4...@react-navigation/stack@5.0.5) (2020-02-14)
**Note:** Version bump only for package @react-navigation/stack
## [5.0.4](https://github.com/react-navigation/react-navigation/tree/master/packages/stack/compare/@react-navigation/stack@5.0.3...@react-navigation/stack@5.0.4) (2020-02-14)
### Bug Fixes
* hard code header height for animation ([8f40a98](https://github.com/react-navigation/react-navigation/tree/master/packages/stack/commit/8f40a980862a182a9e86dbb1e4764a39d824cd70)), closes [#6818](https://github.com/react-navigation/react-navigation/tree/master/packages/stack/issues/6818)
## [5.0.3](https://github.com/react-navigation/react-navigation/tree/master/packages/stack/compare/@react-navigation/stack@5.0.2...@react-navigation/stack@5.0.3) (2020-02-12)
### Bug Fixes
* check if we can go baack before dispatching pop ([6c9447a](https://github.com/react-navigation/react-navigation/tree/master/packages/stack/commit/6c9447a38c74ca029fc9def8aca0a2d2cca9639c))
## [5.0.2](https://github.com/react-navigation/react-navigation/tree/master/packages/stack/compare/@react-navigation/stack@5.0.1...@react-navigation/stack@5.0.2) (2020-02-11) ## [5.0.2](https://github.com/react-navigation/react-navigation/tree/master/packages/stack/compare/@react-navigation/stack@5.0.1...@react-navigation/stack@5.0.2) (2020-02-11)

View File

@@ -1,7 +1,7 @@
{ {
"name": "@react-navigation/stack", "name": "@react-navigation/stack",
"description": "Stack navigator component for iOS and Android with animated transitions and gestures", "description": "Stack navigator component for iOS and Android with animated transitions and gestures",
"version": "5.0.2", "version": "5.0.4",
"keywords": [ "keywords": [
"react-native-component", "react-native-component",
"react-component", "react-component",
@@ -40,7 +40,7 @@
"devDependencies": { "devDependencies": {
"@react-native-community/bob": "^0.9.3", "@react-native-community/bob": "^0.9.3",
"@react-native-community/masked-view": "^0.1.6", "@react-native-community/masked-view": "^0.1.6",
"@react-navigation/native": "^5.0.2", "@react-navigation/native": "^5.0.4",
"@types/color": "^3.0.1", "@types/color": "^3.0.1",
"@types/react": "^16.9.19", "@types/react": "^16.9.19",
"@types/react-native": "^0.60.30", "@types/react-native": "^0.60.30",
@@ -53,13 +53,13 @@
"typescript": "^3.7.5" "typescript": "^3.7.5"
}, },
"peerDependencies": { "peerDependencies": {
"@react-native-community/masked-view": "^0.1.1", "@react-native-community/masked-view": ">= 0.1.0",
"@react-navigation/native": "^5.0.0", "@react-navigation/native": "^5.0.0",
"react": "*", "react": "*",
"react-native": "*", "react-native": "*",
"react-native-gesture-handler": "^1.0.0", "react-native-gesture-handler": ">= 1.0.0",
"react-native-safe-area-context": "^0.6.0", "react-native-safe-area-context": ">= 0.6.0",
"react-native-screens": "^2.0.0-alpha.33" "react-native-screens": ">= 2.0.0-alpha.0 || >= 2.0.0-beta.0"
}, },
"@react-native-community/bob": { "@react-native-community/bob": {
"source": "src", "source": "src",

View File

@@ -230,6 +230,7 @@ export function forSlideRight({
export function forSlideUp({ export function forSlideUp({
current, current,
next, next,
layouts: { header },
}: StackHeaderInterpolationProps): StackHeaderInterpolatedStyle { }: StackHeaderInterpolationProps): StackHeaderInterpolatedStyle {
const progress = add( const progress = add(
current.progress.interpolate({ current.progress.interpolate({
@@ -248,7 +249,7 @@ export function forSlideUp({
const translateY = progress.interpolate({ const translateY = progress.interpolate({
inputRange: [0, 1, 2], inputRange: [0, 1, 2],
outputRange: ['-100%', '0%', '-100%'], outputRange: [-header.height, 0, -header.height],
}); });
const transform = [{ translateY }]; const transform = [{ translateY }];

View File

@@ -548,6 +548,10 @@ export type StackHeaderInterpolationProps = {
* Layout measurements for various items we use for animation. * Layout measurements for various items we use for animation.
*/ */
layouts: { layouts: {
/**
* Layout of the header
*/
header: Layout;
/** /**
* Layout of the whole screen. * Layout of the whole screen.
*/ */

View File

@@ -55,11 +55,14 @@ export default React.memo(function Header(props: StackHeaderProps) {
} }
onGoBack={ onGoBack={
previous previous
? () => ? () => {
navigation.dispatch({ if (navigation.canGoBack()) {
...StackActions.pop(), navigation.dispatch({
source: scene.route.key, ...StackActions.pop(),
}) source: scene.route.key,
});
}
}
: undefined : undefined
} }
styleInterpolator={styleInterpolator} styleInterpolator={styleInterpolator}

View File

@@ -56,7 +56,7 @@ const warnIfHeaderStylesDefined = (styles: Record<string, any>) => {
export const getDefaultHeaderHeight = ( export const getDefaultHeaderHeight = (
layout: Layout, layout: Layout,
statusBarHeight: number statusBarHeight: number
) => { ): number => {
const isLandscape = layout.width > layout.height; const isLandscape = layout.width > layout.height;
let headerHeight; let headerHeight;
@@ -120,12 +120,17 @@ export default class HeaderSegment extends React.Component<Props, State> {
current: Animated.AnimatedInterpolation, current: Animated.AnimatedInterpolation,
next: Animated.AnimatedInterpolation | undefined, next: Animated.AnimatedInterpolation | undefined,
titleLayout: Layout | undefined, titleLayout: Layout | undefined,
leftLabelLayout: Layout | undefined leftLabelLayout: Layout | undefined,
headerHeight: number
) => ) =>
styleInterpolator({ styleInterpolator({
current: { progress: current }, current: { progress: current },
next: next && { progress: next }, next: next && { progress: next },
layouts: { layouts: {
header: {
height: headerHeight,
width: layout.width,
},
screen: layout, screen: layout,
title: titleLayout, title: titleLayout,
leftLabel: leftLabelLayout, leftLabel: leftLabelLayout,
@@ -172,23 +177,10 @@ export default class HeaderSegment extends React.Component<Props, State> {
const { leftLabelLayout, titleLayout } = this.state; const { leftLabelLayout, titleLayout } = this.state;
const { const defaultHeight = getDefaultHeaderHeight(layout, headerStatusBarHeight);
titleStyle,
leftButtonStyle,
leftLabelStyle,
rightButtonStyle,
backgroundStyle,
} = this.getInterpolatedStyle(
styleInterpolator,
layout,
scene.progress.current,
scene.progress.next,
titleLayout,
previousTitle ? leftLabelLayout : undefined
);
const { const {
height = getDefaultHeaderHeight(layout, headerStatusBarHeight), height = defaultHeight,
minHeight, minHeight,
maxHeight, maxHeight,
backgroundColor, backgroundColor,
@@ -281,6 +273,22 @@ export default class HeaderSegment extends React.Component<Props, State> {
} }
} }
const {
titleStyle,
leftButtonStyle,
leftLabelStyle,
rightButtonStyle,
backgroundStyle,
} = this.getInterpolatedStyle(
styleInterpolator,
layout,
scene.progress.current,
scene.progress.next,
titleLayout,
previousTitle ? leftLabelLayout : undefined,
typeof height === 'number' ? height : defaultHeight
);
const leftButton = left const leftButton = left
? left({ ? left({
backImage, backImage,