Skip to content

Commit

Permalink
Add StyleUtils
Browse files Browse the repository at this point in the history
  • Loading branch information
marcaaron committed Nov 24, 2021
1 parent 47d756e commit 3c41171
Show file tree
Hide file tree
Showing 21 changed files with 545 additions and 515 deletions.
5 changes: 3 additions & 2 deletions src/components/Badge.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React from 'react';
import {Pressable, View} from 'react-native';
import PropTypes from 'prop-types';
import styles, {getBadgeColorStyle} from '../styles/styles';
import styles from '../styles/styles';
import * as StyleUtils from '../styles/StyleUtils';
import Text from './Text';

const propTypes = {
Expand Down Expand Up @@ -38,7 +39,7 @@ const Badge = (props) => {
const wrapperStyles = ({pressed}) => ([
styles.badge,
styles.ml2,
getBadgeColorStyle(props.success, props.error, pressed),
StyleUtils.getBadgeColorStyle(props.success, props.error, pressed),
...props.badgeStyles,
]);

Expand Down
7 changes: 4 additions & 3 deletions src/components/ContextMenuItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import {Pressable} from 'react-native';
import MenuItem from './MenuItem';
import Tooltip from './Tooltip';
import Icon from './Icon';
import styles, {getIconFillColor, getButtonBackgroundColorStyle} from '../styles/styles';
import styles from '../styles/styles';
import * as StyleUtils from '../styles/StyleUtils';
import getButtonState from '../libs/getButtonState';

const propTypes = {
Expand Down Expand Up @@ -89,14 +90,14 @@ class ContextMenuItem extends Component {
style={
({hovered, pressed}) => [
styles.reportActionContextMenuMiniButton,
getButtonBackgroundColorStyle(getButtonState(hovered, pressed, this.state.success)),
StyleUtils.getButtonBackgroundColorStyle(getButtonState(hovered, pressed, this.state.success)),
]
}
>
{({hovered, pressed}) => (
<Icon
src={icon}
fill={getIconFillColor(getButtonState(hovered, pressed, this.state.success))}
fill={StyleUtils.getIconFillColor(getButtonState(hovered, pressed, this.state.success))}
/>
)}
</Pressable>
Expand Down
5 changes: 3 additions & 2 deletions src/components/FAB/FAB.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import {
} from 'react-native';
import Icon from '../Icon';
import * as Expensicons from '../Icon/Expensicons';
import styles, {getAnimatedFABStyle} from '../../styles/styles';
import styles from '../../styles/styles';
import * as StyleUtils from '../../styles/StyleUtils';
import themeColors from '../../styles/themes/default';
import fabPropTypes from './fabPropTypes';
import Tooltip from '../Tooltip';
Expand Down Expand Up @@ -69,7 +70,7 @@ class FAB extends PureComponent {
onPress={this.props.onPress}
style={[
styles.floatingActionButton,
getAnimatedFABStyle(rotate, backgroundColor),
StyleUtils.getAnimatedFABStyle(rotate, backgroundColor),
]}
>
<AnimatedIcon src={Expensicons.Plus} fill={fill} />
Expand Down
11 changes: 6 additions & 5 deletions src/components/HTMLEngineProvider/BaseHTMLEngineProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import {
import PropTypes from 'prop-types';
import lodashGet from 'lodash/get';
import Config from '../../CONFIG';
import styles, {webViewStyles, getFontFamilyMonospace} from '../../styles/styles';
import styles from '../../styles/styles';
import * as StyleUtils from '../../styles/StyleUtils';
import fontFamily from '../../styles/fontFamily';
import AnchorForCommentsOnly from '../AnchorForCommentsOnly';
import InlineCodeBlock from '../InlineCodeBlock';
Expand Down Expand Up @@ -150,7 +151,7 @@ function CodeRenderer(props) {
const {boxModelStyle, otherStyle: textStyle} = splitBoxModelStyle(props.style);

// Get the correct fontFamily variant based in the fontStyle and fontWeight
const font = getFontFamilyMonospace({
const font = StyleUtils.getFontFamilyMonospace({
fontStyle: textStyle.fontStyle,
fontWeight: textStyle.fontWeight,
});
Expand Down Expand Up @@ -243,7 +244,7 @@ function ImgRenderer(props) {
>
<ThumbnailImage
previewSourceURL={previewSource}
style={webViewStyles.tagStyles.img}
style={styles.webViewStyles.tagStyles.img}
isAuthTokenRequired={isAttachment}
/>
</TouchableOpacity>
Expand Down Expand Up @@ -297,8 +298,8 @@ const BaseHTMLEngineProvider = (props) => {
return (
<TRenderEngineProvider
customHTMLElementModels={customHTMLElementModels}
baseStyle={webViewStyles.baseFontStyle}
tagsStyles={webViewStyles.tagStyles}
baseStyle={styles.webViewStyles.baseFontStyle}
tagsStyles={styles.webViewStyles.tagStyles}
enableCSSInlineProcessing={false}
dangerouslyDisableWhitespaceCollapsing={false}
systemFonts={EXTRA_FONTS}
Expand Down
7 changes: 4 additions & 3 deletions src/components/ImageView/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import PropTypes from 'prop-types';
import {
View, Image, Pressable,
} from 'react-native';
import styles, {getZoomCursorStyle, getZoomSizingStyle} from '../../styles/styles';
import styles from '../../styles/styles';
import * as StyleUtils from '../../styles/StyleUtils';
import canUseTouchScreen from '../../libs/canUseTouchscreen';
import withWindowDimensions, {windowDimensionsPropTypes} from '../withWindowDimensions';

Expand Down Expand Up @@ -180,8 +181,8 @@ class ImageView extends PureComponent {
>
<Pressable
style={{
...getZoomSizingStyle(this.state.isZoomed, this.state.imgWidth, this.state.imgHeight, this.state.zoomScale, this.state.containerHeight),
...getZoomCursorStyle(this.state.isZoomed, this.state.isDragging),
...StyleUtils.getZoomSizingStyle(this.state.isZoomed, this.state.imgWidth, this.state.imgHeight, this.state.zoomScale, this.state.containerHeight),
...StyleUtils.getZoomCursorStyle(this.state.isZoomed, this.state.isDragging),
...this.state.isZoomed ? styles.pRelative : styles.pAbsolute,
...styles.flex1,
}}
Expand Down
9 changes: 5 additions & 4 deletions src/components/MenuItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import {
View, Pressable,
} from 'react-native';
import Text from './Text';
import styles, {getButtonBackgroundColorStyle, getIconFillColor} from '../styles/styles';
import styles from '../styles/styles';
import * as StyleUtils from '../styles/StyleUtils';
import Icon from './Icon';
import * as Expensicons from './Icon/Expensicons';
import getButtonState from '../libs/getButtonState';
Expand Down Expand Up @@ -48,7 +49,7 @@ const MenuItem = props => (
}}
style={({hovered, pressed}) => ([
styles.popoverMenuItem,
getButtonBackgroundColorStyle(getButtonState(props.focused || hovered, pressed, props.success, props.disabled, props.interactive)),
StyleUtils.getButtonBackgroundColorStyle(getButtonState(props.focused || hovered, pressed, props.success, props.disabled, props.interactive)),
..._.isArray(props.wrapperStyle) ? props.wrapperStyle : [props.wrapperStyle],
])}
disabled={props.disabled}
Expand All @@ -67,7 +68,7 @@ const MenuItem = props => (
src={props.icon}
width={props.iconWidth}
height={props.iconHeight}
fill={props.iconFill || getIconFillColor(
fill={props.iconFill || StyleUtils.getIconFillColor(
getButtonState(props.focused || hovered, pressed, props.success, props.disabled, props.interactive),
)}
/>
Expand Down Expand Up @@ -119,7 +120,7 @@ const MenuItem = props => (
<View style={styles.popoverMenuIcon}>
<Icon
src={props.iconRight}
fill={getIconFillColor(getButtonState(props.focused || hovered, pressed, props.success, props.disabled, props.interactive))}
fill={StyleUtils.getIconFillColor(getButtonState(props.focused || hovered, pressed, props.success, props.disabled, props.interactive))}
/>
</View>
)}
Expand Down
7 changes: 4 additions & 3 deletions src/components/Modal/BaseModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import {View} from 'react-native';
import PropTypes from 'prop-types';
import ReactNativeModal from 'react-native-modal';
import {SafeAreaInsetsContext} from 'react-native-safe-area-context';
import styles, {getModalPaddingStyles, getSafeAreaPadding} from '../../styles/styles';
import styles from '../../styles/styles';
import * as StyleUtils from '../../styles/StyleUtils';
import themeColors from '../../styles/themes/default';
import {propTypes as modalPropTypes, defaultProps as modalDefaultProps} from './modalPropTypes';
import getModalStyles from '../../styles/getModalStyles';
Expand Down Expand Up @@ -119,9 +120,9 @@ class BaseModal extends PureComponent {
paddingBottom: safeAreaPaddingBottom,
paddingLeft: safeAreaPaddingLeft,
paddingRight: safeAreaPaddingRight,
} = getSafeAreaPadding(insets);
} = StyleUtils.getSafeAreaPadding(insets);

const modalPaddingStyles = getModalPaddingStyles({
const modalPaddingStyles = StyleUtils.getModalPaddingStyles({
safeAreaPaddingTop,
safeAreaPaddingBottom,
safeAreaPaddingLeft,
Expand Down
5 changes: 3 additions & 2 deletions src/components/ScreenWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import {View} from 'react-native';
import {withNavigation} from '@react-navigation/compat';
import {SafeAreaInsetsContext} from 'react-native-safe-area-context';
import {withOnyx} from 'react-native-onyx';
import styles, {getSafeAreaPadding} from '../styles/styles';
import styles from '../styles/styles';
import * as StyleUtils from '../styles/StyleUtils';
import HeaderGap from './HeaderGap';
import KeyboardShortcutsModal from './KeyboardShortcutsModal';
import KeyboardShortcut from '../libs/KeyboardShortcut';
Expand Down Expand Up @@ -97,7 +98,7 @@ class ScreenWrapper extends React.Component {
return (
<SafeAreaInsetsContext.Consumer>
{(insets) => {
const {paddingTop, paddingBottom} = getSafeAreaPadding(insets);
const {paddingTop, paddingBottom} = StyleUtils.getSafeAreaPadding(insets);
const paddingStyle = {};

if (this.props.includePaddingTop) {
Expand Down
5 changes: 3 additions & 2 deletions src/components/TextInputAutoWidth.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import React from 'react';
import {View} from 'react-native';
import PropTypes from 'prop-types';
import _ from 'underscore';
import styles, {getAutoGrowTextInputStyle} from '../styles/styles';
import styles from '../styles/styles';
import * as StyleUtils from '../styles/StyleUtils';
import Text from './Text';
import TextInputFocusable from './TextInputFocusable';

Expand Down Expand Up @@ -45,7 +46,7 @@ class TextInputAutoWidth extends React.Component {
<>
<View>
<TextInputFocusable
style={[this.props.inputStyle, getAutoGrowTextInputStyle(this.state.textInputWidth)]}
style={[this.props.inputStyle, StyleUtils.getAutoGrowTextInputStyle(this.state.textInputWidth)]}
ref={this.props.forwardedRef}
/* eslint-disable-next-line react/jsx-props-no-spreading */
{...propsWithoutStyles}
Expand Down
5 changes: 3 additions & 2 deletions src/components/ThumbnailImage.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import {View} from 'react-native';
import PropTypes from 'prop-types';
import ImageWithSizeCalculation from './ImageWithSizeCalculation';
import addEncryptedAuthTokenToURL from '../libs/addEncryptedAuthTokenToURL';
import styles, {getWidthAndHeightStyle} from '../styles/styles';
import styles from '../styles/styles';
import * as StyleUtils from '../styles/StyleUtils';

const propTypes = {
/** Source URL for the preview image */
Expand Down Expand Up @@ -52,7 +53,7 @@ class ThumbnailImage extends PureComponent {
return (
<View
style={[
getWidthAndHeightStyle(this.state.thumbnailWidth, this.state.thumbnailHeight),
StyleUtils.getWidthAndHeightStyle(this.state.thumbnailWidth, this.state.thumbnailHeight),
styles.alignItemsCenter,
styles.justifyContentCenter,
styles.overflowHidden,
Expand Down
8 changes: 5 additions & 3 deletions src/libs/Navigation/AppNavigator/BaseDrawerNavigator.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import PropTypes from 'prop-types';
import {createDrawerNavigator} from '@react-navigation/drawer';
import {View} from 'react-native';
import withWindowDimensions, {windowDimensionsPropTypes} from '../../../components/withWindowDimensions';
import styles, {getNavigationDrawerStyle, getNavigationDrawerType} from '../../../styles/styles';
import styles from '../../../styles/styles';
import * as StyleUtils from '../../../styles/StyleUtils';

import Navigation from '../Navigation';

const propTypes = {
Expand Down Expand Up @@ -43,8 +45,8 @@ const BaseDrawerNavigator = (props) => {
screenOptions={{
cardStyle: styles.navigationScreenCardStyle,
headerShown: false,
drawerType: getNavigationDrawerType(props.isSmallScreenWidth),
drawerStyle: getNavigationDrawerStyle(
drawerType: StyleUtils.getNavigationDrawerType(props.isSmallScreenWidth),
drawerStyle: StyleUtils.getNavigationDrawerStyle(
props.isSmallScreenWidth,
),
swipeEdgeWidth: 500,
Expand Down
5 changes: 3 additions & 2 deletions src/pages/home/report/EmojiPickerMenu/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import {View, FlatList} from 'react-native';
import PropTypes from 'prop-types';
import _ from 'underscore';
import CONST from '../../../../CONST';
import styles, {getEmojiPickerStyle} from '../../../../styles/styles';
import styles from '../../../../styles/styles';
import * as StyleUtils from '../../../../styles/StyleUtils';
import themeColors from '../../../../styles/themes/default';
import emojis from '../../../../../assets/emojis';
import EmojiPickerMenuItem from '../EmojiPickerMenuItem';
Expand Down Expand Up @@ -356,7 +357,7 @@ class EmojiPickerMenu extends Component {
render() {
return (
<View
style={[styles.emojiPickerContainer, getEmojiPickerStyle(this.props.isSmallScreenWidth)]}
style={[styles.emojiPickerContainer, StyleUtils.getEmojiPickerStyle(this.props.isSmallScreenWidth)]}
pointerEvents={this.state.arePointerEventsDisabled ? 'none' : 'auto'}
>
{!this.props.isSmallScreenWidth && (
Expand Down
5 changes: 3 additions & 2 deletions src/pages/home/report/EmojiPickerMenuItem.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React from 'react';
import PropTypes from 'prop-types';
import {Pressable} from 'react-native';
import styles, {getButtonBackgroundColorStyle} from '../../../styles/styles';
import styles from '../../../styles/styles';
import * as StyleUtils from '../../../styles/StyleUtils';
import getButtonState from '../../../libs/getButtonState';
import Hoverable from '../../../components/Hoverable';
import Text from '../../../components/Text';
Expand All @@ -27,7 +28,7 @@ const EmojiPickerMenuItem = props => (
pressed,
}) => ([
styles.pv1,
getButtonBackgroundColorStyle(getButtonState(false, pressed)),
StyleUtils.getButtonBackgroundColorStyle(getButtonState(false, pressed)),
props.isHighlighted ? styles.emojiItemHighlighted : {},
styles.emojiItem,
])}
Expand Down
7 changes: 4 additions & 3 deletions src/pages/home/report/ReportActionCompose.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import _ from 'underscore';
import lodashGet from 'lodash/get';
import {withOnyx} from 'react-native-onyx';
import lodashIntersection from 'lodash/intersection';
import styles, {getButtonBackgroundColorStyle, getIconFillColor} from '../../../styles/styles';
import styles from '../../../styles/styles';
import * as StyleUtils from '../../../styles/StyleUtils';
import themeColors from '../../../styles/themes/default';
import TextInputFocusable from '../../../components/TextInputFocusable';
import ONYXKEYS from '../../../ONYXKEYS';
Expand Down Expand Up @@ -673,7 +674,7 @@ class ReportActionCompose extends React.Component {
<Pressable
style={({hovered, pressed}) => ([
styles.chatItemEmojiButton,
getButtonBackgroundColorStyle(getButtonState(hovered, pressed)),
StyleUtils.getButtonBackgroundColorStyle(getButtonState(hovered, pressed)),
])}
ref={el => this.emojiPopoverAnchor = el}
onLayout={this.measureEmojiPopoverAnchorPosition}
Expand All @@ -684,7 +685,7 @@ class ReportActionCompose extends React.Component {
<Tooltip text={this.props.translate('reportActionCompose.emoji')}>
<Icon
src={Expensicons.Emoji}
fill={getIconFillColor(getButtonState(hovered, pressed))}
fill={StyleUtils.getIconFillColor(getButtonState(hovered, pressed))}
/>
</Tooltip>
)}
Expand Down
11 changes: 6 additions & 5 deletions src/pages/home/sidebar/OptionRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import {
StyleSheet,
} from 'react-native';
import Str from 'expensify-common/lib/str';
import styles, {getBackgroundAndBorderStyle, getBackgroundColorStyle} from '../../../styles/styles';
import styles from '../../../styles/styles';
import * as StyleUtils from '../../../styles/StyleUtils';
import {optionPropTypes} from './optionPropTypes';
import Icon from '../../../components/Icon';
import * as Expensicons from '../../../components/Icon/Expensicons';
Expand Down Expand Up @@ -140,7 +141,7 @@ const OptionRow = (props) => {
styles.justifyContentBetween,
styles.sidebarLink,
styles.sidebarLinkInner,
getBackgroundColorStyle(props.backgroundColor),
StyleUtils.getBackgroundColorStyle(props.backgroundColor),
props.optionIsFocused ? styles.sidebarLinkActive : null,
hovered && !props.optionIsFocused ? props.hoverStyle : null,
props.isDisabled && styles.cursorDisabled,
Expand All @@ -160,12 +161,12 @@ const OptionRow = (props) => {
avatarImageURLs={props.option.icons}
size={props.mode === 'compact' ? 'small' : 'default'}
secondAvatarStyle={[
getBackgroundAndBorderStyle(props.backgroundColor),
StyleUtils.getBackgroundAndBorderStyle(props.backgroundColor),
props.optionIsFocused
? getBackgroundAndBorderStyle(focusedBackgroundColor)
? StyleUtils.getBackgroundAndBorderStyle(focusedBackgroundColor)
: undefined,
hovered && !props.optionIsFocused
? getBackgroundAndBorderStyle(hoveredBackgroundColor)
? StyleUtils.getBackgroundAndBorderStyle(hoveredBackgroundColor)
: undefined,
]}
isDefaultChatRoom={props.option.isDefaultChatRoom}
Expand Down
Loading

0 comments on commit 3c41171

Please sign in to comment.