1
- import { rgba } from 'polished'
2
- import React , { useCallback , useRef } from 'react'
1
+ import React from 'react'
3
2
import { StyleSheet , TextProps , View } from 'react-native'
4
- import { useSpring } from 'react-spring/native'
5
3
6
4
import { GitHubIcon , Omit } from '@devhub/core'
7
- import { useCSSVariablesOrSpringAnimatedTheme } from '../../hooks/use-css-variables-or-spring--animated-theme'
8
- import { useHover } from '../../hooks/use-hover'
9
- import { Platform } from '../../libs/platform'
10
5
import { contentPadding } from '../../styles/variables'
11
- import { getDefaultReactSpringAnimationConfig } from '../../utils/helpers/animations'
12
- import { SpringAnimatedActivityIndicator } from '../animated/spring/SpringAnimatedActivityIndicator'
13
- import { SpringAnimatedIcon } from '../animated/spring/SpringAnimatedIcon'
14
- import { SpringAnimatedText } from '../animated/spring/SpringAnimatedText'
15
- import {
16
- SpringAnimatedTouchableOpacity ,
17
- SpringAnimatedTouchableOpacityProps ,
18
- } from '../animated/spring/SpringAnimatedTouchableOpacity'
19
- import { SpringAnimatedView } from '../animated/spring/SpringAnimatedView'
20
- import { useTheme } from '../context/ThemeContext'
6
+ import { Button , ButtonProps } from '../common/Button'
7
+ import { ThemedActivityIndicator } from '../themed/ThemedActivityIndicator'
8
+ import { ThemedIcon } from '../themed/ThemedIcon'
9
+ import { ThemedText } from '../themed/ThemedText'
10
+ import { ThemedView } from '../themed/ThemedView'
21
11
22
12
export interface GitHubLoginButtonProps
23
- extends Omit < SpringAnimatedTouchableOpacityProps , 'children' > {
13
+ extends Omit < ButtonProps , 'children' | 'onPress '> {
24
14
horizontal ?: boolean
25
15
leftIcon ?: GitHubIcon
26
16
loading ?: boolean
17
+ onPress : ( ) => void
27
18
rightIcon ?: GitHubIcon
28
19
subtitle ?: string
29
20
subtitleProps ?: TextProps
@@ -33,16 +24,13 @@ export interface GitHubLoginButtonProps
33
24
34
25
const styles = StyleSheet . create ( {
35
26
button : {
36
- height : 58 ,
37
- borderRadius : 58 / 2 ,
27
+ width : '100%' ,
38
28
overflow : 'hidden' ,
39
29
} ,
40
30
41
31
contentContainer : {
42
32
flex : 1 ,
43
33
flexDirection : 'row' ,
44
- height : 58 ,
45
- borderRadius : 58 / 2 ,
46
34
overflow : 'hidden' ,
47
35
} ,
48
36
@@ -57,8 +45,8 @@ const styles = StyleSheet.create({
57
45
} ,
58
46
59
47
mainContentContainer : {
60
- alignItems : 'flex-start' ,
61
48
flex : 1 ,
49
+ alignItems : 'flex-start' ,
62
50
justifyContent : 'center' ,
63
51
paddingHorizontal : contentPadding ,
64
52
} ,
@@ -90,157 +78,65 @@ export function GitHubLoginButton(props: GitHubLoginButtonProps) {
90
78
...otherProps
91
79
} = props
92
80
93
- const springAnimatedTheme = useCSSVariablesOrSpringAnimatedTheme ( )
94
-
95
- const getStyles = useCallback ( ( ) => {
96
- const { isHovered, isPressing, theme } = cacheRef . current
97
-
98
- const immediate = isHovered || Platform . realOS === 'android'
99
-
100
- return {
101
- config : getDefaultReactSpringAnimationConfig ( ) ,
102
- immediate,
103
- backgroundColor :
104
- isHovered || isPressing
105
- ? theme . backgroundColorLess2
106
- : rgba ( theme . backgroundColorLess2 , 0 ) ,
107
- }
108
- } , [ ] )
109
-
110
- const updateStyles = useCallback ( ( ) => {
111
- setSpringAnimatedStyles ( getStyles ( ) )
112
- } , [ getStyles ] )
113
-
114
- const initialTheme = useTheme (
115
- useCallback (
116
- theme => {
117
- if ( cacheRef . current . theme === theme ) return
118
- cacheRef . current . theme = theme
119
- updateStyles ( )
120
- } ,
121
- [ updateStyles ] ,
122
- ) ,
123
- )
124
-
125
- const touchableRef = useRef ( null )
126
- const initialIsHovered = useHover ( touchableRef , isHovered => {
127
- cacheRef . current . isHovered = isHovered
128
- updateStyles ( )
129
- } )
130
-
131
- const cacheRef = useRef ( {
132
- isHovered : initialIsHovered ,
133
- isPressing : false ,
134
- theme : initialTheme ,
135
- } )
136
- cacheRef . current . theme = initialTheme
137
-
138
- const [ springAnimatedStyles , setSpringAnimatedStyles ] = useSpring <
139
- ReturnType < typeof getStyles >
140
- > ( getStyles )
141
-
142
81
return (
143
- < SpringAnimatedTouchableOpacity
144
- ref = { touchableRef }
145
- activeOpacity = { 0.8 }
82
+ < Button
83
+ size = { 58 }
146
84
{ ...otherProps }
147
- onPressIn = { ( ) => {
148
- if ( Platform . realOS === 'web' ) return
149
-
150
- cacheRef . current . isPressing = true
151
- updateStyles ( )
152
- } }
153
- onPressOut = { ( ) => {
154
- if ( Platform . realOS === 'web' ) return
155
-
156
- cacheRef . current . isPressing = false
157
- updateStyles ( )
158
- } }
159
- style = { [
160
- styles . button ,
161
- {
162
- backgroundColor : springAnimatedTheme . backgroundColorLess1 ,
163
- } ,
164
- props . style ,
165
- ] }
85
+ style = { styles . button }
86
+ contentContainerStyle = { styles . contentContainer }
166
87
>
167
- < SpringAnimatedView
168
- style = { [ styles . contentContainer , springAnimatedStyles ] }
169
- >
88
+ < >
170
89
{ ! ! leftIcon && (
171
- < SpringAnimatedView
172
- style = { [
173
- styles . iconWrapper ,
174
- {
175
- borderColor : springAnimatedTheme . foregroundColor ,
176
- paddingLeft : contentPadding ,
177
- } ,
178
- ] }
90
+ < ThemedView
91
+ borderColor = "foregroundColor"
92
+ style = { [ styles . iconWrapper , { paddingLeft : contentPadding } ] }
179
93
>
180
- < SpringAnimatedIcon
94
+ < ThemedIcon
181
95
name = { leftIcon }
182
- style = { [
183
- styles . icon ,
184
- { color : springAnimatedTheme . foregroundColor } ,
185
- ] }
96
+ style = { styles . icon }
97
+ color = "foregroundColor"
186
98
/>
187
- </ SpringAnimatedView >
99
+ </ ThemedView >
188
100
) }
189
101
190
102
< View style = { styles . mainContentContainer } >
191
103
{ ! ! title && (
192
- < SpringAnimatedText
104
+ < ThemedText
105
+ color = "foregroundColor"
193
106
{ ...textProps }
194
- style = { [
195
- styles . title ,
196
- {
197
- color : springAnimatedTheme . foregroundColor ,
198
- } ,
199
- textProps . style ,
200
- ] }
107
+ style = { [ styles . title , textProps . style ] }
201
108
>
202
109
{ title }
203
- </ SpringAnimatedText >
110
+ </ ThemedText >
204
111
) }
205
112
206
113
{ ! ! subtitle && (
207
- < SpringAnimatedText
114
+ < ThemedText
115
+ color = "foregroundColorMuted50"
208
116
{ ...subtitleProps }
209
- style = { [
210
- styles . subtitleText ,
211
- {
212
- color : springAnimatedTheme . foregroundColorMuted50 ,
213
- } ,
214
- subtitleProps . style ,
215
- ] }
117
+ style = { [ styles . subtitleText , subtitleProps . style ] }
216
118
>
217
119
{ subtitle }
218
- </ SpringAnimatedText >
120
+ </ ThemedText >
219
121
) }
220
122
</ View >
221
123
222
124
{ ! ! ( rightIcon || loading ) && (
223
125
< View style = { [ styles . iconWrapper , { paddingRight : contentPadding } ] } >
224
126
{ loading ? (
225
- < SpringAnimatedActivityIndicator
226
- color = { springAnimatedTheme . foregroundColor as any }
227
- />
127
+ < ThemedActivityIndicator color = "foregroundColor" />
228
128
) : (
229
129
! ! rightIcon && (
230
- < SpringAnimatedIcon
130
+ < ThemedIcon
131
+ color = "foregroundColor"
231
132
name = { rightIcon }
232
- style = { [
233
- styles . icon ,
234
- {
235
- color : springAnimatedTheme . foregroundColor ,
236
- } ,
237
- ] }
133
+ style = { styles . icon }
238
134
/>
239
135
)
240
136
) }
241
137
</ View >
242
138
) }
243
- </ SpringAnimatedView >
244
- </ SpringAnimatedTouchableOpacity >
139
+ </ >
140
+ </ Button >
245
141
)
246
142
}
0 commit comments