1
- import React from 'react' ;
1
+ import React , { useCallback } from 'react' ;
2
2
import { View } from 'react-native' ;
3
3
import Badge from '@components/Badge' ;
4
4
import Button from '@components/Button' ;
@@ -36,7 +36,7 @@ type ActionCellProps = {
36
36
37
37
function ActionCell ( {
38
38
action = CONST . SEARCH . ACTION_TYPES . VIEW ,
39
- shouldUseSuccessStyle = true ,
39
+ shouldUseSuccessStyle : shouldUseSuccessStyleProp = true ,
40
40
isLargeScreenWidth = true ,
41
41
isSelected = false ,
42
42
goToItem,
@@ -52,6 +52,16 @@ function ActionCell({
52
52
53
53
const text = translate ( actionTranslationsMap [ action ] ) ;
54
54
55
+ const getButtonInnerStyles = useCallback (
56
+ ( shouldUseSuccessStyle : boolean ) => {
57
+ if ( ! isSelected ) {
58
+ return { } ;
59
+ }
60
+ return shouldUseSuccessStyle ? styles . buttonSuccessHovered : styles . buttonDefaultHovered ;
61
+ } ,
62
+ [ isSelected , styles ] ,
63
+ ) ;
64
+
55
65
const shouldUseViewAction = action === CONST . SEARCH . ACTION_TYPES . VIEW || ( parentAction === CONST . SEARCH . ACTION_TYPES . PAID && action === CONST . SEARCH . ACTION_TYPES . PAID ) ;
56
66
57
67
if ( ( parentAction !== CONST . SEARCH . ACTION_TYPES . PAID && action === CONST . SEARCH . ACTION_TYPES . PAID ) || action === CONST . SEARCH . ACTION_TYPES . DONE ) {
@@ -78,30 +88,28 @@ function ActionCell({
78
88
}
79
89
80
90
if ( action === CONST . SEARCH . ACTION_TYPES . VIEW || shouldUseViewAction ) {
81
- const buttonInnerStyles = isSelected ? styles . buttonDefaultHovered : { } ;
82
91
return isLargeScreenWidth ? (
83
92
< Button
84
93
text = { translate ( actionTranslationsMap [ CONST . SEARCH . ACTION_TYPES . VIEW ] ) }
85
94
onPress = { goToItem }
86
95
small
87
96
style = { [ styles . w100 ] }
88
- innerStyles = { buttonInnerStyles }
97
+ innerStyles = { getButtonInnerStyles ( false ) }
89
98
link = { isChildListItem }
90
99
shouldUseDefaultHover = { ! isChildListItem }
91
100
/>
92
101
) : null ;
93
102
}
94
103
95
- const buttonInnerStyles = isSelected ? styles . buttonSuccessHovered : { } ;
96
104
return (
97
105
< Button
98
106
text = { text }
99
107
onPress = { goToItem }
100
108
small
101
109
style = { [ styles . w100 ] }
102
- innerStyles = { buttonInnerStyles }
110
+ innerStyles = { getButtonInnerStyles ( shouldUseSuccessStyleProp ) }
103
111
isLoading = { isLoading }
104
- success = { shouldUseSuccessStyle }
112
+ success = { shouldUseSuccessStyleProp }
105
113
isDisabled = { isOffline }
106
114
/>
107
115
) ;
0 commit comments