Skip to content

Commit

Permalink
Merge pull request Expensify#32264 from koko57/fix/31677-amend-themec…
Browse files Browse the repository at this point in the history
…olors-imports-in-utils

Fix/31677 amend themecolors imports in utils
  • Loading branch information
grgia authored Nov 30, 2023
2 parents 9d0de25 + 946f362 commit 9c3125f
Show file tree
Hide file tree
Showing 63 changed files with 325 additions and 232 deletions.
4 changes: 3 additions & 1 deletion src/components/AddressSearch/CurrentLocationButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import useLocalize from '@hooks/useLocalize';
import getButtonState from '@libs/getButtonState';
import colors from '@styles/colors';
import * as StyleUtils from '@styles/StyleUtils';
import useTheme from '@styles/themes/useTheme';
import useThemeStyles from '@styles/useThemeStyles';

const propTypes = {
Expand All @@ -25,12 +26,13 @@ const defaultProps = {

function CurrentLocationButton({onPress, isDisabled}) {
const styles = useThemeStyles();
const theme = useTheme();
const {translate} = useLocalize();

return (
<PressableWithFeedback
style={[styles.flexRow, styles.pv4, styles.ph3, isDisabled && styles.buttonOpacityDisabled]}
hoverStyle={StyleUtils.getButtonBackgroundColorStyle(getButtonState(true), true)}
hoverStyle={StyleUtils.getButtonBackgroundColorStyle(theme, getButtonState(true), true)}
onPress={onPress}
accessibilityLabel={translate('location.useCurrent')}
disabled={isDisabled}
Expand Down
10 changes: 8 additions & 2 deletions src/components/AddressSearch/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,13 @@ function AddressSearch({
}}
styles={{
textInputContainer: [styles.flexColumn],
listView: [StyleUtils.getGoogleListViewStyle(displayListViewBorder), styles.overflowAuto, styles.borderLeft, styles.borderRight, !isFocused && {height: 0}],
listView: [
StyleUtils.getGoogleListViewStyle(styles, displayListViewBorder),
styles.overflowAuto,
styles.borderLeft,
styles.borderRight,
!isFocused && {height: 0},
],
row: [styles.pv4, styles.ph3, styles.overflowAuto],
description: [styles.googleSearchText],
separator: [styles.googleSearchSeparator],
Expand All @@ -526,7 +532,7 @@ function AddressSearch({
inbetweenCompo={
// We want to show the current location button even if there are no recent destinations
predefinedPlaces.length === 0 && shouldShowCurrentLocationButton ? (
<View style={[StyleUtils.getGoogleListViewStyle(true), styles.overflowAuto, styles.borderLeft, styles.borderRight]}>
<View style={[StyleUtils.getGoogleListViewStyle(styles, true), styles.overflowAuto, styles.borderLeft, styles.borderRight]}>
<CurrentLocationButton
onPress={getCurrentLocation}
isDisabled={network.isOffline}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {ScrollView} from 'react-native-gesture-handler';
import Animated, {Easing, FadeOutDown, useAnimatedStyle, useSharedValue, withTiming} from 'react-native-reanimated';
import PressableWithFeedback from '@components/Pressable/PressableWithFeedback';
import * as StyleUtils from '@styles/StyleUtils';
import useTheme from '@styles/themes/useTheme';
import useThemeStyles from '@styles/useThemeStyles';
import CONST from '@src/CONST';
import viewForwardedRef from '@src/types/utils/viewForwardedRef';
Expand Down Expand Up @@ -39,6 +40,7 @@ function BaseAutoCompleteSuggestions<TSuggestion>(
ref: ForwardedRef<View | HTMLDivElement>,
) {
const styles = useThemeStyles();
const theme = useTheme();
const rowHeight = useSharedValue(0);
const scrollRef = useRef<FlashList<TSuggestion>>(null);
/**
Expand All @@ -47,7 +49,7 @@ function BaseAutoCompleteSuggestions<TSuggestion>(
const renderItem = useCallback(
({item, index}: RenderSuggestionMenuItemProps<TSuggestion>): ReactElement => (
<PressableWithFeedback
style={({hovered}) => StyleUtils.getAutoCompleteSuggestionItemStyle(highlightedSuggestionIndex, CONST.AUTO_COMPLETE_SUGGESTER.SUGGESTION_ROW_HEIGHT, hovered, index)}
style={({hovered}) => StyleUtils.getAutoCompleteSuggestionItemStyle(theme, highlightedSuggestionIndex, CONST.AUTO_COMPLETE_SUGGESTER.SUGGESTION_ROW_HEIGHT, hovered, index)}
hoverDimmingValue={1}
onMouseDown={(e) => e.preventDefault()}
onPress={() => onSelect(index)}
Expand All @@ -57,7 +59,7 @@ function BaseAutoCompleteSuggestions<TSuggestion>(
{renderSuggestionMenuItem(item, index)}
</PressableWithFeedback>
),
[highlightedSuggestionIndex, renderSuggestionMenuItem, onSelect, accessibilityLabelExtractor],
[highlightedSuggestionIndex, renderSuggestionMenuItem, onSelect, accessibilityLabelExtractor, theme],
);

const innerHeight = CONST.AUTO_COMPLETE_SUGGESTER.SUGGESTION_ROW_HEIGHT * suggestions.length;
Expand Down
6 changes: 3 additions & 3 deletions src/components/Avatar.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ function Avatar(props) {

const imageStyle =
props.imageStyles && props.imageStyles.length
? [StyleUtils.getAvatarStyle(props.size), ...props.imageStyles, styles.noBorderRadius]
: [StyleUtils.getAvatarStyle(props.size), styles.noBorderRadius];
? [StyleUtils.getAvatarStyle(theme, props.size), ...props.imageStyles, styles.noBorderRadius]
: [StyleUtils.getAvatarStyle(theme, props.size), styles.noBorderRadius];

const iconStyle = props.imageStyles && props.imageStyles.length ? [StyleUtils.getAvatarStyle(props.size), styles.bgTransparent, ...props.imageStyles] : undefined;
const iconStyle = props.imageStyles && props.imageStyles.length ? [StyleUtils.getAvatarStyle(theme, props.size), styles.bgTransparent, ...props.imageStyles] : undefined;

const iconFillColor = isWorkspace ? StyleUtils.getDefaultWorkspaceAvatarColor(props.name).fill : props.fill || theme.icon;
const fallbackAvatar = isWorkspace ? ReportUtils.getDefaultWorkspaceAvatar(props.name) : props.fallbackIcon || Expensicons.FallbackAvatar;
Expand Down
4 changes: 2 additions & 2 deletions src/components/Badge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ function Badge({success = false, error = false, pressable = false, text, environ
const Wrapper = pressable ? PressableWithoutFeedback : View;

const wrapperStyles: (state: PressableStateCallbackType) => StyleProp<ViewStyle> = useCallback(
({pressed}) => [styles.badge, styles.ml2, StyleUtils.getBadgeColorStyle(success, error, pressed, environment === CONST.ENVIRONMENT.ADHOC), badgeStyles],
[styles.badge, styles.ml2, success, error, environment, badgeStyles],
({pressed}) => [styles.badge, styles.ml2, StyleUtils.getBadgeColorStyle(styles, success, error, pressed, environment === CONST.ENVIRONMENT.ADHOC), badgeStyles],
[success, error, environment, badgeStyles, styles],
);

return (
Expand Down
4 changes: 3 additions & 1 deletion src/components/Banner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {StyleProp, TextStyle, View, ViewStyle} from 'react-native';
import useLocalize from '@hooks/useLocalize';
import getButtonState from '@libs/getButtonState';
import * as StyleUtils from '@styles/StyleUtils';
import useTheme from '@styles/themes/useTheme';
import useThemeStyles from '@styles/useThemeStyles';
import CONST from '@src/CONST';
import Hoverable from './Hoverable';
Expand Down Expand Up @@ -41,6 +42,7 @@ type BannerProps = {

function Banner({text, onClose, onPress, containerStyles, textStyles, shouldRenderHTML = false, shouldShowIcon = false, shouldShowCloseButton = false}: BannerProps) {
const styles = useThemeStyles();
const theme = useTheme();
const {translate} = useLocalize();

return (
Expand All @@ -65,7 +67,7 @@ function Banner({text, onClose, onPress, containerStyles, textStyles, shouldRend
<View style={[styles.mr3]}>
<Icon
src={Expensicons.Exclamation}
fill={StyleUtils.getIconFillColor(getButtonState(shouldHighlight))}
fill={StyleUtils.getIconFillColor(theme, getButtonState(shouldHighlight))}
/>
</View>
)}
Expand Down
4 changes: 3 additions & 1 deletion src/components/BaseMiniContextMenuItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import DomUtils from '@libs/DomUtils';
import getButtonState from '@libs/getButtonState';
import ReportActionComposeFocusManager from '@libs/ReportActionComposeFocusManager';
import * as StyleUtils from '@styles/StyleUtils';
import useTheme from '@styles/themes/useTheme';
import useThemeStyles from '@styles/useThemeStyles';
import variables from '@styles/variables';
import PressableWithoutFeedback from './Pressable/PressableWithoutFeedback';
Expand Down Expand Up @@ -51,6 +52,7 @@ const defaultProps = {
*/
function BaseMiniContextMenuItem(props) {
const styles = useThemeStyles();
const theme = useTheme();
return (
<Tooltip text={props.tooltipText}>
<PressableWithoutFeedback
Expand All @@ -73,7 +75,7 @@ function BaseMiniContextMenuItem(props) {
accessibilityLabel={props.tooltipText}
style={({hovered, pressed}) => [
styles.reportActionContextMenuMiniButton,
StyleUtils.getButtonBackgroundColorStyle(getButtonState(hovered, pressed, props.isDelayButtonStateComplete)),
StyleUtils.getButtonBackgroundColorStyle(theme, getButtonState(hovered, pressed, props.isDelayButtonStateComplete)),
props.isDelayButtonStateComplete && styles.cursorDefault,
]}
>
Expand Down
2 changes: 1 addition & 1 deletion src/components/Checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ function Checkbox(
{children ?? (
<View
style={[
StyleUtils.getCheckboxContainerStyle(containerSize, containerBorderRadius),
StyleUtils.getCheckboxContainerStyle(theme, containerSize, containerBorderRadius),
containerStyle,
isChecked && styles.checkedContainer,
hasError && styles.borderColorDanger,
Expand Down
4 changes: 3 additions & 1 deletion src/components/ContextMenuItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import useWindowDimensions from '@hooks/useWindowDimensions';
import getButtonState from '@libs/getButtonState';
import getContextMenuItemStyles from '@styles/getContextMenuItemStyles';
import * as StyleUtils from '@styles/StyleUtils';
import useTheme from '@styles/themes/useTheme';
import useThemeStyles from '@styles/useThemeStyles';
import BaseMiniContextMenuItem from './BaseMiniContextMenuItem';
import Icon from './Icon';
Expand Down Expand Up @@ -54,6 +55,7 @@ const defaultProps = {

function ContextMenuItem({onPress, successIcon, successText, icon, text, isMini, description, isAnonymousAction, isFocused, innerRef}) {
const styles = useThemeStyles();
const theme = useTheme();
const {windowWidth} = useWindowDimensions();
const [isThrottledButtonActive, setThrottledButtonInactive] = useThrottledButtonState();

Expand Down Expand Up @@ -85,7 +87,7 @@ function ContextMenuItem({onPress, successIcon, successText, icon, text, isMini,
<Icon
small
src={itemIcon}
fill={StyleUtils.getIconFillColor(getButtonState(hovered, pressed, !isThrottledButtonActive))}
fill={StyleUtils.getIconFillColor(theme, getButtonState(hovered, pressed, !isThrottledButtonActive))}
/>
)}
</BaseMiniContextMenuItem>
Expand Down
2 changes: 1 addition & 1 deletion src/components/DotIndicatorMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ function DotIndicatorMessage({messages = {}, style, type, textStyles}: DotIndica
<Text
// eslint-disable-next-line react/no-array-index-key
key={i}
style={[StyleUtils.getDotIndicatorTextStyles(isErrorMessage), textStyles]}
style={[StyleUtils.getDotIndicatorTextStyles(styles, isErrorMessage), textStyles]}
>
{message}
</Text>
Expand Down
6 changes: 5 additions & 1 deletion src/components/EmojiPicker/CategoryShortcutButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ function CategoryShortcutButton(props) {
onPress={props.onPress}
onHoverIn={() => setIsHighlighted(true)}
onHoverOut={() => setIsHighlighted(false)}
style={({pressed}) => [StyleUtils.getButtonBackgroundColorStyle(getButtonState(false, pressed)), styles.categoryShortcutButton, isHighlighted && styles.emojiItemHighlighted]}
style={({pressed}) => [
StyleUtils.getButtonBackgroundColorStyle(theme, getButtonState(false, pressed)),
styles.categoryShortcutButton,
isHighlighted && styles.emojiItemHighlighted,
]}
accessibilityLabel={`emojiPicker.headers.${props.code}`}
role={CONST.ACCESSIBILITY_ROLE.BUTTON}
>
Expand Down
6 changes: 4 additions & 2 deletions src/components/EmojiPicker/EmojiPickerButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Tooltip from '@components/Tooltip/PopoverAnchorTooltip';
import withLocalize, {withLocalizePropTypes} from '@components/withLocalize';
import getButtonState from '@libs/getButtonState';
import * as StyleUtils from '@styles/StyleUtils';
import useTheme from '@styles/themes/useTheme';
import useThemeStyles from '@styles/useThemeStyles';
import * as EmojiPickerAction from '@userActions/EmojiPickerAction';

Expand All @@ -31,6 +32,7 @@ const defaultProps = {

function EmojiPickerButton(props) {
const styles = useThemeStyles();
const theme = useTheme();
const emojiPopoverAnchor = useRef(null);

useEffect(() => EmojiPickerAction.resetEmojiPopoverAnchor, []);
Expand All @@ -39,7 +41,7 @@ function EmojiPickerButton(props) {
<Tooltip text={props.translate('reportActionCompose.emoji')}>
<PressableWithoutFeedback
ref={emojiPopoverAnchor}
style={({hovered, pressed}) => [styles.chatItemEmojiButton, StyleUtils.getButtonBackgroundColorStyle(getButtonState(hovered, pressed))]}
style={({hovered, pressed}) => [styles.chatItemEmojiButton, StyleUtils.getButtonBackgroundColorStyle(theme, getButtonState(hovered, pressed))]}
disabled={props.isDisabled}
onPress={() => {
if (!EmojiPickerAction.emojiPickerRef.current.isEmojiPickerVisible) {
Expand All @@ -54,7 +56,7 @@ function EmojiPickerButton(props) {
{({hovered, pressed}) => (
<Icon
src={Expensicons.Emoji}
fill={StyleUtils.getIconFillColor(getButtonState(hovered, pressed))}
fill={StyleUtils.getIconFillColor(theme, getButtonState(hovered, pressed))}
/>
)}
</PressableWithoutFeedback>
Expand Down
4 changes: 3 additions & 1 deletion src/components/EmojiPicker/EmojiPickerButtonDropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Tooltip from '@components/Tooltip';
import withLocalize, {withLocalizePropTypes} from '@components/withLocalize';
import getButtonState from '@libs/getButtonState';
import * as StyleUtils from '@styles/StyleUtils';
import useTheme from '@styles/themes/useTheme';
import useThemeStyles from '@styles/useThemeStyles';
import * as EmojiPickerAction from '@userActions/EmojiPickerAction';
import CONST from '@src/CONST';
Expand All @@ -26,6 +27,7 @@ const defaultProps = {

function EmojiPickerButtonDropdown(props) {
const styles = useThemeStyles();
const theme = useTheme();
const emojiPopoverAnchor = useRef(null);
useEffect(() => EmojiPickerAction.resetEmojiPopoverAnchor, []);

Expand Down Expand Up @@ -64,7 +66,7 @@ function EmojiPickerButtonDropdown(props) {
<View style={[styles.popoverMenuIcon, styles.pointerEventsAuto, props.disabled && styles.cursorDisabled, styles.rotate90]}>
<Icon
src={Expensicons.ArrowRight}
fill={StyleUtils.getIconFillColor(getButtonState(hovered, pressed))}
fill={StyleUtils.getIconFillColor(theme, getButtonState(hovered, pressed))}
/>
</View>
</View>
Expand Down
15 changes: 10 additions & 5 deletions src/components/EmojiPicker/EmojiPickerMenuItem/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import PropTypes from 'prop-types';
import React, {PureComponent} from 'react';
import PressableWithoutFeedback from '@components/Pressable/PressableWithoutFeedback';
import Text from '@components/Text';
import withTheme, {withThemePropTypes} from '@components/withTheme';
import withThemeStyles, {withThemeStylesPropTypes} from '@components/withThemeStyles';
import * as Browser from '@libs/Browser';
import getButtonState from '@libs/getButtonState';
Expand Down Expand Up @@ -32,7 +33,9 @@ const propTypes = {

/** Whether the menu item should be highlighted or not */
isHighlighted: PropTypes.bool,

...withThemeStylesPropTypes,
...withThemePropTypes,
};

class EmojiPickerMenuItem extends PureComponent {
Expand Down Expand Up @@ -97,7 +100,7 @@ class EmojiPickerMenuItem extends PureComponent {
style={({pressed}) => [
this.props.isFocused ? this.props.themeStyles.emojiItemKeyboardHighlighted : {},
this.state.isHovered || this.props.isHighlighted ? this.props.themeStyles.emojiItemHighlighted : {},
Browser.isMobile() && StyleUtils.getButtonBackgroundColorStyle(getButtonState(false, pressed)),
Browser.isMobile() && StyleUtils.getButtonBackgroundColorStyle(this.props.theme, getButtonState(false, pressed)),
this.props.themeStyles.emojiItem,
]}
accessibilityLabel={this.props.emoji}
Expand All @@ -121,9 +124,11 @@ EmojiPickerMenuItem.defaultProps = {

// Significantly speeds up re-renders of the EmojiPickerMenu's FlatList
// by only re-rendering at most two EmojiPickerMenuItems that are highlighted/un-highlighted per user action.
export default withThemeStyles(
React.memo(
EmojiPickerMenuItem,
(prevProps, nextProps) => prevProps.isFocused === nextProps.isFocused && prevProps.isHighlighted === nextProps.isHighlighted && prevProps.emoji === nextProps.emoji,
export default withTheme(
withThemeStyles(
React.memo(
EmojiPickerMenuItem,
(prevProps, nextProps) => prevProps.isFocused === nextProps.isFocused && prevProps.isHighlighted === nextProps.isHighlighted && prevProps.emoji === nextProps.emoji,
),
),
);
Loading

0 comments on commit 9c3125f

Please sign in to comment.