Last active
August 23, 2019 14:35
-
-
Save vadimkorr/a200ad71aaa516c268890d98aee66d0b 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 { Button, NotificationsStore, withNotifications } from "../../components"; | |
// description of buttons which add notifications | |
const controls = [{ | |
key: "create-success-notification-button", | |
iconName: "check", | |
colorPrimary: "#cbf0c4", | |
colorAccent: "#3c763d", | |
onPress: store => { | |
store.add( | |
createSuccessNotification( | |
"Success", | |
"This message tells that everything goes fine." | |
) | |
); | |
} | |
}, | |
// ... | |
]; | |
const NotificationControlsInner = props => { | |
// 'store' is passed via 'withNotifications' function | |
const { store } = props; | |
return ( | |
<React.Fragment> | |
{controls.map((b, i) => ( | |
<View | |
key={b.key} | |
style={{ marginBottom: i !== controls.length - 1 ? 10 : 0 }} | |
> | |
<Button | |
iconName={b.iconName} | |
colorPrimary={b.colorPrimary} | |
colorAccent={b.colorAccent} | |
onPress={() => b.onPress(store)} | |
/> | |
</View> | |
))} | |
</React.Fragment> | |
); | |
}; | |
NotificationControlsInner.propTypes = { | |
store: PropTypes.instanceOf(NotificationsStore).isRequired | |
}; | |
// 'NotificationControls' has store injected | |
// it is used in the app (not 'NotificationControlsInner' component) | |
export const NotificationControls = withNotifications( | |
NotificationControlsInner | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment