Skip to content
This repository has been archived by the owner on Feb 8, 2020. It is now read-only.

Commit

Permalink
feat: add transitionStart and transitionEnd events
Browse files Browse the repository at this point in the history
  • Loading branch information
satya164 committed Aug 5, 2019
1 parent f4b716a commit 8924b07
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
10 changes: 7 additions & 3 deletions packages/stack/src/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ import {
Route,
} from '@navigation-ex/core';

export type StackNavigationEventMap = {
transitionStart: { closing: boolean };
transitionEnd: { closing: boolean };
};

export type StackNavigationState = NavigationState;

export type StackNavigationProp<
Expand All @@ -22,7 +27,8 @@ export type StackNavigationProp<
ParamList,
RouteName,
StackNavigationState,
StackNavigationOptions
StackNavigationOptions,
StackNavigationEventMap
> & {
/**
* Push a new screen onto the stack.
Expand Down Expand Up @@ -124,8 +130,6 @@ export type StackNavigationOptions = HeaderOptions &
vertical?: number;
horizontal?: number;
};
onTransitionStart?: (props: TransitionCallbackProps) => void;
onTransitionEnd?: (props: TransitionCallbackProps) => void;
};

export type StackNavigationConfig = {
Expand Down
27 changes: 12 additions & 15 deletions packages/stack/src/views/Stack/Stack.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -262,25 +262,22 @@ export default class Stack extends React.Component<Props, State> {
private handleTransitionStart = (
{ route }: { route: Route<string> },
closing: boolean
) => {
const { descriptors } = this.props;
const descriptor = descriptors[route.key];

descriptor &&
descriptor.options.onTransitionStart &&
descriptor.options.onTransitionStart({ closing });
};
) =>
this.props.navigation.emit({
type: 'transitionStart',
data: { closing },
target: route.key,
});

private handleTransitionEnd = (
{ route }: { route: Route<string> },
closing: boolean
) => {
const descriptor = this.props.descriptors[route.key];

descriptor &&
descriptor.options.onTransitionEnd &&
descriptor.options.onTransitionEnd({ closing });
};
) =>
this.props.navigation.emit({
type: 'transitionEnd',
data: { closing },
target: route.key,
});

render() {
const {
Expand Down

0 comments on commit 8924b07

Please sign in to comment.