Skip to content

Commit

Permalink
Merge pull request Expensify#51158 from nkdengineer/fix/50779
Browse files Browse the repository at this point in the history
change background color of focus element
  • Loading branch information
mjasikowski authored Oct 30, 2024
2 parents 95aab1f + 8edc58d commit 10336ac
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 9 deletions.
5 changes: 5 additions & 0 deletions src/components/AttachmentPicker/index.native.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import useArrowKeyFocusManager from '@hooks/useArrowKeyFocusManager';
import useKeyboardShortcut from '@hooks/useKeyboardShortcut';
import useLocalize from '@hooks/useLocalize';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useStyleUtils from '@hooks/useStyleUtils';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import * as FileUtils from '@libs/fileDownload/FileUtils';
import CONST from '@src/CONST';
Expand Down Expand Up @@ -116,6 +118,8 @@ function AttachmentPicker({
fileLimit = 1,
}: AttachmentPickerProps) {
const styles = useThemeStyles();
const StyleUtils = useStyleUtils();
const theme = useTheme();
const [isVisible, setIsVisible] = useState(false);

const completeAttachmentSelection = useRef<(data: FileObject[]) => void>(() => {});
Expand Down Expand Up @@ -444,6 +448,7 @@ function AttachmentPicker({
title={translate(item.textTranslationKey)}
onPress={() => selectItem(item)}
focused={focusedIndex === menuIndex}
wrapperStyle={StyleUtils.getItemBackgroundColorStyle(false, focusedIndex === menuIndex, theme.activeComponentBG, theme.hoverComponentBG)}
/>
))}
</View>
Expand Down
3 changes: 1 addition & 2 deletions src/components/EmojiPicker/EmojiPickerMenuItem/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ function EmojiPickerMenuItem({
ref.current = el ?? null;
}}
style={({pressed}) => [
isFocused ? themeStyles.emojiItemKeyboardHighlighted : {},
isHovered || isHighlighted ? themeStyles.emojiItemHighlighted : {},
isFocused || isHovered || isHighlighted ? themeStyles.emojiItemHighlighted : {},
Browser.isMobile() && StyleUtils.getButtonBackgroundColorStyle(getButtonState(false, pressed)),
themeStyles.emojiItem,
]}
Expand Down
6 changes: 5 additions & 1 deletion src/components/MenuItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,9 @@ type MenuItemBaseProps = {
/** Should we remove the background color of the menu item */
shouldRemoveBackground?: boolean;

/** Should we remove the hover background color of the menu item */
shouldRemoveHoverBackground?: boolean;

/** Should we use default cursor for disabled content */
shouldUseDefaultCursorWhenDisabled?: boolean;

Expand Down Expand Up @@ -411,6 +414,7 @@ function MenuItem(
shouldEscapeText = undefined,
shouldGreyOutWhenDisabled = true,
shouldRemoveBackground = false,
shouldRemoveHoverBackground = false,
shouldUseDefaultCursorWhenDisabled = false,
shouldShowLoadingSpinnerIcon = false,
isAnonymousAction = false,
Expand Down Expand Up @@ -594,7 +598,7 @@ function MenuItem(
StyleUtils.getButtonBackgroundColorStyle(getButtonState(focused || isHovered, pressed, success, disabled, interactive), true),
...(Array.isArray(wrapperStyle) ? wrapperStyle : [wrapperStyle]),
shouldGreyOutWhenDisabled && disabled && styles.buttonOpacityDisabled,
isHovered && interactive && !focused && !pressed && !shouldRemoveBackground && styles.hoveredComponentBG,
isHovered && interactive && !focused && !pressed && !shouldRemoveBackground && !shouldRemoveHoverBackground && styles.hoveredComponentBG,
] as StyleProp<ViewStyle>
}
disabledStyle={shouldUseDefaultCursorWhenDisabled && [styles.cursorDefault]}
Expand Down
5 changes: 4 additions & 1 deletion src/components/PopoverMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type {ModalProps} from 'react-native-modal';
import useArrowKeyFocusManager from '@hooks/useArrowKeyFocusManager';
import useKeyboardShortcut from '@hooks/useKeyboardShortcut';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useStyleUtils from '@hooks/useStyleUtils';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import useWindowDimensions from '@hooks/useWindowDimensions';
Expand Down Expand Up @@ -159,6 +160,7 @@ function PopoverMenu({
shouldUpdateFocusedIndex = true,
}: PopoverMenuProps) {
const styles = useThemeStyles();
const StyleUtils = useStyleUtils();
const theme = useTheme();
// We need to use isSmallScreenWidth instead of shouldUseNarrowLayout to apply correct popover styles
// eslint-disable-next-line rulesdir/prefer-shouldUseNarrowLayout-instead-of-isSmallScreenWidth
Expand Down Expand Up @@ -320,7 +322,8 @@ function PopoverMenu({
}
setFocusedIndex(menuIndex);
}}
style={{backgroundColor: item.isSelected ? theme.activeComponentBG : undefined}}
wrapperStyle={StyleUtils.getItemBackgroundColorStyle(!!item.isSelected, focusedIndex === menuIndex, theme.activeComponentBG, theme.hoverComponentBG)}
shouldRemoveHoverBackground={item.isSelected}
titleStyle={StyleSheet.flatten([styles.flex1, item.titleStyle])}
// eslint-disable-next-line react/jsx-props-no-spreading
{...menuItemProps}
Expand Down
4 changes: 3 additions & 1 deletion src/components/SelectionList/BaseListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import OfflineWithFeedback from '@components/OfflineWithFeedback';
import PressableWithFeedback from '@components/Pressable/PressableWithFeedback';
import useHover from '@hooks/useHover';
import {useMouseContext} from '@hooks/useMouseContext';
import useStyleUtils from '@hooks/useStyleUtils';
import useSyncFocus from '@hooks/useSyncFocus';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
Expand Down Expand Up @@ -38,6 +39,7 @@ function BaseListItem<TItem extends ListItem>({
}: BaseListItemProps<TItem>) {
const theme = useTheme();
const styles = useThemeStyles();
const StyleUtils = useStyleUtils();
const {hovered, bind} = useHover();
const {isMouseDownOnInput, setMouseUp} = useMouseContext();

Expand Down Expand Up @@ -102,7 +104,7 @@ function BaseListItem<TItem extends ListItem>({
tabIndex={item.tabIndex}
wrapperStyle={pressableWrapperStyle}
>
<View style={wrapperStyle}>
<View style={[wrapperStyle, StyleUtils.getItemBackgroundColorStyle(!!item.isSelected, !!isFocused, theme.activeComponentBG, theme.hoverComponentBG)]}>
{typeof children === 'function' ? children(hovered) : children}

{!canSelectMultiple && item.isSelected && !rightHandSideComponent && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function TransactionListItem<TItem extends ListItem>({
// Removing background style because they are added to the parent OpacityView via animatedHighlightStyle
styles.bgTransparent,
item.isSelected && styles.activeComponentBG,
isFocused && styles.sidebarLinkActive,
isFocused && styles.hoveredComponentBG,
styles.mh0,
];

Expand Down
18 changes: 15 additions & 3 deletions src/styles/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1119,6 +1119,19 @@ function getAmountWidth(amount: string): number {
return width;
}

function getItemBackgroundColorStyle(isSelected: boolean, isFocused: boolean, selectedBG: string, focusedBG: string): ViewStyle {
let backgroundColor;
if (isSelected) {
backgroundColor = selectedBG;
} else if (isFocused) {
backgroundColor = focusedBG;
}

return {
backgroundColor,
};
}

const staticStyleUtils = {
positioning,
combineStyles,
Expand Down Expand Up @@ -1193,6 +1206,7 @@ const staticStyleUtils = {
getAmountWidth,
getBorderRadiusStyle,
getHighResolutionInfoWrapperStyle,
getItemBackgroundColorStyle,
};

const createStyleUtils = (theme: ThemeColors, styles: ThemeStyles) => ({
Expand All @@ -1211,9 +1225,7 @@ const createStyleUtils = (theme: ThemeColors, styles: ThemeStyles) => ({
getAutoCompleteSuggestionItemStyle: (highlightedEmojiIndex: number, rowHeight: number, isHovered: boolean, currentEmojiIndex: number): ViewStyle[] => {
let backgroundColor;

if (currentEmojiIndex === highlightedEmojiIndex) {
backgroundColor = theme.activeComponentBG;
} else if (isHovered) {
if (isHovered || currentEmojiIndex === highlightedEmojiIndex) {
backgroundColor = theme.hoverComponentBG;
}

Expand Down

0 comments on commit 10336ac

Please sign in to comment.