Skip to content

Commit

Permalink
feat: add onShown callback function
Browse files Browse the repository at this point in the history
  • Loading branch information
seniv committed Jul 12, 2022
1 parent 606582a commit a3aefcd
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ hideAnimationDuration | Number | animationDuration \|\| 300 | How f
easing | Easing | null | Animation easing. Details: https://reactnative.dev/docs/easing
showEasing | Easing | easing \|\| null | Show Animation easing.
hideEasing | Easing | easing \|\| null | Hide Animation easing.
onShown | () => void | null | Function called when entering animation is finished
onStartHiding | () => void | null | Function called when notification started hiding
onHidden | () => void | null | Function called when notification completely hidden
onPress | () => void | null | Function called when user press on notification
Expand Down
12 changes: 12 additions & 0 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,18 @@ export default function App() {
})
}
/>
<Button
title="Slow animation & onShown"
onPress={() =>
notifierRef.current?.showNotification({
title: 'Called using ref!',
description: 'Amazing!',
showAnimationDuration: 5000,
duration: 7000,
onShown: () => console.log('Notification shown'),
})
}
/>
<Button
title="Styled Notification"
onPress={() =>
Expand Down
3 changes: 2 additions & 1 deletion src/Notifier.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ export class NotifierRoot extends React.PureComponent<ShowNotificationParams, St
translucentStatusBar,
containerStyle,
containerProps,
onShown,
...restParams
} = params;

Expand Down Expand Up @@ -181,7 +182,7 @@ export class NotifierRoot extends React.PureComponent<ShowNotificationParams, St
this.showParams?.animationDuration ??
DEFAULT_ANIMATION_DURATION,
useNativeDriver: true,
}).start();
}).start(onShown);
}

public clearQueue(hideDisplayedNotification?: boolean) {
Expand Down
4 changes: 4 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ export interface ShowParams {
* @default easing || null */
hideEasing?: Animated.TimingAnimationConfig['easing'];

/** Function called when entering animation is finished
* @default null */
onShown?: () => void;

/** Function called when notification started hiding
* @default null */
onStartHiding?: () => void;
Expand Down

0 comments on commit a3aefcd

Please sign in to comment.