Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 3 additions & 2 deletions src/components/Composer/implementation/index.native.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import {containsOnlyEmojis} from '@libs/EmojiUtils';
import {splitExtensionFromFileName} from '@libs/fileDownload/FileUtils';
import Parser from '@libs/Parser';
import type {FileObject} from '@pages/media/AttachmentModalScreen/types';
import CONST from '@src/CONST';

Expand All @@ -38,9 +39,9 @@ function Composer(
ref: ForwardedRef<TextInput>,
) {
const textInput = useRef<AnimatedMarkdownTextInputRef | null>(null);
const textContainsOnlyEmojis = useMemo(() => containsOnlyEmojis(value ?? ''), [value]);
const textContainsOnlyEmojis = useMemo(() => containsOnlyEmojis(Parser.htmlToText(Parser.replace(value ?? ''))), [value]);
const theme = useTheme();
const markdownStyle = useMarkdownStyle(value, !isGroupPolicyReport ? excludeReportMentionStyle : excludeNoStyles);
const markdownStyle = useMarkdownStyle(textContainsOnlyEmojis, !isGroupPolicyReport ? excludeReportMentionStyle : excludeNoStyles);
const styles = useThemeStyles();
const StyleUtils = useStyleUtils();

Expand Down
5 changes: 3 additions & 2 deletions src/components/Composer/implementation/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {isMobileSafari, isSafari} from '@libs/Browser';
import {containsOnlyEmojis} from '@libs/EmojiUtils';
import {base64ToFile} from '@libs/fileDownload/FileUtils';
import isEnterWhileComposition from '@libs/KeyboardShortcut/isEnterWhileComposition';
import Parser from '@libs/Parser';
import CONST from '@src/CONST';

const excludeNoStyles: Array<keyof MarkdownStyle> = [];
Expand Down Expand Up @@ -54,10 +55,10 @@ function Composer(
}: ComposerProps,
ref: ForwardedRef<TextInput | HTMLInputElement>,
) {
const textContainsOnlyEmojis = useMemo(() => containsOnlyEmojis(value ?? ''), [value]);
const textContainsOnlyEmojis = useMemo(() => containsOnlyEmojis(Parser.htmlToText(Parser.replace(value ?? ''))), [value]);
const theme = useTheme();
const styles = useThemeStyles();
const markdownStyle = useMarkdownStyle(value, !isGroupPolicyReport ? excludeReportMentionStyle : excludeNoStyles);
const markdownStyle = useMarkdownStyle(textContainsOnlyEmojis, !isGroupPolicyReport ? excludeReportMentionStyle : excludeNoStyles);
const StyleUtils = useStyleUtils();
const textInput = useRef<AnimatedMarkdownTextInputRef | null>(null);
const [selection, setSelection] = useState<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ function BaseTextInput(
const inputProps = {shouldSaveDraft: false, shouldUseDefaultValue: false, ...props};
const theme = useTheme();
const styles = useThemeStyles();
const markdownStyle = useMarkdownStyle(undefined, excludedMarkdownStyles);
const markdownStyle = useMarkdownStyle(false, excludedMarkdownStyles);
const StyleUtils = useStyleUtils();
const {translate} = useLocalize();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Str} from 'expensify-common';
import type {ForwardedRef, MutableRefObject} from 'react';
import type {ForwardedRef, RefObject} from 'react';
import React, {forwardRef, useCallback, useEffect, useRef, useState} from 'react';
import type {GestureResponderEvent, LayoutChangeEvent, NativeSyntheticEvent, StyleProp, TextInput, TextInputFocusEventData, ViewStyle} from 'react-native';
import {ActivityIndicator, StyleSheet, View} from 'react-native';
Expand Down Expand Up @@ -89,7 +89,7 @@ function BaseTextInput(

const theme = useTheme();
const styles = useThemeStyles();
const markdownStyle = useMarkdownStyle(undefined, excludedMarkdownStyles);
const markdownStyle = useMarkdownStyle(false, excludedMarkdownStyles);
const {hasError = false} = inputProps;
const StyleUtils = useStyleUtils();
const {translate} = useLocalize();
Expand All @@ -114,7 +114,7 @@ function BaseTextInput(
const isLabelActive = useRef(initialActiveLabel);
const didScrollToEndRef = useRef(false);

useHtmlPaste(input as MutableRefObject<TextInput | null>, undefined, isMarkdownEnabled);
useHtmlPaste(input as RefObject<TextInput | null>, undefined, isMarkdownEnabled);

// AutoFocus which only works on mount:
useEffect(() => {
Expand Down
4 changes: 1 addition & 3 deletions src/hooks/useMarkdownStyle.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import type {MarkdownStyle} from '@expensify/react-native-live-markdown';
import {useMemo} from 'react';
import {containsOnlyEmojis} from '@libs/EmojiUtils';
import FontUtils from '@styles/utils/FontUtils';
import variables from '@styles/variables';
import useTheme from './useTheme';

const defaultEmptyArray: Array<keyof MarkdownStyle> = [];

function useMarkdownStyle(message: string | null = null, excludeStyles: Array<keyof MarkdownStyle> = defaultEmptyArray): MarkdownStyle {
function useMarkdownStyle(hasMessageOnlyEmojis: boolean, excludeStyles: Array<keyof MarkdownStyle> = defaultEmptyArray): MarkdownStyle {
const theme = useTheme();
const hasMessageOnlyEmojis = message != null && message.length > 0 && containsOnlyEmojis(message);
const emojiFontSize = hasMessageOnlyEmojis ? variables.fontSizeOnlyEmojis : variables.fontSizeEmojisWithinText;

// this map is used to reset the styles that are not needed - passing undefined value can break the native side
Expand Down
46 changes: 46 additions & 0 deletions tests/ui/ComposerTest.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import {render} from '@testing-library/react-native';
import Onyx from 'react-native-onyx';
import Composer from '@components/Composer';
import OnyxProvider from '@components/OnyxProvider';
import RNMarkdownTextInput from '@components/RNMarkdownTextInput';
import variables from '@styles/variables';
import ONYXKEYS from '@src/ONYXKEYS';
import waitForBatchedUpdates from '../utils/waitForBatchedUpdates';

jest.mock('@components/RNMarkdownTextInput', () => {
return jest.fn().mockImplementation(() => null);
});

describe('Composer', () => {
beforeAll(() => {
Onyx.init({
keys: ONYXKEYS,
evictableKeys: [ONYXKEYS.COLLECTION.REPORT_ACTIONS],
});
});

afterEach(async () => {
await Onyx.clear();
});

it('should show large emoji size if only has header markdown + emoji', async () => {
render(
<OnyxProvider>
<Composer value="# 😄" />
</OnyxProvider>,
);

await waitForBatchedUpdates();

const props = (RNMarkdownTextInput as jest.MockedFunction<typeof RNMarkdownTextInput>).mock.calls.at(0)?.at(0);
expect(props).toEqual(
expect.objectContaining({
markdownStyle: expect.objectContaining({
emoji: expect.objectContaining({
fontSize: variables.fontSizeOnlyEmojis,
}),
}),
}),
);
});
});