From 72eca7f8819b6a6bb72f42639447916dbfa22105 Mon Sep 17 00:00:00 2001 From: bartlomiej obudzinski Date: Wed, 13 May 2026 11:29:20 +0200 Subject: [PATCH 01/12] refactor: complete OptionRowLHN decomposition with ArchivedOptionRowLHN variant --- .../OptionRowLHN/ArchivedOptionRowLHN.tsx | 104 +++++++++++ .../Pressable.tsx} | 107 +++++++---- .../OptionRowLHN/OptionRowLHN.tsx | 127 ++++++++++++++ .../OptionRowLHN/OptionRowLHNCore.tsx | 166 ------------------ .../OptionRowLHN/OptionRowLHNData.tsx | 7 +- .../useLHNRowProductTrainingTooltip.ts | 2 +- 6 files changed, 311 insertions(+), 202 deletions(-) create mode 100644 src/components/LHNOptionsList/OptionRowLHN/ArchivedOptionRowLHN.tsx rename src/components/LHNOptionsList/OptionRowLHN/{OptionRowPressable.tsx => OptionRow/Pressable.tsx} (59%) create mode 100644 src/components/LHNOptionsList/OptionRowLHN/OptionRowLHN.tsx delete mode 100644 src/components/LHNOptionsList/OptionRowLHN/OptionRowLHNCore.tsx diff --git a/src/components/LHNOptionsList/OptionRowLHN/ArchivedOptionRowLHN.tsx b/src/components/LHNOptionsList/OptionRowLHN/ArchivedOptionRowLHN.tsx new file mode 100644 index 000000000000..4856c293dbdf --- /dev/null +++ b/src/components/LHNOptionsList/OptionRowLHN/ArchivedOptionRowLHN.tsx @@ -0,0 +1,104 @@ +import React, {useState} from 'react'; +import type {ViewStyle} from 'react-native'; +import {StyleSheet, View} from 'react-native'; +import type {OptionRowLHNProps} from '@components/LHNOptionsList/types'; +import useStyleUtils from '@hooks/useStyleUtils'; +import useTheme from '@hooks/useTheme'; +import useThemeStyles from '@hooks/useThemeStyles'; +import {shouldUseBoldText} from '@libs/OptionsListUtils'; +import CONST from '@src/CONST'; +import Avatar from './OptionRow/Avatar'; +import DescriptiveText from './OptionRow/DescriptiveText'; +import OfflineWrapper from './OptionRow/OfflineWrapper'; +import Pressable from './OptionRow/Pressable'; +import Status from './OptionRow/Status'; +import Subtitle from './OptionRow/Subtitle'; +import Title from './OptionRow/Title'; + +/** + * Sibling variant of `OptionRowLHN` used for archived reports. Strips the product training + * tooltip layer, all brick-road badges (Error/Info/Onboarding), and the trailing indicator + * row (Draft/Pin) because none of them apply to a historical, write-locked row. + */ +function ArchivedOptionRowLHN({isOptionFocused = false, onSelectRow = () => {}, optionItem, viewMode = 'default', style, onLayout = () => {}, testID}: OptionRowLHNProps) { + const theme = useTheme(); + const styles = useThemeStyles(); + const StyleUtils = useStyleUtils(); + const [hovered, setHovered] = useState(false); + + const isInFocusMode = viewMode === CONST.OPTION_MODE.COMPACT; + + const sidebarInnerRowStyle = StyleSheet.flatten( + isInFocusMode + ? [styles.chatLinkRowPressable, styles.flexGrow1, styles.optionItemAvatarNameWrapper, styles.optionRowCompact, styles.justifyContentCenter] + : [styles.chatLinkRowPressable, styles.flexGrow1, styles.optionItemAvatarNameWrapper, styles.optionRow, styles.justifyContentCenter], + ); + const contentContainerStyles = isInFocusMode + ? [styles.flex1, styles.flexRow, styles.overflowHidden, StyleUtils.getCompactContentContainerStyles()] + : [styles.flex1]; + const singleAvatarContainerStyle = [styles.actionAvatar, styles.mr3]; + + const hoveredBackgroundColor = !!styles.sidebarLinkHover && 'backgroundColor' in styles.sidebarLinkHover ? styles.sidebarLinkHover.backgroundColor : theme.sidebar; + const focusedBackgroundColor = styles.sidebarLinkActive.backgroundColor; + const subscriptAvatarBorderColor = isOptionFocused ? focusedBackgroundColor : theme.sidebar; + + let secondaryAvatarBgColor = theme.sidebar; + if (isOptionFocused) { + secondaryAvatarBgColor = focusedBackgroundColor; + } else if (hovered) { + secondaryAvatarBgColor = hoveredBackgroundColor; + } + + const textStyle = isOptionFocused ? styles.sidebarLinkActiveText : styles.sidebarLinkText; + const textUnreadStyle = shouldUseBoldText(optionItem) ? [textStyle, styles.sidebarLinkTextBold] : [textStyle]; + const displayNameStyle = [styles.optionDisplayName, styles.optionDisplayNameCompact, styles.pre, textUnreadStyle, styles.flexShrink0, style]; + + return ( + + setHovered(true)} + onHoverOut={() => setHovered(false)} + > + + + + + + + <Status optionItem={optionItem} /> + </View> + <Subtitle + optionItem={optionItem} + viewMode={viewMode} + isOptionFocused={isOptionFocused} + style={style} + /> + </View> + <DescriptiveText optionItem={optionItem} /> + </View> + </View> + </Pressable> + </OfflineWrapper> + ); +} + +ArchivedOptionRowLHN.displayName = 'ArchivedOptionRowLHN'; + +export default React.memo(ArchivedOptionRowLHN); diff --git a/src/components/LHNOptionsList/OptionRowLHN/OptionRowPressable.tsx b/src/components/LHNOptionsList/OptionRowLHN/OptionRow/Pressable.tsx similarity index 59% rename from src/components/LHNOptionsList/OptionRowLHN/OptionRowPressable.tsx rename to src/components/LHNOptionsList/OptionRowLHN/OptionRow/Pressable.tsx index e88e8daf840e..632bb73b6ce1 100644 --- a/src/components/LHNOptionsList/OptionRowLHN/OptionRowPressable.tsx +++ b/src/components/LHNOptionsList/OptionRowLHN/OptionRow/Pressable.tsx @@ -1,8 +1,14 @@ -import type {ReactNode, RefObject} from 'react'; -import React, {useState} from 'react'; +import type {ReactNode} from 'react'; +import React, {useRef, useState} from 'react'; import type {GestureResponderEvent, LayoutChangeEvent, View} from 'react-native'; import Hoverable from '@components/Hoverable'; +import {useLHNTooltipContext} from '@components/LHNOptionsList/LHNTooltipContext'; +import useLHNRowProductTrainingTooltip from '@components/LHNOptionsList/OptionRowLHN/useLHNRowProductTrainingTooltip'; import PressableWithSecondaryInteraction from '@components/PressableWithSecondaryInteraction'; +import getContextMenuAccessibilityHint from '@components/utils/getContextMenuAccessibilityHint'; +import getContextMenuAccessibilityProps from '@components/utils/getContextMenuAccessibilityProps'; +import useEnvironment from '@hooks/useEnvironment'; +import useLocalize from '@hooks/useLocalize'; import useResponsiveLayout from '@hooks/useResponsiveLayout'; import useStyleUtils from '@hooks/useStyleUtils'; import useTheme from '@hooks/useTheme'; @@ -14,35 +20,72 @@ import {startSpan} from '@libs/telemetry/activeSpans'; import {showContextMenu} from '@pages/inbox/report/ContextMenu/ReportActionContextMenu'; import variables from '@styles/variables'; import CONST from '@src/CONST'; -import useLHNRowProductTrainingTooltip from './useLHNRowProductTrainingTooltip'; -type OptionRowPressableProps = { +type PressableProps = { + /** Option data for the row. Source of accessibility text and the report ID used by press/context-menu actions. */ optionItem: OptionData; + + /** Whether the row is the currently focused/active option. Drives the focused background and accessibility metadata. */ isOptionFocused: boolean; - isScreenFocused: boolean; - popoverAnchor: RefObject<View | null>; - onSelectRow: (optionItem: OptionData, popoverAnchor: RefObject<View | null>) => void; + + /** Press handler invoked with the option data and the popover anchor ref. */ + onSelectRow: (optionItem: OptionData, popoverAnchor: React.RefObject<View | null>) => void; + + /** Layout handler forwarded to the underlying pressable. */ onLayout?: (event: LayoutChangeEvent) => void; - accessibilityLabel: string; - accessibilityHint?: string; - testID?: string; - children: (hovered: boolean) => ReactNode; + + /** Fires when the mouse enters the row. Hover state lives in the parent so leaves like Avatar can react. */ + onHoverIn?: () => void; + + /** Fires when the mouse leaves the row. */ + onHoverOut?: () => void; + + /** Row content. */ + children: ReactNode; }; -function OptionRowPressable({ - optionItem, - isOptionFocused, - isScreenFocused, - popoverAnchor, - onSelectRow, - onLayout, - accessibilityLabel, - accessibilityHint, - testID, - children, -}: OptionRowPressableProps) { +function Pressable({optionItem, isOptionFocused, onSelectRow, onLayout, onHoverIn, onHoverOut, children}: PressableProps) { + const theme = useTheme(); + const styles = useThemeStyles(); + const StyleUtils = useStyleUtils(); + const {translate} = useLocalize(); + const {isProduction} = useEnvironment(); + const {isScreenFocused} = useLHNTooltipContext(); + const {shouldUseNarrowLayout} = useResponsiveLayout(); const {hideProductTrainingTooltip} = useLHNRowProductTrainingTooltip(); + + const popoverAnchor = useRef<View>(null); + const [isContextMenuActive, setIsContextMenuActive] = useState(false); + const reportID = optionItem.reportID; + const brickRoadIndicator = optionItem.brickRoadIndicator; + const actionBadgeText = !isProduction && optionItem.actionBadge ? translate(`common.actionBadge.${optionItem.actionBadge}`) : ''; + + let accessibilityLabelForBadge = ''; + if (brickRoadIndicator) { + accessibilityLabelForBadge = [translate('common.yourReviewIsRequired'), actionBadgeText].filter(Boolean).join(', '); + } else if (optionItem.isPinned) { + accessibilityLabelForBadge = translate('common.pinned'); + } + + const accessibilityLabel = [ + `${translate('accessibilityHints.navigatesToChat')} ${optionItem.text}`, + optionItem.isUnread ? translate('common.unread') : '', + optionItem.alternateText ?? '', + accessibilityLabelForBadge, + ] + .filter(Boolean) + .join('. '); + const contextMenuHint = getContextMenuAccessibilityHint({translate}); + const {accessibilityLabel: accessibilityLabelWithContextMenuHint, accessibilityHint} = getContextMenuAccessibilityProps({ + accessibilityLabel, + nativeAccessibilityHint: accessibilityLabel, + contextMenuHint, + }); + + // reportID may be a number contrary to the type definition + const testID = typeof reportID === 'number' ? String(reportID) : reportID; + const onPress = (event: GestureResponderEvent | KeyboardEvent | undefined) => { hideProductTrainingTooltip(); startSpan(`${CONST.TELEMETRY.SPAN_OPEN_REPORT}_${reportID}`, { @@ -55,11 +98,6 @@ function OptionRowPressable({ ReportActionComposeFocusManager.focus(); onSelectRow(optionItem, popoverAnchor); }; - const theme = useTheme(); - const styles = useThemeStyles(); - const StyleUtils = useStyleUtils(); - const {shouldUseNarrowLayout} = useResponsiveLayout(); - const [isContextMenuActive, setIsContextMenuActive] = useState(false); const showPopover = (event: MouseEvent | GestureResponderEvent) => { if (!isScreenFocused && shouldUseNarrowLayout) { @@ -86,7 +124,10 @@ function OptionRowPressable({ }; return ( - <Hoverable> + <Hoverable + onHoverIn={onHoverIn} + onHoverOut={onHoverOut} + > {(hovered) => ( <PressableWithSecondaryInteraction ref={popoverAnchor} @@ -121,19 +162,19 @@ function OptionRowPressable({ (hovered || isContextMenuActive) && !isOptionFocused ? styles.sidebarLinkHover : null, ]} role={CONST.ROLE.BUTTON} - accessibilityLabel={accessibilityLabel} + accessibilityLabel={accessibilityLabelWithContextMenuHint} accessibilityHint={accessibilityHint} onLayout={onLayout} needsOffscreenAlphaCompositing={(optionItem?.icons?.length ?? 0) >= 2} sentryLabel={CONST.SENTRY_LABEL.LHN.OPTION_ROW} > - {children(hovered)} + {children} </PressableWithSecondaryInteraction> )} </Hoverable> ); } -OptionRowPressable.displayName = 'OptionRowPressable'; +Pressable.displayName = 'OptionRow.Pressable'; -export default OptionRowPressable; +export default Pressable; diff --git a/src/components/LHNOptionsList/OptionRowLHN/OptionRowLHN.tsx b/src/components/LHNOptionsList/OptionRowLHN/OptionRowLHN.tsx new file mode 100644 index 000000000000..295095e5d31a --- /dev/null +++ b/src/components/LHNOptionsList/OptionRowLHN/OptionRowLHN.tsx @@ -0,0 +1,127 @@ +import React, {useState} from 'react'; +import type {ViewStyle} from 'react-native'; +import {StyleSheet, View} from 'react-native'; +import type {OptionRowLHNProps} from '@components/LHNOptionsList/types'; +import useStyleUtils from '@hooks/useStyleUtils'; +import useTheme from '@hooks/useTheme'; +import useThemeStyles from '@hooks/useThemeStyles'; +import {shouldUseBoldText} from '@libs/OptionsListUtils'; +import CONST from '@src/CONST'; +import Avatar from './OptionRow/Avatar'; +import DescriptiveText from './OptionRow/DescriptiveText'; +import DraftIndicator from './OptionRow/DraftIndicator'; +import ErrorBadge from './OptionRow/ErrorBadge'; +import InfoBadge from './OptionRow/InfoBadge'; +import OfflineWrapper from './OptionRow/OfflineWrapper'; +import OnboardingBadge from './OptionRow/OnboardingBadge'; +import PinIndicator from './OptionRow/PinIndicator'; +import Pressable from './OptionRow/Pressable'; +import ProductTrainingTooltip from './OptionRow/ProductTrainingTooltip'; +import Status from './OptionRow/Status'; +import Subtitle from './OptionRow/Subtitle'; +import Title from './OptionRow/Title'; + +function OptionRowLHN({isOptionFocused = false, onSelectRow = () => {}, optionItem, viewMode = 'default', style, onLayout = () => {}, hasDraftComment, testID}: OptionRowLHNProps) { + const theme = useTheme(); + const styles = useThemeStyles(); + const StyleUtils = useStyleUtils(); + const [hovered, setHovered] = useState(false); + + const isInFocusMode = viewMode === CONST.OPTION_MODE.COMPACT; + const brickRoadIndicator = optionItem.brickRoadIndicator; + + const sidebarInnerRowStyle = StyleSheet.flatten<ViewStyle>( + isInFocusMode + ? [styles.chatLinkRowPressable, styles.flexGrow1, styles.optionItemAvatarNameWrapper, styles.optionRowCompact, styles.justifyContentCenter] + : [styles.chatLinkRowPressable, styles.flexGrow1, styles.optionItemAvatarNameWrapper, styles.optionRow, styles.justifyContentCenter], + ); + const contentContainerStyles = isInFocusMode + ? [styles.flex1, styles.flexRow, styles.overflowHidden, StyleUtils.getCompactContentContainerStyles()] + : [styles.flex1]; + const singleAvatarContainerStyle = [styles.actionAvatar, styles.mr3]; + + const hoveredBackgroundColor = !!styles.sidebarLinkHover && 'backgroundColor' in styles.sidebarLinkHover ? styles.sidebarLinkHover.backgroundColor : theme.sidebar; + const focusedBackgroundColor = styles.sidebarLinkActive.backgroundColor; + const subscriptAvatarBorderColor = isOptionFocused ? focusedBackgroundColor : theme.sidebar; + + let secondaryAvatarBgColor = theme.sidebar; + if (isOptionFocused) { + secondaryAvatarBgColor = focusedBackgroundColor; + } else if (hovered) { + secondaryAvatarBgColor = hoveredBackgroundColor; + } + + const textStyle = isOptionFocused ? styles.sidebarLinkActiveText : styles.sidebarLinkText; + const textUnreadStyle = shouldUseBoldText(optionItem) ? [textStyle, styles.sidebarLinkTextBold] : [textStyle]; + const displayNameStyle = [styles.optionDisplayName, styles.optionDisplayNameCompact, styles.pre, textUnreadStyle, styles.flexShrink0, style]; + + return ( + <OfflineWrapper + pendingAction={optionItem.pendingAction} + errors={optionItem.allReportErrors} + > + <ProductTrainingTooltip optionItem={optionItem}> + <Pressable + optionItem={optionItem} + isOptionFocused={isOptionFocused} + onSelectRow={onSelectRow} + onLayout={onLayout} + onHoverIn={() => setHovered(true)} + onHoverOut={() => setHovered(false)} + > + <View style={sidebarInnerRowStyle}> + <View style={[styles.flexRow, styles.alignItemsCenter]}> + <Avatar + optionItem={optionItem} + isInFocusMode={isInFocusMode} + subscriptAvatarBorderColor={hovered && !isOptionFocused ? hoveredBackgroundColor : subscriptAvatarBorderColor} + secondaryAvatarBackgroundColor={secondaryAvatarBgColor} + singleAvatarContainerStyle={singleAvatarContainerStyle} + /> + <View style={contentContainerStyles}> + <View style={[styles.flexRow, styles.alignItemsCenter, styles.mw100, styles.overflowHidden]}> + <Title + optionItem={optionItem} + displayNameStyle={displayNameStyle} + testID={testID} + /> + <OnboardingBadge optionItem={optionItem} /> + <Status optionItem={optionItem} /> + </View> + <Subtitle + optionItem={optionItem} + viewMode={viewMode} + isOptionFocused={isOptionFocused} + style={style} + /> + </View> + <DescriptiveText optionItem={optionItem} /> + <ErrorBadge + brickRoadIndicator={brickRoadIndicator} + actionBadge={optionItem.actionBadge} + /> + </View> + </View> + <View style={[styles.flexRow, styles.alignItemsCenter]}> + <InfoBadge + brickRoadIndicator={brickRoadIndicator} + actionBadge={optionItem.actionBadge} + /> + <DraftIndicator + hasDraftComment={hasDraftComment} + isAllowedToComment={optionItem.isAllowedToComment} + /> + <PinIndicator + isPinned={optionItem.isPinned} + brickRoadIndicator={brickRoadIndicator} + /> + </View> + </Pressable> + </ProductTrainingTooltip> + </OfflineWrapper> + ); +} + +OptionRowLHN.displayName = 'OptionRowLHN'; + +export default React.memo(OptionRowLHN); diff --git a/src/components/LHNOptionsList/OptionRowLHN/OptionRowLHNCore.tsx b/src/components/LHNOptionsList/OptionRowLHN/OptionRowLHNCore.tsx deleted file mode 100644 index 8bdb1b948538..000000000000 --- a/src/components/LHNOptionsList/OptionRowLHN/OptionRowLHNCore.tsx +++ /dev/null @@ -1,166 +0,0 @@ -import React, {useRef} from 'react'; -import type {ViewStyle} from 'react-native'; -import {StyleSheet, View} from 'react-native'; -import {useLHNTooltipContext} from '@components/LHNOptionsList/LHNTooltipContext'; -import type {OptionRowLHNProps} from '@components/LHNOptionsList/types'; -import getContextMenuAccessibilityHint from '@components/utils/getContextMenuAccessibilityHint'; -import getContextMenuAccessibilityProps from '@components/utils/getContextMenuAccessibilityProps'; -import useEnvironment from '@hooks/useEnvironment'; -import useLocalize from '@hooks/useLocalize'; -import useStyleUtils from '@hooks/useStyleUtils'; -import useTheme from '@hooks/useTheme'; -import useThemeStyles from '@hooks/useThemeStyles'; -import {shouldUseBoldText} from '@libs/OptionsListUtils'; -import CONST from '@src/CONST'; -import Avatar from './OptionRow/Avatar'; -import DescriptiveText from './OptionRow/DescriptiveText'; -import DraftIndicator from './OptionRow/DraftIndicator'; -import ErrorBadge from './OptionRow/ErrorBadge'; -import InfoBadge from './OptionRow/InfoBadge'; -import OfflineWrapper from './OptionRow/OfflineWrapper'; -import OnboardingBadge from './OptionRow/OnboardingBadge'; -import PinIndicator from './OptionRow/PinIndicator'; -import ProductTrainingTooltip from './OptionRow/ProductTrainingTooltip'; -import Status from './OptionRow/Status'; -import Subtitle from './OptionRow/Subtitle'; -import Title from './OptionRow/Title'; -import OptionRowPressable from './OptionRowPressable'; - -function OptionRowLHN({isOptionFocused = false, onSelectRow = () => {}, optionItem, viewMode = 'default', style, onLayout = () => {}, hasDraftComment, testID}: OptionRowLHNProps) { - const {isProduction} = useEnvironment(); - const theme = useTheme(); - const styles = useThemeStyles(); - const popoverAnchor = useRef<View>(null); - const StyleUtils = useStyleUtils(); - - const {isScreenFocused} = useLHNTooltipContext(); - - const {translate} = useLocalize(); - const isInFocusMode = viewMode === CONST.OPTION_MODE.COMPACT; - const sidebarInnerRowStyle = StyleSheet.flatten<ViewStyle>( - isInFocusMode - ? [styles.chatLinkRowPressable, styles.flexGrow1, styles.optionItemAvatarNameWrapper, styles.optionRowCompact, styles.justifyContentCenter] - : [styles.chatLinkRowPressable, styles.flexGrow1, styles.optionItemAvatarNameWrapper, styles.optionRow, styles.justifyContentCenter], - ); - - const singleAvatarContainerStyle = [styles.actionAvatar, styles.mr3]; - - const brickRoadIndicator = optionItem.brickRoadIndicator; - const actionBadgeText = !isProduction && optionItem.actionBadge ? translate(`common.actionBadge.${optionItem.actionBadge}`) : ''; - let accessibilityLabelForBadge = ''; - if (brickRoadIndicator) { - accessibilityLabelForBadge = [translate('common.yourReviewIsRequired'), actionBadgeText].filter(Boolean).join(', '); - } else if (optionItem.isPinned) { - accessibilityLabelForBadge = translate('common.pinned'); - } - const textStyle = isOptionFocused ? styles.sidebarLinkActiveText : styles.sidebarLinkText; - const textUnreadStyle = shouldUseBoldText(optionItem) ? [textStyle, styles.sidebarLinkTextBold] : [textStyle]; - const displayNameStyle = [styles.optionDisplayName, styles.optionDisplayNameCompact, styles.pre, textUnreadStyle, styles.flexShrink0, style]; - - const contentContainerStyles = isInFocusMode ? [styles.flex1, styles.flexRow, styles.overflowHidden, StyleUtils.getCompactContentContainerStyles()] : [styles.flex1]; - const hoveredBackgroundColor = !!styles.sidebarLinkHover && 'backgroundColor' in styles.sidebarLinkHover ? styles.sidebarLinkHover.backgroundColor : theme.sidebar; - const focusedBackgroundColor = styles.sidebarLinkActive.backgroundColor; - - const subscriptAvatarBorderColor = isOptionFocused ? focusedBackgroundColor : theme.sidebar; - - const accessibilityLabel = [ - `${translate('accessibilityHints.navigatesToChat')} ${optionItem.text}`, - optionItem.isUnread ? translate('common.unread') : '', - optionItem.alternateText ?? '', - accessibilityLabelForBadge, - ] - .filter(Boolean) - .join('. '); - const contextMenuHint = getContextMenuAccessibilityHint({translate}); - const {accessibilityLabel: accessibilityLabelWithContextMenuHint, accessibilityHint} = getContextMenuAccessibilityProps({ - accessibilityLabel, - nativeAccessibilityHint: accessibilityLabel, - contextMenuHint, - }); - - return ( - <OfflineWrapper - pendingAction={optionItem.pendingAction} - errors={optionItem.allReportErrors} - > - <ProductTrainingTooltip optionItem={optionItem}> - <OptionRowPressable - optionItem={optionItem} - isOptionFocused={isOptionFocused} - isScreenFocused={isScreenFocused} - popoverAnchor={popoverAnchor} - onSelectRow={onSelectRow} - onLayout={onLayout} - accessibilityLabel={accessibilityLabelWithContextMenuHint} - accessibilityHint={accessibilityHint} - // reportID may be a number contrary to the type definition - testID={typeof optionItem.reportID === 'number' ? String(optionItem.reportID) : optionItem.reportID} - > - {(hovered) => { - let secondaryAvatarBgColor = theme.sidebar; - if (isOptionFocused) { - secondaryAvatarBgColor = focusedBackgroundColor; - } else if (hovered) { - secondaryAvatarBgColor = hoveredBackgroundColor; - } - return ( - <> - <View style={sidebarInnerRowStyle}> - <View style={[styles.flexRow, styles.alignItemsCenter]}> - <Avatar - optionItem={optionItem} - isInFocusMode={isInFocusMode} - subscriptAvatarBorderColor={hovered && !isOptionFocused ? hoveredBackgroundColor : subscriptAvatarBorderColor} - secondaryAvatarBackgroundColor={secondaryAvatarBgColor} - singleAvatarContainerStyle={singleAvatarContainerStyle} - /> - <View style={contentContainerStyles}> - <View style={[styles.flexRow, styles.alignItemsCenter, styles.mw100, styles.overflowHidden]}> - <Title - optionItem={optionItem} - displayNameStyle={displayNameStyle} - testID={testID} - /> - <OnboardingBadge optionItem={optionItem} /> - <Status optionItem={optionItem} /> - </View> - <Subtitle - optionItem={optionItem} - viewMode={viewMode} - isOptionFocused={isOptionFocused} - style={style} - /> - </View> - <DescriptiveText optionItem={optionItem} /> - <ErrorBadge - brickRoadIndicator={brickRoadIndicator} - actionBadge={optionItem.actionBadge} - /> - </View> - </View> - <View style={[styles.flexRow, styles.alignItemsCenter]}> - <InfoBadge - brickRoadIndicator={brickRoadIndicator} - actionBadge={optionItem.actionBadge} - /> - <DraftIndicator - hasDraftComment={hasDraftComment} - isAllowedToComment={optionItem.isAllowedToComment} - /> - <PinIndicator - isPinned={optionItem.isPinned} - brickRoadIndicator={brickRoadIndicator} - /> - </View> - </> - ); - }} - </OptionRowPressable> - </ProductTrainingTooltip> - </OfflineWrapper> - ); -} - -OptionRowLHN.displayName = 'OptionRowLHN'; - -export default React.memo(OptionRowLHN); diff --git a/src/components/LHNOptionsList/OptionRowLHN/OptionRowLHNData.tsx b/src/components/LHNOptionsList/OptionRowLHN/OptionRowLHNData.tsx index 5f0f5e9b3059..3420ecb9bb8d 100644 --- a/src/components/LHNOptionsList/OptionRowLHN/OptionRowLHNData.tsx +++ b/src/components/LHNOptionsList/OptionRowLHN/OptionRowLHNData.tsx @@ -20,7 +20,8 @@ import ONYXKEYS from '@src/ONYXKEYS'; import type {ReportActions as ReportActionsType} from '@src/types/onyx'; import type {VisibleReportActionsDerivedValue} from '@src/types/onyx/DerivedValues'; import type {Icon} from '@src/types/onyx/OnyxCommon'; -import OptionRowLHN from './OptionRowLHNCore'; +import ArchivedOptionRowLHN from './ArchivedOptionRowLHN'; +import OptionRowLHN from './OptionRowLHN'; /* * This component gets the data from onyx for the actual @@ -190,8 +191,10 @@ function OptionRowLHNData({ return isReportFocused ? null : <View style={placeholderRowStyle} />; } + const Row = isReportArchived ? ArchivedOptionRowLHN : OptionRowLHN; + return ( - <OptionRowLHN + <Row // eslint-disable-next-line react/jsx-props-no-spreading {...propsToForward} viewMode={viewMode} diff --git a/src/components/LHNOptionsList/OptionRowLHN/useLHNRowProductTrainingTooltip.ts b/src/components/LHNOptionsList/OptionRowLHN/useLHNRowProductTrainingTooltip.ts index e2a400aa4b19..d28bf1f589a6 100644 --- a/src/components/LHNOptionsList/OptionRowLHN/useLHNRowProductTrainingTooltip.ts +++ b/src/components/LHNOptionsList/OptionRowLHN/useLHNRowProductTrainingTooltip.ts @@ -6,7 +6,7 @@ import CONST from '@src/CONST'; /** * Resolves the product-training tooltip state (CONCIERGE_LHN_GBR) for an LHN row. - * Used by both ProductTrainingTooltipInner (render the tooltip) and OptionRowPressable (hide on press). + * Used by both ProductTrainingTooltipInner (render the tooltip) and OptionRow/Pressable (hide on press). */ function useLHNRowProductTrainingTooltip() { const {shouldUseNarrowLayout} = useResponsiveLayout(); From 164235bfbf585b8c6a5978714a4fafcf6881828f Mon Sep 17 00:00:00 2001 From: bartlomiej obudzinski <bartlomiej.obudzinski@callstack.com> Date: Wed, 13 May 2026 11:48:14 +0200 Subject: [PATCH 02/12] refactor: adopt OptionRow.X compound dot-notation in variants --- .../OptionRowLHN/ArchivedOptionRowLHN.tsx | 26 ++++------- .../OptionRowLHN/OptionRow/index.ts | 31 +++++++++++++ .../OptionRowLHN/OptionRowLHN.tsx | 46 +++++++------------ 3 files changed, 58 insertions(+), 45 deletions(-) create mode 100644 src/components/LHNOptionsList/OptionRowLHN/OptionRow/index.ts diff --git a/src/components/LHNOptionsList/OptionRowLHN/ArchivedOptionRowLHN.tsx b/src/components/LHNOptionsList/OptionRowLHN/ArchivedOptionRowLHN.tsx index 4856c293dbdf..b11440f42e68 100644 --- a/src/components/LHNOptionsList/OptionRowLHN/ArchivedOptionRowLHN.tsx +++ b/src/components/LHNOptionsList/OptionRowLHN/ArchivedOptionRowLHN.tsx @@ -7,13 +7,7 @@ import useTheme from '@hooks/useTheme'; import useThemeStyles from '@hooks/useThemeStyles'; import {shouldUseBoldText} from '@libs/OptionsListUtils'; import CONST from '@src/CONST'; -import Avatar from './OptionRow/Avatar'; -import DescriptiveText from './OptionRow/DescriptiveText'; -import OfflineWrapper from './OptionRow/OfflineWrapper'; -import Pressable from './OptionRow/Pressable'; -import Status from './OptionRow/Status'; -import Subtitle from './OptionRow/Subtitle'; -import Title from './OptionRow/Title'; +import OptionRow from './OptionRow'; /** * Sibling variant of `OptionRowLHN` used for archived reports. Strips the product training @@ -54,11 +48,11 @@ function ArchivedOptionRowLHN({isOptionFocused = false, onSelectRow = () => {}, const displayNameStyle = [styles.optionDisplayName, styles.optionDisplayNameCompact, styles.pre, textUnreadStyle, styles.flexShrink0, style]; return ( - <OfflineWrapper + <OptionRow.OfflineWrapper pendingAction={optionItem.pendingAction} errors={optionItem.allReportErrors} > - <Pressable + <OptionRow.Pressable optionItem={optionItem} isOptionFocused={isOptionFocused} onSelectRow={onSelectRow} @@ -68,7 +62,7 @@ function ArchivedOptionRowLHN({isOptionFocused = false, onSelectRow = () => {}, > <View style={sidebarInnerRowStyle}> <View style={[styles.flexRow, styles.alignItemsCenter]}> - <Avatar + <OptionRow.Avatar optionItem={optionItem} isInFocusMode={isInFocusMode} subscriptAvatarBorderColor={hovered && !isOptionFocused ? hoveredBackgroundColor : subscriptAvatarBorderColor} @@ -77,25 +71,25 @@ function ArchivedOptionRowLHN({isOptionFocused = false, onSelectRow = () => {}, /> <View style={contentContainerStyles}> <View style={[styles.flexRow, styles.alignItemsCenter, styles.mw100, styles.overflowHidden]}> - <Title + <OptionRow.Title optionItem={optionItem} displayNameStyle={displayNameStyle} testID={testID} /> - <Status optionItem={optionItem} /> + <OptionRow.Status optionItem={optionItem} /> </View> - <Subtitle + <OptionRow.Subtitle optionItem={optionItem} viewMode={viewMode} isOptionFocused={isOptionFocused} style={style} /> </View> - <DescriptiveText optionItem={optionItem} /> + <OptionRow.DescriptiveText optionItem={optionItem} /> </View> </View> - </Pressable> - </OfflineWrapper> + </OptionRow.Pressable> + </OptionRow.OfflineWrapper> ); } diff --git a/src/components/LHNOptionsList/OptionRowLHN/OptionRow/index.ts b/src/components/LHNOptionsList/OptionRowLHN/OptionRow/index.ts new file mode 100644 index 000000000000..9ddea46008cc --- /dev/null +++ b/src/components/LHNOptionsList/OptionRowLHN/OptionRow/index.ts @@ -0,0 +1,31 @@ +import Avatar from './Avatar'; +import DescriptiveText from './DescriptiveText'; +import DraftIndicator from './DraftIndicator'; +import ErrorBadge from './ErrorBadge'; +import InfoBadge from './InfoBadge'; +import OfflineWrapper from './OfflineWrapper'; +import OnboardingBadge from './OnboardingBadge'; +import PinIndicator from './PinIndicator'; +import Pressable from './Pressable'; +import ProductTrainingTooltip from './ProductTrainingTooltip'; +import Status from './Status'; +import Subtitle from './Subtitle'; +import Title from './Title'; + +const OptionRow = { + Avatar, + DescriptiveText, + DraftIndicator, + ErrorBadge, + InfoBadge, + OfflineWrapper, + OnboardingBadge, + PinIndicator, + Pressable, + ProductTrainingTooltip, + Status, + Subtitle, + Title, +}; + +export default OptionRow; diff --git a/src/components/LHNOptionsList/OptionRowLHN/OptionRowLHN.tsx b/src/components/LHNOptionsList/OptionRowLHN/OptionRowLHN.tsx index 295095e5d31a..e5154ccfb9ee 100644 --- a/src/components/LHNOptionsList/OptionRowLHN/OptionRowLHN.tsx +++ b/src/components/LHNOptionsList/OptionRowLHN/OptionRowLHN.tsx @@ -7,19 +7,7 @@ import useTheme from '@hooks/useTheme'; import useThemeStyles from '@hooks/useThemeStyles'; import {shouldUseBoldText} from '@libs/OptionsListUtils'; import CONST from '@src/CONST'; -import Avatar from './OptionRow/Avatar'; -import DescriptiveText from './OptionRow/DescriptiveText'; -import DraftIndicator from './OptionRow/DraftIndicator'; -import ErrorBadge from './OptionRow/ErrorBadge'; -import InfoBadge from './OptionRow/InfoBadge'; -import OfflineWrapper from './OptionRow/OfflineWrapper'; -import OnboardingBadge from './OptionRow/OnboardingBadge'; -import PinIndicator from './OptionRow/PinIndicator'; -import Pressable from './OptionRow/Pressable'; -import ProductTrainingTooltip from './OptionRow/ProductTrainingTooltip'; -import Status from './OptionRow/Status'; -import Subtitle from './OptionRow/Subtitle'; -import Title from './OptionRow/Title'; +import OptionRow from './OptionRow'; function OptionRowLHN({isOptionFocused = false, onSelectRow = () => {}, optionItem, viewMode = 'default', style, onLayout = () => {}, hasDraftComment, testID}: OptionRowLHNProps) { const theme = useTheme(); @@ -56,12 +44,12 @@ function OptionRowLHN({isOptionFocused = false, onSelectRow = () => {}, optionIt const displayNameStyle = [styles.optionDisplayName, styles.optionDisplayNameCompact, styles.pre, textUnreadStyle, styles.flexShrink0, style]; return ( - <OfflineWrapper + <OptionRow.OfflineWrapper pendingAction={optionItem.pendingAction} errors={optionItem.allReportErrors} > - <ProductTrainingTooltip optionItem={optionItem}> - <Pressable + <OptionRow.ProductTrainingTooltip optionItem={optionItem}> + <OptionRow.Pressable optionItem={optionItem} isOptionFocused={isOptionFocused} onSelectRow={onSelectRow} @@ -71,7 +59,7 @@ function OptionRowLHN({isOptionFocused = false, onSelectRow = () => {}, optionIt > <View style={sidebarInnerRowStyle}> <View style={[styles.flexRow, styles.alignItemsCenter]}> - <Avatar + <OptionRow.Avatar optionItem={optionItem} isInFocusMode={isInFocusMode} subscriptAvatarBorderColor={hovered && !isOptionFocused ? hoveredBackgroundColor : subscriptAvatarBorderColor} @@ -80,45 +68,45 @@ function OptionRowLHN({isOptionFocused = false, onSelectRow = () => {}, optionIt /> <View style={contentContainerStyles}> <View style={[styles.flexRow, styles.alignItemsCenter, styles.mw100, styles.overflowHidden]}> - <Title + <OptionRow.Title optionItem={optionItem} displayNameStyle={displayNameStyle} testID={testID} /> - <OnboardingBadge optionItem={optionItem} /> - <Status optionItem={optionItem} /> + <OptionRow.OnboardingBadge optionItem={optionItem} /> + <OptionRow.Status optionItem={optionItem} /> </View> - <Subtitle + <OptionRow.Subtitle optionItem={optionItem} viewMode={viewMode} isOptionFocused={isOptionFocused} style={style} /> </View> - <DescriptiveText optionItem={optionItem} /> - <ErrorBadge + <OptionRow.DescriptiveText optionItem={optionItem} /> + <OptionRow.ErrorBadge brickRoadIndicator={brickRoadIndicator} actionBadge={optionItem.actionBadge} /> </View> </View> <View style={[styles.flexRow, styles.alignItemsCenter]}> - <InfoBadge + <OptionRow.InfoBadge brickRoadIndicator={brickRoadIndicator} actionBadge={optionItem.actionBadge} /> - <DraftIndicator + <OptionRow.DraftIndicator hasDraftComment={hasDraftComment} isAllowedToComment={optionItem.isAllowedToComment} /> - <PinIndicator + <OptionRow.PinIndicator isPinned={optionItem.isPinned} brickRoadIndicator={brickRoadIndicator} /> </View> - </Pressable> - </ProductTrainingTooltip> - </OfflineWrapper> + </OptionRow.Pressable> + </OptionRow.ProductTrainingTooltip> + </OptionRow.OfflineWrapper> ); } From 14ba17e494bde9214566384cd6b96bb66ede82eb Mon Sep 17 00:00:00 2001 From: bartlomiej obudzinski <bartlomiej.obudzinski@callstack.com> Date: Wed, 13 May 2026 12:07:49 +0200 Subject: [PATCH 03/12] refactor: dedupe variant chrome derivations into useOptionRowChrome --- .../OptionRowLHN/ArchivedOptionRowLHN.tsx | 50 +++---------- .../OptionRowLHN/OptionRowLHN.tsx | 49 +++--------- .../OptionRowLHN/useOptionRowChrome.ts | 75 +++++++++++++++++++ 3 files changed, 97 insertions(+), 77 deletions(-) create mode 100644 src/components/LHNOptionsList/OptionRowLHN/useOptionRowChrome.ts diff --git a/src/components/LHNOptionsList/OptionRowLHN/ArchivedOptionRowLHN.tsx b/src/components/LHNOptionsList/OptionRowLHN/ArchivedOptionRowLHN.tsx index b11440f42e68..ec4e51dbb7ab 100644 --- a/src/components/LHNOptionsList/OptionRowLHN/ArchivedOptionRowLHN.tsx +++ b/src/components/LHNOptionsList/OptionRowLHN/ArchivedOptionRowLHN.tsx @@ -1,13 +1,9 @@ -import React, {useState} from 'react'; -import type {ViewStyle} from 'react-native'; -import {StyleSheet, View} from 'react-native'; +import React from 'react'; +import {View} from 'react-native'; import type {OptionRowLHNProps} from '@components/LHNOptionsList/types'; -import useStyleUtils from '@hooks/useStyleUtils'; -import useTheme from '@hooks/useTheme'; import useThemeStyles from '@hooks/useThemeStyles'; -import {shouldUseBoldText} from '@libs/OptionsListUtils'; -import CONST from '@src/CONST'; import OptionRow from './OptionRow'; +import useOptionRowChrome from './useOptionRowChrome'; /** * Sibling variant of `OptionRowLHN` used for archived reports. Strips the product training @@ -15,37 +11,13 @@ import OptionRow from './OptionRow'; * row (Draft/Pin) because none of them apply to a historical, write-locked row. */ function ArchivedOptionRowLHN({isOptionFocused = false, onSelectRow = () => {}, optionItem, viewMode = 'default', style, onLayout = () => {}, testID}: OptionRowLHNProps) { - const theme = useTheme(); const styles = useThemeStyles(); - const StyleUtils = useStyleUtils(); - const [hovered, setHovered] = useState(false); - - const isInFocusMode = viewMode === CONST.OPTION_MODE.COMPACT; - - const sidebarInnerRowStyle = StyleSheet.flatten<ViewStyle>( - isInFocusMode - ? [styles.chatLinkRowPressable, styles.flexGrow1, styles.optionItemAvatarNameWrapper, styles.optionRowCompact, styles.justifyContentCenter] - : [styles.chatLinkRowPressable, styles.flexGrow1, styles.optionItemAvatarNameWrapper, styles.optionRow, styles.justifyContentCenter], - ); - const contentContainerStyles = isInFocusMode - ? [styles.flex1, styles.flexRow, styles.overflowHidden, StyleUtils.getCompactContentContainerStyles()] - : [styles.flex1]; - const singleAvatarContainerStyle = [styles.actionAvatar, styles.mr3]; - - const hoveredBackgroundColor = !!styles.sidebarLinkHover && 'backgroundColor' in styles.sidebarLinkHover ? styles.sidebarLinkHover.backgroundColor : theme.sidebar; - const focusedBackgroundColor = styles.sidebarLinkActive.backgroundColor; - const subscriptAvatarBorderColor = isOptionFocused ? focusedBackgroundColor : theme.sidebar; - - let secondaryAvatarBgColor = theme.sidebar; - if (isOptionFocused) { - secondaryAvatarBgColor = focusedBackgroundColor; - } else if (hovered) { - secondaryAvatarBgColor = hoveredBackgroundColor; - } - - const textStyle = isOptionFocused ? styles.sidebarLinkActiveText : styles.sidebarLinkText; - const textUnreadStyle = shouldUseBoldText(optionItem) ? [textStyle, styles.sidebarLinkTextBold] : [textStyle]; - const displayNameStyle = [styles.optionDisplayName, styles.optionDisplayNameCompact, styles.pre, textUnreadStyle, styles.flexShrink0, style]; + const {setHovered, isInFocusMode, sidebarInnerRowStyle, contentContainerStyles, singleAvatarContainerStyle, avatarBackgroundColor, displayNameStyle} = useOptionRowChrome({ + optionItem, + isOptionFocused, + viewMode, + style, + }); return ( <OptionRow.OfflineWrapper @@ -65,8 +37,8 @@ function ArchivedOptionRowLHN({isOptionFocused = false, onSelectRow = () => {}, <OptionRow.Avatar optionItem={optionItem} isInFocusMode={isInFocusMode} - subscriptAvatarBorderColor={hovered && !isOptionFocused ? hoveredBackgroundColor : subscriptAvatarBorderColor} - secondaryAvatarBackgroundColor={secondaryAvatarBgColor} + subscriptAvatarBorderColor={avatarBackgroundColor} + secondaryAvatarBackgroundColor={avatarBackgroundColor} singleAvatarContainerStyle={singleAvatarContainerStyle} /> <View style={contentContainerStyles}> diff --git a/src/components/LHNOptionsList/OptionRowLHN/OptionRowLHN.tsx b/src/components/LHNOptionsList/OptionRowLHN/OptionRowLHN.tsx index e5154ccfb9ee..fccf9f78dbac 100644 --- a/src/components/LHNOptionsList/OptionRowLHN/OptionRowLHN.tsx +++ b/src/components/LHNOptionsList/OptionRowLHN/OptionRowLHN.tsx @@ -1,48 +1,21 @@ -import React, {useState} from 'react'; -import type {ViewStyle} from 'react-native'; -import {StyleSheet, View} from 'react-native'; +import React from 'react'; +import {View} from 'react-native'; import type {OptionRowLHNProps} from '@components/LHNOptionsList/types'; -import useStyleUtils from '@hooks/useStyleUtils'; -import useTheme from '@hooks/useTheme'; import useThemeStyles from '@hooks/useThemeStyles'; -import {shouldUseBoldText} from '@libs/OptionsListUtils'; -import CONST from '@src/CONST'; import OptionRow from './OptionRow'; +import useOptionRowChrome from './useOptionRowChrome'; function OptionRowLHN({isOptionFocused = false, onSelectRow = () => {}, optionItem, viewMode = 'default', style, onLayout = () => {}, hasDraftComment, testID}: OptionRowLHNProps) { - const theme = useTheme(); const styles = useThemeStyles(); - const StyleUtils = useStyleUtils(); - const [hovered, setHovered] = useState(false); + const {setHovered, isInFocusMode, sidebarInnerRowStyle, contentContainerStyles, singleAvatarContainerStyle, avatarBackgroundColor, displayNameStyle} = useOptionRowChrome({ + optionItem, + isOptionFocused, + viewMode, + style, + }); - const isInFocusMode = viewMode === CONST.OPTION_MODE.COMPACT; const brickRoadIndicator = optionItem.brickRoadIndicator; - const sidebarInnerRowStyle = StyleSheet.flatten<ViewStyle>( - isInFocusMode - ? [styles.chatLinkRowPressable, styles.flexGrow1, styles.optionItemAvatarNameWrapper, styles.optionRowCompact, styles.justifyContentCenter] - : [styles.chatLinkRowPressable, styles.flexGrow1, styles.optionItemAvatarNameWrapper, styles.optionRow, styles.justifyContentCenter], - ); - const contentContainerStyles = isInFocusMode - ? [styles.flex1, styles.flexRow, styles.overflowHidden, StyleUtils.getCompactContentContainerStyles()] - : [styles.flex1]; - const singleAvatarContainerStyle = [styles.actionAvatar, styles.mr3]; - - const hoveredBackgroundColor = !!styles.sidebarLinkHover && 'backgroundColor' in styles.sidebarLinkHover ? styles.sidebarLinkHover.backgroundColor : theme.sidebar; - const focusedBackgroundColor = styles.sidebarLinkActive.backgroundColor; - const subscriptAvatarBorderColor = isOptionFocused ? focusedBackgroundColor : theme.sidebar; - - let secondaryAvatarBgColor = theme.sidebar; - if (isOptionFocused) { - secondaryAvatarBgColor = focusedBackgroundColor; - } else if (hovered) { - secondaryAvatarBgColor = hoveredBackgroundColor; - } - - const textStyle = isOptionFocused ? styles.sidebarLinkActiveText : styles.sidebarLinkText; - const textUnreadStyle = shouldUseBoldText(optionItem) ? [textStyle, styles.sidebarLinkTextBold] : [textStyle]; - const displayNameStyle = [styles.optionDisplayName, styles.optionDisplayNameCompact, styles.pre, textUnreadStyle, styles.flexShrink0, style]; - return ( <OptionRow.OfflineWrapper pendingAction={optionItem.pendingAction} @@ -62,8 +35,8 @@ function OptionRowLHN({isOptionFocused = false, onSelectRow = () => {}, optionIt <OptionRow.Avatar optionItem={optionItem} isInFocusMode={isInFocusMode} - subscriptAvatarBorderColor={hovered && !isOptionFocused ? hoveredBackgroundColor : subscriptAvatarBorderColor} - secondaryAvatarBackgroundColor={secondaryAvatarBgColor} + subscriptAvatarBorderColor={avatarBackgroundColor} + secondaryAvatarBackgroundColor={avatarBackgroundColor} singleAvatarContainerStyle={singleAvatarContainerStyle} /> <View style={contentContainerStyles}> diff --git a/src/components/LHNOptionsList/OptionRowLHN/useOptionRowChrome.ts b/src/components/LHNOptionsList/OptionRowLHN/useOptionRowChrome.ts new file mode 100644 index 000000000000..c5cd1506d51e --- /dev/null +++ b/src/components/LHNOptionsList/OptionRowLHN/useOptionRowChrome.ts @@ -0,0 +1,75 @@ +import {useState} from 'react'; +import type {ColorValue, StyleProp, TextStyle, ViewStyle} from 'react-native'; +import {StyleSheet} from 'react-native'; +import type {OptionRowLHNProps} from '@components/LHNOptionsList/types'; +import useStyleUtils from '@hooks/useStyleUtils'; +import useTheme from '@hooks/useTheme'; +import useThemeStyles from '@hooks/useThemeStyles'; +import {shouldUseBoldText} from '@libs/OptionsListUtils'; +import type {OptionData} from '@libs/ReportUtils'; +import CONST from '@src/CONST'; + +type UseOptionRowChromeParams = { + optionItem: OptionData; + isOptionFocused: boolean; + viewMode: NonNullable<OptionRowLHNProps['viewMode']>; + style: OptionRowLHNProps['style']; +}; + +/** + * Shared row-level state and style derivations for `OptionRowLHN` and `ArchivedOptionRowLHN`. + * + * Both variants need the same hover state, layout styles, avatar background colour, and + * display-name style. Centralising avoids drift between the two and keeps each variant a + * thin wiring file. + * + * `avatarBackgroundColor` is a single value: the parent previously passed two separate + * colour props to `LHNAvatar` (`subscriptAvatarBorderColor`, `secondaryAvatarBackgroundColor`) + * whose values collapsed to the same result in every state. The hook returns one value and + * variant call sites pass it to both props. + */ +function useOptionRowChrome({optionItem, isOptionFocused, viewMode, style}: UseOptionRowChromeParams) { + const theme = useTheme(); + const styles = useThemeStyles(); + const StyleUtils = useStyleUtils(); + const [hovered, setHovered] = useState(false); + + const isInFocusMode = viewMode === CONST.OPTION_MODE.COMPACT; + + const sidebarInnerRowStyle = StyleSheet.flatten<ViewStyle>( + isInFocusMode + ? [styles.chatLinkRowPressable, styles.flexGrow1, styles.optionItemAvatarNameWrapper, styles.optionRowCompact, styles.justifyContentCenter] + : [styles.chatLinkRowPressable, styles.flexGrow1, styles.optionItemAvatarNameWrapper, styles.optionRow, styles.justifyContentCenter], + ); + const contentContainerStyles: ViewStyle[] = isInFocusMode + ? [styles.flex1, styles.flexRow, styles.overflowHidden, StyleUtils.getCompactContentContainerStyles()] + : [styles.flex1]; + const singleAvatarContainerStyle: ViewStyle[] = [styles.actionAvatar, styles.mr3]; + + const hoveredBackgroundColor = !!styles.sidebarLinkHover && 'backgroundColor' in styles.sidebarLinkHover ? styles.sidebarLinkHover.backgroundColor : theme.sidebar; + const focusedBackgroundColor = styles.sidebarLinkActive.backgroundColor; + + let avatarBackgroundColor: ColorValue = theme.sidebar; + if (isOptionFocused) { + avatarBackgroundColor = focusedBackgroundColor; + } else if (hovered) { + avatarBackgroundColor = hoveredBackgroundColor; + } + + const textStyle = isOptionFocused ? styles.sidebarLinkActiveText : styles.sidebarLinkText; + const textUnreadStyle: StyleProp<TextStyle>[] = shouldUseBoldText(optionItem) ? [textStyle, styles.sidebarLinkTextBold] : [textStyle]; + const displayNameStyle: StyleProp<TextStyle>[] = [styles.optionDisplayName, styles.optionDisplayNameCompact, styles.pre, textUnreadStyle, styles.flexShrink0, style]; + + return { + hovered, + setHovered, + isInFocusMode, + sidebarInnerRowStyle, + contentContainerStyles, + singleAvatarContainerStyle, + avatarBackgroundColor, + displayNameStyle, + }; +} + +export default useOptionRowChrome; From 3407755d264287c7108cc123fa00f902203ff3ba Mon Sep 17 00:00:00 2001 From: bartlomiej obudzinski <bartlomiej.obudzinski@callstack.com> Date: Wed, 13 May 2026 12:13:28 +0200 Subject: [PATCH 04/12] docs: add JSDoc to all OptionRow subcomponent prop types --- .../LHNOptionsList/OptionRowLHN/OptionRow/Avatar.tsx | 9 +++++++++ .../OptionRowLHN/OptionRow/DescriptiveText.tsx | 1 + .../OptionRowLHN/OptionRow/DraftIndicator.tsx | 3 +++ .../LHNOptionsList/OptionRowLHN/OptionRow/ErrorBadge.tsx | 3 +++ .../OptionRowLHN/OptionRow/ProductTrainingTooltip.tsx | 1 + .../LHNOptionsList/OptionRowLHN/OptionRow/Subtitle.tsx | 7 +++++++ .../LHNOptionsList/OptionRowLHN/OptionRow/Title.tsx | 5 +++++ .../LHNOptionsList/OptionRowLHN/useOptionRowChrome.ts | 7 +++++++ 8 files changed, 36 insertions(+) diff --git a/src/components/LHNOptionsList/OptionRowLHN/OptionRow/Avatar.tsx b/src/components/LHNOptionsList/OptionRowLHN/OptionRow/Avatar.tsx index 482f682199be..6188c87d262f 100644 --- a/src/components/LHNOptionsList/OptionRowLHN/OptionRow/Avatar.tsx +++ b/src/components/LHNOptionsList/OptionRowLHN/OptionRow/Avatar.tsx @@ -8,10 +8,19 @@ import type {OptionData} from '@libs/ReportUtils'; import CONST from '@src/CONST'; type AvatarProps = { + /** Option data for the row. Source of avatar icons, subscript flag, tooltip eligibility, and delegate metadata. */ optionItem: OptionData; + + /** Whether the row is in compact mode. Switches the avatar size between `SMALL` and `DEFAULT`. */ isInFocusMode: boolean; + + /** Border colour for the subscript icon. Matches the row background so the subscript blends in. */ subscriptAvatarBorderColor: ColorValue; + + /** Background colour for the secondary avatar in a multi-avatar group. Matches the row background. */ secondaryAvatarBackgroundColor: ColorValue; + + /** Layout style applied when the row renders a single avatar (no group). */ singleAvatarContainerStyle: ViewStyle[]; }; diff --git a/src/components/LHNOptionsList/OptionRowLHN/OptionRow/DescriptiveText.tsx b/src/components/LHNOptionsList/OptionRowLHN/OptionRow/DescriptiveText.tsx index edb0a4c7f8a8..6518ebb876ea 100644 --- a/src/components/LHNOptionsList/OptionRowLHN/OptionRow/DescriptiveText.tsx +++ b/src/components/LHNOptionsList/OptionRowLHN/OptionRow/DescriptiveText.tsx @@ -6,6 +6,7 @@ import FS from '@libs/Fullstory'; import type {OptionData} from '@libs/ReportUtils'; type DescriptiveTextProps = { + /** Option data for the row. Renders `optionItem.descriptiveText` when present; component returns null otherwise. */ optionItem: OptionData; }; diff --git a/src/components/LHNOptionsList/OptionRowLHN/OptionRow/DraftIndicator.tsx b/src/components/LHNOptionsList/OptionRowLHN/OptionRow/DraftIndicator.tsx index aad0f26a3452..f2ac472d3e39 100644 --- a/src/components/LHNOptionsList/OptionRowLHN/OptionRow/DraftIndicator.tsx +++ b/src/components/LHNOptionsList/OptionRowLHN/OptionRow/DraftIndicator.tsx @@ -8,7 +8,10 @@ import useThemeStyles from '@hooks/useThemeStyles'; import variables from '@styles/variables'; type DraftIndicatorProps = { + /** Whether the report has an unsent draft comment. Required for the pencil icon to render. */ hasDraftComment: boolean; + + /** Whether the current user can comment in the report. The icon is hidden in read-only rows even when a draft exists. */ isAllowedToComment: boolean | null | undefined; }; diff --git a/src/components/LHNOptionsList/OptionRowLHN/OptionRow/ErrorBadge.tsx b/src/components/LHNOptionsList/OptionRowLHN/OptionRow/ErrorBadge.tsx index 39f663314053..c5bcd4f645cd 100644 --- a/src/components/LHNOptionsList/OptionRowLHN/OptionRow/ErrorBadge.tsx +++ b/src/components/LHNOptionsList/OptionRowLHN/OptionRow/ErrorBadge.tsx @@ -11,7 +11,10 @@ import type {OptionData} from '@libs/ReportUtils'; import CONST from '@src/CONST'; type ErrorBadgeProps = { + /** Brick road indicator for the row. The badge only renders when this equals ERROR (RBR). */ brickRoadIndicator: OptionData['brickRoadIndicator']; + + /** Action badge key used to derive the badge label (translated locally, debug builds only). */ actionBadge: OptionData['actionBadge']; }; diff --git a/src/components/LHNOptionsList/OptionRowLHN/OptionRow/ProductTrainingTooltip.tsx b/src/components/LHNOptionsList/OptionRowLHN/OptionRow/ProductTrainingTooltip.tsx index cc33a9b92bcf..63484349684d 100644 --- a/src/components/LHNOptionsList/OptionRowLHN/OptionRow/ProductTrainingTooltip.tsx +++ b/src/components/LHNOptionsList/OptionRowLHN/OptionRow/ProductTrainingTooltip.tsx @@ -21,6 +21,7 @@ type ProductTrainingTooltipProps = { }; type ProductTrainingTooltipInnerProps = { + /** Row content the tooltip anchors to. Mounted only when the row is eligible to show a tooltip. */ children: ReactElement; }; diff --git a/src/components/LHNOptionsList/OptionRowLHN/OptionRow/Subtitle.tsx b/src/components/LHNOptionsList/OptionRowLHN/OptionRow/Subtitle.tsx index 8205b0fc04ce..f94d98afd844 100644 --- a/src/components/LHNOptionsList/OptionRowLHN/OptionRow/Subtitle.tsx +++ b/src/components/LHNOptionsList/OptionRowLHN/OptionRow/Subtitle.tsx @@ -13,9 +13,16 @@ import CONST from '@src/CONST'; type OptionMode = ValueOf<typeof CONST.OPTION_MODE>; type SubtitleProps = { + /** Option data for the row. Source of `alternateText` and emoji rendering hints. */ optionItem: OptionData; + + /** Display density mode. Compact rows hide the subtitle entirely. */ viewMode: OptionMode; + + /** Whether the row is the currently focused/active option. Drives the active text style. */ isOptionFocused: boolean; + + /** Optional text style override forwarded from the parent. */ style?: StyleProp<TextStyle>; }; diff --git a/src/components/LHNOptionsList/OptionRowLHN/OptionRow/Title.tsx b/src/components/LHNOptionsList/OptionRowLHN/OptionRow/Title.tsx index e558622dcf18..26c6ec1fcce3 100644 --- a/src/components/LHNOptionsList/OptionRowLHN/OptionRow/Title.tsx +++ b/src/components/LHNOptionsList/OptionRowLHN/OptionRow/Title.tsx @@ -7,8 +7,13 @@ import {isGroupChat, isSystemChat} from '@libs/ReportUtils'; import CONST from '@src/CONST'; type TitleProps = { + /** Option data for the row. Source of `text`, `displayNamesWithTooltips`, chat-type flags, and parse-mode hints. */ optionItem: OptionData; + + /** Composed text style for the display name (focus, unread, bold variants pre-applied by the parent). */ displayNameStyle: StyleProp<TextStyle>; + + /** Numeric testID for the title node (mirrors `reportID`). */ testID: number; }; diff --git a/src/components/LHNOptionsList/OptionRowLHN/useOptionRowChrome.ts b/src/components/LHNOptionsList/OptionRowLHN/useOptionRowChrome.ts index c5cd1506d51e..17539745068c 100644 --- a/src/components/LHNOptionsList/OptionRowLHN/useOptionRowChrome.ts +++ b/src/components/LHNOptionsList/OptionRowLHN/useOptionRowChrome.ts @@ -10,9 +10,16 @@ import type {OptionData} from '@libs/ReportUtils'; import CONST from '@src/CONST'; type UseOptionRowChromeParams = { + /** Option data for the row. Source of `optionItem` flags that drive the bold/unread text style. */ optionItem: OptionData; + + /** Whether the row is the currently focused/active option. Drives the focused colour path. */ isOptionFocused: boolean; + + /** Display density mode. `COMPACT` switches to the compact layout styles. */ viewMode: NonNullable<OptionRowLHNProps['viewMode']>; + + /** Optional outer text style override forwarded by the variant to the display name. */ style: OptionRowLHNProps['style']; }; From 619043f4113502644daff62f2cda5709682060da Mon Sep 17 00:00:00 2001 From: bartlomiej obudzinski <bartlomiej.obudzinski@callstack.com> Date: Wed, 13 May 2026 14:08:36 +0200 Subject: [PATCH 05/12] refactor: drop redundant React.memo on variants (compiler handles it) --- .../LHNOptionsList/OptionRowLHN/ArchivedOptionRowLHN.tsx | 2 +- src/components/LHNOptionsList/OptionRowLHN/OptionRowLHN.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/LHNOptionsList/OptionRowLHN/ArchivedOptionRowLHN.tsx b/src/components/LHNOptionsList/OptionRowLHN/ArchivedOptionRowLHN.tsx index ec4e51dbb7ab..5a4d43c86d12 100644 --- a/src/components/LHNOptionsList/OptionRowLHN/ArchivedOptionRowLHN.tsx +++ b/src/components/LHNOptionsList/OptionRowLHN/ArchivedOptionRowLHN.tsx @@ -67,4 +67,4 @@ function ArchivedOptionRowLHN({isOptionFocused = false, onSelectRow = () => {}, ArchivedOptionRowLHN.displayName = 'ArchivedOptionRowLHN'; -export default React.memo(ArchivedOptionRowLHN); +export default ArchivedOptionRowLHN; diff --git a/src/components/LHNOptionsList/OptionRowLHN/OptionRowLHN.tsx b/src/components/LHNOptionsList/OptionRowLHN/OptionRowLHN.tsx index fccf9f78dbac..a2ba72eda710 100644 --- a/src/components/LHNOptionsList/OptionRowLHN/OptionRowLHN.tsx +++ b/src/components/LHNOptionsList/OptionRowLHN/OptionRowLHN.tsx @@ -85,4 +85,4 @@ function OptionRowLHN({isOptionFocused = false, onSelectRow = () => {}, optionIt OptionRowLHN.displayName = 'OptionRowLHN'; -export default React.memo(OptionRowLHN); +export default OptionRowLHN; From 4ab215ba3dab68e455770cd8fe23b8ea1fe33683 Mon Sep 17 00:00:00 2001 From: bartlomiej obudzinski <bartlomiej.obudzinski@callstack.com> Date: Wed, 13 May 2026 14:15:20 +0200 Subject: [PATCH 06/12] fix: use American spelling in JSDoc and drop redundant type annotations --- .../OptionRowLHN/OptionRow/Avatar.tsx | 4 ++-- .../OptionRowLHN/useOptionRowChrome.ts | 20 +++++++++---------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/components/LHNOptionsList/OptionRowLHN/OptionRow/Avatar.tsx b/src/components/LHNOptionsList/OptionRowLHN/OptionRow/Avatar.tsx index 6188c87d262f..df77c2a18cb4 100644 --- a/src/components/LHNOptionsList/OptionRowLHN/OptionRow/Avatar.tsx +++ b/src/components/LHNOptionsList/OptionRowLHN/OptionRow/Avatar.tsx @@ -14,10 +14,10 @@ type AvatarProps = { /** Whether the row is in compact mode. Switches the avatar size between `SMALL` and `DEFAULT`. */ isInFocusMode: boolean; - /** Border colour for the subscript icon. Matches the row background so the subscript blends in. */ + /** Border color for the subscript icon. Matches the row background so the subscript blends in. */ subscriptAvatarBorderColor: ColorValue; - /** Background colour for the secondary avatar in a multi-avatar group. Matches the row background. */ + /** Background color for the secondary avatar in a multi-avatar group. Matches the row background. */ secondaryAvatarBackgroundColor: ColorValue; /** Layout style applied when the row renders a single avatar (no group). */ diff --git a/src/components/LHNOptionsList/OptionRowLHN/useOptionRowChrome.ts b/src/components/LHNOptionsList/OptionRowLHN/useOptionRowChrome.ts index 17539745068c..fb7e653f00f0 100644 --- a/src/components/LHNOptionsList/OptionRowLHN/useOptionRowChrome.ts +++ b/src/components/LHNOptionsList/OptionRowLHN/useOptionRowChrome.ts @@ -1,5 +1,5 @@ import {useState} from 'react'; -import type {ColorValue, StyleProp, TextStyle, ViewStyle} from 'react-native'; +import type {ColorValue, ViewStyle} from 'react-native'; import {StyleSheet} from 'react-native'; import type {OptionRowLHNProps} from '@components/LHNOptionsList/types'; import useStyleUtils from '@hooks/useStyleUtils'; @@ -13,7 +13,7 @@ type UseOptionRowChromeParams = { /** Option data for the row. Source of `optionItem` flags that drive the bold/unread text style. */ optionItem: OptionData; - /** Whether the row is the currently focused/active option. Drives the focused colour path. */ + /** Whether the row is the currently focused/active option. Drives the focused color path. */ isOptionFocused: boolean; /** Display density mode. `COMPACT` switches to the compact layout styles. */ @@ -26,12 +26,12 @@ type UseOptionRowChromeParams = { /** * Shared row-level state and style derivations for `OptionRowLHN` and `ArchivedOptionRowLHN`. * - * Both variants need the same hover state, layout styles, avatar background colour, and - * display-name style. Centralising avoids drift between the two and keeps each variant a + * Both variants need the same hover state, layout styles, avatar background color, and + * display-name style. Centralizing avoids drift between the two and keeps each variant a * thin wiring file. * * `avatarBackgroundColor` is a single value: the parent previously passed two separate - * colour props to `LHNAvatar` (`subscriptAvatarBorderColor`, `secondaryAvatarBackgroundColor`) + * color props to `LHNAvatar` (`subscriptAvatarBorderColor`, `secondaryAvatarBackgroundColor`) * whose values collapsed to the same result in every state. The hook returns one value and * variant call sites pass it to both props. */ @@ -48,10 +48,8 @@ function useOptionRowChrome({optionItem, isOptionFocused, viewMode, style}: UseO ? [styles.chatLinkRowPressable, styles.flexGrow1, styles.optionItemAvatarNameWrapper, styles.optionRowCompact, styles.justifyContentCenter] : [styles.chatLinkRowPressable, styles.flexGrow1, styles.optionItemAvatarNameWrapper, styles.optionRow, styles.justifyContentCenter], ); - const contentContainerStyles: ViewStyle[] = isInFocusMode - ? [styles.flex1, styles.flexRow, styles.overflowHidden, StyleUtils.getCompactContentContainerStyles()] - : [styles.flex1]; - const singleAvatarContainerStyle: ViewStyle[] = [styles.actionAvatar, styles.mr3]; + const contentContainerStyles = isInFocusMode ? [styles.flex1, styles.flexRow, styles.overflowHidden, StyleUtils.getCompactContentContainerStyles()] : [styles.flex1]; + const singleAvatarContainerStyle = [styles.actionAvatar, styles.mr3]; const hoveredBackgroundColor = !!styles.sidebarLinkHover && 'backgroundColor' in styles.sidebarLinkHover ? styles.sidebarLinkHover.backgroundColor : theme.sidebar; const focusedBackgroundColor = styles.sidebarLinkActive.backgroundColor; @@ -64,8 +62,8 @@ function useOptionRowChrome({optionItem, isOptionFocused, viewMode, style}: UseO } const textStyle = isOptionFocused ? styles.sidebarLinkActiveText : styles.sidebarLinkText; - const textUnreadStyle: StyleProp<TextStyle>[] = shouldUseBoldText(optionItem) ? [textStyle, styles.sidebarLinkTextBold] : [textStyle]; - const displayNameStyle: StyleProp<TextStyle>[] = [styles.optionDisplayName, styles.optionDisplayNameCompact, styles.pre, textUnreadStyle, styles.flexShrink0, style]; + const textUnreadStyle = shouldUseBoldText(optionItem) ? [textStyle, styles.sidebarLinkTextBold] : [textStyle]; + const displayNameStyle = [styles.optionDisplayName, styles.optionDisplayNameCompact, styles.pre, textUnreadStyle, styles.flexShrink0, style]; return { hovered, From 2884c85bb31d5a6b93e6c0deaaf9e0973a5b35c9 Mon Sep 17 00:00:00 2001 From: bartlomiej obudzinski <bartlomiej.obudzinski@callstack.com> Date: Thu, 14 May 2026 08:49:11 +0200 Subject: [PATCH 07/12] refactor: push isInFocusMode/singleAvatarContainerStyle/displayNameStyle derivation into Avatar and Title --- .../OptionRowLHN/ArchivedOptionRowLHN.tsx | 10 +++--- .../OptionRowLHN/OptionRow/Avatar.tsx | 24 ++++++++------ .../OptionRowLHN/OptionRow/Title.tsx | 18 ++++++++--- .../OptionRowLHN/OptionRowLHN.tsx | 10 +++--- .../OptionRowLHN/useOptionRowChrome.ts | 32 ++++--------------- 5 files changed, 43 insertions(+), 51 deletions(-) diff --git a/src/components/LHNOptionsList/OptionRowLHN/ArchivedOptionRowLHN.tsx b/src/components/LHNOptionsList/OptionRowLHN/ArchivedOptionRowLHN.tsx index 5a4d43c86d12..0e1734dbe0b0 100644 --- a/src/components/LHNOptionsList/OptionRowLHN/ArchivedOptionRowLHN.tsx +++ b/src/components/LHNOptionsList/OptionRowLHN/ArchivedOptionRowLHN.tsx @@ -12,11 +12,9 @@ import useOptionRowChrome from './useOptionRowChrome'; */ function ArchivedOptionRowLHN({isOptionFocused = false, onSelectRow = () => {}, optionItem, viewMode = 'default', style, onLayout = () => {}, testID}: OptionRowLHNProps) { const styles = useThemeStyles(); - const {setHovered, isInFocusMode, sidebarInnerRowStyle, contentContainerStyles, singleAvatarContainerStyle, avatarBackgroundColor, displayNameStyle} = useOptionRowChrome({ - optionItem, + const {setHovered, sidebarInnerRowStyle, contentContainerStyles, avatarBackgroundColor} = useOptionRowChrome({ isOptionFocused, viewMode, - style, }); return ( @@ -36,16 +34,16 @@ function ArchivedOptionRowLHN({isOptionFocused = false, onSelectRow = () => {}, <View style={[styles.flexRow, styles.alignItemsCenter]}> <OptionRow.Avatar optionItem={optionItem} - isInFocusMode={isInFocusMode} + viewMode={viewMode} subscriptAvatarBorderColor={avatarBackgroundColor} secondaryAvatarBackgroundColor={avatarBackgroundColor} - singleAvatarContainerStyle={singleAvatarContainerStyle} /> <View style={contentContainerStyles}> <View style={[styles.flexRow, styles.alignItemsCenter, styles.mw100, styles.overflowHidden]}> <OptionRow.Title optionItem={optionItem} - displayNameStyle={displayNameStyle} + isOptionFocused={isOptionFocused} + style={style} testID={testID} /> <OptionRow.Status optionItem={optionItem} /> diff --git a/src/components/LHNOptionsList/OptionRowLHN/OptionRow/Avatar.tsx b/src/components/LHNOptionsList/OptionRowLHN/OptionRow/Avatar.tsx index df77c2a18cb4..5accb8d763c5 100644 --- a/src/components/LHNOptionsList/OptionRowLHN/OptionRow/Avatar.tsx +++ b/src/components/LHNOptionsList/OptionRowLHN/OptionRow/Avatar.tsx @@ -1,32 +1,37 @@ import React from 'react'; -import type {ColorValue, ViewStyle} from 'react-native'; +import type {ColorValue} from 'react-native'; +import type {ValueOf} from 'type-fest'; import LHNAvatar from '@components/LHNOptionsList/LHNAvatar'; import {usePersonalDetails} from '@components/OnyxListItemProvider'; +import useThemeStyles from '@hooks/useThemeStyles'; import {shouldOptionShowTooltip} from '@libs/OptionsListUtils'; import {getDelegateAccountIDFromReportAction} from '@libs/ReportActionsUtils'; import type {OptionData} from '@libs/ReportUtils'; import CONST from '@src/CONST'; +type OptionMode = ValueOf<typeof CONST.OPTION_MODE>; + type AvatarProps = { /** Option data for the row. Source of avatar icons, subscript flag, tooltip eligibility, and delegate metadata. */ optionItem: OptionData; - /** Whether the row is in compact mode. Switches the avatar size between `SMALL` and `DEFAULT`. */ - isInFocusMode: boolean; + /** Display density mode. `COMPACT` switches the avatar size to `SMALL`. */ + viewMode: OptionMode; /** Border color for the subscript icon. Matches the row background so the subscript blends in. */ subscriptAvatarBorderColor: ColorValue; /** Background color for the secondary avatar in a multi-avatar group. Matches the row background. */ secondaryAvatarBackgroundColor: ColorValue; - - /** Layout style applied when the row renders a single avatar (no group). */ - singleAvatarContainerStyle: ViewStyle[]; }; -function AvatarInner({optionItem, isInFocusMode, subscriptAvatarBorderColor, secondaryAvatarBackgroundColor, singleAvatarContainerStyle}: AvatarProps) { +function AvatarInner({optionItem, viewMode, subscriptAvatarBorderColor, secondaryAvatarBackgroundColor}: AvatarProps) { + const styles = useThemeStyles(); const personalDetails = usePersonalDetails(); + const isInFocusMode = viewMode === CONST.OPTION_MODE.COMPACT; + const singleAvatarContainerStyle = [styles.actionAvatar, styles.mr3]; + const delegateAccountID = getDelegateAccountIDFromReportAction(optionItem?.parentReportAction); // Match the header's delegate avatar logic: when a delegate exists on the @@ -75,7 +80,7 @@ function AvatarInner({optionItem, isInFocusMode, subscriptAvatarBorderColor, sec AvatarInner.displayName = 'OptionRow.AvatarInner'; -function Avatar({optionItem, isInFocusMode, subscriptAvatarBorderColor, secondaryAvatarBackgroundColor, singleAvatarContainerStyle}: AvatarProps) { +function Avatar({optionItem, viewMode, subscriptAvatarBorderColor, secondaryAvatarBackgroundColor}: AvatarProps) { // Bail out before subscribing to personal details when the row has no avatar to render. if (!optionItem.icons?.length || !optionItem.icons.at(0)) { return null; @@ -83,10 +88,9 @@ function Avatar({optionItem, isInFocusMode, subscriptAvatarBorderColor, secondar return ( <AvatarInner optionItem={optionItem} - isInFocusMode={isInFocusMode} + viewMode={viewMode} subscriptAvatarBorderColor={subscriptAvatarBorderColor} secondaryAvatarBackgroundColor={secondaryAvatarBackgroundColor} - singleAvatarContainerStyle={singleAvatarContainerStyle} /> ); } diff --git a/src/components/LHNOptionsList/OptionRowLHN/OptionRow/Title.tsx b/src/components/LHNOptionsList/OptionRowLHN/OptionRow/Title.tsx index 26c6ec1fcce3..a657b0358632 100644 --- a/src/components/LHNOptionsList/OptionRowLHN/OptionRow/Title.tsx +++ b/src/components/LHNOptionsList/OptionRowLHN/OptionRow/Title.tsx @@ -2,23 +2,33 @@ import React from 'react'; import type {StyleProp, TextStyle} from 'react-native'; import DisplayNames from '@components/DisplayNames'; import useLocalize from '@hooks/useLocalize'; +import useThemeStyles from '@hooks/useThemeStyles'; +import {shouldUseBoldText} from '@libs/OptionsListUtils'; import type {OptionData} from '@libs/ReportUtils'; import {isGroupChat, isSystemChat} from '@libs/ReportUtils'; import CONST from '@src/CONST'; type TitleProps = { - /** Option data for the row. Source of `text`, `displayNamesWithTooltips`, chat-type flags, and parse-mode hints. */ + /** Option data for the row. Source of `text`, `displayNamesWithTooltips`, chat-type flags, parse-mode hints, and unread/bold derivation. */ optionItem: OptionData; - /** Composed text style for the display name (focus, unread, bold variants pre-applied by the parent). */ - displayNameStyle: StyleProp<TextStyle>; + /** Whether the row is the currently focused/active option. Drives the active text style. */ + isOptionFocused: boolean; + + /** Optional outer text style override forwarded by the variant. */ + style?: StyleProp<TextStyle>; /** Numeric testID for the title node (mirrors `reportID`). */ testID: number; }; -function Title({optionItem, displayNameStyle, testID}: TitleProps) { +function Title({optionItem, isOptionFocused, style, testID}: TitleProps) { const {translate} = useLocalize(); + const styles = useThemeStyles(); + + const textStyle = isOptionFocused ? styles.sidebarLinkActiveText : styles.sidebarLinkText; + const textUnreadStyle = shouldUseBoldText(optionItem) ? [textStyle, styles.sidebarLinkTextBold] : [textStyle]; + const displayNameStyle = [styles.optionDisplayName, styles.optionDisplayNameCompact, styles.pre, textUnreadStyle, styles.flexShrink0, style]; const shouldParseFullTitle = optionItem?.parentReportAction?.actionName !== CONST.REPORT.ACTIONS.TYPE.ADD_COMMENT && !isGroupChat(optionItem); const shouldUseFullTitle = diff --git a/src/components/LHNOptionsList/OptionRowLHN/OptionRowLHN.tsx b/src/components/LHNOptionsList/OptionRowLHN/OptionRowLHN.tsx index a2ba72eda710..725109c3b8be 100644 --- a/src/components/LHNOptionsList/OptionRowLHN/OptionRowLHN.tsx +++ b/src/components/LHNOptionsList/OptionRowLHN/OptionRowLHN.tsx @@ -7,11 +7,9 @@ import useOptionRowChrome from './useOptionRowChrome'; function OptionRowLHN({isOptionFocused = false, onSelectRow = () => {}, optionItem, viewMode = 'default', style, onLayout = () => {}, hasDraftComment, testID}: OptionRowLHNProps) { const styles = useThemeStyles(); - const {setHovered, isInFocusMode, sidebarInnerRowStyle, contentContainerStyles, singleAvatarContainerStyle, avatarBackgroundColor, displayNameStyle} = useOptionRowChrome({ - optionItem, + const {setHovered, sidebarInnerRowStyle, contentContainerStyles, avatarBackgroundColor} = useOptionRowChrome({ isOptionFocused, viewMode, - style, }); const brickRoadIndicator = optionItem.brickRoadIndicator; @@ -34,16 +32,16 @@ function OptionRowLHN({isOptionFocused = false, onSelectRow = () => {}, optionIt <View style={[styles.flexRow, styles.alignItemsCenter]}> <OptionRow.Avatar optionItem={optionItem} - isInFocusMode={isInFocusMode} + viewMode={viewMode} subscriptAvatarBorderColor={avatarBackgroundColor} secondaryAvatarBackgroundColor={avatarBackgroundColor} - singleAvatarContainerStyle={singleAvatarContainerStyle} /> <View style={contentContainerStyles}> <View style={[styles.flexRow, styles.alignItemsCenter, styles.mw100, styles.overflowHidden]}> <OptionRow.Title optionItem={optionItem} - displayNameStyle={displayNameStyle} + isOptionFocused={isOptionFocused} + style={style} testID={testID} /> <OptionRow.OnboardingBadge optionItem={optionItem} /> diff --git a/src/components/LHNOptionsList/OptionRowLHN/useOptionRowChrome.ts b/src/components/LHNOptionsList/OptionRowLHN/useOptionRowChrome.ts index fb7e653f00f0..ee12ce11643f 100644 --- a/src/components/LHNOptionsList/OptionRowLHN/useOptionRowChrome.ts +++ b/src/components/LHNOptionsList/OptionRowLHN/useOptionRowChrome.ts @@ -5,37 +5,27 @@ import type {OptionRowLHNProps} from '@components/LHNOptionsList/types'; import useStyleUtils from '@hooks/useStyleUtils'; import useTheme from '@hooks/useTheme'; import useThemeStyles from '@hooks/useThemeStyles'; -import {shouldUseBoldText} from '@libs/OptionsListUtils'; -import type {OptionData} from '@libs/ReportUtils'; import CONST from '@src/CONST'; type UseOptionRowChromeParams = { - /** Option data for the row. Source of `optionItem` flags that drive the bold/unread text style. */ - optionItem: OptionData; - /** Whether the row is the currently focused/active option. Drives the focused color path. */ isOptionFocused: boolean; /** Display density mode. `COMPACT` switches to the compact layout styles. */ viewMode: NonNullable<OptionRowLHNProps['viewMode']>; - - /** Optional outer text style override forwarded by the variant to the display name. */ - style: OptionRowLHNProps['style']; }; /** - * Shared row-level state and style derivations for `OptionRowLHN` and `ArchivedOptionRowLHN`. + * Shared row-level state and layout-skeleton styles for `OptionRowLHN` and `ArchivedOptionRowLHN`. * - * Both variants need the same hover state, layout styles, avatar background color, and - * display-name style. Centralizing avoids drift between the two and keeps each variant a - * thin wiring file. + * Owns the cross-variant pieces that cannot be pushed into leaves: the hover `useState`, + * the wrapper `<View>` styles (`sidebarInnerRowStyle`, `contentContainerStyles`) that wrap + * multiple leaves, and the single `avatarBackgroundColor` derived from hover and focus state. * - * `avatarBackgroundColor` is a single value: the parent previously passed two separate - * color props to `LHNAvatar` (`subscriptAvatarBorderColor`, `secondaryAvatarBackgroundColor`) - * whose values collapsed to the same result in every state. The hook returns one value and - * variant call sites pass it to both props. + * Per-leaf derivations (`isInFocusMode`, `singleAvatarContainerStyle`, `displayNameStyle`) live + * inside their consuming leaf component (`Avatar`, `Title`) and are not returned here. */ -function useOptionRowChrome({optionItem, isOptionFocused, viewMode, style}: UseOptionRowChromeParams) { +function useOptionRowChrome({isOptionFocused, viewMode}: UseOptionRowChromeParams) { const theme = useTheme(); const styles = useThemeStyles(); const StyleUtils = useStyleUtils(); @@ -49,7 +39,6 @@ function useOptionRowChrome({optionItem, isOptionFocused, viewMode, style}: UseO : [styles.chatLinkRowPressable, styles.flexGrow1, styles.optionItemAvatarNameWrapper, styles.optionRow, styles.justifyContentCenter], ); const contentContainerStyles = isInFocusMode ? [styles.flex1, styles.flexRow, styles.overflowHidden, StyleUtils.getCompactContentContainerStyles()] : [styles.flex1]; - const singleAvatarContainerStyle = [styles.actionAvatar, styles.mr3]; const hoveredBackgroundColor = !!styles.sidebarLinkHover && 'backgroundColor' in styles.sidebarLinkHover ? styles.sidebarLinkHover.backgroundColor : theme.sidebar; const focusedBackgroundColor = styles.sidebarLinkActive.backgroundColor; @@ -61,19 +50,12 @@ function useOptionRowChrome({optionItem, isOptionFocused, viewMode, style}: UseO avatarBackgroundColor = hoveredBackgroundColor; } - const textStyle = isOptionFocused ? styles.sidebarLinkActiveText : styles.sidebarLinkText; - const textUnreadStyle = shouldUseBoldText(optionItem) ? [textStyle, styles.sidebarLinkTextBold] : [textStyle]; - const displayNameStyle = [styles.optionDisplayName, styles.optionDisplayNameCompact, styles.pre, textUnreadStyle, styles.flexShrink0, style]; - return { hovered, setHovered, - isInFocusMode, sidebarInnerRowStyle, contentContainerStyles, - singleAvatarContainerStyle, avatarBackgroundColor, - displayNameStyle, }; } From ee45ca53f80f01382ef46e8a9af73de41c18b2f0 Mon Sep 17 00:00:00 2001 From: bartlomiej obudzinski <bartlomiej.obudzinski@callstack.com> Date: Thu, 14 May 2026 10:48:14 +0200 Subject: [PATCH 08/12] fix: preserve pin indicator on pinned archived rows --- .../OptionRowLHN/ArchivedOptionRowLHN.tsx | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/components/LHNOptionsList/OptionRowLHN/ArchivedOptionRowLHN.tsx b/src/components/LHNOptionsList/OptionRowLHN/ArchivedOptionRowLHN.tsx index 0e1734dbe0b0..5250c103b356 100644 --- a/src/components/LHNOptionsList/OptionRowLHN/ArchivedOptionRowLHN.tsx +++ b/src/components/LHNOptionsList/OptionRowLHN/ArchivedOptionRowLHN.tsx @@ -7,8 +7,9 @@ import useOptionRowChrome from './useOptionRowChrome'; /** * Sibling variant of `OptionRowLHN` used for archived reports. Strips the product training - * tooltip layer, all brick-road badges (Error/Info/Onboarding), and the trailing indicator - * row (Draft/Pin) because none of them apply to a historical, write-locked row. + * tooltip layer, all brick-road badges (Error/Info/Onboarding), and the draft indicator + * (write-locked rows cannot have an actionable draft). The pin indicator is kept because + * pinned archived chats stay in the pinned section of the LHN and must show the pin icon. */ function ArchivedOptionRowLHN({isOptionFocused = false, onSelectRow = () => {}, optionItem, viewMode = 'default', style, onLayout = () => {}, testID}: OptionRowLHNProps) { const styles = useThemeStyles(); @@ -58,6 +59,12 @@ function ArchivedOptionRowLHN({isOptionFocused = false, onSelectRow = () => {}, <OptionRow.DescriptiveText optionItem={optionItem} /> </View> </View> + <View style={[styles.flexRow, styles.alignItemsCenter]}> + <OptionRow.PinIndicator + isPinned={optionItem.isPinned} + brickRoadIndicator={optionItem.brickRoadIndicator} + /> + </View> </OptionRow.Pressable> </OptionRow.OfflineWrapper> ); From 815663442277e0145662fbdbe96487938c3e9e29 Mon Sep 17 00:00:00 2001 From: bartlomiej obudzinski <bartlomiej.obudzinski@callstack.com> Date: Thu, 14 May 2026 11:47:11 +0200 Subject: [PATCH 09/12] refactor: remove ArchivedOptionRowLHN variant to keep PR scope strict decomposition --- .../OptionRowLHN/ArchivedOptionRowLHN.tsx | 75 ------------------- .../OptionRowLHN/OptionRowLHNData.tsx | 5 +- .../OptionRowLHN/useOptionRowChrome.ts | 12 +-- 3 files changed, 7 insertions(+), 85 deletions(-) delete mode 100644 src/components/LHNOptionsList/OptionRowLHN/ArchivedOptionRowLHN.tsx diff --git a/src/components/LHNOptionsList/OptionRowLHN/ArchivedOptionRowLHN.tsx b/src/components/LHNOptionsList/OptionRowLHN/ArchivedOptionRowLHN.tsx deleted file mode 100644 index 5250c103b356..000000000000 --- a/src/components/LHNOptionsList/OptionRowLHN/ArchivedOptionRowLHN.tsx +++ /dev/null @@ -1,75 +0,0 @@ -import React from 'react'; -import {View} from 'react-native'; -import type {OptionRowLHNProps} from '@components/LHNOptionsList/types'; -import useThemeStyles from '@hooks/useThemeStyles'; -import OptionRow from './OptionRow'; -import useOptionRowChrome from './useOptionRowChrome'; - -/** - * Sibling variant of `OptionRowLHN` used for archived reports. Strips the product training - * tooltip layer, all brick-road badges (Error/Info/Onboarding), and the draft indicator - * (write-locked rows cannot have an actionable draft). The pin indicator is kept because - * pinned archived chats stay in the pinned section of the LHN and must show the pin icon. - */ -function ArchivedOptionRowLHN({isOptionFocused = false, onSelectRow = () => {}, optionItem, viewMode = 'default', style, onLayout = () => {}, testID}: OptionRowLHNProps) { - const styles = useThemeStyles(); - const {setHovered, sidebarInnerRowStyle, contentContainerStyles, avatarBackgroundColor} = useOptionRowChrome({ - isOptionFocused, - viewMode, - }); - - return ( - <OptionRow.OfflineWrapper - pendingAction={optionItem.pendingAction} - errors={optionItem.allReportErrors} - > - <OptionRow.Pressable - optionItem={optionItem} - isOptionFocused={isOptionFocused} - onSelectRow={onSelectRow} - onLayout={onLayout} - onHoverIn={() => setHovered(true)} - onHoverOut={() => setHovered(false)} - > - <View style={sidebarInnerRowStyle}> - <View style={[styles.flexRow, styles.alignItemsCenter]}> - <OptionRow.Avatar - optionItem={optionItem} - viewMode={viewMode} - subscriptAvatarBorderColor={avatarBackgroundColor} - secondaryAvatarBackgroundColor={avatarBackgroundColor} - /> - <View style={contentContainerStyles}> - <View style={[styles.flexRow, styles.alignItemsCenter, styles.mw100, styles.overflowHidden]}> - <OptionRow.Title - optionItem={optionItem} - isOptionFocused={isOptionFocused} - style={style} - testID={testID} - /> - <OptionRow.Status optionItem={optionItem} /> - </View> - <OptionRow.Subtitle - optionItem={optionItem} - viewMode={viewMode} - isOptionFocused={isOptionFocused} - style={style} - /> - </View> - <OptionRow.DescriptiveText optionItem={optionItem} /> - </View> - </View> - <View style={[styles.flexRow, styles.alignItemsCenter]}> - <OptionRow.PinIndicator - isPinned={optionItem.isPinned} - brickRoadIndicator={optionItem.brickRoadIndicator} - /> - </View> - </OptionRow.Pressable> - </OptionRow.OfflineWrapper> - ); -} - -ArchivedOptionRowLHN.displayName = 'ArchivedOptionRowLHN'; - -export default ArchivedOptionRowLHN; diff --git a/src/components/LHNOptionsList/OptionRowLHN/OptionRowLHNData.tsx b/src/components/LHNOptionsList/OptionRowLHN/OptionRowLHNData.tsx index 3420ecb9bb8d..f88e571feec4 100644 --- a/src/components/LHNOptionsList/OptionRowLHN/OptionRowLHNData.tsx +++ b/src/components/LHNOptionsList/OptionRowLHN/OptionRowLHNData.tsx @@ -20,7 +20,6 @@ import ONYXKEYS from '@src/ONYXKEYS'; import type {ReportActions as ReportActionsType} from '@src/types/onyx'; import type {VisibleReportActionsDerivedValue} from '@src/types/onyx/DerivedValues'; import type {Icon} from '@src/types/onyx/OnyxCommon'; -import ArchivedOptionRowLHN from './ArchivedOptionRowLHN'; import OptionRowLHN from './OptionRowLHN'; /* @@ -191,10 +190,8 @@ function OptionRowLHNData({ return isReportFocused ? null : <View style={placeholderRowStyle} />; } - const Row = isReportArchived ? ArchivedOptionRowLHN : OptionRowLHN; - return ( - <Row + <OptionRowLHN // eslint-disable-next-line react/jsx-props-no-spreading {...propsToForward} viewMode={viewMode} diff --git a/src/components/LHNOptionsList/OptionRowLHN/useOptionRowChrome.ts b/src/components/LHNOptionsList/OptionRowLHN/useOptionRowChrome.ts index ee12ce11643f..e39170c798a4 100644 --- a/src/components/LHNOptionsList/OptionRowLHN/useOptionRowChrome.ts +++ b/src/components/LHNOptionsList/OptionRowLHN/useOptionRowChrome.ts @@ -16,14 +16,14 @@ type UseOptionRowChromeParams = { }; /** - * Shared row-level state and layout-skeleton styles for `OptionRowLHN` and `ArchivedOptionRowLHN`. + * Row-level state and layout-skeleton styles for `OptionRowLHN`. * - * Owns the cross-variant pieces that cannot be pushed into leaves: the hover `useState`, - * the wrapper `<View>` styles (`sidebarInnerRowStyle`, `contentContainerStyles`) that wrap - * multiple leaves, and the single `avatarBackgroundColor` derived from hover and focus state. + * Owns the pieces that cannot be pushed into leaves: the hover `useState`, the wrapper + * `<View>` styles (`sidebarInnerRowStyle`, `contentContainerStyles`) that wrap multiple + * leaves, and the single `avatarBackgroundColor` derived from hover and focus state. * - * Per-leaf derivations (`isInFocusMode`, `singleAvatarContainerStyle`, `displayNameStyle`) live - * inside their consuming leaf component (`Avatar`, `Title`) and are not returned here. + * Per-leaf derivations (`isInFocusMode`, `singleAvatarContainerStyle`, `displayNameStyle`) + * live inside their consuming leaf component (`Avatar`, `Title`) and are not returned here. */ function useOptionRowChrome({isOptionFocused, viewMode}: UseOptionRowChromeParams) { const theme = useTheme(); From b57ada271598a38fa58630a5fd87872d3c95ab0f Mon Sep 17 00:00:00 2001 From: bartlomiej obudzinski <bartlomiej.obudzinski@callstack.com> Date: Thu, 14 May 2026 12:00:16 +0200 Subject: [PATCH 10/12] refactor: drop unused style prop chain and collapse Avatar color props --- .../OptionRowLHN/OptionRow/Avatar.tsx | 18 +++++++----------- .../OptionRowLHN/OptionRow/Subtitle.tsx | 10 +++------- .../OptionRowLHN/OptionRow/Title.tsx | 8 ++------ .../OptionRowLHN/OptionRowLHN.tsx | 7 ++----- src/components/LHNOptionsList/types.ts | 5 +---- 5 files changed, 15 insertions(+), 33 deletions(-) diff --git a/src/components/LHNOptionsList/OptionRowLHN/OptionRow/Avatar.tsx b/src/components/LHNOptionsList/OptionRowLHN/OptionRow/Avatar.tsx index 5accb8d763c5..a92e3c869e7c 100644 --- a/src/components/LHNOptionsList/OptionRowLHN/OptionRow/Avatar.tsx +++ b/src/components/LHNOptionsList/OptionRowLHN/OptionRow/Avatar.tsx @@ -18,14 +18,11 @@ type AvatarProps = { /** Display density mode. `COMPACT` switches the avatar size to `SMALL`. */ viewMode: OptionMode; - /** Border color for the subscript icon. Matches the row background so the subscript blends in. */ - subscriptAvatarBorderColor: ColorValue; - - /** Background color for the secondary avatar in a multi-avatar group. Matches the row background. */ - secondaryAvatarBackgroundColor: ColorValue; + /** Background color used for both the subscript icon border and the secondary avatar background. Matches the row background so the chrome blends in. */ + avatarBackgroundColor: ColorValue; }; -function AvatarInner({optionItem, viewMode, subscriptAvatarBorderColor, secondaryAvatarBackgroundColor}: AvatarProps) { +function AvatarInner({optionItem, viewMode, avatarBackgroundColor}: AvatarProps) { const styles = useThemeStyles(); const personalDetails = usePersonalDetails(); @@ -67,9 +64,9 @@ function AvatarInner({optionItem, viewMode, subscriptAvatarBorderColor, secondar icons={icons} shouldShowSubscript={!!optionItem.shouldShowSubscript} size={isInFocusMode ? CONST.AVATAR_SIZE.SMALL : CONST.AVATAR_SIZE.DEFAULT} - subscriptAvatarBorderColor={subscriptAvatarBorderColor} + subscriptAvatarBorderColor={avatarBackgroundColor} useMidSubscriptSize={isInFocusMode} - secondaryAvatarBackgroundColor={secondaryAvatarBackgroundColor} + secondaryAvatarBackgroundColor={avatarBackgroundColor} singleAvatarContainerStyle={singleAvatarContainerStyle} shouldShowTooltip={shouldOptionShowTooltip(optionItem)} delegateAccountID={skipDelegate ? undefined : delegateAccountID} @@ -80,7 +77,7 @@ function AvatarInner({optionItem, viewMode, subscriptAvatarBorderColor, secondar AvatarInner.displayName = 'OptionRow.AvatarInner'; -function Avatar({optionItem, viewMode, subscriptAvatarBorderColor, secondaryAvatarBackgroundColor}: AvatarProps) { +function Avatar({optionItem, viewMode, avatarBackgroundColor}: AvatarProps) { // Bail out before subscribing to personal details when the row has no avatar to render. if (!optionItem.icons?.length || !optionItem.icons.at(0)) { return null; @@ -89,8 +86,7 @@ function Avatar({optionItem, viewMode, subscriptAvatarBorderColor, secondaryAvat <AvatarInner optionItem={optionItem} viewMode={viewMode} - subscriptAvatarBorderColor={subscriptAvatarBorderColor} - secondaryAvatarBackgroundColor={secondaryAvatarBackgroundColor} + avatarBackgroundColor={avatarBackgroundColor} /> ); } diff --git a/src/components/LHNOptionsList/OptionRowLHN/OptionRow/Subtitle.tsx b/src/components/LHNOptionsList/OptionRowLHN/OptionRow/Subtitle.tsx index f94d98afd844..eac3c6a73f78 100644 --- a/src/components/LHNOptionsList/OptionRowLHN/OptionRow/Subtitle.tsx +++ b/src/components/LHNOptionsList/OptionRowLHN/OptionRow/Subtitle.tsx @@ -1,5 +1,4 @@ import React from 'react'; -import type {StyleProp, TextStyle} from 'react-native'; import type {ValueOf} from 'type-fest'; import Text from '@components/Text'; import useLocalize from '@hooks/useLocalize'; @@ -21,12 +20,9 @@ type SubtitleProps = { /** Whether the row is the currently focused/active option. Drives the active text style. */ isOptionFocused: boolean; - - /** Optional text style override forwarded from the parent. */ - style?: StyleProp<TextStyle>; }; -function Subtitle({optionItem, viewMode, isOptionFocused, style}: SubtitleProps) { +function Subtitle({optionItem, viewMode, isOptionFocused}: SubtitleProps) { const {translate} = useLocalize(); const styles = useThemeStyles(); @@ -38,8 +34,8 @@ function Subtitle({optionItem, viewMode, isOptionFocused, style}: SubtitleProps) const isInFocusMode = viewMode === CONST.OPTION_MODE.COMPACT; const textStyle = isOptionFocused ? styles.sidebarLinkActiveText : styles.sidebarLinkText; const alternateTextStyle = isInFocusMode - ? [textStyle, styles.textLabelSupporting, styles.optionAlternateTextCompact, styles.ml2, style] - : [textStyle, styles.optionAlternateText, styles.textLabelSupporting, style]; + ? [textStyle, styles.textLabelSupporting, styles.optionAlternateTextCompact, styles.ml2] + : [textStyle, styles.optionAlternateText, styles.textLabelSupporting]; const alternateTextFSClass = FS.getChatFSClass(optionItem); const containsCustomEmojiWithText = containsCustomEmojiUtils(alternateText) && !containsOnlyCustomEmoji(alternateText); diff --git a/src/components/LHNOptionsList/OptionRowLHN/OptionRow/Title.tsx b/src/components/LHNOptionsList/OptionRowLHN/OptionRow/Title.tsx index a657b0358632..3b28fa2bf8b8 100644 --- a/src/components/LHNOptionsList/OptionRowLHN/OptionRow/Title.tsx +++ b/src/components/LHNOptionsList/OptionRowLHN/OptionRow/Title.tsx @@ -1,5 +1,4 @@ import React from 'react'; -import type {StyleProp, TextStyle} from 'react-native'; import DisplayNames from '@components/DisplayNames'; import useLocalize from '@hooks/useLocalize'; import useThemeStyles from '@hooks/useThemeStyles'; @@ -15,20 +14,17 @@ type TitleProps = { /** Whether the row is the currently focused/active option. Drives the active text style. */ isOptionFocused: boolean; - /** Optional outer text style override forwarded by the variant. */ - style?: StyleProp<TextStyle>; - /** Numeric testID for the title node (mirrors `reportID`). */ testID: number; }; -function Title({optionItem, isOptionFocused, style, testID}: TitleProps) { +function Title({optionItem, isOptionFocused, testID}: TitleProps) { const {translate} = useLocalize(); const styles = useThemeStyles(); const textStyle = isOptionFocused ? styles.sidebarLinkActiveText : styles.sidebarLinkText; const textUnreadStyle = shouldUseBoldText(optionItem) ? [textStyle, styles.sidebarLinkTextBold] : [textStyle]; - const displayNameStyle = [styles.optionDisplayName, styles.optionDisplayNameCompact, styles.pre, textUnreadStyle, styles.flexShrink0, style]; + const displayNameStyle = [styles.optionDisplayName, styles.optionDisplayNameCompact, styles.pre, textUnreadStyle, styles.flexShrink0]; const shouldParseFullTitle = optionItem?.parentReportAction?.actionName !== CONST.REPORT.ACTIONS.TYPE.ADD_COMMENT && !isGroupChat(optionItem); const shouldUseFullTitle = diff --git a/src/components/LHNOptionsList/OptionRowLHN/OptionRowLHN.tsx b/src/components/LHNOptionsList/OptionRowLHN/OptionRowLHN.tsx index 725109c3b8be..44e8b25fabe2 100644 --- a/src/components/LHNOptionsList/OptionRowLHN/OptionRowLHN.tsx +++ b/src/components/LHNOptionsList/OptionRowLHN/OptionRowLHN.tsx @@ -5,7 +5,7 @@ import useThemeStyles from '@hooks/useThemeStyles'; import OptionRow from './OptionRow'; import useOptionRowChrome from './useOptionRowChrome'; -function OptionRowLHN({isOptionFocused = false, onSelectRow = () => {}, optionItem, viewMode = 'default', style, onLayout = () => {}, hasDraftComment, testID}: OptionRowLHNProps) { +function OptionRowLHN({isOptionFocused = false, onSelectRow = () => {}, optionItem, viewMode = 'default', onLayout = () => {}, hasDraftComment, testID}: OptionRowLHNProps) { const styles = useThemeStyles(); const {setHovered, sidebarInnerRowStyle, contentContainerStyles, avatarBackgroundColor} = useOptionRowChrome({ isOptionFocused, @@ -33,15 +33,13 @@ function OptionRowLHN({isOptionFocused = false, onSelectRow = () => {}, optionIt <OptionRow.Avatar optionItem={optionItem} viewMode={viewMode} - subscriptAvatarBorderColor={avatarBackgroundColor} - secondaryAvatarBackgroundColor={avatarBackgroundColor} + avatarBackgroundColor={avatarBackgroundColor} /> <View style={contentContainerStyles}> <View style={[styles.flexRow, styles.alignItemsCenter, styles.mw100, styles.overflowHidden]}> <OptionRow.Title optionItem={optionItem} isOptionFocused={isOptionFocused} - style={style} testID={testID} /> <OptionRow.OnboardingBadge optionItem={optionItem} /> @@ -51,7 +49,6 @@ function OptionRowLHN({isOptionFocused = false, onSelectRow = () => {}, optionIt optionItem={optionItem} viewMode={viewMode} isOptionFocused={isOptionFocused} - style={style} /> </View> <OptionRow.DescriptiveText optionItem={optionItem} /> diff --git a/src/components/LHNOptionsList/types.ts b/src/components/LHNOptionsList/types.ts index cae7909e523d..829de863508a 100644 --- a/src/components/LHNOptionsList/types.ts +++ b/src/components/LHNOptionsList/types.ts @@ -1,5 +1,5 @@ import type {RefObject} from 'react'; -import type {LayoutChangeEvent, StyleProp, TextStyle, View, ViewStyle} from 'react-native'; +import type {LayoutChangeEvent, StyleProp, View, ViewStyle} from 'react-native'; import type {OnyxEntry} from 'react-native-onyx'; import type {ValueOf} from 'type-fest'; import type CONST from '@src/CONST'; @@ -85,9 +85,6 @@ type OptionRowLHNProps = { /** Toggle between compact and default view */ viewMode?: OptionMode; - /** Additional style props */ - style?: StyleProp<TextStyle>; - /** The item that should be rendered */ optionItem: OptionData; From 9a96c0ba41e99520e2021798061b997c9ce4d808 Mon Sep 17 00:00:00 2001 From: bartlomiej obudzinski <bartlomiej.obudzinski@callstack.com> Date: Thu, 14 May 2026 12:26:50 +0200 Subject: [PATCH 11/12] test: add unit tests for useOptionRowChrome hook --- tests/unit/hooks/useOptionRowChrome.test.ts | 124 ++++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100644 tests/unit/hooks/useOptionRowChrome.test.ts diff --git a/tests/unit/hooks/useOptionRowChrome.test.ts b/tests/unit/hooks/useOptionRowChrome.test.ts new file mode 100644 index 000000000000..3630dc64664f --- /dev/null +++ b/tests/unit/hooks/useOptionRowChrome.test.ts @@ -0,0 +1,124 @@ +import {act, renderHook} from '@testing-library/react-native'; +import useOptionRowChrome from '@components/LHNOptionsList/OptionRowLHN/useOptionRowChrome'; +import CONST from '@src/CONST'; + +const FOCUSED_COLOR = '#focused'; +const HOVERED_COLOR = '#hovered'; +const DEFAULT_SIDEBAR = '#sidebar'; + +const MOCK_STYLES = { + sidebarLinkActive: {backgroundColor: FOCUSED_COLOR}, + sidebarLinkHover: {backgroundColor: HOVERED_COLOR}, + chatLinkRowPressable: {chatLinkRowPressable: true}, + flexGrow1: {flexGrow1: true}, + optionItemAvatarNameWrapper: {optionItemAvatarNameWrapper: true}, + optionRow: {optionRow: true}, + optionRowCompact: {optionRowCompact: true}, + justifyContentCenter: {justifyContentCenter: true}, + flex1: {flex1: true}, + flexRow: {flexRow: true}, + overflowHidden: {overflowHidden: true}, +}; + +const MOCK_THEME = {sidebar: DEFAULT_SIDEBAR}; + +const MOCK_STYLE_UTILS = { + getCompactContentContainerStyles: () => ({getCompactContentContainerStyles: true}), +}; + +jest.mock('@hooks/useTheme', () => ({ + __esModule: true, + default: jest.fn(() => MOCK_THEME), +})); + +jest.mock('@hooks/useThemeStyles', () => ({ + __esModule: true, + default: jest.fn(() => MOCK_STYLES), +})); + +jest.mock('@hooks/useStyleUtils', () => ({ + __esModule: true, + default: jest.fn(() => MOCK_STYLE_UTILS), +})); + +describe('useOptionRowChrome', () => { + describe('hover state', () => { + it('initialises hovered to false', () => { + const {result} = renderHook(() => useOptionRowChrome({isOptionFocused: false, viewMode: CONST.OPTION_MODE.DEFAULT})); + + expect(result.current.hovered).toBe(false); + }); + + it('setHovered(true) toggles hovered to true', () => { + const {result} = renderHook(() => useOptionRowChrome({isOptionFocused: false, viewMode: CONST.OPTION_MODE.DEFAULT})); + + act(() => { + result.current.setHovered(true); + }); + + expect(result.current.hovered).toBe(true); + }); + }); + + describe('avatarBackgroundColor precedence', () => { + it('returns the default sidebar color when neither focused nor hovered', () => { + const {result} = renderHook(() => useOptionRowChrome({isOptionFocused: false, viewMode: CONST.OPTION_MODE.DEFAULT})); + + expect(result.current.avatarBackgroundColor).toBe(DEFAULT_SIDEBAR); + }); + + it('returns the focused color when isOptionFocused is true', () => { + const {result} = renderHook(() => useOptionRowChrome({isOptionFocused: true, viewMode: CONST.OPTION_MODE.DEFAULT})); + + expect(result.current.avatarBackgroundColor).toBe(FOCUSED_COLOR); + }); + + it('returns the hovered color when hovered and not focused', () => { + const {result} = renderHook(() => useOptionRowChrome({isOptionFocused: false, viewMode: CONST.OPTION_MODE.DEFAULT})); + + act(() => { + result.current.setHovered(true); + }); + + expect(result.current.avatarBackgroundColor).toBe(HOVERED_COLOR); + }); + + it('focused beats hovered when both are true', () => { + const {result} = renderHook(() => useOptionRowChrome({isOptionFocused: true, viewMode: CONST.OPTION_MODE.DEFAULT})); + + act(() => { + result.current.setHovered(true); + }); + + expect(result.current.avatarBackgroundColor).toBe(FOCUSED_COLOR); + }); + }); + + describe('layout styles by viewMode', () => { + it('default viewMode uses optionRow in sidebarInnerRowStyle', () => { + const {result} = renderHook(() => useOptionRowChrome({isOptionFocused: false, viewMode: CONST.OPTION_MODE.DEFAULT})); + + expect(result.current.sidebarInnerRowStyle).toMatchObject({optionRow: true}); + expect(result.current.sidebarInnerRowStyle).not.toMatchObject({optionRowCompact: true}); + }); + + it('compact viewMode uses optionRowCompact in sidebarInnerRowStyle', () => { + const {result} = renderHook(() => useOptionRowChrome({isOptionFocused: false, viewMode: CONST.OPTION_MODE.COMPACT})); + + expect(result.current.sidebarInnerRowStyle).toMatchObject({optionRowCompact: true}); + expect(result.current.sidebarInnerRowStyle).not.toMatchObject({optionRow: true}); + }); + + it('default viewMode returns flex1 contentContainerStyles', () => { + const {result} = renderHook(() => useOptionRowChrome({isOptionFocused: false, viewMode: CONST.OPTION_MODE.DEFAULT})); + + expect(result.current.contentContainerStyles).toEqual([MOCK_STYLES.flex1]); + }); + + it('compact viewMode returns the compact content container set', () => { + const {result} = renderHook(() => useOptionRowChrome({isOptionFocused: false, viewMode: CONST.OPTION_MODE.COMPACT})); + + expect(result.current.contentContainerStyles).toEqual([MOCK_STYLES.flex1, MOCK_STYLES.flexRow, MOCK_STYLES.overflowHidden, MOCK_STYLE_UTILS.getCompactContentContainerStyles()]); + }); + }); +}); From fc685b285c5ad65d0538bdd9137237a952f6c334 Mon Sep 17 00:00:00 2001 From: bartlomiej obudzinski <bartlomiej.obudzinski@callstack.com> Date: Thu, 14 May 2026 12:35:28 +0200 Subject: [PATCH 12/12] fix: address Copilot review comments on JSDoc and hook return shape --- .../OptionRowLHN/OptionRow/Subtitle.tsx | 2 +- .../OptionRowLHN/OptionRow/Title.tsx | 2 +- .../OptionRowLHN/OptionRowLHNData.tsx | 4 ++-- .../OptionRowLHN/useOptionRowChrome.ts | 1 - tests/unit/hooks/useOptionRowChrome.test.ts | 18 ------------------ 5 files changed, 4 insertions(+), 23 deletions(-) diff --git a/src/components/LHNOptionsList/OptionRowLHN/OptionRow/Subtitle.tsx b/src/components/LHNOptionsList/OptionRowLHN/OptionRow/Subtitle.tsx index eac3c6a73f78..71f8ffa73100 100644 --- a/src/components/LHNOptionsList/OptionRowLHN/OptionRow/Subtitle.tsx +++ b/src/components/LHNOptionsList/OptionRowLHN/OptionRow/Subtitle.tsx @@ -15,7 +15,7 @@ type SubtitleProps = { /** Option data for the row. Source of `alternateText` and emoji rendering hints. */ optionItem: OptionData; - /** Display density mode. Compact rows hide the subtitle entirely. */ + /** Display density mode. Compact rows render the subtitle with compact styles; the subtitle is hidden only when `optionItem.alternateText` is empty. */ viewMode: OptionMode; /** Whether the row is the currently focused/active option. Drives the active text style. */ diff --git a/src/components/LHNOptionsList/OptionRowLHN/OptionRow/Title.tsx b/src/components/LHNOptionsList/OptionRowLHN/OptionRow/Title.tsx index 3b28fa2bf8b8..9b887d3fb7dc 100644 --- a/src/components/LHNOptionsList/OptionRowLHN/OptionRow/Title.tsx +++ b/src/components/LHNOptionsList/OptionRowLHN/OptionRow/Title.tsx @@ -14,7 +14,7 @@ type TitleProps = { /** Whether the row is the currently focused/active option. Drives the active text style. */ isOptionFocused: boolean; - /** Numeric testID for the title node (mirrors `reportID`). */ + /** Numeric testID for the title node. This is the FlashList row index passed in from the renderItem callback, not the report ID. */ testID: number; }; diff --git a/src/components/LHNOptionsList/OptionRowLHN/OptionRowLHNData.tsx b/src/components/LHNOptionsList/OptionRowLHN/OptionRowLHNData.tsx index f88e571feec4..672e4e5ec2dd 100644 --- a/src/components/LHNOptionsList/OptionRowLHN/OptionRowLHNData.tsx +++ b/src/components/LHNOptionsList/OptionRowLHN/OptionRowLHNData.tsx @@ -25,8 +25,8 @@ import OptionRowLHN from './OptionRowLHN'; /* * This component gets the data from onyx for the actual * OptionRowLHN component. - * The OptionRowLHN component is memoized, so it will only - * re-render if the data really changed. + * OptionRowLHN is auto-memoized by React Compiler, so it will + * only re-render when the inputs derived from this wrapper change. */ function OptionRowLHNData({ isOptionFocused = false, diff --git a/src/components/LHNOptionsList/OptionRowLHN/useOptionRowChrome.ts b/src/components/LHNOptionsList/OptionRowLHN/useOptionRowChrome.ts index e39170c798a4..65e481fee47e 100644 --- a/src/components/LHNOptionsList/OptionRowLHN/useOptionRowChrome.ts +++ b/src/components/LHNOptionsList/OptionRowLHN/useOptionRowChrome.ts @@ -51,7 +51,6 @@ function useOptionRowChrome({isOptionFocused, viewMode}: UseOptionRowChromeParam } return { - hovered, setHovered, sidebarInnerRowStyle, contentContainerStyles, diff --git a/tests/unit/hooks/useOptionRowChrome.test.ts b/tests/unit/hooks/useOptionRowChrome.test.ts index 3630dc64664f..33576d96d0e6 100644 --- a/tests/unit/hooks/useOptionRowChrome.test.ts +++ b/tests/unit/hooks/useOptionRowChrome.test.ts @@ -42,24 +42,6 @@ jest.mock('@hooks/useStyleUtils', () => ({ })); describe('useOptionRowChrome', () => { - describe('hover state', () => { - it('initialises hovered to false', () => { - const {result} = renderHook(() => useOptionRowChrome({isOptionFocused: false, viewMode: CONST.OPTION_MODE.DEFAULT})); - - expect(result.current.hovered).toBe(false); - }); - - it('setHovered(true) toggles hovered to true', () => { - const {result} = renderHook(() => useOptionRowChrome({isOptionFocused: false, viewMode: CONST.OPTION_MODE.DEFAULT})); - - act(() => { - result.current.setHovered(true); - }); - - expect(result.current.hovered).toBe(true); - }); - }); - describe('avatarBackgroundColor precedence', () => { it('returns the default sidebar color when neither focused nor hovered', () => { const {result} = renderHook(() => useOptionRowChrome({isOptionFocused: false, viewMode: CONST.OPTION_MODE.DEFAULT}));