Last active
August 23, 2019 14:37
-
-
Save vadimkorr/79ae0a0a12d33cf1e374664eb495a29a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react"; | |
import PropTypes from "prop-types"; | |
import { View } from "react-native"; | |
import { observer } from "mobx-react"; | |
import { Notification } from "../Notification"; | |
import { NotificationsStore, withNotifications } from "../store"; | |
// 'observer' function turns component into reactive component | |
// component will be rerendered upon 'notifications' array change | |
const NotificationsInner = observer(props => { | |
const { store } = props; | |
return ( | |
<React.Fragment> | |
{store.notifications.map((notification, index) => ( | |
<View | |
key={notification.id} | |
style={{ | |
marginTop: index !== 0 ? 15 : 0 | |
}} | |
> | |
<Notification | |
type={notification.type} | |
title={notification.title} | |
message={notification.message} | |
onClosePress={() => { | |
store.remove(notification); | |
}} | |
/> | |
</View> | |
))} | |
</React.Fragment> | |
); | |
}); | |
NotificationsInner.propTypes = { | |
store: PropTypes.instanceOf(NotificationsStore) | |
}; | |
export const Notifications = withNotifications(NotificationsInner); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment