From c0c17e9affecbaa90401fa0971cce8c4f471aca3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Czaj=C4=99cki?= Date: Fri, 26 Jul 2019 13:24:30 +0200 Subject: [PATCH] feat: inform whether screen is opening/closing in onTransition callbacks (#169) --- packages/stack/src/types.tsx | 4 ++-- packages/stack/src/views/Stack/Stack.tsx | 14 ++++++++++---- packages/stack/src/views/Stack/StackItem.tsx | 10 +++++----- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/packages/stack/src/types.tsx b/packages/stack/src/types.tsx index 2615178cb77b0e..eb6978982ddbe7 100644 --- a/packages/stack/src/types.tsx +++ b/packages/stack/src/types.tsx @@ -107,8 +107,8 @@ export type NavigationStackOptions = HeaderOptions & vertical?: number; horizontal?: number; }; - onTransitionStart?: () => void; - onTransitionEnd?: () => void; + onTransitionStart?: (closing: boolean) => void; + onTransitionEnd?: (closing: boolean) => void; }; export type NavigationStackConfig = { diff --git a/packages/stack/src/views/Stack/Stack.tsx b/packages/stack/src/views/Stack/Stack.tsx index 1d3750e0a89a33..8e64cebc0f0729 100755 --- a/packages/stack/src/views/Stack/Stack.tsx +++ b/packages/stack/src/views/Stack/Stack.tsx @@ -254,21 +254,27 @@ export default class Stack extends React.Component { })); }; - private handleTransitionStart = ({ route }: { route: Route }) => { + private handleTransitionStart = ( + { route }: { route: Route }, + closing: boolean + ) => { const { descriptors } = this.props; const descriptor = descriptors[route.key]; descriptor && descriptor.options.onTransitionStart && - descriptor.options.onTransitionStart(); + descriptor.options.onTransitionStart(closing); }; - private handleTransitionEnd = ({ route }: { route: Route }) => { + private handleTransitionEnd = ( + { route }: { route: Route }, + closing: boolean + ) => { const descriptor = this.props.descriptors[route.key]; descriptor && descriptor.options.onTransitionEnd && - descriptor.options.onTransitionEnd(); + descriptor.options.onTransitionEnd(closing); }; render() { diff --git a/packages/stack/src/views/Stack/StackItem.tsx b/packages/stack/src/views/Stack/StackItem.tsx index 758ddcfa1af392..a01f102d6b4eda 100644 --- a/packages/stack/src/views/Stack/StackItem.tsx +++ b/packages/stack/src/views/Stack/StackItem.tsx @@ -33,8 +33,8 @@ type Props = TransitionPreset & { onOpenRoute: (props: { route: Route }) => void; onCloseRoute: (props: { route: Route }) => void; onGoBack: (props: { route: Route }) => void; - onTransitionStart?: (props: { route: Route }) => void; - onTransitionEnd?: (props: { route: Route }) => void; + onTransitionStart?: (props: { route: Route }, closing: boolean) => void; + onTransitionEnd?: (props: { route: Route }, closing: boolean) => void; onPageChangeStart?: () => void; onPageChangeConfirm?: () => void; onPageChangeCancel?: () => void; @@ -52,14 +52,14 @@ export default class StackItem extends React.PureComponent { private handleOpen = () => { const { scene, onTransitionEnd, onOpenRoute } = this.props; - onTransitionEnd && onTransitionEnd({ route: scene.route }); + onTransitionEnd && onTransitionEnd({ route: scene.route }, false); onOpenRoute({ route: scene.route }); }; private handleClose = () => { const { scene, onTransitionEnd, onCloseRoute } = this.props; - onTransitionEnd && onTransitionEnd({ route: scene.route }); + onTransitionEnd && onTransitionEnd({ route: scene.route }, true); onCloseRoute({ route: scene.route }); }; @@ -78,7 +78,7 @@ export default class StackItem extends React.PureComponent { onPageChangeCancel && onPageChangeCancel(); } - onTransitionStart && onTransitionStart({ route: scene.route }); + onTransitionStart && onTransitionStart({ route: scene.route }, closing); closing && onGoBack({ route: scene.route }); };