Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[No QA] [TS migration] Review and clean up Styles files #27660

Merged
merged 44 commits into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
ba8a3c1
First version of styles refactor
fabioh8010 Sep 4, 2023
b1ee74b
Add more typings
fabioh8010 Sep 5, 2023
f967e37
Merge branch 'main' into ts/style/styles-refactor
fabioh8010 Sep 13, 2023
4aef004
Remove more CSSProperties usage from styles
fabioh8010 Sep 13, 2023
58d4a25
Add more props and styles
fabioh8010 Sep 14, 2023
c3fc096
Merge remote-tracking branch 'origin/main' into ts/style/styles-refactor
fabioh8010 Sep 14, 2023
091104e
Refactor styles and implement missing ones
fabioh8010 Sep 14, 2023
c7d0164
Merge branch 'main' into ts/style/styles-refactor
blazejkustra Sep 15, 2023
e4a3313
Migrate styles.ts
blazejkustra Sep 15, 2023
b8d36f7
Remove unused imports
blazejkustra Sep 15, 2023
24f363b
Fix return types in styles.ts
blazejkustra Sep 15, 2023
88bb36f
Merge remote-tracking branch 'origin/main' into ts/style/styles-refactor
fabioh8010 Sep 15, 2023
1be0bf5
Minor fixes in styles.ts
fabioh8010 Sep 15, 2023
1338157
Add stricter types to styles.ts
fabioh8010 Sep 15, 2023
5feb1fe
Isolate some web-only styles
fabioh8010 Sep 15, 2023
98e5d4a
Merge remote-tracking branch 'origin/main' into ts/style/styles-refactor
fabioh8010 Sep 18, 2023
b223759
Merge remote-tracking branch 'origin/main' into ts/style/styles-refactor
fabioh8010 Sep 18, 2023
dc0722d
Merge branch 'main' into ts/style/styles-refactor
fabioh8010 Sep 20, 2023
05a58d8
Address review comments
fabioh8010 Sep 20, 2023
d60c00d
Improve some StyleUtils functions
fabioh8010 Sep 25, 2023
0f44880
Merge branch 'main' into ts/style/styles-refactor
fabioh8010 Sep 25, 2023
dfdf05f
Merge branch 'main' into ts/style/styles-refactor
fabioh8010 Sep 27, 2023
b9e14d7
Minor fix in theme files
fabioh8010 Sep 27, 2023
ad14917
Merge branch 'main' into ts/style/styles-refactor
fabioh8010 Sep 28, 2023
e381128
Merge branch 'main' into ts/style/styles-refactor
fabioh8010 Oct 2, 2023
bcd1a65
Minor fixes
fabioh8010 Oct 2, 2023
6005765
Fix findUnusedKeys to look for the correct styles file
fabioh8010 Oct 2, 2023
c0239e2
added a new condition to handle inner function with returning object …
gedu Oct 3, 2023
8ee979d
Merge pull request #1 from gedu/ts/style/styles-refactor
fabioh8010 Oct 3, 2023
b4f158e
Merge branch 'main' into ts/style/styles-refactor
fabioh8010 Oct 3, 2023
7188a33
Merge branch 'main' into ts/style/styles-refactor
fabioh8010 Oct 4, 2023
ce0c277
Merge branch 'main' into ts/style/styles-refactor
fabioh8010 Oct 5, 2023
f3fc5a5
Merge branch 'main' into ts/style/styles-refactor
kubabutkiewicz Oct 9, 2023
a8d62d0
fix: added proper color to receiptDropUIBG
kubabutkiewicz Oct 9, 2023
f4f6501
fix: lint and type errors
kubabutkiewicz Oct 9, 2023
a2914cd
fix: use theme colors instead of hardcoded
kubabutkiewicz Oct 10, 2023
76b7336
Merge branch 'main' into ts/style/styles-refactor
kubabutkiewicz Oct 11, 2023
2450338
Merge branch 'main' into ts/style/styles-refactor
kubabutkiewicz Oct 11, 2023
96e9ce7
fix: fix lottie type
kubabutkiewicz Oct 11, 2023
947f024
fix: lint problem
kubabutkiewicz Oct 11, 2023
94bb435
Merge branch 'main' of github.com:fabioh8010/expensify-app into ts/st…
kubabutkiewicz Oct 12, 2023
f9ed59f
fix: typo
kubabutkiewicz Oct 12, 2023
bfc8c1b
Merge branch 'main' of github.com:fabioh8010/expensify-app into ts/st…
kubabutkiewicz Oct 13, 2023
3477ee7
Merge branch 'main' of github.com:fabioh8010/expensify-app into ts/st…
kubabutkiewicz Oct 13, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions .github/scripts/findUnusedKeys.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ LIB_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")" && cd ../../ && pwd)"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you know what is the purpose of this file?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I understand its a script used in gh action for removing unused styles

readonly SRC_DIR="${LIB_PATH}/src"
readonly STYLES_DIR="${LIB_PATH}/src/styles"
readonly STYLES_FILE="${LIB_PATH}/src/styles/styles.js"
readonly STYLES_FILE="${LIB_PATH}/src/styles/styles.ts"
readonly UTILITIES_STYLES_FILE="${LIB_PATH}/src/styles/utilities"
readonly STYLES_KEYS_FILE="${LIB_PATH}/scripts/style_keys_list_temp.txt"
readonly UTILITY_STYLES_KEYS_FILE="${LIB_PATH}/scripts/utility_keys_list_temp.txt"
Expand Down Expand Up @@ -210,7 +210,12 @@ find_theme_style_and_store_keys() {
fi

# Check if we are inside an arrow function
if [[ "$line" =~ ^[[:space:]]*([a-zA-Z0-9_-])+:[[:space:]]*\(.*\)[[:space:]]*'=>'[[:space:]]*\(\{ || "$line" =~ ^[[:space:]]*(const|let|var)[[:space:]]+([a-zA-Z0-9_-]+)[[:space:]]*=[[:space:]]*\(.*\)[[:space:]]*'=>' ]]; then
if [[ "$line" =~ ^[[:space:]]*([a-zA-Zgv 0-9_-])+:[[:space:]]*\(.*\)[[:space:]]*'=>'[[:space:]]*\(\{ || "$line" =~ ^[[:space:]]*([a-zA-Zgv 0-9_-])+:[[:space:]]*\(.*\)[[:space:]]*'=>' ]]; then
inside_arrow_function=true
continue
fi

if [[ "$line" =~ ^[[:space:]]*(const|let|var)[[:space:]]+([a-zA-Z0-9_-]+)[[:space:]]*=[[:space:]]*\(.*\)[[:space:]]*'=>' ]]; then
inside_arrow_function=true
continue
fi
Expand Down Expand Up @@ -348,7 +353,7 @@ echo "🔍 Looking for styles."
find_utility_styles_store_prefix
find_utility_usage_as_styles

# Find and store keys from styles.js
# Find and store keys from styles.ts
find_styles_object_and_store_keys "$STYLES_FILE"
find_styles_functions_and_store_keys "$STYLES_FILE"
collect_theme_keys_from_styles "$STYLES_FILE"
Expand Down
3 changes: 1 addition & 2 deletions src/components/SelectionList/BaseSelectionList.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import Log from '../../libs/Log';
import OptionsListSkeletonView from '../OptionsListSkeletonView';
import useActiveElement from '../../hooks/useActiveElement';
import BaseListItem from './BaseListItem';
import themeColors from '../../styles/themes/default';
import ArrowKeyFocusManager from '../ArrowKeyFocusManager';

const propTypes = {
Expand Down Expand Up @@ -424,7 +423,7 @@ function BaseSelectionList({
onScrollBeginDrag={onScrollBeginDrag}
keyExtractor={(item) => item.keyForList}
extraData={focusedIndex}
indicatorStyle={themeColors.selectionListIndicatorColor}
indicatorStyle="white"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why did you hard code the color?

keyboardShouldPersistTaps="always"
showsVerticalScrollIndicator={showScrollIndicator}
initialNumToRender={12}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import UpdateNumberOfLines from './types';
* divide by line height to get the total number of rows for the textarea.
*/
const updateNumberOfLines: UpdateNumberOfLines = (props, event) => {
const lineHeight = styles.textInputCompose.lineHeight;
const lineHeight = styles.textInputCompose.lineHeight ?? 0;
const paddingTopAndBottom = styles.textInputComposeSpacing.paddingVertical * 2;
const inputHeight = event?.nativeEvent?.contentSize?.height ?? null;
if (!inputHeight) {
Expand Down
339 changes: 176 additions & 163 deletions src/styles/StyleUtils.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/styles/ThemeStylesProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import ThemeStylesContext from './ThemeStylesContext';
// TODO: Rename this to "styles" once the app is migrated to theme switching hooks and HOCs
import {stylesGenerator as stylesUntyped} from './styles';

const styles = stylesUntyped as (theme: Record<string, string>) => Record<string, unknown>;
const styles = stylesUntyped;

type ThemeStylesProviderProps = {
children: React.ReactNode;
Expand Down
4 changes: 2 additions & 2 deletions src/styles/addOutlineWidth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import AddOutlineWidth from './types';
/**
* Adds the addOutlineWidth property to an object to be used when styling
*/
const addOutlineWidth: AddOutlineWidth = (obj, val, error = false) => ({
const addOutlineWidth: AddOutlineWidth = (obj, val, hasError = false) => ({
...obj,
outlineWidth: val,
outlineStyle: val ? 'auto' : 'none',
boxShadow: val !== 0 ? `0px 0px 0px ${val}px ${error ? themeDefault.danger : themeDefault.borderFocus}` : 'none',
boxShadow: val !== 0 ? `0px 0px 0px ${val}px ${hasError ? themeDefault.danger : themeDefault.borderFocus}` : 'none',
});

export default addOutlineWidth;
3 changes: 1 addition & 2 deletions src/styles/addOutlineWidth/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {CSSProperties} from 'react';
import {TextStyle} from 'react-native';

type AddOutlineWidth = (obj: TextStyle | CSSProperties, val?: number, error?: boolean) => TextStyle | CSSProperties;
type AddOutlineWidth = (obj: TextStyle, val?: number, hasError?: boolean) => TextStyle;

export default AddOutlineWidth;
3 changes: 2 additions & 1 deletion src/styles/cardStyles/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import positioning from '../utilities/positioning';
import GetCardStyles from './types';

/**
* Get card style for cardStyleInterpolator
*/
const getCardStyles: GetCardStyles = (screenWidth) => ({
position: 'fixed',
...positioning.pFixed,
width: screenWidth,
height: '100%',
});
Expand Down
3 changes: 1 addition & 2 deletions src/styles/cardStyles/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {CSSProperties} from 'react';
import {ViewStyle} from 'react-native';

type GetCardStyles = (screenWidth: number) => Partial<Pick<CSSProperties | ViewStyle, 'position' | 'width' | 'height'>>;
type GetCardStyles = (screenWidth: number) => ViewStyle;

export default GetCardStyles;
9 changes: 4 additions & 5 deletions src/styles/codeStyles/types.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import {CSSProperties} from 'react';
import {TextStyle, ViewStyle} from 'react-native';

type CodeWordWrapperStyles = ViewStyle | CSSProperties;
type CodeWordStyles = TextStyle | CSSProperties;
type CodeTextStyles = TextStyle | CSSProperties;
type CodeWordWrapperStyles = ViewStyle;
type CodeWordStyles = TextStyle;
type CodeTextStyles = TextStyle;

export type {CodeWordWrapperStyles, CodeWordStyles, CodeTextStyles};
export type {CodeTextStyles, CodeWordStyles, CodeWordWrapperStyles};
4 changes: 2 additions & 2 deletions src/styles/containerComposeStyles/index.native.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {StyleProp, ViewStyle} from 'react-native';
import styles from '../styles';
import ContainerComposeStyles from './types';

const containerComposeStyles: StyleProp<ViewStyle> = [styles.textInputComposeSpacing];
const containerComposeStyles: ContainerComposeStyles = [styles.textInputComposeSpacing];

export default containerComposeStyles;
4 changes: 2 additions & 2 deletions src/styles/containerComposeStyles/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {StyleProp, ViewStyle} from 'react-native';
import styles from '../styles';
import ContainerComposeStyles from './types';

// We need to set paddingVertical = 0 on web to avoid displaying a normal pointer on some parts of compose box when not in focus
const containerComposeStyles: StyleProp<ViewStyle> = [styles.textInputComposeSpacing, {paddingVertical: 0}];
const containerComposeStyles: ContainerComposeStyles = [styles.textInputComposeSpacing, {paddingVertical: 0}];

export default containerComposeStyles;
5 changes: 5 additions & 0 deletions src/styles/containerComposeStyles/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import {ViewStyle} from 'react-native';

type ContainerComposeStyles = ViewStyle[];

export default ContainerComposeStyles;
7 changes: 5 additions & 2 deletions src/styles/editedLabelStyles/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import EditedLabelStyles from './types';
import display from '../utilities/display';
import flex from '../utilities/flex';
import EditedLabelStyles from './types';

const editedLabelStyles: EditedLabelStyles = {...display.dInlineFlex, ...flex.alignItemsBaseline};
const editedLabelStyles: EditedLabelStyles = {
...display.dInlineFlex,
...flex.alignItemsBaseline,
};

export default editedLabelStyles;
3 changes: 1 addition & 2 deletions src/styles/editedLabelStyles/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {CSSProperties} from 'react';
import {TextStyle} from 'react-native';

type EditedLabelStyles = CSSProperties | TextStyle;
type EditedLabelStyles = TextStyle;

export default EditedLabelStyles;
3 changes: 0 additions & 3 deletions src/styles/fontFamily/bold/index.android.js

This file was deleted.

5 changes: 5 additions & 0 deletions src/styles/fontFamily/bold/index.android.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import FontFamilyBoldStyles from './types';

const bold: FontFamilyBoldStyles = 'ExpensifyNeue-Bold';

export default bold;
3 changes: 0 additions & 3 deletions src/styles/fontFamily/bold/index.ios.js

This file was deleted.

5 changes: 5 additions & 0 deletions src/styles/fontFamily/bold/index.ios.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import FontFamilyBoldStyles from './types';

const bold: FontFamilyBoldStyles = 'ExpensifyNeue-Regular';

export default bold;
3 changes: 0 additions & 3 deletions src/styles/fontFamily/bold/index.js

This file was deleted.

5 changes: 5 additions & 0 deletions src/styles/fontFamily/bold/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import FontFamilyBoldStyles from './types';

const bold: FontFamilyBoldStyles = 'ExpensifyNeue-Regular, Segoe UI Emoji, Noto Color Emoji';

export default bold;
5 changes: 5 additions & 0 deletions src/styles/fontFamily/bold/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import {TextStyle} from 'react-native';

type FontFamilyBoldStyles = NonNullable<TextStyle['fontFamily']>;

export default FontFamilyBoldStyles;
4 changes: 3 additions & 1 deletion src/styles/fontFamily/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import {TextStyle} from 'react-native';

type FontFamilyKeys =
| 'EXP_NEUE_ITALIC'
| 'EXP_NEUE_BOLD'
Expand All @@ -10,6 +12,6 @@ type FontFamilyKeys =
| 'MONOSPACE_BOLD'
| 'MONOSPACE_BOLD_ITALIC';

type FontFamilyStyles = Record<FontFamilyKeys, string>;
type FontFamilyStyles = Record<FontFamilyKeys, NonNullable<TextStyle['fontFamily']>>;

export default FontFamilyStyles;
3 changes: 1 addition & 2 deletions src/styles/fontWeight/bold/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {CSSProperties} from 'react';
import {TextStyle} from 'react-native';

type FontWeightBoldStyles = (TextStyle | CSSProperties)['fontWeight'];
type FontWeightBoldStyles = NonNullable<TextStyle['fontWeight']>;

export default FontWeightBoldStyles;
15 changes: 8 additions & 7 deletions src/styles/getModalStyles.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import {CSSProperties} from 'react';
import {ViewStyle} from 'react-native';
import {ValueOf} from 'type-fest';
import {ModalProps} from 'react-native-modal';
import {ValueOf} from 'type-fest';
import CONST from '../CONST';
import variables from './variables';
import themeColors from './themes/default';
import styles from './styles';
import themeColors from './themes/default';
import variables from './variables';

function getCenteredModalStyles(windowWidth: number, isSmallScreenWidth: boolean, isFullScreenWhenSmall = false): ViewStyle {
const modalStyles = styles.centeredModalStyles(isSmallScreenWidth, isFullScreenWhenSmall);

return {
borderWidth: styles.centeredModalStyles(isSmallScreenWidth, isFullScreenWhenSmall).borderWidth,
width: isSmallScreenWidth ? '100%' : windowWidth - styles.centeredModalStyles(isSmallScreenWidth, isFullScreenWhenSmall).marginHorizontal * 2,
borderWidth: modalStyles.borderWidth,
width: isSmallScreenWidth ? '100%' : windowWidth - modalStyles.marginHorizontal * 2,
};
}

Expand All @@ -26,7 +27,7 @@ type WindowDimensions = {

type GetModalStyles = {
modalStyle: ViewStyle;
modalContainerStyle: ViewStyle | Pick<CSSProperties, 'boxShadow'>;
modalContainerStyle: ViewStyle;
swipeDirection: ModalProps['swipeDirection'];
animationIn: ModalProps['animationIn'];
animationOut: ModalProps['animationOut'];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
export default () => ({
import positioning from '../utilities/positioning';
import GetNavigationModalCardStyles from './types';

const getNavigationModalCardStyles: GetNavigationModalCardStyles = () => ({
// position: fixed is set instead of position absolute to workaround Safari known issues of updating heights in DOM.
// Safari issues:
// https://github.com/Expensify/App/issues/12005
// https://github.com/Expensify/App/issues/17824
// https://github.com/Expensify/App/issues/20709
width: '100%',
height: '100%',
position: 'fixed',

...positioning.pFixed,
});

export default getNavigationModalCardStyles;
6 changes: 5 additions & 1 deletion src/styles/getNavigationModalCardStyles/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
export default () => ({
import GetNavigationModalCardStyles from './types';

const getNavigationModalCardStyles: GetNavigationModalCardStyles = () => ({
height: '100%',
});

export default getNavigationModalCardStyles;
4 changes: 3 additions & 1 deletion src/styles/getNavigationModalCardStyles/index.website.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import positioning from '../utilities/positioning';
import GetNavigationModalCardStyles from './types';

const getNavigationModalCardStyles: GetNavigationModalCardStyles = () => ({
Expand All @@ -8,7 +9,8 @@ const getNavigationModalCardStyles: GetNavigationModalCardStyles = () => ({
// https://github.com/Expensify/App/issues/20709
width: '100%',
height: '100%',
position: 'fixed',

...positioning.pFixed,
});

export default getNavigationModalCardStyles;
4 changes: 1 addition & 3 deletions src/styles/getNavigationModalCardStyles/types.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import {CSSProperties} from 'react';
import {ViewStyle} from 'react-native';
import {Merge} from 'type-fest';

type GetNavigationModalCardStylesParams = {isSmallScreenWidth: number};

type GetNavigationModalCardStyles = (params: GetNavigationModalCardStylesParams) => Merge<ViewStyle, Pick<CSSProperties, 'position'>>;
type GetNavigationModalCardStyles = (params: GetNavigationModalCardStylesParams) => ViewStyle;

export default GetNavigationModalCardStyles;
16 changes: 7 additions & 9 deletions src/styles/getReportActionContextMenuStyles.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,34 @@
import {CSSProperties} from 'react';
import {ViewStyle} from 'react-native';
import styles from './styles';
import variables from './variables';
import themeColors from './themes/default';
import variables from './variables';

type StylesArray = Array<ViewStyle | CSSProperties>;

const defaultWrapperStyle: ViewStyle | CSSProperties = {
const defaultWrapperStyle: ViewStyle = {
backgroundColor: themeColors.componentBG,
};

const miniWrapperStyle: StylesArray = [
const miniWrapperStyle: ViewStyle[] = [
styles.flexRow,
defaultWrapperStyle,
{
borderRadius: variables.buttonBorderRadius,
borderWidth: 1,
borderColor: themeColors.border,
// In Safari, when welcome messages use a code block (triple backticks), they would overlap the context menu below when there is no scrollbar without the transform style.
transform: 'translateZ(0)',
// NOTE: asserting "transform" to a valid type, because it isn't possible to augment "transform".
transform: 'translateZ(0)' as unknown as ViewStyle['transform'],
},
];

const bigWrapperStyle: StylesArray = [styles.flexColumn, defaultWrapperStyle];
const bigWrapperStyle: ViewStyle[] = [styles.flexColumn, defaultWrapperStyle];

/**
* Generate the wrapper styles for the ReportActionContextMenu.
*
* @param isMini
* @param isSmallScreenWidth
*/
function getReportActionContextMenuStyles(isMini: boolean, isSmallScreenWidth: boolean): StylesArray {
function getReportActionContextMenuStyles(isMini: boolean, isSmallScreenWidth: boolean): ViewStyle[] {
if (isMini) {
return miniWrapperStyle;
}
Expand Down
Loading