Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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' }}
});
}}
>
Expand Down
6 changes: 5 additions & 1 deletion src/Notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -53,6 +54,7 @@ class Notification extends Component {
onPress,
icon,
vibrate,
additionalProps,
},
() => this.showNotification(() => {
this.currentNotificationInterval = setTimeout(() => {
Expand All @@ -64,6 +66,7 @@ class Notification extends Component {
onPress: null,
icon: null,
vibrate: true,
additionalProps,
},
this.closeNotification,
);
Expand Down Expand Up @@ -134,6 +137,7 @@ class Notification extends Component {
icon={icon}
vibrate={vibrate}
onClose={() => this.setState({ isOpen: false }, this.closeNotification)}
additionalProps={this.state.additionalProps}
/>
</Animated.View>
);
Expand Down