Skip to content

Commit

Permalink
Merge pull request Expensify#32801 from tienifr/fix/31427
Browse files Browse the repository at this point in the history
Fix: Text in code block not vertically centered
  • Loading branch information
robertjchen authored Dec 29, 2023
2 parents f508a90 + 02b9460 commit d34b673
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 4 deletions.
9 changes: 8 additions & 1 deletion src/components/InlineCodeBlock/WrappedText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ function getTextMatrix(text: string): string[][] {
return text.split('\n').map((row) => row.split(CONST.REGEX.SPACE_OR_EMOJI).filter((value) => value !== ''));
}

/**
* Validates if the text contains any emoji
*/
function containsEmoji(text: string): boolean {
return CONST.REGEX.EMOJI.test(text);
}

function WrappedText({children, wordStyles, textStyles}: WrappedTextProps) {
const styles = useThemeStyles();

Expand All @@ -53,7 +60,7 @@ function WrappedText({children, wordStyles, textStyles}: WrappedTextProps) {
style={styles.codeWordWrapper}
>
<View style={[wordStyles, colIndex === 0 && styles.codeFirstWordStyle, colIndex === rowText.length - 1 && styles.codeLastWordStyle]}>
<Text style={textStyles}>{colText}</Text>
<Text style={[textStyles, !containsEmoji(colText) && styles.codePlainTextStyle]}>{colText}</Text>
</View>
</View>
))}
Expand Down
4 changes: 4 additions & 0 deletions src/styles/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2769,6 +2769,10 @@ const styles = (theme: ThemeColors) =>
paddingRight: 5,
},

codePlainTextStyle: {
...codeStyles.codePlainTextStyle,
},

fullScreenLoading: {
backgroundColor: theme.componentBG,
opacity: 0.8,
Expand Down
6 changes: 5 additions & 1 deletion src/styles/utils/codeStyles/index.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,8 @@ const codeTextStyle: CodeTextStyles = {
lineHeight: 15,
};

export default {codeWordWrapper, codeWordStyle, codeTextStyle};
const codePlainTextStyle: CodeTextStyles = {
lineHeight: 14.5,
};

export default {codeWordWrapper, codeWordStyle, codeTextStyle, codePlainTextStyle};
6 changes: 5 additions & 1 deletion src/styles/utils/codeStyles/index.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,8 @@ const codeTextStyle: CodeTextStyles = {
lineHeight: 18,
};

export default {codeWordWrapper, codeWordStyle, codeTextStyle};
const codePlainTextStyle: CodeTextStyles = {
lineHeight: 15,
};

export default {codeWordWrapper, codeWordStyle, codeTextStyle, codePlainTextStyle};
3 changes: 2 additions & 1 deletion src/styles/utils/codeStyles/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ import {CodeTextStyles, CodeWordStyles, CodeWordWrapperStyles} from './types';
const codeWordWrapper: CodeWordWrapperStyles = {};
const codeWordStyle: CodeWordStyles = {};
const codeTextStyle: CodeTextStyles = {};
export default {codeWordWrapper, codeWordStyle, codeTextStyle};
const codePlainTextStyle: CodeTextStyles = {};
export default {codeWordWrapper, codeWordStyle, codeTextStyle, codePlainTextStyle};

0 comments on commit d34b673

Please sign in to comment.