Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions Notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,25 @@ class Notification extends Component {
}

showNotification(done = () => {}) {
this.props.onShowing && this.props.onShowing();
Animated.timing(this.state.animatedValue, {
toValue: 1,
duration: this.props.openCloseDuration,
}).start(done);
}).start(() => {
done();
this.props.onShown && this.props.onShown();
});
}

closeNotification(done = () => {}) {
closeNotification(done) {
this.props.onClosing && this.props.onClosing();
Animated.timing(this.state.animatedValue, {
toValue: 0,
duration: this.props.openCloseDuration,
}).start(done);
}).start(() => {
done && done();
this.props.onClosed && this.props.onClosed(done != null);
});
}

render() {
Expand Down Expand Up @@ -120,7 +128,11 @@ class Notification extends Component {
iconApp={iconApp}
icon={icon}
vibrate={vibrate}
onClose={() => this.setState({ isOpen: false }, this.closeNotification)}
onClose={() => {
//clear timeout
clearTimeout(this.currentNotificationInterval);
this.setState({ isOpen: false }, this.closeNotification);
}}
/>
</Animated.View>
);
Expand All @@ -137,6 +149,10 @@ Notification.propTypes = {
PropTypes.func,
]),
iconApp: Image.propTypes.source,
onShowing: PropTypes.func,
onShown: PropTypes.func,
onClosing: PropTypes.func,
onClosed: PropTypes.func
};

Notification.defaultProps = {
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ npm install react-native-in-app-notification --save
| backgroundColour | The background colour of the Notification component | String | No | `white` |
| iconApp | App Icon | ImageSourcePropType | No | `null` |
| notificationBodyComponent | **See below about NotificationBody** | React Node or Function | Recommended | `./DefaultNotificationBody` |
| onShowing | Method called before showing notification | Function | No | `null` |
| onShown | Method called after notification shown | Function | No | `null` |
| onClosing | Method called before closing notification | Function | No | `null` |
| onClosed | Method called after notification closed | Function | No | `null` |

### NotificationBody
The notification body is what is rendered inside the main Notification component and gives you the ability to customise how the notification looks. You can use the default notification body component in `./DefaultNotificationBody.js` as inspiration and guidance.
Expand Down