Skip to content

Commit

Permalink
rebase wip
Browse files Browse the repository at this point in the history
  • Loading branch information
kbieganowski committed May 16, 2024
1 parent ee38c51 commit 0208efe
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 13 deletions.
3 changes: 2 additions & 1 deletion src/components/Composer/index.native.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import updateIsFullComposerAvailable from '@libs/ComposerUtils/updateIsFullComposerAvailable';
import {containsOnlyEmojis} from '@libs/EmojiUtils';
import variables from '@styles/variables';
import type {ComposerProps} from './types';

function Composer(
Expand Down Expand Up @@ -68,7 +69,7 @@ function Composer(
}, [shouldClear, onClear]);

const maxHeightStyle = useMemo(() => StyleUtils.getComposerMaxHeightStyle(maxLines, isComposerFullSize), [StyleUtils, isComposerFullSize, maxLines]);
const composerStyle = useMemo(() => StyleSheet.flatten([style, textContainsOnlyEmojis ? {lineHeight: 32} : null]), [style, textContainsOnlyEmojis]);
const composerStyle = useMemo(() => StyleSheet.flatten([style, textContainsOnlyEmojis ? {lineHeight: variables.lineHeightEmojisOnlyComposer} : null]), [style, textContainsOnlyEmojis]);

return (
<RNMarkdownTextInput
Expand Down
3 changes: 2 additions & 1 deletion src/components/InlineCodeBlock/WrappedText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ function getTextMatrix(text: string): string[][] {
* Validates if the text contains any emoji
*/
function containsEmoji(text: string): boolean {
return CONST.REGEX.EMOJIS.test(text);
const emojisRegex = new RegExp(CONST.REGEX.EMOJIS, CONST.REGEX.EMOJIS.flags.concat('g'));
return emojisRegex.test(text);
}

function WrappedText({children, wordStyles, textStyles}: WrappedTextProps) {
Expand Down
2 changes: 1 addition & 1 deletion src/components/TextInput/BaseTextInput/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ function BaseTextInput(
// Add disabled color theme when field is not editable.
inputProps.disabled && styles.textInputDisabled,
styles.pointerEventsAuto,
isMarkdownEnabled ? {lineHeight: 18} : null,
isMarkdownEnabled ? {lineHeight: variables.lineHeightMarkdownEnabledInput} : null,
]}
multiline={isMultiline}
maxLength={maxLength}
Expand Down
6 changes: 3 additions & 3 deletions src/hooks/useMarkdownStyle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import FontUtils from '@styles/utils/FontUtils';
import variables from '@styles/variables';
import useTheme from './useTheme';

function useMarkdownStyle(containsEmojisOnly?: boolean, excludeStyles: Array<keyof MarkdownStyle> = []): MarkdownStyle {
function useMarkdownStyle(inputContainsOnlyEmojis?: boolean, excludeStyles: Array<keyof MarkdownStyle> = []): MarkdownStyle {
const theme = useTheme();

// this map is used to reset the styles that are not needed - passing undefined value can break the native side
Expand Down Expand Up @@ -32,7 +32,7 @@ function useMarkdownStyle(containsEmojisOnly?: boolean, excludeStyles: Array<key
fontSize: variables.fontSizeLarge,
},
emoji: {
fontSize: containsEmojisOnly ? 27 : 19,
fontSize: inputContainsOnlyEmojis ? variables.fontSizeEmojisOnlyComposer : variables.fontSizeEmojisWithinText,
},
blockquote: {
borderColor: theme.border,
Expand Down Expand Up @@ -78,7 +78,7 @@ function useMarkdownStyle(containsEmojisOnly?: boolean, excludeStyles: Array<key
}

return styling;
}, [theme, containsEmojisOnly, excludeStyles, nonStylingDefaultValues]);
}, [theme, inputContainsOnlyEmojis, excludeStyles, nonStylingDefaultValues]);

return markdownStyle;
}
Expand Down
6 changes: 4 additions & 2 deletions src/libs/EmojiUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ function trimEmojiUnicode(emojiCode: string): string {
*/
function isFirstLetterEmoji(message: string): boolean {
const trimmedMessage = Str.replaceAll(message.replace(/ /g, ''), '\n', '');
const match = trimmedMessage.match(CONST.REGEX.EMOJIS);
const emojisRegex = new RegExp(CONST.REGEX.EMOJIS, CONST.REGEX.EMOJIS.flags.concat('g'));
const match = trimmedMessage.match(emojisRegex);

if (!match) {
return false;
Expand Down Expand Up @@ -269,7 +270,8 @@ function extractEmojis(text: string): Emoji[] {
}

// Parse Emojis including skin tones - Eg: ['👩🏻', '👩🏻', '👩🏼', '👩🏻', '👩🏼', '👩']
const parsedEmojis = text.match(CONST.REGEX.EMOJIS);
const emojisRegex = new RegExp(CONST.REGEX.EMOJIS, CONST.REGEX.EMOJIS.flags.concat('g'));
const parsedEmojis = text.match(emojisRegex);

if (!parsedEmojis) {
return [];
Expand Down
7 changes: 5 additions & 2 deletions src/libs/ValidationUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ function isValidAddress(value: FormValue): boolean {
return false;
}

if (!CONST.REGEX.ANY_VALUE.test(value) || value.match(CONST.REGEX.EMOJIS)) {
const emojisRegex = new RegExp(CONST.REGEX.EMOJIS, CONST.REGEX.EMOJIS.flags.concat('g'));

if (!CONST.REGEX.ANY_VALUE.test(value) || value.match(emojisRegex)) {
return false;
}

Expand Down Expand Up @@ -333,7 +335,8 @@ function isValidRoutingNumber(routingNumber: string): boolean {
* Checks that the provided name doesn't contain any emojis
*/
function isValidCompanyName(name: string) {
return !name.match(CONST.REGEX.EMOJIS);
const emojisRegex = new RegExp(CONST.REGEX.EMOJIS, CONST.REGEX.EMOJIS.flags.concat('g'));
return !name.match(emojisRegex);
}

function isValidReportName(name: string) {
Expand Down
14 changes: 11 additions & 3 deletions src/pages/home/report/comment/TextWithEmojiFragment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,24 @@ import {splitTextWithEmojis} from '@libs/EmojiUtils';
import variables from '@styles/variables';
import CONST from '@src/CONST';

type ComponentProps = {
type TextWithEmojiFragmentProps = {
/** The message to be displayed */
message: string;
passedStyles: StyleProp<TextStyle>;
/** Additional styles to add after local styles. */
passedStyles?: StyleProp<TextStyle>;
/** Should this message fragment be styled as deleted? */
styleAsDeleted?: boolean;
/** Should this message fragment be styled as muted? */
styleAsMuted?: boolean;
/** Is message displayed on narrow screen? */
isSmallScreenWidth?: boolean;
/** Should "(edited)" suffix be rendered? */
isEdited?: boolean;
/** Does message contain only emojis? */
emojisOnly?: boolean;
};
function TextWithEmojiFragment({message, passedStyles, styleAsDeleted, styleAsMuted, isSmallScreenWidth, isEdited, emojisOnly}: ComponentProps) {

function TextWithEmojiFragment({message, passedStyles, styleAsDeleted, styleAsMuted, isSmallScreenWidth, isEdited, emojisOnly}: TextWithEmojiFragmentProps) {
const styles = useThemeStyles();
const {translate} = useLocalize();
const theme = useTheme();
Expand Down
3 changes: 3 additions & 0 deletions src/styles/variables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export default {
fontSizeOnlyEmojis: 30,
fontSizeOnlyEmojisHeight: 35,
fontSizeEmojisWithinText: 19,
fontSizeEmojisOnlyComposer: 27,
fontSizeSmall: getValueUsingPixelRatio(11, 17),
fontSizeExtraSmall: 9,
fontSizeLabel: getValueUsingPixelRatio(13, 19),
Expand Down Expand Up @@ -115,6 +116,8 @@ export default {
lineHeightSizeh2: getValueUsingPixelRatio(24, 28),
lineHeightSignInHeroXSmall: getValueUsingPixelRatio(32, 37),
lineHeightComment: 23,
lineHeightMarkdownEnabledInput: 18,
lineHeightEmojisOnlyComposer: 32,
inputHeight: getValueUsingPixelRatio(52, 72),
inputHeightSmall: 28,
formErrorLineHeight: getValueUsingPixelRatio(18, 23),
Expand Down

0 comments on commit 0208efe

Please sign in to comment.