mirror of
https://github.com/zhigang1992/react-navigation.git
synced 2026-01-28 22:31:33 +08:00
586 lines
20 KiB
Diff
586 lines
20 KiB
Diff
diff -ruN node_modules/@react-navigation/stack/src/index.tsx src/vendor/index.tsx
|
|
--- node_modules/@react-navigation/stack/src/index.tsx 2020-01-05 14:32:09.000000000 +0100
|
|
+++ src/vendor/index.tsx 2020-01-05 14:37:29.000000000 +0100
|
|
@@ -3,11 +3,6 @@
|
|
import * as TransitionSpecs from './TransitionConfigs/TransitionSpecs';
|
|
import * as TransitionPresets from './TransitionConfigs/TransitionPresets';
|
|
|
|
-/**
|
|
- * Navigators
|
|
- */
|
|
-export { default as createStackNavigator } from './navigators/createStackNavigator';
|
|
-
|
|
export const Assets = [
|
|
// eslint-disable-next-line import/no-commonjs
|
|
require('./views/assets/back-icon.png'),
|
|
@@ -48,9 +43,10 @@
|
|
* Types
|
|
*/
|
|
export {
|
|
- StackNavigationOptions,
|
|
- StackNavigationProp,
|
|
- StackHeaderProps,
|
|
+ NavigationStackState,
|
|
+ StackNavigationProp as NavigationStackProp,
|
|
+ StackNavigationOptions as NavigationStackOptions,
|
|
+ StackNavigationConfig as NavigationStackConfig,
|
|
StackHeaderLeftButtonProps,
|
|
StackHeaderTitleProps,
|
|
StackCardInterpolatedStyle,
|
|
diff -ruN node_modules/@react-navigation/stack/src/navigators/createStackNavigator.tsx src/vendor/navigators/createStackNavigator.tsx
|
|
--- node_modules/@react-navigation/stack/src/navigators/createStackNavigator.tsx 2020-01-05 14:32:09.000000000 +0100
|
|
+++ src/vendor/navigators/createStackNavigator.tsx 1970-01-01 01:00:00.000000000 +0100
|
|
@@ -1,77 +0,0 @@
|
|
-import * as React from 'react';
|
|
-import {
|
|
- useNavigationBuilder,
|
|
- createNavigatorFactory,
|
|
- DefaultNavigatorOptions,
|
|
- EventArg,
|
|
-} from '@react-navigation/native';
|
|
-import {
|
|
- StackRouter,
|
|
- StackRouterOptions,
|
|
- StackNavigationState,
|
|
- StackActions,
|
|
-} from '@react-navigation/routers';
|
|
-import StackView from '../views/Stack/StackView';
|
|
-import {
|
|
- StackNavigationConfig,
|
|
- StackNavigationOptions,
|
|
- StackNavigationEventMap,
|
|
-} from '../types';
|
|
-
|
|
-type Props = DefaultNavigatorOptions<StackNavigationOptions> &
|
|
- StackRouterOptions &
|
|
- StackNavigationConfig;
|
|
-
|
|
-function StackNavigator({
|
|
- initialRouteName,
|
|
- children,
|
|
- screenOptions,
|
|
- ...rest
|
|
-}: Props) {
|
|
- const { state, descriptors, navigation } = useNavigationBuilder<
|
|
- StackNavigationState,
|
|
- StackRouterOptions,
|
|
- StackNavigationOptions,
|
|
- StackNavigationEventMap
|
|
- >(StackRouter, {
|
|
- initialRouteName,
|
|
- children,
|
|
- screenOptions,
|
|
- });
|
|
-
|
|
- React.useEffect(
|
|
- () =>
|
|
- navigation.addListener &&
|
|
- navigation.addListener('tabPress', (e: EventArg<'tabPress'>) => {
|
|
- const isFocused = navigation.isFocused();
|
|
-
|
|
- // Run the operation in the next frame so we're sure all listeners have been run
|
|
- // This is necessary to know if preventDefault() has been called
|
|
- requestAnimationFrame(() => {
|
|
- if (state.index > 0 && isFocused && !e.defaultPrevented) {
|
|
- // When user taps on already focused tab and we're inside the tab,
|
|
- // reset the stack to replicate native behaviour
|
|
- navigation.dispatch({
|
|
- ...StackActions.popToTop(),
|
|
- target: state.key,
|
|
- });
|
|
- }
|
|
- });
|
|
- }),
|
|
- [navigation, state.index, state.key]
|
|
- );
|
|
-
|
|
- return (
|
|
- <StackView
|
|
- {...rest}
|
|
- state={state}
|
|
- descriptors={descriptors}
|
|
- navigation={navigation}
|
|
- />
|
|
- );
|
|
-}
|
|
-
|
|
-export default createNavigatorFactory<
|
|
- StackNavigationOptions,
|
|
- typeof StackNavigator
|
|
->(StackNavigator);
|
|
diff -ruN node_modules/@react-navigation/stack/src/types.tsx src/vendor/types.tsx
|
|
--- node_modules/@react-navigation/stack/src/types.tsx 2020-01-05 14:32:09.000000000 +0100
|
|
+++ src/vendor/types.tsx 2020-01-05 14:33:03.000000000 +0100
|
|
@@ -8,13 +8,28 @@
|
|
} from 'react-native';
|
|
import { EdgeInsets } from 'react-native-safe-area-context';
|
|
import {
|
|
+ NavigationRoute,
|
|
+ NavigationState,
|
|
+ NavigationScreenProp,
|
|
NavigationProp,
|
|
- ParamListBase,
|
|
- Descriptor,
|
|
- Route,
|
|
- NavigationHelpers,
|
|
-} from '@react-navigation/native';
|
|
-import { StackNavigationState } from '@react-navigation/routers';
|
|
+ NavigationParams,
|
|
+ NavigationNavigateAction,
|
|
+ NavigationAction,
|
|
+ NavigationEventCallback,
|
|
+ NavigationEventSubscription,
|
|
+ NavigationDescriptor,
|
|
+} from 'react-navigation';
|
|
+
|
|
+// @ts-ignore
|
|
+export type Route<T extends string> = NavigationRoute;
|
|
+
|
|
+export type NavigationStackState = NavigationState;
|
|
+
|
|
+export type NavigationStackEventName =
|
|
+ | 'willFocus'
|
|
+ | 'didFocus'
|
|
+ | 'willBlur'
|
|
+ | 'didBlur';
|
|
|
|
export type StackNavigationEventMap = {
|
|
/**
|
|
@@ -27,42 +42,29 @@
|
|
transitionEnd: { closing: boolean };
|
|
};
|
|
|
|
-export type StackNavigationHelpers = NavigationHelpers<
|
|
- ParamListBase,
|
|
- StackNavigationEventMap
|
|
->;
|
|
+export type StackNavigationHelpers = NavigationProp<NavigationStackState>
|
|
|
|
export type StackNavigationProp<
|
|
- ParamList extends ParamListBase,
|
|
- RouteName extends keyof ParamList = string
|
|
-> = NavigationProp<
|
|
- ParamList,
|
|
- RouteName,
|
|
- StackNavigationState,
|
|
- StackNavigationOptions,
|
|
- StackNavigationEventMap
|
|
-> & {
|
|
- /**
|
|
- * Push a new screen onto the stack.
|
|
- *
|
|
- * @param name Name of the route for the tab.
|
|
- * @param [params] Params object for the route.
|
|
- */
|
|
- push<RouteName extends keyof ParamList>(
|
|
- ...args: ParamList[RouteName] extends undefined | any
|
|
- ? [RouteName] | [RouteName, ParamList[RouteName]]
|
|
- : [RouteName, ParamList[RouteName]]
|
|
- ): void;
|
|
-
|
|
- /**
|
|
- * Pop a screen from the stack.
|
|
- */
|
|
- pop(count?: number): void;
|
|
-
|
|
- /**
|
|
- * Pop to the first route in the stack, dismissing all other screens.
|
|
- */
|
|
- popToTop(): void;
|
|
+State = NavigationRoute,
|
|
+Params = NavigationParams
|
|
+> = NavigationScreenProp<State, Params> & {
|
|
+ push: (
|
|
+ routeName: string,
|
|
+ params?: NavigationParams,
|
|
+ action?: NavigationNavigateAction
|
|
+ ) => boolean;
|
|
+ replace: (
|
|
+ routeName: string,
|
|
+ params?: NavigationParams,
|
|
+ action?: NavigationNavigateAction
|
|
+ ) => boolean;
|
|
+ reset: (actions: NavigationAction[], index: number) => boolean;
|
|
+ pop: (n?: number, params?: { immediate?: boolean }) => boolean;
|
|
+ popToTop: (params?: { immediate?: boolean }) => boolean;
|
|
+ addListener: (
|
|
+ event: NavigationStackEventName,
|
|
+ callback: NavigationEventCallback
|
|
+ ) => NavigationEventSubscription;
|
|
};
|
|
|
|
export type Layout = { width: number; height: number };
|
|
@@ -238,24 +240,27 @@
|
|
/**
|
|
* Navigation prop for the header.
|
|
*/
|
|
- navigation: StackNavigationProp<ParamListBase>;
|
|
+ navigation: StackNavigationProp;
|
|
/**
|
|
* Interpolated styles for various elements in the header.
|
|
*/
|
|
styleInterpolator: StackHeaderStyleInterpolator;
|
|
};
|
|
|
|
-export type StackDescriptor = Descriptor<
|
|
- ParamListBase,
|
|
- string,
|
|
- StackNavigationState,
|
|
- StackNavigationOptions
|
|
->;
|
|
+export type StackDescriptor = NavigationDescriptor<
|
|
+ NavigationParams,
|
|
+ StackNavigationOptions,
|
|
+ StackNavigationProp
|
|
+>
|
|
|
|
export type StackDescriptorMap = {
|
|
[key: string]: StackDescriptor;
|
|
};
|
|
|
|
+export type TransitionCallbackProps = {
|
|
+ closing: boolean;
|
|
+};
|
|
+
|
|
export type StackNavigationOptions = StackHeaderOptions &
|
|
Partial<TransitionPreset> & {
|
|
/**
|
|
@@ -328,6 +333,8 @@
|
|
bottom?: number;
|
|
left?: number;
|
|
};
|
|
+ onTransitionStart?: (props: TransitionCallbackProps) => void;
|
|
+ onTransitionEnd?: (props: TransitionCallbackProps) => void;
|
|
};
|
|
|
|
export type StackNavigationConfig = {
|
|
diff -ruN node_modules/@react-navigation/stack/src/views/Header/Header.tsx src/vendor/views/Header/Header.tsx
|
|
--- node_modules/@react-navigation/stack/src/views/Header/Header.tsx 2020-01-05 14:32:09.000000000 +0100
|
|
+++ src/vendor/views/Header/Header.tsx 2020-01-05 14:33:03.000000000 +0100
|
|
@@ -1,5 +1,5 @@
|
|
import * as React from 'react';
|
|
-import { StackActions } from '@react-navigation/routers';
|
|
+import { StackActions } from 'react-navigation';
|
|
|
|
import HeaderSegment from './HeaderSegment';
|
|
import { StackHeaderProps, StackHeaderTitleProps } from '../../types';
|
|
@@ -21,7 +21,7 @@
|
|
? options.headerTitle
|
|
: options.title !== undefined
|
|
? options.title
|
|
- : scene.route.name;
|
|
+ : scene.route.routeName;
|
|
|
|
let leftLabel;
|
|
|
|
@@ -37,7 +37,7 @@
|
|
? o.headerTitle
|
|
: o.title !== undefined
|
|
? o.title
|
|
- : previous.route.name;
|
|
+ : previous.route.routeName;
|
|
}
|
|
|
|
return (
|
|
@@ -55,11 +55,8 @@
|
|
}
|
|
onGoBack={
|
|
previous
|
|
- ? () =>
|
|
- navigation.dispatch({
|
|
- ...StackActions.pop(),
|
|
- source: scene.route.key,
|
|
- })
|
|
+ // @ts-ignore
|
|
+ ? () => navigation.dispatch(StackActions.pop({ key: scene.route.key }))
|
|
: undefined
|
|
}
|
|
styleInterpolator={styleInterpolator}
|
|
diff -ruN node_modules/@react-navigation/stack/src/views/Header/HeaderBackButton.tsx src/vendor/views/Header/HeaderBackButton.tsx
|
|
--- node_modules/@react-navigation/stack/src/views/Header/HeaderBackButton.tsx 2020-01-05 14:32:09.000000000 +0100
|
|
+++ src/vendor/views/Header/HeaderBackButton.tsx 2020-01-05 14:33:03.000000000 +0100
|
|
@@ -8,9 +8,9 @@
|
|
StyleSheet,
|
|
LayoutChangeEvent,
|
|
} from 'react-native';
|
|
-import { useTheme } from '@react-navigation/native';
|
|
import MaskedView from '../MaskedView';
|
|
import TouchableItem from '../TouchableItem';
|
|
+import useTheme from '../../../utils/useTheme';
|
|
import { StackHeaderLeftButtonProps } from '../../types';
|
|
|
|
type Props = StackHeaderLeftButtonProps;
|
|
diff -ruN node_modules/@react-navigation/stack/src/views/Header/HeaderBackground.tsx src/vendor/views/Header/HeaderBackground.tsx
|
|
--- node_modules/@react-navigation/stack/src/views/Header/HeaderBackground.tsx 2020-01-05 14:32:09.000000000 +0100
|
|
+++ src/vendor/views/Header/HeaderBackground.tsx 2020-01-05 14:33:03.000000000 +0100
|
|
@@ -1,6 +1,6 @@
|
|
import * as React from 'react';
|
|
import { Animated, StyleSheet, Platform, ViewProps } from 'react-native';
|
|
-import { useTheme } from '@react-navigation/native';
|
|
+import useTheme from '../../../utils/useTheme';
|
|
|
|
export default function HeaderBackground({ style, ...rest }: ViewProps) {
|
|
const { colors } = useTheme();
|
|
diff -ruN node_modules/@react-navigation/stack/src/views/Header/HeaderContainer.tsx src/vendor/views/Header/HeaderContainer.tsx
|
|
--- node_modules/@react-navigation/stack/src/views/Header/HeaderContainer.tsx 2020-01-05 14:32:09.000000000 +0100
|
|
+++ src/vendor/views/Header/HeaderContainer.tsx 2020-01-05 14:33:03.000000000 +0100
|
|
@@ -1,16 +1,13 @@
|
|
import * as React from 'react';
|
|
import { View, StyleSheet, StyleProp, ViewStyle } from 'react-native';
|
|
-import {
|
|
- NavigationContext,
|
|
- Route,
|
|
- ParamListBase,
|
|
-} from '@react-navigation/native';
|
|
-import { StackNavigationState } from '@react-navigation/routers';
|
|
+import { NavigationContext } from 'react-navigation';
|
|
+import { NavigationState as StackNavigationState } from 'react-navigation';
|
|
import { EdgeInsets } from 'react-native-safe-area-context';
|
|
|
|
import Header from './Header';
|
|
import { forStatic } from '../../TransitionConfigs/HeaderStyleInterpolators';
|
|
import {
|
|
+ Route,
|
|
Layout,
|
|
Scene,
|
|
StackHeaderStyleInterpolator,
|
|
@@ -93,9 +90,7 @@
|
|
insets,
|
|
scene,
|
|
previous,
|
|
- navigation: scene.descriptor.navigation as StackNavigationProp<
|
|
- ParamListBase
|
|
- >,
|
|
+ navigation: scene.descriptor.navigation as StackNavigationProp,
|
|
styleInterpolator: isHeaderStatic ? forStatic : styleInterpolator,
|
|
};
|
|
|
|
diff -ruN node_modules/@react-navigation/stack/src/views/Header/HeaderSegment.tsx src/vendor/views/Header/HeaderSegment.tsx
|
|
--- node_modules/@react-navigation/stack/src/views/Header/HeaderSegment.tsx 2020-01-05 14:32:09.000000000 +0100
|
|
+++ src/vendor/views/Header/HeaderSegment.tsx 2020-01-05 14:33:03.000000000 +0100
|
|
@@ -8,7 +8,7 @@
|
|
ViewStyle,
|
|
} from 'react-native';
|
|
import { EdgeInsets } from 'react-native-safe-area-context';
|
|
-import { Route } from '@react-navigation/native';
|
|
+import { NavigationRoute } from 'react-navigation';
|
|
import HeaderBackButton from './HeaderBackButton';
|
|
import HeaderBackground from './HeaderBackground';
|
|
import memoize from '../../utils/memoize';
|
|
@@ -28,7 +28,7 @@
|
|
onGoBack?: () => void;
|
|
title?: string;
|
|
leftLabel?: string;
|
|
- scene: Scene<Route<string>>;
|
|
+ scene: Scene<NavigationRoute>;
|
|
styleInterpolator: StackHeaderStyleInterpolator;
|
|
};
|
|
|
|
diff -ruN node_modules/@react-navigation/stack/src/views/Header/HeaderTitle.tsx src/vendor/views/Header/HeaderTitle.tsx
|
|
--- node_modules/@react-navigation/stack/src/views/Header/HeaderTitle.tsx 2020-01-05 14:32:09.000000000 +0100
|
|
+++ src/vendor/views/Header/HeaderTitle.tsx 2020-01-05 14:33:03.000000000 +0100
|
|
@@ -1,6 +1,6 @@
|
|
import * as React from 'react';
|
|
import { Animated, StyleSheet, Platform, TextProps } from 'react-native';
|
|
-import { useTheme } from '@react-navigation/native';
|
|
+import useTheme from '../../../utils/useTheme';
|
|
|
|
type Props = TextProps & {
|
|
tintColor?: string;
|
|
diff -ruN node_modules/@react-navigation/stack/src/views/Stack/Card.tsx src/vendor/views/Stack/Card.tsx
|
|
--- node_modules/@react-navigation/stack/src/views/Stack/Card.tsx 2020-01-05 14:32:09.000000000 +0100
|
|
+++ src/vendor/views/Stack/Card.tsx 2020-01-05 14:43:46.000000000 +0100
|
|
@@ -452,7 +452,7 @@
|
|
pointerEvents="none"
|
|
/>
|
|
) : null}
|
|
- <View ref={this.content} style={[styles.content, contentStyle]}>
|
|
+ <View ref={this.content} style={[styles.content, contentStyle] as any}>
|
|
<StackGestureRefContext.Provider value={this.gestureRef}>
|
|
<CardAnimationContext.Provider value={animationContext}>
|
|
{children}
|
|
diff -ruN node_modules/@react-navigation/stack/src/views/Stack/CardContainer.tsx src/vendor/views/Stack/CardContainer.tsx
|
|
--- node_modules/@react-navigation/stack/src/views/Stack/CardContainer.tsx 2020-01-05 14:32:09.000000000 +0100
|
|
+++ src/vendor/views/Stack/CardContainer.tsx 2020-01-05 14:40:18.000000000 +0100
|
|
@@ -1,11 +1,17 @@
|
|
import * as React from 'react';
|
|
import { Animated, View, StyleSheet, StyleProp, ViewStyle } from 'react-native';
|
|
-import { StackNavigationState } from '@react-navigation/routers';
|
|
-import { Route, useTheme } from '@react-navigation/native';
|
|
+import { NavigationState as StackNavigationState } from 'react-navigation';
|
|
import { Props as HeaderContainerProps } from '../Header/HeaderContainer';
|
|
import Card from './Card';
|
|
import FloatingHeaderHeightContext from '../../utils/FloatingHeaderHeightContext';
|
|
-import { Scene, Layout, StackHeaderMode, TransitionPreset } from '../../types';
|
|
+import useTheme from '../../../utils/useTheme';
|
|
+import {
|
|
+ Route,
|
|
+ Scene,
|
|
+ Layout,
|
|
+ StackHeaderMode,
|
|
+ TransitionPreset,
|
|
+} from '../../types';
|
|
|
|
type Props = TransitionPreset & {
|
|
index: number;
|
|
@@ -153,7 +159,7 @@
|
|
? { marginTop: floatingHeaderHeight }
|
|
: null
|
|
}
|
|
- contentStyle={[{ backgroundColor: colors.background }, cardStyle]}
|
|
+ contentStyle={[{ backgroundColor: colors.background }, cardStyle] as any}
|
|
style={StyleSheet.absoluteFill}
|
|
>
|
|
<View style={styles.container}>
|
|
diff -ruN node_modules/@react-navigation/stack/src/views/Stack/CardStack.tsx src/vendor/views/Stack/CardStack.tsx
|
|
--- node_modules/@react-navigation/stack/src/views/Stack/CardStack.tsx 2020-01-05 14:32:09.000000000 +0100
|
|
+++ src/vendor/views/Stack/CardStack.tsx 2020-01-05 14:33:03.000000000 +0100
|
|
@@ -11,8 +11,7 @@
|
|
import { EdgeInsets } from 'react-native-safe-area-context';
|
|
// eslint-disable-next-line import/no-unresolved
|
|
import { ScreenContainer, Screen, screensEnabled } from 'react-native-screens'; // Import with * as to prevent getters being called
|
|
-import { Route } from '@react-navigation/native';
|
|
-import { StackNavigationState } from '@react-navigation/routers';
|
|
+import { NavigationState as StackNavigationState } from 'react-navigation';
|
|
|
|
import { getDefaultHeaderHeight } from '../Header/HeaderSegment';
|
|
import { Props as HeaderContainerProps } from '../Header/HeaderContainer';
|
|
@@ -25,6 +24,7 @@
|
|
import { forNoAnimation as forNoAnimationCard } from '../../TransitionConfigs/CardStyleInterpolators';
|
|
import getDistanceForDirection from '../../utils/getDistanceForDirection';
|
|
import {
|
|
+ Route,
|
|
Layout,
|
|
StackHeaderMode,
|
|
StackCardMode,
|
|
diff -ruN node_modules/@react-navigation/stack/src/views/Stack/StackView.tsx src/vendor/views/Stack/StackView.tsx
|
|
--- node_modules/@react-navigation/stack/src/views/Stack/StackView.tsx 2020-01-05 14:32:09.000000000 +0100
|
|
+++ src/vendor/views/Stack/StackView.tsx 2020-01-05 14:33:03.000000000 +0100
|
|
@@ -1,8 +1,11 @@
|
|
import * as React from 'react';
|
|
import { Platform } from 'react-native';
|
|
import { SafeAreaConsumer, EdgeInsets } from 'react-native-safe-area-context';
|
|
-import { Route } from '@react-navigation/native';
|
|
-import { StackActions, StackNavigationState } from '@react-navigation/routers';
|
|
+import {
|
|
+ StackActions,
|
|
+ NavigationState as StackNavigationState,
|
|
+ SceneView,
|
|
+} from 'react-navigation';
|
|
|
|
import CardStack from './CardStack';
|
|
import KeyboardManager from '../KeyboardManager';
|
|
@@ -11,6 +14,7 @@
|
|
} from '../Header/HeaderContainer';
|
|
import SafeAreaProviderCompat from '../SafeAreaProviderCompat';
|
|
import {
|
|
+ Route,
|
|
StackNavigationHelpers,
|
|
StackNavigationConfig,
|
|
StackDescriptorMap,
|
|
@@ -20,6 +24,7 @@
|
|
state: StackNavigationState;
|
|
navigation: StackNavigationHelpers;
|
|
descriptors: StackDescriptorMap;
|
|
+ screenProps: unknown;
|
|
};
|
|
|
|
type State = {
|
|
@@ -257,14 +262,31 @@
|
|
return null;
|
|
}
|
|
|
|
- return descriptor.render();
|
|
+ const { navigation, getComponent } = descriptor;
|
|
+ const SceneComponent = getComponent();
|
|
+
|
|
+ return (
|
|
+ <SceneView
|
|
+ screenProps={this.props.screenProps}
|
|
+ navigation={navigation}
|
|
+ component={SceneComponent}
|
|
+ />
|
|
+ );
|
|
};
|
|
|
|
private renderHeader = (props: HeaderContainerProps) => {
|
|
return <HeaderContainer {...props} />;
|
|
};
|
|
|
|
+ private handleTransitionComplete = ({ route }: { route: Route<string> }) => {
|
|
+ // TODO: remove when the new event system lands
|
|
+ this.props.navigation.dispatch(
|
|
+ StackActions.completeTransition({ toChildKey: route.key })
|
|
+ );
|
|
+ };
|
|
+
|
|
private handleOpenRoute = ({ route }: { route: Route<string> }) => {
|
|
+ this.handleTransitionComplete({ route });
|
|
this.setState(state => ({
|
|
routes: state.replacingRouteKeys.length
|
|
? state.routes.filter(r => !state.replacingRouteKeys.includes(r.key))
|
|
@@ -283,15 +305,19 @@
|
|
// This will happen in when the route was closed from the card component
|
|
// e.g. When the close animation triggered from a gesture ends
|
|
// For the cleanup, the card needs to call this function again from its componentDidUpdate
|
|
- navigation.dispatch({
|
|
- ...StackActions.pop(),
|
|
- source: route.key,
|
|
- target: state.key,
|
|
- });
|
|
+ // @ts-ignore
|
|
+ navigation.dispatch(StackActions.pop({ key: route.key }));
|
|
} else {
|
|
// Otherwise, the animation was triggered due to a route removal
|
|
// In this case, we need to clean up any state tracking the route and pop it immediately
|
|
|
|
+ // While closing route we need to point to the previous one assuming that
|
|
+ // this previous one in routes array
|
|
+ const index = this.state.routes.findIndex(r => r.key === route.key);
|
|
+ this.handleTransitionComplete({
|
|
+ route: this.state.routes[Math.max(index - 1, 0)],
|
|
+ });
|
|
+
|
|
// @ts-ignore
|
|
this.setState(state => ({
|
|
routes: state.routes.filter(r => r.key !== route.key),
|
|
@@ -308,22 +334,26 @@
|
|
private handleTransitionStart = (
|
|
{ route }: { route: Route<string> },
|
|
closing: boolean
|
|
- ) =>
|
|
- this.props.navigation.emit({
|
|
- type: 'transitionStart',
|
|
- data: { closing },
|
|
- target: route.key,
|
|
- });
|
|
+ ) => {
|
|
+ const { descriptors } = this.props;
|
|
+ const descriptor = descriptors[route.key];
|
|
+
|
|
+ descriptor &&
|
|
+ descriptor.options.onTransitionStart &&
|
|
+ descriptor.options.onTransitionStart({ closing });
|
|
+ };
|
|
|
|
private handleTransitionEnd = (
|
|
{ route }: { route: Route<string> },
|
|
closing: boolean
|
|
- ) =>
|
|
- this.props.navigation.emit({
|
|
- type: 'transitionEnd',
|
|
- data: { closing },
|
|
- target: route.key,
|
|
- });
|
|
+ ) => {
|
|
+ const { descriptors } = this.props;
|
|
+ const descriptor = descriptors[route.key];
|
|
+
|
|
+ descriptor &&
|
|
+ descriptor.options.onTransitionStart &&
|
|
+ descriptor.options.onTransitionStart({ closing });
|
|
+ };
|
|
|
|
render() {
|
|
const {
|