mirror of
https://github.com/zhigang1992/react-navigation.git
synced 2026-01-30 22:50:22 +08:00
Compare commits
5 Commits
@react-nav
...
@react-nav
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3aaf6eb648 | ||
|
|
477c08858d | ||
|
|
300791ab49 | ||
|
|
3e92e22941 | ||
|
|
a543f1bfc3 |
@@ -3,6 +3,22 @@
|
|||||||
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.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)
|
# [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-native",
|
||||||
"react-navigation"
|
"react-navigation"
|
||||||
],
|
],
|
||||||
"version": "5.0.0-alpha.15",
|
"version": "5.0.0-alpha.16",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|||||||
@@ -108,7 +108,24 @@ export default function MockRouter(options: DefaultRouterOptions) {
|
|||||||
return null;
|
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:
|
default:
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import NavigationContainer from '../NavigationContainer';
|
|||||||
import useNavigationBuilder from '../useNavigationBuilder';
|
import useNavigationBuilder from '../useNavigationBuilder';
|
||||||
import useNavigation from '../useNavigation';
|
import useNavigation from '../useNavigation';
|
||||||
import MockRouter, { MockRouterKey } from './__fixtures__/MockRouter';
|
import MockRouter, { MockRouterKey } from './__fixtures__/MockRouter';
|
||||||
import { NavigationState } from '../types';
|
import { NavigationState, NavigationContainerRef } from '../types';
|
||||||
|
|
||||||
beforeEach(() => (MockRouterKey.current = 0));
|
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', () => {
|
it('gives access to internal state', () => {
|
||||||
const TestNavigator = (props: any): any => {
|
const TestNavigator = (props: any): any => {
|
||||||
const { state, descriptors } = useNavigationBuilder(MockRouter, props);
|
const { state, descriptors } = useNavigationBuilder(MockRouter, props);
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import { NavigationStateContext } from './NavigationContainer';
|
import { NavigationStateContext } from './NavigationContainer';
|
||||||
|
import NavigationRouteContext from './NavigationRouteContext';
|
||||||
import Screen from './Screen';
|
import Screen from './Screen';
|
||||||
|
import { navigate } from './CommonActions';
|
||||||
import useEventEmitter from './useEventEmitter';
|
import useEventEmitter from './useEventEmitter';
|
||||||
import useRegisterNavigator from './useRegisterNavigator';
|
import useRegisterNavigator from './useRegisterNavigator';
|
||||||
import useDescriptors from './useDescriptors';
|
import useDescriptors from './useDescriptors';
|
||||||
@@ -30,6 +32,13 @@ import useOnGetState from './useOnGetState';
|
|||||||
// eslint-disable-next-line babel/no-unused-expressions
|
// eslint-disable-next-line babel/no-unused-expressions
|
||||||
PrivateValueStore;
|
PrivateValueStore;
|
||||||
|
|
||||||
|
type NavigatorRoute = {
|
||||||
|
params?: {
|
||||||
|
screen?: string;
|
||||||
|
params?: object;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compare two arrays with primitive values as the content.
|
* Compare two arrays with primitive values as the content.
|
||||||
* We need to make sure that both values and order match.
|
* We need to make sure that both values and order match.
|
||||||
@@ -96,9 +105,24 @@ export default function useNavigationBuilder<
|
|||||||
) {
|
) {
|
||||||
useRegisterNavigator();
|
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 { children, ...rest } = options;
|
||||||
const { current: router } = React.useRef<Router<State, any>>(
|
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(
|
const screens = getRouteConfigsFromChildren<ScreenOptions>(children).reduce(
|
||||||
@@ -118,7 +142,20 @@ export default function useNavigationBuilder<
|
|||||||
const routeNames = Object.keys(screens);
|
const routeNames = Object.keys(screens);
|
||||||
const routeParamList = routeNames.reduce(
|
const routeParamList = routeNames.reduce(
|
||||||
(acc, curr) => {
|
(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;
|
return acc;
|
||||||
},
|
},
|
||||||
{} as { [key: string]: object | undefined }
|
{} as { [key: string]: object | undefined }
|
||||||
@@ -175,12 +212,38 @@ export default function useNavigationBuilder<
|
|||||||
? (initializedStateRef.current as State)
|
? (initializedStateRef.current as State)
|
||||||
: (currentState as State);
|
: (currentState as State);
|
||||||
|
|
||||||
|
let nextState: State = state;
|
||||||
|
|
||||||
if (!isArrayEqual(state.routeNames, routeNames)) {
|
if (!isArrayEqual(state.routeNames, routeNames)) {
|
||||||
// When the list of route names change, the router should handle it to remove invalid routes
|
// 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,
|
routeNames,
|
||||||
routeParamList,
|
routeParamList,
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
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 (state !== nextState) {
|
||||||
// If the state needs to be updated, we'll schedule an update with React
|
// If the state needs to be updated, we'll schedule an update with React
|
||||||
@@ -195,7 +258,6 @@ export default function useNavigationBuilder<
|
|||||||
// We can't use the outdated state since the screens have changed, which will cause error due to mismatched config
|
// 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
|
// So we override the state objec we return to use the latest state as soon as possible
|
||||||
state = nextState;
|
state = nextState;
|
||||||
}
|
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
return () => {
|
return () => {
|
||||||
|
|||||||
@@ -3,6 +3,17 @@
|
|||||||
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.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)
|
# 5.0.0-alpha.1 (2019-10-15)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
"react-native",
|
"react-native",
|
||||||
"react-navigation"
|
"react-navigation"
|
||||||
],
|
],
|
||||||
"version": "5.0.0-alpha.1",
|
"version": "5.0.0-alpha.2",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ export default function HeaderConfig(props: Props) {
|
|||||||
: route.name
|
: route.name
|
||||||
}
|
}
|
||||||
titleFontFamily={headerTitleStyle.fontFamily}
|
titleFontFamily={headerTitleStyle.fontFamily}
|
||||||
titleFontSize={headerTitleStyle.fontFamily}
|
titleFontSize={headerTitleStyle.fontSize}
|
||||||
titleColor={
|
titleColor={
|
||||||
headerTitleStyle.color !== undefined
|
headerTitleStyle.color !== undefined
|
||||||
? headerTitleStyle.color
|
? headerTitleStyle.color
|
||||||
|
|||||||
@@ -3,6 +3,17 @@
|
|||||||
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.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)
|
# [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)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
"android",
|
"android",
|
||||||
"stack"
|
"stack"
|
||||||
],
|
],
|
||||||
"version": "5.0.0-alpha.26",
|
"version": "5.0.0-alpha.27",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import {
|
|||||||
LayoutChangeEvent,
|
LayoutChangeEvent,
|
||||||
} from 'react-native';
|
} from 'react-native';
|
||||||
import Animated from 'react-native-reanimated';
|
import Animated from 'react-native-reanimated';
|
||||||
|
import { EdgeInsets } from 'react-native-safe-area-context';
|
||||||
import {
|
import {
|
||||||
NavigationProp,
|
NavigationProp,
|
||||||
ParamListBase,
|
ParamListBase,
|
||||||
@@ -207,6 +208,10 @@ export type StackHeaderProps = {
|
|||||||
* Layout of the screen.
|
* Layout of the screen.
|
||||||
*/
|
*/
|
||||||
layout: Layout;
|
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.
|
* 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.
|
* Defaults to 0.3.
|
||||||
*/
|
*/
|
||||||
gestureVelocityImpact?: number;
|
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 = {
|
export type StackNavigationConfig = {
|
||||||
|
|||||||
@@ -1,15 +1,19 @@
|
|||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import { StackActions } from '@react-navigation/routers';
|
import { StackActions } from '@react-navigation/routers';
|
||||||
import { useSafeArea } from 'react-native-safe-area-context';
|
|
||||||
|
|
||||||
import HeaderSegment from './HeaderSegment';
|
import HeaderSegment from './HeaderSegment';
|
||||||
import { StackHeaderProps, StackHeaderTitleProps } from '../../types';
|
import { StackHeaderProps, StackHeaderTitleProps } from '../../types';
|
||||||
import HeaderTitle from './HeaderTitle';
|
import HeaderTitle from './HeaderTitle';
|
||||||
|
|
||||||
export default React.memo(function Header(props: StackHeaderProps) {
|
export default React.memo(function Header(props: StackHeaderProps) {
|
||||||
const insets = useSafeArea();
|
const {
|
||||||
|
scene,
|
||||||
const { scene, previous, layout, navigation, styleInterpolator } = props;
|
previous,
|
||||||
|
layout,
|
||||||
|
insets,
|
||||||
|
navigation,
|
||||||
|
styleInterpolator,
|
||||||
|
} = props;
|
||||||
const { options } = scene.descriptor;
|
const { options } = scene.descriptor;
|
||||||
const title =
|
const title =
|
||||||
typeof options.headerTitle !== 'function' &&
|
typeof options.headerTitle !== 'function' &&
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import {
|
|||||||
ParamListBase,
|
ParamListBase,
|
||||||
} from '@react-navigation/core';
|
} from '@react-navigation/core';
|
||||||
import { StackNavigationState } from '@react-navigation/routers';
|
import { StackNavigationState } from '@react-navigation/routers';
|
||||||
|
import { EdgeInsets } from 'react-native-safe-area-context';
|
||||||
|
|
||||||
import Header from './Header';
|
import Header from './Header';
|
||||||
import { forStatic } from '../../TransitionConfigs/HeaderStyleInterpolators';
|
import { forStatic } from '../../TransitionConfigs/HeaderStyleInterpolators';
|
||||||
@@ -19,6 +20,7 @@ import {
|
|||||||
export type Props = {
|
export type Props = {
|
||||||
mode: 'float' | 'screen';
|
mode: 'float' | 'screen';
|
||||||
layout: Layout;
|
layout: Layout;
|
||||||
|
insets: EdgeInsets;
|
||||||
scenes: Array<Scene<Route<string>> | undefined>;
|
scenes: Array<Scene<Route<string>> | undefined>;
|
||||||
state: StackNavigationState;
|
state: StackNavigationState;
|
||||||
getPreviousRoute: (props: {
|
getPreviousRoute: (props: {
|
||||||
@@ -36,6 +38,7 @@ export default function HeaderContainer({
|
|||||||
mode,
|
mode,
|
||||||
scenes,
|
scenes,
|
||||||
layout,
|
layout,
|
||||||
|
insets,
|
||||||
state,
|
state,
|
||||||
getPreviousRoute,
|
getPreviousRoute,
|
||||||
onContentHeightChange,
|
onContentHeightChange,
|
||||||
@@ -87,6 +90,7 @@ export default function HeaderContainer({
|
|||||||
const props = {
|
const props = {
|
||||||
mode,
|
mode,
|
||||||
layout,
|
layout,
|
||||||
|
insets,
|
||||||
scene,
|
scene,
|
||||||
previous,
|
previous,
|
||||||
navigation: scene.descriptor.navigation as StackNavigationProp<
|
navigation: scene.descriptor.navigation as StackNavigationProp<
|
||||||
|
|||||||
@@ -385,7 +385,10 @@ export default class Card extends React.Component<Props> {
|
|||||||
this.props.current,
|
this.props.current,
|
||||||
this.props.next,
|
this.props.next,
|
||||||
this.props.layout,
|
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>,
|
current: Animated.Node<number>,
|
||||||
next: Animated.Node<number> | undefined,
|
next: Animated.Node<number> | undefined,
|
||||||
layout: Layout,
|
layout: Layout,
|
||||||
insets: EdgeInsets
|
insetTop: number,
|
||||||
|
insetRight: number,
|
||||||
|
insetBottom: number,
|
||||||
|
insetLeft: number
|
||||||
) =>
|
) =>
|
||||||
styleInterpolator({
|
styleInterpolator({
|
||||||
index,
|
index,
|
||||||
@@ -694,7 +700,12 @@ export default class Card extends React.Component<Props> {
|
|||||||
layouts: {
|
layouts: {
|
||||||
screen: layout,
|
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.current,
|
||||||
this.props.next,
|
this.props.next,
|
||||||
this.props.layout,
|
this.props.layout,
|
||||||
this.props.insets
|
this.props.insets.top,
|
||||||
|
this.props.insets.right,
|
||||||
|
this.props.insets.bottom,
|
||||||
|
this.props.insets.left
|
||||||
);
|
);
|
||||||
|
|
||||||
private gestureActivationCriteria() {
|
private gestureActivationCriteria() {
|
||||||
@@ -776,7 +790,10 @@ export default class Card extends React.Component<Props> {
|
|||||||
current,
|
current,
|
||||||
next,
|
next,
|
||||||
layout,
|
layout,
|
||||||
insets
|
insets.top,
|
||||||
|
insets.right,
|
||||||
|
insets.bottom,
|
||||||
|
insets.left
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -332,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 (
|
return (
|
||||||
<React.Fragment>
|
<React.Fragment>
|
||||||
<MaybeScreenContainer
|
<MaybeScreenContainer
|
||||||
@@ -358,6 +365,7 @@ export default class Stack extends React.Component<Props, State> {
|
|||||||
: 0;
|
: 0;
|
||||||
|
|
||||||
const {
|
const {
|
||||||
|
safeAreaInsets,
|
||||||
headerShown,
|
headerShown,
|
||||||
headerTransparent,
|
headerTransparent,
|
||||||
cardTransparent,
|
cardTransparent,
|
||||||
@@ -406,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 (
|
return (
|
||||||
<MaybeScreen
|
<MaybeScreen
|
||||||
key={route.key}
|
key={route.key}
|
||||||
@@ -420,12 +435,15 @@ export default class Stack extends React.Component<Props, State> {
|
|||||||
focused={focused}
|
focused={focused}
|
||||||
closing={closingRouteKeys.includes(route.key)}
|
closing={closingRouteKeys.includes(route.key)}
|
||||||
layout={layout}
|
layout={layout}
|
||||||
insets={insets}
|
|
||||||
current={current}
|
current={current}
|
||||||
scene={scene}
|
scene={scene}
|
||||||
previousScene={scenes[index - 1]}
|
previousScene={scenes[index - 1]}
|
||||||
navigation={navigation}
|
navigation={navigation}
|
||||||
state={state}
|
state={state}
|
||||||
|
safeAreaInsetTop={safeAreaInsetTop}
|
||||||
|
safeAreaInsetRight={safeAreaInsetRight}
|
||||||
|
safeAreaInsetBottom={safeAreaInsetBottom}
|
||||||
|
safeAreaInsetLeft={safeAreaInsetLeft}
|
||||||
cardTransparent={cardTransparent}
|
cardTransparent={cardTransparent}
|
||||||
cardOverlayEnabled={cardOverlayEnabled}
|
cardOverlayEnabled={cardOverlayEnabled}
|
||||||
cardShadowEnabled={cardShadowEnabled}
|
cardShadowEnabled={cardShadowEnabled}
|
||||||
@@ -459,6 +477,7 @@ export default class Stack extends React.Component<Props, State> {
|
|||||||
? renderHeader({
|
? renderHeader({
|
||||||
mode: 'float',
|
mode: 'float',
|
||||||
layout,
|
layout,
|
||||||
|
insets: { top, right, bottom, left },
|
||||||
scenes,
|
scenes,
|
||||||
state,
|
state,
|
||||||
getPreviousRoute,
|
getPreviousRoute,
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import { View, StyleSheet, StyleProp, ViewStyle } from 'react-native';
|
import { View, StyleSheet, StyleProp, ViewStyle } from 'react-native';
|
||||||
import Animated from 'react-native-reanimated';
|
import Animated from 'react-native-reanimated';
|
||||||
import { EdgeInsets } from 'react-native-safe-area-context';
|
|
||||||
import { StackNavigationState } from '@react-navigation/routers';
|
import { StackNavigationState } from '@react-navigation/routers';
|
||||||
import { Route } from '@react-navigation/core';
|
import { Route } from '@react-navigation/core';
|
||||||
import { Props as HeaderContainerProps } from '../Header/HeaderContainer';
|
import { Props as HeaderContainerProps } from '../Header/HeaderContainer';
|
||||||
@@ -20,12 +19,15 @@ type Props = TransitionPreset & {
|
|||||||
focused: boolean;
|
focused: boolean;
|
||||||
closing: boolean;
|
closing: boolean;
|
||||||
layout: Layout;
|
layout: Layout;
|
||||||
insets: EdgeInsets;
|
|
||||||
current: Animated.Value<number>;
|
current: Animated.Value<number>;
|
||||||
previousScene?: Scene<Route<string>>;
|
previousScene?: Scene<Route<string>>;
|
||||||
scene: Scene<Route<string>>;
|
scene: Scene<Route<string>>;
|
||||||
state: StackNavigationState;
|
state: StackNavigationState;
|
||||||
navigation: StackNavigationHelpers;
|
navigation: StackNavigationHelpers;
|
||||||
|
safeAreaInsetTop: number;
|
||||||
|
safeAreaInsetRight: number;
|
||||||
|
safeAreaInsetBottom: number;
|
||||||
|
safeAreaInsetLeft: number;
|
||||||
cardTransparent?: boolean;
|
cardTransparent?: boolean;
|
||||||
cardOverlayEnabled?: boolean;
|
cardOverlayEnabled?: boolean;
|
||||||
cardShadowEnabled?: boolean;
|
cardShadowEnabled?: boolean;
|
||||||
@@ -96,7 +98,6 @@ export default class StackItem extends React.PureComponent<Props> {
|
|||||||
const {
|
const {
|
||||||
index,
|
index,
|
||||||
layout,
|
layout,
|
||||||
insets,
|
|
||||||
active,
|
active,
|
||||||
focused,
|
focused,
|
||||||
closing,
|
closing,
|
||||||
@@ -104,6 +105,10 @@ export default class StackItem extends React.PureComponent<Props> {
|
|||||||
state,
|
state,
|
||||||
scene,
|
scene,
|
||||||
previousScene,
|
previousScene,
|
||||||
|
safeAreaInsetTop,
|
||||||
|
safeAreaInsetRight,
|
||||||
|
safeAreaInsetBottom,
|
||||||
|
safeAreaInsetLeft,
|
||||||
cardTransparent,
|
cardTransparent,
|
||||||
cardOverlayEnabled,
|
cardOverlayEnabled,
|
||||||
cardShadowEnabled,
|
cardShadowEnabled,
|
||||||
@@ -126,6 +131,13 @@ export default class StackItem extends React.PureComponent<Props> {
|
|||||||
headerStyleInterpolator,
|
headerStyleInterpolator,
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
|
||||||
|
const insets = {
|
||||||
|
top: safeAreaInsetTop,
|
||||||
|
right: safeAreaInsetRight,
|
||||||
|
bottom: safeAreaInsetBottom,
|
||||||
|
left: safeAreaInsetLeft,
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card
|
<Card
|
||||||
index={index}
|
index={index}
|
||||||
@@ -168,6 +180,7 @@ export default class StackItem extends React.PureComponent<Props> {
|
|||||||
? renderHeader({
|
? renderHeader({
|
||||||
mode: 'screen',
|
mode: 'screen',
|
||||||
layout,
|
layout,
|
||||||
|
insets,
|
||||||
scenes: [previousScene, scene],
|
scenes: [previousScene, scene],
|
||||||
state,
|
state,
|
||||||
getPreviousRoute,
|
getPreviousRoute,
|
||||||
|
|||||||
Reference in New Issue
Block a user