mirror of
https://github.com/zhigang1992/react-navigation.git
synced 2026-01-14 22:41:55 +08:00
Compare commits
11 Commits
@react-nav
...
@react-nav
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3aaf6eb648 | ||
|
|
477c08858d | ||
|
|
300791ab49 | ||
|
|
3e92e22941 | ||
|
|
a543f1bfc3 | ||
|
|
cd5f355bd0 | ||
|
|
cab616069f | ||
|
|
f90e00cc93 | ||
|
|
731cf7d5b1 | ||
|
|
c6d0c19b49 | ||
|
|
442b95d9e4 |
@@ -3,6 +3,22 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
# [5.0.0-alpha.16](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/core@5.0.0-alpha.15...@react-navigation/core@5.0.0-alpha.16) (2019-10-18)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* rehydrate state before using it ([3e92e22](https://github.com/react-navigation/navigation-ex/commit/3e92e22))
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* make it easier to navigate to a specific route in navigator ([#114](https://github.com/react-navigation/navigation-ex/issues/114)) ([a543f1b](https://github.com/react-navigation/navigation-ex/commit/a543f1b)), closes [#90](https://github.com/react-navigation/navigation-ex/issues/90)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# [5.0.0-alpha.15](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/core@5.0.0-alpha.14...@react-navigation/core@5.0.0-alpha.15) (2019-10-15)
|
||||
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
"react-native",
|
||||
"react-navigation"
|
||||
],
|
||||
"version": "5.0.0-alpha.15",
|
||||
"version": "5.0.0-alpha.16",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
||||
@@ -108,7 +108,24 @@ export default function MockRouter(options: DefaultRouterOptions) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return { ...state, index };
|
||||
return {
|
||||
...state,
|
||||
index,
|
||||
routes:
|
||||
action.payload.params !== undefined
|
||||
? state.routes.map((route, i) =>
|
||||
i === index
|
||||
? {
|
||||
...route,
|
||||
params: {
|
||||
...route.params,
|
||||
...action.payload.params,
|
||||
},
|
||||
}
|
||||
: route
|
||||
)
|
||||
: state.routes,
|
||||
};
|
||||
}
|
||||
|
||||
default:
|
||||
|
||||
@@ -5,7 +5,7 @@ import NavigationContainer from '../NavigationContainer';
|
||||
import useNavigationBuilder from '../useNavigationBuilder';
|
||||
import useNavigation from '../useNavigation';
|
||||
import MockRouter, { MockRouterKey } from './__fixtures__/MockRouter';
|
||||
import { NavigationState } from '../types';
|
||||
import { NavigationState, NavigationContainerRef } from '../types';
|
||||
|
||||
beforeEach(() => (MockRouterKey.current = 0));
|
||||
|
||||
@@ -523,6 +523,80 @@ it('handles change in route names', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('navigates to nested child in a navigator', () => {
|
||||
const TestNavigator = (props: any): any => {
|
||||
const { state, descriptors } = useNavigationBuilder(MockRouter, props);
|
||||
|
||||
return descriptors[state.routes[state.index].key].render();
|
||||
};
|
||||
|
||||
const TestComponent = ({ route }: any): any =>
|
||||
`[${route.name}, ${JSON.stringify(route.params)}]`;
|
||||
|
||||
const onStateChange = jest.fn();
|
||||
|
||||
const navigation = React.createRef<NavigationContainerRef>();
|
||||
|
||||
const element = render(
|
||||
<NavigationContainer ref={navigation} onStateChange={onStateChange}>
|
||||
<TestNavigator>
|
||||
<Screen name="foo">
|
||||
{() => (
|
||||
<TestNavigator>
|
||||
<Screen name="foo-a" component={TestComponent} />
|
||||
<Screen name="foo-b" component={TestComponent} />
|
||||
</TestNavigator>
|
||||
)}
|
||||
</Screen>
|
||||
<Screen name="bar">
|
||||
{() => (
|
||||
<TestNavigator initialRouteName="bar-a">
|
||||
<Screen
|
||||
name="bar-a"
|
||||
component={TestComponent}
|
||||
initialParams={{ lol: 'why' }}
|
||||
/>
|
||||
<Screen
|
||||
name="bar-b"
|
||||
component={TestComponent}
|
||||
initialParams={{ some: 'stuff' }}
|
||||
/>
|
||||
</TestNavigator>
|
||||
)}
|
||||
</Screen>
|
||||
</TestNavigator>
|
||||
</NavigationContainer>
|
||||
);
|
||||
|
||||
expect(element).toMatchInlineSnapshot(`"[foo-a, undefined]"`);
|
||||
|
||||
act(
|
||||
() =>
|
||||
navigation.current &&
|
||||
navigation.current.navigate('bar', {
|
||||
screen: 'bar-b',
|
||||
params: { test: 42 },
|
||||
})
|
||||
);
|
||||
|
||||
expect(element).toMatchInlineSnapshot(
|
||||
`"[bar-b, {\\"some\\":\\"stuff\\",\\"test\\":42}]"`
|
||||
);
|
||||
|
||||
act(
|
||||
() =>
|
||||
navigation.current &&
|
||||
navigation.current.navigate('bar', {
|
||||
screen: 'bar-a',
|
||||
params: { whoa: 'test' },
|
||||
})
|
||||
);
|
||||
|
||||
expect(element).toMatchInlineSnapshot(
|
||||
`"[bar-a, {\\"lol\\":\\"why\\",\\"whoa\\":\\"test\\"}]"`
|
||||
);
|
||||
});
|
||||
|
||||
it('gives access to internal state', () => {
|
||||
const TestNavigator = (props: any): any => {
|
||||
const { state, descriptors } = useNavigationBuilder(MockRouter, props);
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import * as React from 'react';
|
||||
import { NavigationStateContext } from './NavigationContainer';
|
||||
import NavigationRouteContext from './NavigationRouteContext';
|
||||
import Screen from './Screen';
|
||||
import { navigate } from './CommonActions';
|
||||
import useEventEmitter from './useEventEmitter';
|
||||
import useRegisterNavigator from './useRegisterNavigator';
|
||||
import useDescriptors from './useDescriptors';
|
||||
@@ -30,6 +32,13 @@ import useOnGetState from './useOnGetState';
|
||||
// eslint-disable-next-line babel/no-unused-expressions
|
||||
PrivateValueStore;
|
||||
|
||||
type NavigatorRoute = {
|
||||
params?: {
|
||||
screen?: string;
|
||||
params?: object;
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Compare two arrays with primitive values as the content.
|
||||
* We need to make sure that both values and order match.
|
||||
@@ -96,9 +105,24 @@ export default function useNavigationBuilder<
|
||||
) {
|
||||
useRegisterNavigator();
|
||||
|
||||
const route = React.useContext(NavigationRouteContext) as (
|
||||
| NavigatorRoute
|
||||
| undefined);
|
||||
|
||||
const previousRouteRef = React.useRef(route);
|
||||
|
||||
React.useEffect(() => {
|
||||
previousRouteRef.current = route;
|
||||
}, [route]);
|
||||
|
||||
const { children, ...rest } = options;
|
||||
const { current: router } = React.useRef<Router<State, any>>(
|
||||
createRouter((rest as unknown) as RouterOptions)
|
||||
createRouter({
|
||||
...((rest as unknown) as RouterOptions),
|
||||
...(route && route.params && typeof route.params.screen === 'string'
|
||||
? { initialRouteName: route.params.screen }
|
||||
: null),
|
||||
})
|
||||
);
|
||||
|
||||
const screens = getRouteConfigsFromChildren<ScreenOptions>(children).reduce(
|
||||
@@ -118,7 +142,20 @@ export default function useNavigationBuilder<
|
||||
const routeNames = Object.keys(screens);
|
||||
const routeParamList = routeNames.reduce(
|
||||
(acc, curr) => {
|
||||
acc[curr] = screens[curr].initialParams;
|
||||
const { initialParams } = screens[curr];
|
||||
const initialParamsFromParams =
|
||||
route && route.params && route.params.screen === curr
|
||||
? route.params.params
|
||||
: undefined;
|
||||
|
||||
acc[curr] =
|
||||
initialParams !== undefined || initialParamsFromParams !== undefined
|
||||
? {
|
||||
...initialParams,
|
||||
...initialParamsFromParams,
|
||||
}
|
||||
: undefined;
|
||||
|
||||
return acc;
|
||||
},
|
||||
{} as { [key: string]: object | undefined }
|
||||
@@ -175,28 +212,53 @@ export default function useNavigationBuilder<
|
||||
? (initializedStateRef.current as State)
|
||||
: (currentState as State);
|
||||
|
||||
let nextState: State = state;
|
||||
|
||||
if (!isArrayEqual(state.routeNames, routeNames)) {
|
||||
// When the list of route names change, the router should handle it to remove invalid routes
|
||||
const nextState = router.getStateForRouteNamesChange(state, {
|
||||
nextState = router.getStateForRouteNamesChange(state, {
|
||||
routeNames,
|
||||
routeParamList,
|
||||
});
|
||||
|
||||
if (state !== nextState) {
|
||||
// If the state needs to be updated, we'll schedule an update with React
|
||||
// setState in render seems hacky, but that's how React docs implement getDerivedPropsFromState
|
||||
// https://reactjs.org/docs/hooks-faq.html#how-do-i-implement-getderivedstatefromprops
|
||||
performTransaction(() => {
|
||||
setState(nextState);
|
||||
});
|
||||
}
|
||||
|
||||
// The up-to-date state will come in next render, but we don't need to wait for it
|
||||
// We can't use the outdated state since the screens have changed, which will cause error due to mismatched config
|
||||
// So we override the state objec we return to use the latest state as soon as possible
|
||||
state = nextState;
|
||||
}
|
||||
|
||||
if (
|
||||
previousRouteRef.current &&
|
||||
route &&
|
||||
route.params &&
|
||||
typeof route.params.screen === 'string' &&
|
||||
route.params !== previousRouteRef.current.params
|
||||
) {
|
||||
// If the route was updated with new name and/or params, we should navigate there
|
||||
// The update should be limited to current navigator only, so we call the router manually
|
||||
const updatedState = router.getStateForAction(
|
||||
state,
|
||||
navigate(route.params.screen, route.params.params)
|
||||
);
|
||||
|
||||
nextState =
|
||||
updatedState !== null
|
||||
? router.getRehydratedState(updatedState, {
|
||||
routeNames,
|
||||
routeParamList,
|
||||
})
|
||||
: state;
|
||||
}
|
||||
|
||||
if (state !== nextState) {
|
||||
// If the state needs to be updated, we'll schedule an update with React
|
||||
// setState in render seems hacky, but that's how React docs implement getDerivedPropsFromState
|
||||
// https://reactjs.org/docs/hooks-faq.html#how-do-i-implement-getderivedstatefromprops
|
||||
performTransaction(() => {
|
||||
setState(nextState);
|
||||
});
|
||||
}
|
||||
|
||||
// The up-to-date state will come in next render, but we don't need to wait for it
|
||||
// We can't use the outdated state since the screens have changed, which will cause error due to mismatched config
|
||||
// So we override the state objec we return to use the latest state as soon as possible
|
||||
state = nextState;
|
||||
|
||||
React.useEffect(() => {
|
||||
return () => {
|
||||
// We need to clean up state for this navigator on unmount
|
||||
|
||||
@@ -3,6 +3,17 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
# [5.0.0-alpha.15](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/drawer@5.0.0-alpha.14...@react-navigation/drawer@5.0.0-alpha.15) (2019-10-17)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* fix passing content options in drawer ([cab6160](https://github.com/react-navigation/navigation-ex/commit/cab6160))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# [5.0.0-alpha.14](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/drawer@5.0.0-alpha.13...@react-navigation/drawer@5.0.0-alpha.14) (2019-10-15)
|
||||
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
"material",
|
||||
"drawer"
|
||||
],
|
||||
"version": "5.0.0-alpha.14",
|
||||
"version": "5.0.0-alpha.15",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
||||
@@ -136,6 +136,7 @@ export default class DrawerView extends React.PureComponent<Props, State> {
|
||||
descriptors,
|
||||
drawerPosition,
|
||||
contentComponent: ContentComponent,
|
||||
contentOptions,
|
||||
} = this.props;
|
||||
|
||||
return (
|
||||
@@ -145,6 +146,7 @@ export default class DrawerView extends React.PureComponent<Props, State> {
|
||||
navigation={navigation}
|
||||
descriptors={descriptors}
|
||||
drawerPosition={drawerPosition}
|
||||
{...contentOptions}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -3,6 +3,14 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
# [5.0.0-alpha.14](https://github.com/satya164/navigation-ex/compare/@react-navigation/example@5.0.0-alpha.13...@react-navigation/example@5.0.0-alpha.14) (2019-10-17)
|
||||
|
||||
**Note:** Version bump only for package @react-navigation/example
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# [5.0.0-alpha.13](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/example@5.0.0-alpha.12...@react-navigation/example@5.0.0-alpha.13) (2019-10-15)
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@react-navigation/example",
|
||||
"description": "Demo app to showcase various functionality of React Navigation",
|
||||
"version": "5.0.0-alpha.13",
|
||||
"version": "5.0.0-alpha.14",
|
||||
"private": true,
|
||||
"workspaces": {
|
||||
"nohoist": [
|
||||
@@ -27,7 +27,7 @@
|
||||
"react-dom": "~16.8.3",
|
||||
"react-native": "~0.59.10",
|
||||
"react-native-gesture-handler": "~1.3.0",
|
||||
"react-native-paper": "^3.0.0-alpha.3",
|
||||
"react-native-paper": "^3.0.0-alpha.7",
|
||||
"react-native-reanimated": "~1.2.0",
|
||||
"react-native-safe-area-context": "~0.3.6",
|
||||
"react-native-screens": "2.0.0-alpha.4",
|
||||
|
||||
@@ -3,6 +3,14 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
# [5.0.0-alpha.14](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/material-bottom-tabs@5.0.0-alpha.13...@react-navigation/material-bottom-tabs@5.0.0-alpha.14) (2019-10-17)
|
||||
|
||||
**Note:** Version bump only for package @react-navigation/material-bottom-tabs
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# [5.0.0-alpha.13](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/material-bottom-tabs@5.0.0-alpha.12...@react-navigation/material-bottom-tabs@5.0.0-alpha.13) (2019-10-15)
|
||||
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
"material",
|
||||
"tab"
|
||||
],
|
||||
"version": "5.0.0-alpha.13",
|
||||
"version": "5.0.0-alpha.14",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@@ -44,7 +44,7 @@
|
||||
"del-cli": "^3.0.0",
|
||||
"react": "~16.8.3",
|
||||
"react-native": "~0.59.10",
|
||||
"react-native-paper": "^3.0.0-alpha.3",
|
||||
"react-native-paper": "^3.0.0-alpha.7",
|
||||
"react-native-vector-icons": "^6.6.0",
|
||||
"typescript": "^3.6.3"
|
||||
},
|
||||
@@ -52,7 +52,7 @@
|
||||
"@react-navigation/core": "^5.0.0-alpha.0",
|
||||
"react": "*",
|
||||
"react-native": "*",
|
||||
"react-native-paper": "^3.0.0-alpha.3",
|
||||
"react-native-paper": "^3.0.0-alpha.0",
|
||||
"react-native-vector-icons": "^6.0.0"
|
||||
},
|
||||
"@react-native-community/bob": {
|
||||
|
||||
@@ -96,6 +96,16 @@ export type MaterialBottomTabDescriptorMap = {
|
||||
export type MaterialBottomTabNavigationConfig = Partial<
|
||||
Omit<
|
||||
React.ComponentProps<typeof BottomNavigation>,
|
||||
'navigationState' | 'onIndexChange' | 'renderScene'
|
||||
| 'navigationState'
|
||||
| 'onIndexChange'
|
||||
| 'onTabPress'
|
||||
| 'renderScene'
|
||||
| 'renderLabel'
|
||||
| 'renderIcon'
|
||||
| 'getAccessibilityLabel'
|
||||
| 'getBadge'
|
||||
| 'getColor'
|
||||
| 'getLabelText'
|
||||
| 'getTestID'
|
||||
>
|
||||
>;
|
||||
|
||||
@@ -2,7 +2,6 @@ import * as React from 'react';
|
||||
import { StyleSheet } from 'react-native';
|
||||
import { BottomNavigation } from 'react-native-paper';
|
||||
import MaterialCommunityIcons from 'react-native-vector-icons/MaterialCommunityIcons';
|
||||
import { Route } from '@react-navigation/core';
|
||||
import { TabNavigationState, TabActions } from '@react-navigation/routers';
|
||||
|
||||
import {
|
||||
@@ -17,7 +16,7 @@ type Props = MaterialBottomTabNavigationConfig & {
|
||||
descriptors: MaterialBottomTabDescriptorMap;
|
||||
};
|
||||
|
||||
type Scene = { route: Route<string> };
|
||||
type Scene = { route: { key: string } };
|
||||
|
||||
export default class MaterialBottomTabView extends React.PureComponent<Props> {
|
||||
private getColor = ({ route }: Scene) => {
|
||||
@@ -35,7 +34,7 @@ export default class MaterialBottomTabView extends React.PureComponent<Props> {
|
||||
? options.tabBarLabel
|
||||
: typeof options.title === 'string'
|
||||
? options.title
|
||||
: route.name;
|
||||
: ((route as any) as { name: string }).name;
|
||||
};
|
||||
|
||||
private getAccessibilityLabel = ({ route }: Scene) => {
|
||||
@@ -49,9 +48,9 @@ export default class MaterialBottomTabView extends React.PureComponent<Props> {
|
||||
const label = this.getLabelText({ route });
|
||||
|
||||
if (typeof label === 'string') {
|
||||
return `${label}, tab, ${state.routes.indexOf(route) + 1} of ${
|
||||
state.routes.length
|
||||
}`;
|
||||
return `${label}, tab, ${state.routes.findIndex(
|
||||
r => r.key === route.key
|
||||
) + 1} of ${state.routes.length}`;
|
||||
}
|
||||
|
||||
return undefined;
|
||||
@@ -75,7 +74,7 @@ export default class MaterialBottomTabView extends React.PureComponent<Props> {
|
||||
focused,
|
||||
color,
|
||||
}: {
|
||||
route: Route<string>;
|
||||
route: { key: string };
|
||||
focused: boolean;
|
||||
color: string;
|
||||
}) => {
|
||||
@@ -114,7 +113,7 @@ export default class MaterialBottomTabView extends React.PureComponent<Props> {
|
||||
target: state.key,
|
||||
})
|
||||
}
|
||||
renderScene={({ route }: Scene) => descriptors[route.key].render()}
|
||||
renderScene={({ route }) => descriptors[route.key].render()}
|
||||
renderIcon={this.renderIcon}
|
||||
getLabelText={this.getLabelText}
|
||||
getColor={this.getColor}
|
||||
|
||||
@@ -3,6 +3,17 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
# [5.0.0-alpha.2](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/native-stack@5.0.0-alpha.1...@react-navigation/native-stack@5.0.0-alpha.2) (2019-10-18)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* fix header font size config in native stack ([#128](https://github.com/react-navigation/navigation-ex/issues/128)) ([477c088](https://github.com/react-navigation/navigation-ex/commit/477c088))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# 5.0.0-alpha.1 (2019-10-15)
|
||||
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
"react-native",
|
||||
"react-navigation"
|
||||
],
|
||||
"version": "5.0.0-alpha.1",
|
||||
"version": "5.0.0-alpha.2",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
||||
@@ -46,7 +46,7 @@ export default function HeaderConfig(props: Props) {
|
||||
: route.name
|
||||
}
|
||||
titleFontFamily={headerTitleStyle.fontFamily}
|
||||
titleFontSize={headerTitleStyle.fontFamily}
|
||||
titleFontSize={headerTitleStyle.fontSize}
|
||||
titleColor={
|
||||
headerTitleStyle.color !== undefined
|
||||
? headerTitleStyle.color
|
||||
|
||||
@@ -3,6 +3,30 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
# [5.0.0-alpha.27](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/stack@5.0.0-alpha.26...@react-navigation/stack@5.0.0-alpha.27) (2019-10-18)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* add an option to override safe area insets ([300791a](https://github.com/react-navigation/navigation-ex/commit/300791a))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# [5.0.0-alpha.26](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/stack@5.0.0-alpha.25...@react-navigation/stack@5.0.0-alpha.26) (2019-10-17)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* don't fade incoming background when fading header ([#127](https://github.com/react-navigation/navigation-ex/issues/127)) ([c6d0c19](https://github.com/react-navigation/navigation-ex/commit/c6d0c19))
|
||||
* fix incorrect type ([731cf7d](https://github.com/react-navigation/navigation-ex/commit/731cf7d))
|
||||
* use header height from style if specified ([442b95d](https://github.com/react-navigation/navigation-ex/commit/442b95d))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# [5.0.0-alpha.25](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/stack@5.0.0-alpha.24...@react-navigation/stack@5.0.0-alpha.25) (2019-10-15)
|
||||
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
"android",
|
||||
"stack"
|
||||
],
|
||||
"version": "5.0.0-alpha.25",
|
||||
"version": "5.0.0-alpha.27",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
||||
@@ -109,7 +109,7 @@ export function forFade({
|
||||
leftButtonStyle: { opacity },
|
||||
rightButtonStyle: { opacity },
|
||||
titleStyle: { opacity },
|
||||
backgroundStyle: { opacity },
|
||||
backgroundStyle: { opacity: current.progress },
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import {
|
||||
LayoutChangeEvent,
|
||||
} from 'react-native';
|
||||
import Animated from 'react-native-reanimated';
|
||||
import { EdgeInsets } from 'react-native-safe-area-context';
|
||||
import {
|
||||
NavigationProp,
|
||||
ParamListBase,
|
||||
@@ -207,6 +208,10 @@ export type StackHeaderProps = {
|
||||
* Layout of the screen.
|
||||
*/
|
||||
layout: Layout;
|
||||
/**
|
||||
* Safe area insets to use in the header, e.g. to apply extra spacing for statusbar and notch.
|
||||
*/
|
||||
insets: EdgeInsets;
|
||||
/**
|
||||
* Object representing the current scene, such as the route object and animation progress.
|
||||
*/
|
||||
@@ -302,6 +307,17 @@ export type StackNavigationOptions = StackHeaderOptions &
|
||||
* Defaults to 0.3.
|
||||
*/
|
||||
gestureVelocityImpact?: number;
|
||||
/**
|
||||
* Safe area insets for the screen. This is used to avoid elements like notch and status bar.
|
||||
* By default, the device's safe area insets are automatically detected. You can override the behavior with this option.
|
||||
* For example, to remove the extra spacing for status bar, pass `safeAreaInsets: { top: 0 }`.
|
||||
*/
|
||||
safeAreaInsets?: {
|
||||
top?: number;
|
||||
right?: number;
|
||||
bottom?: number;
|
||||
left?: number;
|
||||
};
|
||||
};
|
||||
|
||||
export type StackNavigationConfig = {
|
||||
|
||||
@@ -1,15 +1,19 @@
|
||||
import * as React from 'react';
|
||||
import { StackActions } from '@react-navigation/routers';
|
||||
import { useSafeArea } from 'react-native-safe-area-context';
|
||||
|
||||
import HeaderSegment from './HeaderSegment';
|
||||
import { StackHeaderProps, StackHeaderTitleProps } from '../../types';
|
||||
import HeaderTitle from './HeaderTitle';
|
||||
|
||||
export default React.memo(function Header(props: StackHeaderProps) {
|
||||
const insets = useSafeArea();
|
||||
|
||||
const { scene, previous, layout, navigation, styleInterpolator } = props;
|
||||
const {
|
||||
scene,
|
||||
previous,
|
||||
layout,
|
||||
insets,
|
||||
navigation,
|
||||
styleInterpolator,
|
||||
} = props;
|
||||
const { options } = scene.descriptor;
|
||||
const title =
|
||||
typeof options.headerTitle !== 'function' &&
|
||||
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
ParamListBase,
|
||||
} from '@react-navigation/core';
|
||||
import { StackNavigationState } from '@react-navigation/routers';
|
||||
import { EdgeInsets } from 'react-native-safe-area-context';
|
||||
|
||||
import Header from './Header';
|
||||
import { forStatic } from '../../TransitionConfigs/HeaderStyleInterpolators';
|
||||
@@ -19,6 +20,7 @@ import {
|
||||
export type Props = {
|
||||
mode: 'float' | 'screen';
|
||||
layout: Layout;
|
||||
insets: EdgeInsets;
|
||||
scenes: Array<Scene<Route<string>> | undefined>;
|
||||
state: StackNavigationState;
|
||||
getPreviousRoute: (props: {
|
||||
@@ -36,6 +38,7 @@ export default function HeaderContainer({
|
||||
mode,
|
||||
scenes,
|
||||
layout,
|
||||
insets,
|
||||
state,
|
||||
getPreviousRoute,
|
||||
onContentHeightChange,
|
||||
@@ -87,6 +90,7 @@ export default function HeaderContainer({
|
||||
const props = {
|
||||
mode,
|
||||
layout,
|
||||
insets,
|
||||
scene,
|
||||
previous,
|
||||
navigation: scene.descriptor.navigation as StackNavigationProp<
|
||||
|
||||
@@ -385,7 +385,10 @@ export default class Card extends React.Component<Props> {
|
||||
this.props.current,
|
||||
this.props.next,
|
||||
this.props.layout,
|
||||
this.props.insets
|
||||
this.props.insets.top,
|
||||
this.props.insets.right,
|
||||
this.props.insets.bottom,
|
||||
this.props.insets.left
|
||||
);
|
||||
};
|
||||
|
||||
@@ -684,7 +687,10 @@ export default class Card extends React.Component<Props> {
|
||||
current: Animated.Node<number>,
|
||||
next: Animated.Node<number> | undefined,
|
||||
layout: Layout,
|
||||
insets: EdgeInsets
|
||||
insetTop: number,
|
||||
insetRight: number,
|
||||
insetBottom: number,
|
||||
insetLeft: number
|
||||
) =>
|
||||
styleInterpolator({
|
||||
index,
|
||||
@@ -694,7 +700,12 @@ export default class Card extends React.Component<Props> {
|
||||
layouts: {
|
||||
screen: layout,
|
||||
},
|
||||
insets,
|
||||
insets: {
|
||||
top: insetTop,
|
||||
right: insetRight,
|
||||
bottom: insetBottom,
|
||||
left: insetLeft,
|
||||
},
|
||||
})
|
||||
);
|
||||
|
||||
@@ -708,7 +719,10 @@ export default class Card extends React.Component<Props> {
|
||||
this.props.current,
|
||||
this.props.next,
|
||||
this.props.layout,
|
||||
this.props.insets
|
||||
this.props.insets.top,
|
||||
this.props.insets.right,
|
||||
this.props.insets.bottom,
|
||||
this.props.insets.left
|
||||
);
|
||||
|
||||
private gestureActivationCriteria() {
|
||||
@@ -776,7 +790,10 @@ export default class Card extends React.Component<Props> {
|
||||
current,
|
||||
next,
|
||||
layout,
|
||||
insets
|
||||
insets.top,
|
||||
insets.right,
|
||||
insets.bottom,
|
||||
insets.left
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -117,6 +117,7 @@ const FALLBACK_DESCRIPTOR = Object.freeze({ options: {} });
|
||||
const getFloatingHeaderHeights = (
|
||||
routes: Route<string>[],
|
||||
insets: EdgeInsets,
|
||||
descriptors: StackDescriptorMap,
|
||||
layout: Layout,
|
||||
previous: { [key: string]: number }
|
||||
) => {
|
||||
@@ -124,7 +125,12 @@ const getFloatingHeaderHeights = (
|
||||
|
||||
return routes.reduce(
|
||||
(acc, curr) => {
|
||||
acc[curr.key] = previous[curr.key] || defaultHeaderHeight;
|
||||
const { options = {} } = descriptors[curr.key] || {};
|
||||
const { height = previous[curr.key] } = StyleSheet.flatten(
|
||||
options.headerStyle || {}
|
||||
);
|
||||
|
||||
acc[curr.key] = typeof height === 'number' ? height : defaultHeaderHeight;
|
||||
|
||||
return acc;
|
||||
},
|
||||
@@ -141,24 +147,21 @@ export default class Stack extends React.Component<Props, State> {
|
||||
return null;
|
||||
}
|
||||
|
||||
const progress = props.routes.reduce(
|
||||
(acc, curr) => {
|
||||
const descriptor = props.descriptors[curr.key];
|
||||
const progress = props.routes.reduce<ProgressValues>((acc, curr) => {
|
||||
const descriptor = props.descriptors[curr.key];
|
||||
|
||||
acc[curr.key] =
|
||||
state.progress[curr.key] ||
|
||||
new Animated.Value(
|
||||
props.openingRouteKeys.includes(curr.key) &&
|
||||
descriptor &&
|
||||
descriptor.options.animationEnabled !== false
|
||||
? 0
|
||||
: 1
|
||||
);
|
||||
acc[curr.key] =
|
||||
state.progress[curr.key] ||
|
||||
new Animated.Value(
|
||||
props.openingRouteKeys.includes(curr.key) &&
|
||||
descriptor &&
|
||||
descriptor.options.animationEnabled !== false
|
||||
? 0
|
||||
: 1
|
||||
);
|
||||
|
||||
return acc;
|
||||
},
|
||||
{} as ProgressValues
|
||||
);
|
||||
return acc;
|
||||
}, {});
|
||||
|
||||
return {
|
||||
routes: props.routes,
|
||||
@@ -205,6 +208,7 @@ export default class Stack extends React.Component<Props, State> {
|
||||
floatingHeaderHeights: getFloatingHeaderHeights(
|
||||
props.routes,
|
||||
props.insets,
|
||||
state.descriptors,
|
||||
state.layout,
|
||||
state.floatingHeaderHeights
|
||||
),
|
||||
@@ -237,15 +241,16 @@ export default class Stack extends React.Component<Props, State> {
|
||||
|
||||
const layout = { width, height };
|
||||
|
||||
this.setState({
|
||||
this.setState(state => ({
|
||||
layout,
|
||||
floatingHeaderHeights: getFloatingHeaderHeights(
|
||||
this.props.routes,
|
||||
this.props.insets,
|
||||
state.descriptors,
|
||||
layout,
|
||||
{}
|
||||
),
|
||||
});
|
||||
}));
|
||||
};
|
||||
|
||||
private handleFloatingHeaderLayout = ({
|
||||
@@ -327,6 +332,13 @@ export default class Stack extends React.Component<Props, State> {
|
||||
};
|
||||
}
|
||||
|
||||
const {
|
||||
top = insets.top,
|
||||
right = insets.right,
|
||||
bottom = insets.bottom,
|
||||
left = insets.left,
|
||||
} = focusedOptions.safeAreaInsets || {};
|
||||
|
||||
return (
|
||||
<React.Fragment>
|
||||
<MaybeScreenContainer
|
||||
@@ -353,6 +365,7 @@ export default class Stack extends React.Component<Props, State> {
|
||||
: 0;
|
||||
|
||||
const {
|
||||
safeAreaInsets,
|
||||
headerShown,
|
||||
headerTransparent,
|
||||
cardTransparent,
|
||||
@@ -401,6 +414,13 @@ export default class Stack extends React.Component<Props, State> {
|
||||
}
|
||||
}
|
||||
|
||||
const {
|
||||
top: safeAreaInsetTop = insets.top,
|
||||
right: safeAreaInsetRight = insets.right,
|
||||
bottom: safeAreaInsetBottom = insets.bottom,
|
||||
left: safeAreaInsetLeft = insets.left,
|
||||
} = safeAreaInsets || {};
|
||||
|
||||
return (
|
||||
<MaybeScreen
|
||||
key={route.key}
|
||||
@@ -415,12 +435,15 @@ export default class Stack extends React.Component<Props, State> {
|
||||
focused={focused}
|
||||
closing={closingRouteKeys.includes(route.key)}
|
||||
layout={layout}
|
||||
insets={insets}
|
||||
current={current}
|
||||
scene={scene}
|
||||
previousScene={scenes[index - 1]}
|
||||
navigation={navigation}
|
||||
state={state}
|
||||
safeAreaInsetTop={safeAreaInsetTop}
|
||||
safeAreaInsetRight={safeAreaInsetRight}
|
||||
safeAreaInsetBottom={safeAreaInsetBottom}
|
||||
safeAreaInsetLeft={safeAreaInsetLeft}
|
||||
cardTransparent={cardTransparent}
|
||||
cardOverlayEnabled={cardOverlayEnabled}
|
||||
cardShadowEnabled={cardShadowEnabled}
|
||||
@@ -454,6 +477,7 @@ export default class Stack extends React.Component<Props, State> {
|
||||
? renderHeader({
|
||||
mode: 'float',
|
||||
layout,
|
||||
insets: { top, right, bottom, left },
|
||||
scenes,
|
||||
state,
|
||||
getPreviousRoute,
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import * as React from 'react';
|
||||
import { View, StyleSheet, StyleProp, ViewStyle } from 'react-native';
|
||||
import Animated from 'react-native-reanimated';
|
||||
import { EdgeInsets } from 'react-native-safe-area-context';
|
||||
import { StackNavigationState } from '@react-navigation/routers';
|
||||
import { Route } from '@react-navigation/core';
|
||||
import { Props as HeaderContainerProps } from '../Header/HeaderContainer';
|
||||
@@ -20,12 +19,15 @@ type Props = TransitionPreset & {
|
||||
focused: boolean;
|
||||
closing: boolean;
|
||||
layout: Layout;
|
||||
insets: EdgeInsets;
|
||||
current: Animated.Value<number>;
|
||||
previousScene?: Scene<Route<string>>;
|
||||
scene: Scene<Route<string>>;
|
||||
state: StackNavigationState;
|
||||
navigation: StackNavigationHelpers;
|
||||
safeAreaInsetTop: number;
|
||||
safeAreaInsetRight: number;
|
||||
safeAreaInsetBottom: number;
|
||||
safeAreaInsetLeft: number;
|
||||
cardTransparent?: boolean;
|
||||
cardOverlayEnabled?: boolean;
|
||||
cardShadowEnabled?: boolean;
|
||||
@@ -96,7 +98,6 @@ export default class StackItem extends React.PureComponent<Props> {
|
||||
const {
|
||||
index,
|
||||
layout,
|
||||
insets,
|
||||
active,
|
||||
focused,
|
||||
closing,
|
||||
@@ -104,6 +105,10 @@ export default class StackItem extends React.PureComponent<Props> {
|
||||
state,
|
||||
scene,
|
||||
previousScene,
|
||||
safeAreaInsetTop,
|
||||
safeAreaInsetRight,
|
||||
safeAreaInsetBottom,
|
||||
safeAreaInsetLeft,
|
||||
cardTransparent,
|
||||
cardOverlayEnabled,
|
||||
cardShadowEnabled,
|
||||
@@ -126,6 +131,13 @@ export default class StackItem extends React.PureComponent<Props> {
|
||||
headerStyleInterpolator,
|
||||
} = this.props;
|
||||
|
||||
const insets = {
|
||||
top: safeAreaInsetTop,
|
||||
right: safeAreaInsetRight,
|
||||
bottom: safeAreaInsetBottom,
|
||||
left: safeAreaInsetLeft,
|
||||
};
|
||||
|
||||
return (
|
||||
<Card
|
||||
index={index}
|
||||
@@ -168,6 +180,7 @@ export default class StackItem extends React.PureComponent<Props> {
|
||||
? renderHeader({
|
||||
mode: 'screen',
|
||||
layout,
|
||||
insets,
|
||||
scenes: [previousScene, scene],
|
||||
state,
|
||||
getPreviousRoute,
|
||||
|
||||
@@ -53,14 +53,14 @@ class StackView extends React.Component<Props, State> {
|
||||
// If there was no change in routes, we don't need to compute anything
|
||||
if (props.state.routes === state.previousRoutes && state.routes.length) {
|
||||
if (props.descriptors !== state.previousDescriptors) {
|
||||
const descriptors = state.routes.reduce(
|
||||
const descriptors = state.routes.reduce<StackDescriptorMap>(
|
||||
(acc, route) => {
|
||||
acc[route.key] =
|
||||
props.descriptors[route.key] || state.descriptors[route.key];
|
||||
|
||||
return acc;
|
||||
},
|
||||
{} as StackDescriptorMap
|
||||
{}
|
||||
);
|
||||
|
||||
return {
|
||||
@@ -195,15 +195,12 @@ class StackView extends React.Component<Props, State> {
|
||||
throw new Error(`There should always be at least one route.`);
|
||||
}
|
||||
|
||||
const descriptors = routes.reduce(
|
||||
(acc, route) => {
|
||||
acc[route.key] =
|
||||
props.descriptors[route.key] || state.descriptors[route.key];
|
||||
const descriptors = routes.reduce<StackDescriptorMap>((acc, route) => {
|
||||
acc[route.key] =
|
||||
props.descriptors[route.key] || state.descriptors[route.key];
|
||||
|
||||
return acc;
|
||||
},
|
||||
{} as StackDescriptorMap
|
||||
);
|
||||
return acc;
|
||||
}, {});
|
||||
|
||||
return {
|
||||
routes,
|
||||
|
||||
27
yarn.lock
27
yarn.lock
@@ -864,12 +864,11 @@
|
||||
lodash "^4.17.13"
|
||||
to-fast-properties "^2.0.0"
|
||||
|
||||
"@callstack/react-theme-provider@^3.0.2":
|
||||
version "3.0.3"
|
||||
resolved "https://registry.yarnpkg.com/@callstack/react-theme-provider/-/react-theme-provider-3.0.3.tgz#f964dda28cd6e731c3fbcf916b0579c6f9fb2db7"
|
||||
integrity sha512-B+9JBK7zsND/AdVkjwHvbb4cR05fJofLFG30hOeoXke8WkKAWN36yFljauAhI8qwlXlGFGZMYE1wQvsqBSccrA==
|
||||
"@callstack/react-theme-provider@^3.0.5":
|
||||
version "3.0.5"
|
||||
resolved "https://registry.yarnpkg.com/@callstack/react-theme-provider/-/react-theme-provider-3.0.5.tgz#a173e455e9603c9c45357a3b6ace1273086527ca"
|
||||
integrity sha512-Iec+ybWN0FvNj87sD3oWo/49edGUP0UOSdMnzCJEFJIDYr992ECIuOV89burAAh2/ibPCxgLiK6dmgv2mO/8Tg==
|
||||
dependencies:
|
||||
"@types/hoist-non-react-statics" "^3.3.1"
|
||||
deepmerge "^3.2.0"
|
||||
hoist-non-react-statics "^3.3.0"
|
||||
|
||||
@@ -2530,14 +2529,6 @@
|
||||
"@types/minimatch" "*"
|
||||
"@types/node" "*"
|
||||
|
||||
"@types/hoist-non-react-statics@^3.3.1":
|
||||
version "3.3.1"
|
||||
resolved "https://registry.yarnpkg.com/@types/hoist-non-react-statics/-/hoist-non-react-statics-3.3.1.tgz#1124aafe5118cb591977aeb1ceaaed1070eb039f"
|
||||
integrity sha512-iMIqiko6ooLrTh1joXodJK5X9xeEALT1kM5G3ZLhD3hszxBdIEd5C75U834D9mLcINgD4OyZf5uQXjkuYydWvA==
|
||||
dependencies:
|
||||
"@types/react" "*"
|
||||
hoist-non-react-statics "^3.3.0"
|
||||
|
||||
"@types/http-proxy-middleware@*":
|
||||
version "0.19.3"
|
||||
resolved "https://registry.yarnpkg.com/@types/http-proxy-middleware/-/http-proxy-middleware-0.19.3.tgz#b2eb96fbc0f9ac7250b5d9c4c53aade049497d03"
|
||||
@@ -13111,12 +13102,12 @@ react-native-gesture-handler@~1.3.0:
|
||||
invariant "^2.2.2"
|
||||
prop-types "^15.5.10"
|
||||
|
||||
react-native-paper@^3.0.0-alpha.3:
|
||||
version "3.0.0-alpha.5"
|
||||
resolved "https://registry.yarnpkg.com/react-native-paper/-/react-native-paper-3.0.0-alpha.5.tgz#2a3e23c52ec717d7c6a1df1e7adc1005611b08a2"
|
||||
integrity sha512-LSsmhCIo2EgT9azd1usjBmfGBgNkKOMdHWkFJnwmGrXo/JMxhlD/KMt+GRTz4ZjFWmJu3GO635ihYleSJhW6Mg==
|
||||
react-native-paper@^3.0.0-alpha.7:
|
||||
version "3.0.0-alpha.7"
|
||||
resolved "https://registry.yarnpkg.com/react-native-paper/-/react-native-paper-3.0.0-alpha.7.tgz#fbbfe5dc9ef8dbd18932786aa3d7f0479501538b"
|
||||
integrity sha512-tjqewrUMnucLM4yqMiVtCOnrqilnvDDNr2guIImwsUpJ6HWaJKBEFKqB25SEdMvuo88MWSdA0gyRNtS3WRpS3w==
|
||||
dependencies:
|
||||
"@callstack/react-theme-provider" "^3.0.2"
|
||||
"@callstack/react-theme-provider" "^3.0.5"
|
||||
color "^3.1.2"
|
||||
react-native-safe-area-view "^0.12.0"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user