Browse Source

Navigation interface for showing in-app notifications in iOS

Artal Druk 8 years ago
parent
commit
a89c088076

+ 9
- 0
example/src/screens/FirstTabScreen.js View File

67
           <Text style={styles.button}>Show LightBox</Text>
67
           <Text style={styles.button}>Show LightBox</Text>
68
         </TouchableOpacity>
68
         </TouchableOpacity>
69
 
69
 
70
+        <TouchableOpacity onPress={ this.onInAppNotificationPress.bind(this) }>
71
+          <Text style={styles.button}>Show In-App Notification</Text>
72
+        </TouchableOpacity>
73
+
70
       </View>
74
       </View>
71
     );
75
     );
72
   }
76
   }
96
       }
100
       }
97
     });
101
     });
98
   }
102
   }
103
+  onInAppNotificationPress() {
104
+    this.props.navigator.showInAppNotification({
105
+      screen: "example.NotificationScreen"
106
+    });
107
+  }
99
 }
108
 }
100
 
109
 
101
 const styles = StyleSheet.create({
110
 const styles = StyleSheet.create({

+ 52
- 0
example/src/screens/NotificationScreen.js View File

1
+import React, {Component} from 'react';
2
+import {
3
+  StyleSheet,
4
+  Text,
5
+  View,
6
+  TouchableOpacity,
7
+  Dimensions
8
+} from 'react-native';
9
+
10
+export default class NotificationScreen extends Component {
11
+  constructor(props) {
12
+    super(props);
13
+  }
14
+  render() {
15
+    return (
16
+      <View style={styles.container}>
17
+        <Text style={styles.welcome}>
18
+          This is a Notification!
19
+        </Text>
20
+        <TouchableOpacity onPress={ this.onDismissPress.bind(this) }>
21
+          <Text style={styles.button}>Dismiss</Text>
22
+        </TouchableOpacity>
23
+      </View>
24
+    );
25
+  }
26
+  onDismissPress() {
27
+    this.props.navigator.dismissInAppNotification();
28
+  }
29
+}
30
+
31
+var styles = StyleSheet.create({
32
+  container: {
33
+    flex: 1,
34
+    width: Dimensions.get('window').width,
35
+    justifyContent: 'center',
36
+    alignItems: 'center',
37
+    backgroundColor: '#d6e7ad'
38
+  },
39
+  welcome: {
40
+    fontSize: 20,
41
+    textAlign: 'center',
42
+    margin: 10,
43
+    paddingTop: 20
44
+  },
45
+  button: {
46
+    textAlign: 'center',
47
+    fontSize: 18,
48
+    marginBottom: 10,
49
+    marginTop:10,
50
+    color: '#4692ad'
51
+  }
52
+});

+ 1
- 0
example/src/screens/index.android.js View File

7
 import StyledScreen from './StyledScreen';
7
 import StyledScreen from './StyledScreen';
8
 import ModalScreen from './ModalScreen';
8
 import ModalScreen from './ModalScreen';
9
 import LightBoxScreen from './LightBoxScreen';
9
 import LightBoxScreen from './LightBoxScreen';
10
+import NotificationScreen from './NotificationScreen'
10
 import SideMenu from './SideMenu';
11
 import SideMenu from './SideMenu';
11
 
12
 
12
 // register all screens of the app (including internal ones)
13
 // register all screens of the app (including internal ones)

+ 2
- 0
example/src/screens/index.ios.js View File

7
 import StyledScreen from './StyledScreen';
7
 import StyledScreen from './StyledScreen';
8
 import ModalScreen from './ModalScreen';
8
 import ModalScreen from './ModalScreen';
9
 import LightBoxScreen from './LightBoxScreen';
9
 import LightBoxScreen from './LightBoxScreen';
10
+import NotificationScreen from './NotificationScreen'
10
 import SideMenu from './SideMenu';
11
 import SideMenu from './SideMenu';
11
 
12
 
12
 // register all screens of the app (including internal ones)
13
 // register all screens of the app (including internal ones)
18
   Navigation.registerComponent('example.StyledScreen', () => StyledScreen);
19
   Navigation.registerComponent('example.StyledScreen', () => StyledScreen);
19
   Navigation.registerComponent('example.ModalScreen', () => ModalScreen);
20
   Navigation.registerComponent('example.ModalScreen', () => ModalScreen);
20
   Navigation.registerComponent('example.LightBoxScreen', () => LightBoxScreen);
21
   Navigation.registerComponent('example.LightBoxScreen', () => LightBoxScreen);
22
+  Navigation.registerComponent('example.NotificationScreen', () => NotificationScreen);
21
   Navigation.registerComponent('example.SideMenu', () => SideMenu);
23
   Navigation.registerComponent('example.SideMenu', () => SideMenu);
22
 }
24
 }

+ 1
- 1
package.json View File

7
     "type": "git",
7
     "type": "git",
8
     "url": "https://github.com/wix/react-native-navigation.git"
8
     "url": "https://github.com/wix/react-native-navigation.git"
9
   },
9
   },
10
-  "version": "1.0.17",
10
+  "version": "1.0.18",
11
   "description": "React Native Navigation - truly native navigation for iOS and Android",
11
   "description": "React Native Navigation - truly native navigation for iOS and Android",
12
   "nativePackage": true,
12
   "nativePackage": true,
13
   "bugs": {
13
   "bugs": {

+ 10
- 0
src/Navigation.js View File

83
   return platformSpecific.dismissLightBox(params);
83
   return platformSpecific.dismissLightBox(params);
84
 }
84
 }
85
 
85
 
86
+function showInAppNotification(params = {}) {
87
+  return platformSpecific.showInAppNotification(params);
88
+}
89
+
90
+function dismissInAppNotification(params = {}) {
91
+  return platformSpecific.dismissInAppNotification(params);
92
+}
93
+
86
 export default {
94
 export default {
87
   registerScreen,
95
   registerScreen,
88
   getRegisteredScreen,
96
   getRegisteredScreen,
92
   dismissAllModals,
100
   dismissAllModals,
93
   showLightBox,
101
   showLightBox,
94
   dismissLightBox,
102
   dismissLightBox,
103
+  showInAppNotification,
104
+  dismissInAppNotification,
95
   startTabBasedApp: platformSpecific.startTabBasedApp,
105
   startTabBasedApp: platformSpecific.startTabBasedApp,
96
   startSingleScreenApp: platformSpecific.startSingleScreenApp
106
   startSingleScreenApp: platformSpecific.startSingleScreenApp
97
 }
107
 }

+ 8
- 0
src/Screen.js View File

53
     return Navigation.dismissLightBox(params);
53
     return Navigation.dismissLightBox(params);
54
   }
54
   }
55
 
55
 
56
+  showInAppNotification(params = {}) {
57
+    return Navigation.showInAppNotification(params);
58
+  }
59
+
60
+  dismissInAppNotification(params = {}) {
61
+    return Navigation.dismissInAppNotification(params);
62
+  }
63
+
56
   setButtons(params = {}) {
64
   setButtons(params = {}) {
57
     return platformSpecific.navigatorSetButtons(this, this.navigatorEventID, params);
65
     return platformSpecific.navigatorSetButtons(this, this.navigatorEventID, params);
58
   }
66
   }

+ 38
- 1
src/platformSpecific.ios.js View File

1
 import utils from './utils';
1
 import utils from './utils';
2
 import Navigation from './Navigation';
2
 import Navigation from './Navigation';
3
-import Controllers, { Modal } from 'react-native-controllers';
3
+import Controllers, { Modal, Notification } from 'react-native-controllers';
4
 const React = Controllers.hijackReact();
4
 const React = Controllers.hijackReact();
5
 const {
5
 const {
6
   ControllerRegistry,
6
   ControllerRegistry,
404
   Modal.dismissLightBox();
404
   Modal.dismissLightBox();
405
 }
405
 }
406
 
406
 
407
+function showInAppNotification(params) {
408
+  if (!params.screen) {
409
+    console.error('showInAppNotification(params): params.screen is required');
410
+    return;
411
+  }
412
+
413
+  const controllerID = utils.getRandomId();
414
+  const navigatorID = controllerID + '_nav';
415
+  const screenInstanceID = utils.getRandomId();
416
+  const {
417
+    navigatorStyle,
418
+    navigatorButtons,
419
+    navigatorEventID
420
+  } = _mergeScreenSpecificSettings(params.screen, screenInstanceID, params);
421
+  const passProps = Object.assign({}, params.passProps);
422
+  passProps.navigatorID = navigatorID;
423
+  passProps.screenInstanceID = screenInstanceID;
424
+  passProps.navigatorEventID = navigatorEventID;
425
+
426
+  Notification.show({
427
+    component: params.screen,
428
+    passProps: passProps,
429
+    style: params.style,
430
+    animation: params.animation || Notification.AnimationPresets.default,
431
+    position: params.position,
432
+    shadowRadius: params.shadowRadius,
433
+    dismissWithSwipe: params.dismissWithSwipe || true,
434
+    autoDismissTimerSec: params.autoDismissTimerSec || 5
435
+  });
436
+}
437
+
438
+function dismissInAppNotification(params) {
439
+  Notification.dismiss(params);
440
+}
441
+
407
 export default {
442
 export default {
408
   startTabBasedApp,
443
   startTabBasedApp,
409
   startSingleScreenApp,
444
   startSingleScreenApp,
416
   dismissAllModals,
451
   dismissAllModals,
417
   showLightBox,
452
   showLightBox,
418
   dismissLightBox,
453
   dismissLightBox,
454
+  showInAppNotification,
455
+  dismissInAppNotification,
419
   navigatorSetButtons,
456
   navigatorSetButtons,
420
   navigatorSetTitle,
457
   navigatorSetTitle,
421
   navigatorSetTitleImage,
458
   navigatorSetTitleImage,