diff --git a/README.md b/README.md index b0e0757..af93c8c 100644 --- a/README.md +++ b/README.md @@ -104,16 +104,19 @@ class AppWithNotifications extends Component { When you want to show the notification, just wrap the component which needs to display a notification with the `withInAppNotification` HOC and call the `.showNotification` methods from its props. -`.showNotification` can take three arguments (all of which are optional): +`.showNotification` can take four arguments (all of which are optional): - `title` - `message` - `onPress` +- `additionalProps` **N.B:** you should probably include at least one of `title` or `message`! `onPress` doesn't need to be used for passive notifications and you can use `onClose` in your `NotificationBody` component to allow your users to close the notification. +`additionalProps` can be used to pass arbitory props to `NotificationBody` component. Can be accessed in `NotificationBody` component via `props.additionalProps`. + ```javascript import React, { Component } from 'react'; import { View, Text, TouchableHighlight } from 'react-native'; @@ -130,6 +133,7 @@ class MyApp extends Component { title: 'You pressed it!', message: 'The notification has been triggered', onPress: () => Alert.alert('Alert', 'You clicked the notification!') + additionalProps={{ type: 'error' }} }); }} > diff --git a/src/Notification.js b/src/Notification.js index 68ade1a..5c37832 100644 --- a/src/Notification.js +++ b/src/Notification.js @@ -29,12 +29,13 @@ class Notification extends Component { } show( - { title, message, onPress, icon, vibrate } = { + { title, message, onPress, icon, vibrate, additionalProps } = { title: '', message: '', onPress: null, icon: null, vibrate: true, + additionalProps: {}, }, ) { const { closeInterval } = this.props; @@ -53,6 +54,7 @@ class Notification extends Component { onPress, icon, vibrate, + additionalProps, }, () => this.showNotification(() => { this.currentNotificationInterval = setTimeout(() => { @@ -64,6 +66,7 @@ class Notification extends Component { onPress: null, icon: null, vibrate: true, + additionalProps, }, this.closeNotification, ); @@ -134,6 +137,7 @@ class Notification extends Component { icon={icon} vibrate={vibrate} onClose={() => this.setState({ isOpen: false }, this.closeNotification)} + additionalProps={this.state.additionalProps} /> );