@@ -14,16 +14,17 @@ import {
14
14
Modal ,
15
15
} from 'react-native' ;
16
16
import { Button , Icon } from 'react-native-elements' ;
17
- import AppIntro from 'rn-app-intro ' ;
17
+ import Swiper from 'react-native-swiper ' ;
18
18
import queryString from 'query-string' ;
19
+ import CookieManager from 'react-native-cookies' ;
19
20
20
21
import { ViewContainer } from 'components' ;
21
22
import { colors , fonts , normalize } from 'config' ;
22
23
import { CLIENT_ID } from 'api' ;
23
24
import { auth , getUser } from 'auth' ;
24
25
import { translate , resetNavigationTo } from 'utils' ;
25
26
26
- const stateRandom = Math . random ( ) . toString ( ) ;
27
+ let stateRandom = Math . random ( ) . toString ( ) ;
27
28
28
29
const mapStateToProps = state => ( {
29
30
locale : state . auth . locale ,
@@ -101,6 +102,14 @@ const styles = StyleSheet.create({
101
102
justifyContent : 'center' ,
102
103
alignItems : 'center' ,
103
104
} ,
105
+ signInContainer : {
106
+ position : 'absolute' ,
107
+ right : 0 ,
108
+ left : 0 ,
109
+ bottom : 80 ,
110
+ justifyContent : 'center' ,
111
+ alignItems : 'center' ,
112
+ } ,
104
113
slide : {
105
114
flex : 1 ,
106
115
justifyContent : 'center' ,
@@ -218,15 +227,25 @@ class Login extends Component {
218
227
loaderText : translate ( 'auth.login.preparingGitPoint' , this . locale ) ,
219
228
} ) ;
220
229
221
- auth ( code , state ) . then ( ( ) => {
222
- getUser ( ) . then ( ( ) => {
223
- resetNavigationTo ( 'Main' , navigation ) ;
230
+ stateRandom = Math . random ( ) . toString ( ) ;
231
+
232
+ CookieManager . clearAll ( ) . then ( ( ) => {
233
+ auth ( code , state ) . then ( ( ) => {
234
+ getUser ( ) . then ( ( ) => {
235
+ resetNavigationTo ( 'Main' , navigation ) ;
236
+ } ) ;
224
237
} ) ;
225
238
} ) ;
226
239
}
227
240
}
228
241
} ;
229
242
243
+ shouldDisplayIntro ( ) {
244
+ const { isLoggingIn, isAuthenticated } = this . props ;
245
+
246
+ return ! isAuthenticated && ! isLoggingIn && this . state . asyncStorageChecked ;
247
+ }
248
+
230
249
renderLoading ( ) {
231
250
return (
232
251
< View style = { styles . browserLoader } >
@@ -241,126 +260,116 @@ class Login extends Component {
241
260
242
261
return (
243
262
< ViewContainer barColor = "light" >
244
- { ! isAuthenticated &&
245
- ! isLoggingIn &&
246
- this . state . asyncStorageChecked && (
247
- < View style = { styles . container } >
248
- < Modal
249
- animationType = "slide"
250
- onRequestClose = { ( ) => null }
251
- visible = { this . state . modalVisible }
252
- style = { styles . container }
253
- >
254
- < View style = { styles . modalContainer } >
255
- < View style = { styles . browserSection } >
256
- < WebView
257
- source = { {
258
- uri : `https://github.com/login/oauth/authorize?response_type=token&client_id=${ CLIENT_ID } &redirect_uri=gitpoint://welcome&scope=user%20repo&state=${ stateRandom } ` ,
259
- } }
260
- onLoadStart = { e => this . toggleCancelButton ( e , true ) }
261
- onLoadEnd = { e => this . toggleCancelButton ( e , false ) }
262
- onNavigationStateChange = { e =>
263
- this . onNavigationStateChange ( e ) }
264
- renderLoading = { ( ) => this . renderLoading ( ) }
265
- startInLoadingState
266
- />
267
- </ View >
268
- < View style = { styles . miniSection } >
269
- < Button
270
- title = { translate ( 'auth.login.cancel' , locale ) }
271
- buttonStyle = { styles . button }
272
- disabled = { this . state . cancelDisabled }
273
- textStyle = { styles . buttonText }
274
- onPress = { ( ) =>
275
- this . setModalVisible ( ! this . state . modalVisible ) }
276
- />
277
- </ View >
278
- </ View >
279
- </ Modal >
280
- < View style = { styles . miniSection } >
281
- < Image
282
- style = { styles . logo }
283
- source = { require ( '../../assets/logo.png' ) }
263
+ { this . shouldDisplayIntro ( ) && (
264
+ < Swiper
265
+ loop = { false }
266
+ dotColor = "#FFFFFF55"
267
+ activeDotColor = { colors . white }
268
+ >
269
+ < View style = { [ styles . slide , styles . slide1 ] } >
270
+ < Image
271
+ style = { styles . logo }
272
+ source = { require ( '../../assets/logo.png' ) }
273
+ />
274
+ < Text style = { styles . title } >
275
+ { translate ( 'auth.login.welcomeTitle' , locale ) }
276
+ </ Text >
277
+ < Text style = { styles . message } >
278
+ { translate ( 'auth.login.welcomeMessage' , locale ) }
279
+ </ Text >
280
+ </ View >
281
+ < View style = { [ styles . slide , styles . slide2 ] } >
282
+ < Icon
283
+ style = { styles . icon }
284
+ color = { colors . white }
285
+ size = { 85 }
286
+ name = "bell"
287
+ type = "octicon"
288
+ />
289
+ < Text style = { styles . title } >
290
+ { translate ( 'auth.login.notificationsTitle' , locale ) }
291
+ </ Text >
292
+ < Text style = { styles . message } >
293
+ { translate ( 'auth.login.notificationsMessage' , locale ) }
294
+ </ Text >
295
+ </ View >
296
+ < View style = { [ styles . slide , styles . slide3 ] } >
297
+ < Icon
298
+ containerStyle = { styles . iconMargin }
299
+ style = { styles . icon }
300
+ color = { colors . white }
301
+ size = { 85 }
302
+ name = "repo"
303
+ type = "octicon"
304
+ />
305
+ < Text style = { styles . title } >
306
+ { translate ( 'auth.login.reposTitle' , locale ) }
307
+ </ Text >
308
+ < Text style = { styles . message } >
309
+ { translate ( 'auth.login.reposMessage' , locale ) }
310
+ </ Text >
311
+ </ View >
312
+ < View style = { [ styles . slide , styles . slide4 ] } >
313
+ < Icon
314
+ containerStyle = { styles . iconMargin }
315
+ style = { styles . icon }
316
+ color = { colors . white }
317
+ size = { 85 }
318
+ name = "git-pull-request"
319
+ type = "octicon"
320
+ />
321
+ < Text style = { styles . title } >
322
+ { translate ( 'auth.login.issuesTitle' , locale ) }
323
+ </ Text >
324
+ < Text style = { styles . message } >
325
+ { translate ( 'auth.login.issuesMessage' , locale ) }
326
+ </ Text >
327
+ </ View >
328
+ </ Swiper >
329
+ ) }
330
+ { this . shouldDisplayIntro ( ) && (
331
+ < View style = { styles . signInContainer } >
332
+ < Button
333
+ raised
334
+ title = { translate ( 'auth.login.signInButton' , locale ) }
335
+ buttonStyle = { styles . button }
336
+ textStyle = { styles . buttonText }
337
+ onPress = { ( ) => this . setModalVisible ( true ) }
338
+ />
339
+ </ View >
340
+ ) }
341
+ { this . shouldDisplayIntro ( ) && (
342
+ < Modal
343
+ animationType = "slide"
344
+ onRequestClose = { ( ) => null }
345
+ visible = { this . state . modalVisible }
346
+ style = { styles . container }
347
+ >
348
+ < View style = { styles . modalContainer } >
349
+ < View style = { styles . browserSection } >
350
+ < WebView
351
+ source = { {
352
+ uri : `https://github.com/login/oauth/authorize?response_type=token&client_id=${ CLIENT_ID } &redirect_uri=gitpoint://welcome&scope=user%20repo&state=${ stateRandom } ` ,
353
+ } }
354
+ onLoadStart = { e => this . toggleCancelButton ( e , true ) }
355
+ onLoadEnd = { e => this . toggleCancelButton ( e , false ) }
356
+ onNavigationStateChange = { e => this . onNavigationStateChange ( e ) }
357
+ renderLoading = { ( ) => this . renderLoading ( ) }
358
+ startInLoadingState
284
359
/>
285
360
</ View >
286
- < View style = { styles . contentSection } >
287
- < AppIntro
288
- activeDotColor = { colors . white }
289
- showSkipButton = { false }
290
- showDoneButton = { false }
291
- >
292
- < View style = { [ styles . slide , styles . slide1 ] } >
293
- < Image
294
- style = { styles . logo }
295
- source = { require ( '../../assets/logo.png' ) }
296
- />
297
- < Text style = { styles . title } >
298
- { translate ( 'auth.login.welcomeTitle' , locale ) }
299
- </ Text >
300
- < Text style = { styles . message } >
301
- { translate ( 'auth.login.welcomeMessage' , locale ) }
302
- </ Text >
303
- </ View >
304
- < View style = { [ styles . slide , styles . slide2 ] } >
305
- < Icon
306
- style = { styles . icon }
307
- color = { colors . white }
308
- size = { 85 }
309
- name = "bell"
310
- type = "octicon"
311
- />
312
- < Text style = { styles . title } >
313
- { translate ( 'auth.login.notificationsTitle' , locale ) }
314
- </ Text >
315
- < Text style = { styles . message } >
316
- { translate ( 'auth.login.notificationsMessage' , locale ) }
317
- </ Text >
318
- </ View >
319
- < View style = { [ styles . slide , styles . slide3 ] } >
320
- < Icon
321
- containerStyle = { styles . iconMargin }
322
- style = { styles . icon }
323
- color = { colors . white }
324
- size = { 85 }
325
- name = "repo"
326
- type = "octicon"
327
- />
328
- < Text style = { styles . title } >
329
- { translate ( 'auth.login.reposTitle' , locale ) }
330
- </ Text >
331
- < Text style = { styles . message } >
332
- { translate ( 'auth.login.reposMessage' , locale ) }
333
- </ Text >
334
- </ View >
335
- < View style = { [ styles . slide , styles . slide4 ] } >
336
- < Icon
337
- containerStyle = { styles . iconMargin }
338
- style = { styles . icon }
339
- color = { colors . white }
340
- size = { 85 }
341
- name = "git-pull-request"
342
- type = "octicon"
343
- />
344
- < Text style = { styles . title } >
345
- { translate ( 'auth.login.issuesTitle' , locale ) }
346
- </ Text >
347
- < Text style = { styles . message } >
348
- { translate ( 'auth.login.issuesMessage' , locale ) }
349
- </ Text >
350
- </ View >
351
- </ AppIntro >
352
- </ View >
353
361
< View style = { styles . miniSection } >
354
362
< Button
355
- raised
356
- title = { translate ( 'auth.login.signInButton' , locale ) }
363
+ title = { translate ( 'auth.login.cancel' , locale ) }
357
364
buttonStyle = { styles . button }
365
+ disabled = { this . state . cancelDisabled }
358
366
textStyle = { styles . buttonText }
359
- onPress = { ( ) => this . setModalVisible ( true ) }
367
+ onPress = { ( ) => this . setModalVisible ( ! this . state . modalVisible ) }
360
368
/>
361
369
</ View >
362
370
</ View >
363
- ) }
371
+ </ Modal >
372
+ ) }
364
373
{ isLoggingIn &&
365
374
! hasInitialUser && (
366
375
< View style = { styles . browserLoader } >
@@ -373,7 +382,7 @@ class Login extends Component {
373
382
size = "large"
374
383
/>
375
384
</ View >
376
- ) }
385
+ ) }
377
386
</ ViewContainer >
378
387
) ;
379
388
}
0 commit comments