1- import { useFocusEffect } from '@react-navigation/native' ;
2- import React , { useCallback , useMemo , useRef , useState } from 'react' ;
1+ import React , { useMemo , useRef , useState } from 'react' ;
32import type { GestureResponderEvent , ViewStyle } from 'react-native' ;
43import { StyleSheet , View } from 'react-native' ;
54import { useOnyx } from 'react-native-onyx' ;
@@ -51,20 +50,20 @@ import type {OptionRowLHNProps} from './types';
5150
5251function OptionRowLHN ( {
5352 reportID,
54- isFocused = false ,
53+ isOptionFocused = false ,
5554 onSelectRow = ( ) => { } ,
5655 optionItem,
5756 viewMode = 'default' ,
5857 style,
5958 onLayout = ( ) => { } ,
6059 hasDraftComment,
6160 shouldShowRBRorGBRTooltip,
61+ isScreenFocused,
6262} : OptionRowLHNProps ) {
6363 const theme = useTheme ( ) ;
6464 const styles = useThemeStyles ( ) ;
6565 const popoverAnchor = useRef < View > ( null ) ;
6666 const StyleUtils = useStyleUtils ( ) ;
67- const [ isScreenFocused , setIsScreenFocused ] = useState ( false ) ;
6867 const { shouldUseNarrowLayout} = useResponsiveLayout ( ) ;
6968
7069 const [ report ] = useOnyx ( `${ ONYXKEYS . COLLECTION . REPORT } ${ optionItem ?. reportID } ` , { canBeMissing : true } ) ;
@@ -105,23 +104,14 @@ function OptionRowLHN({
105104 const { translate} = useLocalize ( ) ;
106105 const [ isContextMenuActive , setIsContextMenuActive ] = useState ( false ) ;
107106
108- useFocusEffect (
109- useCallback ( ( ) => {
110- setIsScreenFocused ( true ) ;
111- return ( ) => {
112- setIsScreenFocused ( false ) ;
113- } ;
114- } , [ ] ) ,
115- ) ;
116-
117107 const isInFocusMode = viewMode === CONST . OPTION_MODE . COMPACT ;
118108 const sidebarInnerRowStyle = StyleSheet . flatten < ViewStyle > (
119109 isInFocusMode
120110 ? [ styles . chatLinkRowPressable , styles . flexGrow1 , styles . optionItemAvatarNameWrapper , styles . optionRowCompact , styles . justifyContentCenter ]
121111 : [ styles . chatLinkRowPressable , styles . flexGrow1 , styles . optionItemAvatarNameWrapper , styles . optionRow , styles . justifyContentCenter ] ,
122112 ) ;
123113
124- if ( ! optionItem && ! isFocused ) {
114+ if ( ! optionItem && ! isOptionFocused ) {
125115 // rendering null as a render item causes the FlashList to render all
126116 // its children and consume significant memory on the first render. We can avoid this by
127117 // rendering a placeholder view instead. This behaviour is only observed when we
@@ -140,7 +130,7 @@ function OptionRowLHN({
140130 }
141131
142132 const brickRoadIndicator = optionItem . brickRoadIndicator ;
143- const textStyle = isFocused ? styles . sidebarLinkActiveText : styles . sidebarLinkText ;
133+ const textStyle = isOptionFocused ? styles . sidebarLinkActiveText : styles . sidebarLinkText ;
144134 const textUnreadStyle = shouldUseBoldText ( optionItem ) ? [ textStyle , styles . sidebarLinkTextBold ] : [ textStyle ] ;
145135 const displayNameStyle = [ styles . optionDisplayName , styles . optionDisplayNameCompact , styles . pre , textUnreadStyle , style ] ;
146136 const alternateTextStyle = isInFocusMode
@@ -188,7 +178,7 @@ function OptionRowLHN({
188178 const statusContent = formattedDate ? `${ statusText ? `${ statusText } ` : '' } (${ formattedDate } )` : statusText ;
189179 const isStatusVisible = ! ! emojiCode && isOneOnOneChat ( ! isEmptyObject ( report ) ? report : undefined ) ;
190180
191- const subscriptAvatarBorderColor = isFocused ? focusedBackgroundColor : theme . sidebar ;
181+ const subscriptAvatarBorderColor = isOptionFocused ? focusedBackgroundColor : theme . sidebar ;
192182 const firstIcon = optionItem . icons ?. at ( 0 ) ;
193183
194184 const onOptionPress = ( event : GestureResponderEvent | KeyboardEvent | undefined ) => {
@@ -256,8 +246,8 @@ function OptionRowLHN({
256246 styles . sidebarLink ,
257247 styles . sidebarLinkInnerLHN ,
258248 StyleUtils . getBackgroundColorStyle ( theme . sidebar ) ,
259- isFocused ? styles . sidebarLinkActive : null ,
260- ( hovered || isContextMenuActive ) && ! isFocused ? styles . sidebarLinkHover : null ,
249+ isOptionFocused ? styles . sidebarLinkActive : null ,
250+ ( hovered || isContextMenuActive ) && ! isOptionFocused ? styles . sidebarLinkHover : null ,
261251 ] }
262252 role = { CONST . ROLE . BUTTON }
263253 accessibilityLabel = { `${ translate ( 'accessibilityHints.navigatesToChat' ) } ${ optionItem . text } . ${ optionItem . isUnread ? `${ translate ( 'common.unread' ) } .` : '' } ${
@@ -272,7 +262,7 @@ function OptionRowLHN({
272262 firstIcon &&
273263 ( optionItem . shouldShowSubscript ? (
274264 < SubscriptAvatar
275- backgroundColor = { hovered && ! isFocused ? hoveredBackgroundColor : subscriptAvatarBorderColor }
265+ backgroundColor = { hovered && ! isOptionFocused ? hoveredBackgroundColor : subscriptAvatarBorderColor }
276266 mainAvatar = { firstIcon }
277267 secondaryAvatar = { optionItem . icons . at ( 1 ) }
278268 size = { isInFocusMode ? CONST . AVATAR_SIZE . SMALL : CONST . AVATAR_SIZE . DEFAULT }
@@ -284,8 +274,8 @@ function OptionRowLHN({
284274 size = { isInFocusMode ? CONST . AVATAR_SIZE . SMALL : CONST . AVATAR_SIZE . DEFAULT }
285275 secondAvatarStyle = { [
286276 StyleUtils . getBackgroundAndBorderStyle ( theme . sidebar ) ,
287- isFocused ? StyleUtils . getBackgroundAndBorderStyle ( focusedBackgroundColor ) : undefined ,
288- hovered && ! isFocused ? StyleUtils . getBackgroundAndBorderStyle ( hoveredBackgroundColor ) : undefined ,
277+ isOptionFocused ? StyleUtils . getBackgroundAndBorderStyle ( focusedBackgroundColor ) : undefined ,
278+ hovered && ! isOptionFocused ? StyleUtils . getBackgroundAndBorderStyle ( hoveredBackgroundColor ) : undefined ,
289279 ] }
290280 shouldShowTooltip = { shouldOptionShowTooltip ( optionItem ) }
291281 />
0 commit comments