1
1
import Line , { AccessToken , UserProfile } from '@xmartlabs/react-native-line'
2
2
import { useRouter } from 'expo-router'
3
- import { useEffect , useState } from 'react'
4
- import {
5
- ActivityIndicator ,
6
- Alert ,
7
- Dimensions ,
8
- Image ,
9
- StyleSheet ,
10
- } from 'react-native'
3
+ import { Fragment , useEffect , useState } from 'react'
4
+ import { Alert , Dimensions , Image , StyleSheet } from 'react-native'
11
5
12
6
import {
13
7
removeLocalStorageItem ,
14
8
setLocalStorageItem ,
15
9
} from '@/common/localStorage'
10
+ import { ActivityBanner } from '@/components/ActivityBanner'
16
11
import { Bullet } from '@/components/Bullet'
17
12
import { Button } from '@/components/Button'
18
13
import { ThemedView } from '@/components/ThemedView'
@@ -39,56 +34,60 @@ export default function () {
39
34
} , [ ] )
40
35
41
36
function logOut ( ) {
42
- return Line . logout ( ) . then ( ( ) => {
43
- removeLocalStorageItem ( 'accessToken' )
44
- router . replace ( '/login' )
45
- } )
37
+ setLoading ( true )
38
+ return Line . logout ( )
39
+ . then ( ( ) => {
40
+ removeLocalStorageItem ( 'accessToken' )
41
+ router . replace ( '/login' )
42
+ } )
43
+ . finally ( ( ) => setLoading ( false ) )
46
44
}
47
45
48
46
function getFriendshipStatus ( ) {
47
+ setLoading ( true )
49
48
return Line . getFriendshipStatus ( )
50
49
. then ( result => Alert . alert ( strings . isFriend , String ( result . friendFlag ) ) )
51
50
. catch ( handleError )
51
+ . finally ( ( ) => setLoading ( false ) )
52
52
}
53
53
54
54
function refreshAccessToken ( ) {
55
+ setLoading ( true )
55
56
return Line . refreshAccessToken ( )
56
57
. then ( accessToken => {
57
58
setLocalStorageItem ( 'accessToken' , accessToken . accessToken )
58
59
setToken ( accessToken )
59
60
} )
60
61
. catch ( handleError )
62
+ . finally ( ( ) => setLoading ( false ) )
61
63
}
62
64
63
65
function verifyAccessToken ( ) {
66
+ setLoading ( true )
64
67
return Line . verifyAccessToken ( )
65
68
. then ( result => Alert . alert ( result . clientId , result . expiresIn . toString ( ) ) )
66
69
. catch ( handleError )
67
- }
68
-
69
- if ( loading ) {
70
- return (
71
- < ThemedView style = { styles . container } >
72
- < ActivityIndicator size = "large" />
73
- </ ThemedView >
74
- )
70
+ . finally ( ( ) => setLoading ( false ) )
75
71
}
76
72
77
73
return (
78
- < ThemedView style = { styles . container } >
79
- < ThemedView style = { styles . contentContainer } >
80
- < Image source = { { uri : user ?. pictureUrl } } style = { styles . image } />
81
- < Bullet header = { strings . name } text = { user ?. displayName } />
82
- < Bullet header = { strings . userId } text = { user ?. userId } />
83
- < Bullet header = { strings . accessToken } text = { token ?. accessToken } />
84
- </ ThemedView >
85
- < Button onPress = { getFriendshipStatus } text = { strings . isFriend } />
86
- < ThemedView style = { styles . row } >
87
- < Button onPress = { verifyAccessToken } text = { strings . verifyToken } />
88
- < Button onPress = { refreshAccessToken } text = { strings . refreshToken } />
74
+ < Fragment >
75
+ < ThemedView style = { styles . container } >
76
+ < ThemedView style = { styles . contentContainer } >
77
+ < Image source = { { uri : user ?. pictureUrl } } style = { styles . image } />
78
+ < Bullet header = { strings . name } text = { user ?. displayName } />
79
+ < Bullet header = { strings . userId } text = { user ?. userId } />
80
+ < Bullet header = { strings . accessToken } text = { token ?. accessToken } />
81
+ </ ThemedView >
82
+ < Button onPress = { getFriendshipStatus } text = { strings . isFriend } />
83
+ < ThemedView style = { styles . row } >
84
+ < Button onPress = { verifyAccessToken } text = { strings . verifyToken } />
85
+ < Button onPress = { refreshAccessToken } text = { strings . refreshToken } />
86
+ </ ThemedView >
87
+ < Button onPress = { logOut } text = { strings . logOut } />
89
88
</ ThemedView >
90
- < Button onPress = { logOut } text = { strings . logOut } />
91
- </ ThemedView >
89
+ { loading && < ActivityBanner /> }
90
+ </ Fragment >
92
91
)
93
92
}
94
93
0 commit comments