File tree Expand file tree Collapse file tree 5 files changed +76
-0
lines changed
Expand file tree Collapse file tree 5 files changed +76
-0
lines changed Original file line number Diff line number Diff line change 1515 "react-native" : " >=0.54.0"
1616 },
1717 "dependencies" : {
18+ "hoist-non-react-statics" : " ^3.0.1" ,
1819 "react-native-iphone-x-helper" : " ^1.2.0" ,
1920 "react-native-swipe-gestures" : " ^1.0.2"
2021 },
Original file line number Diff line number Diff line change 1+ import React from 'react' ;
2+
3+ const context = React . createContext ( ( ) => { } ) ;
4+
5+ export default context ;
Original file line number Diff line number Diff line change 11export { default as Notification } from './notification' ;
2+
3+ export { default as Provider } from './provider' ;
4+ export { default as withInAppNotification } from './with-in-app-notification.hoc' ;
Original file line number Diff line number Diff line change 1+ import React , { Children } from 'react' ;
2+ import PropTypes from 'prop-types' ;
3+
4+ import Context from './context' ;
5+ import Notification from './notification' ;
6+
7+ class Provider extends React . PureComponent {
8+ constructor ( props ) {
9+ super ( props ) ;
10+
11+ this . showNotification = this . showNotification . bind ( this ) ;
12+ }
13+
14+ showNotification ( notificationOptions ) {
15+ if ( this . notification ) {
16+ this . notification . show ( notificationOptions ) ;
17+ }
18+ }
19+
20+ render ( ) {
21+ return (
22+ < Context . Provider value = { this . showNotification } >
23+ { Children . only ( this . props . children ) }
24+ < Notification
25+ ref = { ( ref ) => {
26+ this . notification = ref ;
27+ } }
28+ />
29+ </ Context . Provider >
30+ ) ;
31+ }
32+ }
33+
34+ Provider . propTypes = {
35+ children : PropTypes . element . isRequired ,
36+ } ;
37+
38+ export default Provider ;
Original file line number Diff line number Diff line change 1+ import React from 'react' ;
2+
3+ import hoistNonReactStatic from 'hoist-non-react-statics' ;
4+
5+ import Context from '~/react-native-in-app-notification/src/context' ;
6+
7+ function withInAppNotification ( WrappedComponent ) {
8+ class Enhanced extends React . PureComponent {
9+ render ( ) {
10+ return (
11+ < Context . Consumer >
12+ { showNotification => (
13+ < WrappedComponent
14+ { ...this . props }
15+ showNotification = { showNotification }
16+ />
17+ ) }
18+ </ Context . Consumer >
19+ ) ;
20+ }
21+ }
22+
23+ // Pass over static props
24+ hoistNonReactStatic ( Enhanced , WrappedComponent ) ;
25+
26+ return Enhanced ;
27+ }
28+
29+ export default withInAppNotification ;
You can’t perform that action at this time.
0 commit comments