@@ -11,6 +11,11 @@ import {
11
11
12
12
import CodePush from "react-native-code-push" ;
13
13
14
+ /**
15
+ * Configured with a MANUAL check frequency for easy testing. For production apps, it is recommended to configure a
16
+ * different check frequency, such as ON_APP_START, for a 'hands-off' approach where CodePush.sync() does not
17
+ * need to be explicitly called. All options of CodePush.sync() are also available in this decorator.
18
+ */
14
19
@CodePush ( { checkFrequency : CodePush . CheckFrequency . MANUAL } )
15
20
class CodePushDemoApp extends Component {
16
21
constructor ( ) {
@@ -39,7 +44,7 @@ class CodePushDemoApp extends Component {
39
44
this . setState ( { syncMessage : "Update cancelled by user." , progress : false } ) ;
40
45
break ;
41
46
case CodePush . SyncStatus . UPDATE_INSTALLED :
42
- this . setState ( { syncMessage : "Update installed." , progress : false } ) ;
47
+ this . setState ( { syncMessage : "Update installed and will be applied on restart ." , progress : false } ) ;
43
48
break ;
44
49
case CodePush . SyncStatus . UNKNOWN_ERROR :
45
50
this . setState ( { syncMessage : "An unknown error occurred." , progress : false } ) ;
@@ -59,12 +64,28 @@ class CodePushDemoApp extends Component {
59
64
this . setState ( { restartAllowed : ! this . state . restartAllowed } ) ;
60
65
}
61
66
67
+ getUpdateMetadata ( ) {
68
+ CodePush . getUpdateMetadata ( CodePush . UpdateState . RUNNING )
69
+ . then ( ( metadata : LocalPackage ) => {
70
+ this . setState ( { syncMessage : metadata ? JSON . stringify ( metadata ) : "Running binary version" , progress : false } ) ;
71
+ } , ( error : any ) => {
72
+ this . setState ( { syncMessage : "Error: " + error , progress : false } ) ;
73
+ } ) ;
74
+ }
75
+
76
+ /** Update is downloaded silently, and applied on restart (recommended) */
62
77
sync ( ) {
63
78
CodePush . sync (
64
- {
65
- installMode : CodePush . InstallMode . IMMEDIATE ,
66
- updateDialog : true
67
- } ,
79
+ { } ,
80
+ this . codePushStatusDidChange . bind ( this ) ,
81
+ this . codePushDownloadDidProgress . bind ( this )
82
+ ) ;
83
+ }
84
+
85
+ /** Update pops a confirmation dialog, and then immediately reboots the app */
86
+ syncImmediate ( ) {
87
+ CodePush . sync (
88
+ { installMode : CodePush . InstallMode . IMMEDIATE , updateDialog : true } ,
68
89
this . codePushStatusDidChange . bind ( this ) ,
69
90
this . codePushDownloadDidProgress . bind ( this )
70
91
) ;
@@ -85,14 +106,20 @@ class CodePushDemoApp extends Component {
85
106
Welcome to CodePush!
86
107
</ Text >
87
108
< TouchableOpacity onPress = { this . sync . bind ( this ) } >
88
- < Text style = { styles . syncButton } > Start Sync!</ Text >
109
+ < Text style = { styles . syncButton } > Press for background sync</ Text >
110
+ </ TouchableOpacity >
111
+ < TouchableOpacity onPress = { this . syncImmediate . bind ( this ) } >
112
+ < Text style = { styles . syncButton } > Press for dialog-driven sync</ Text >
89
113
</ TouchableOpacity >
90
- < Text style = { styles . messages } > { this . state . syncMessage || "" } </ Text >
91
114
{ progressView }
92
115
< Image style = { styles . image } resizeMode = { Image . resizeMode . contain } source = { require ( "./images/laptop_phone_howitworks.png" ) } />
93
116
< TouchableOpacity onPress = { this . toggleAllowRestart . bind ( this ) } >
94
117
< Text style = { styles . restartToggleButton } > Restart { this . state . restartAllowed ? "allowed" : "forbidden" } </ Text >
95
118
</ TouchableOpacity >
119
+ < TouchableOpacity onPress = { this . getUpdateMetadata . bind ( this ) } >
120
+ < Text style = { styles . syncButton } > Press for Update Metadata</ Text >
121
+ </ TouchableOpacity >
122
+ < Text style = { styles . messages } > { this . state . syncMessage || "" } </ Text >
96
123
</ View >
97
124
) ;
98
125
}
@@ -106,11 +133,12 @@ const styles = StyleSheet.create({
106
133
paddingTop : 50
107
134
} ,
108
135
image : {
109
- marginTop : 50 ,
136
+ margin : 30 ,
110
137
width : Dimensions . get ( "window" ) . width - 100 ,
111
138
height : 365 * ( Dimensions . get ( "window" ) . width - 100 ) / 651 ,
112
139
} ,
113
140
messages : {
141
+ marginTop : 30 ,
114
142
textAlign : "center" ,
115
143
} ,
116
144
restartToggleButton : {
@@ -124,7 +152,7 @@ const styles = StyleSheet.create({
124
152
welcome : {
125
153
fontSize : 20 ,
126
154
textAlign : "center" ,
127
- margin : 10
155
+ margin : 20
128
156
} ,
129
157
} ) ;
130
158
0 commit comments