1
+ 'use strict' ;
2
+
3
+ var NativeCodePush = require ( "react-native" ) . NativeModules . CodePush ;
4
+
5
+ var Platform = require ( "Platform" ) ;
6
+ var Alert ;
7
+
8
+ if ( Platform . OS === "android" ) {
9
+ /*
10
+ * Promisify native methods. Assumes that every native method takes
11
+ * two callback functions, resolve and reject.
12
+ */
13
+ var methodsToPromisify = [
14
+ "installUpdate" ,
15
+ "downloadUpdate" ,
16
+ "getConfiguration" ,
17
+ "getCurrentPackage" ,
18
+ "isFailedUpdate" ,
19
+ "isFirstRun" ,
20
+ "notifyApplicationReady"
21
+ ] ;
22
+
23
+ methodsToPromisify . forEach ( ( methodName ) => {
24
+ var aMethod = NativeCodePush [ methodName ] ;
25
+ NativeCodePush [ methodName ] = function ( ) {
26
+ var args = [ ] . slice . apply ( arguments ) ;
27
+ return new Promise ( ( resolve , reject ) => {
28
+ args . push ( resolve ) ;
29
+ args . push ( reject ) ;
30
+ aMethod . apply ( this , args ) ;
31
+ } ) ;
32
+ }
33
+ } ) ;
34
+
35
+ var CodePushDialog = require ( "react-native" ) . NativeModules . CodePushDialog ;
36
+ Alert = {
37
+ alert : function ( title , message , buttons ) {
38
+ if ( buttons . length > 2 ) {
39
+ throw "Can only show 2 buttons for Android dialog." ;
40
+ }
41
+
42
+ var button1Text = buttons [ 0 ] ? buttons [ 0 ] . text : null ;
43
+ var button2Text = buttons [ 1 ] ? buttons [ 1 ] . text : null ;
44
+
45
+ CodePushDialog . showDialog (
46
+ title , message , button1Text , button2Text ,
47
+ ( buttonPressedId ) => {
48
+ buttons [ buttonPressedId ] . onPress && buttons [ buttonPressedId ] . onPress ( ) ;
49
+ } ,
50
+ ( error ) => {
51
+ throw error ;
52
+ } ) ;
53
+ }
54
+ } ;
55
+ } else if ( Platform . OS === "ios" ) {
56
+ var { AlertIOS } = require ( "react-native" ) ;
57
+ Alert = AlertIOS ;
58
+ }
59
+
60
+ var PackageMixins = require ( "./package-mixins" ) ( NativeCodePush ) ;
61
+
62
+ module . exports = {
63
+ NativeCodePush : NativeCodePush ,
64
+ PackageMixins : PackageMixins ,
65
+ Alert : Alert
66
+ }
0 commit comments