Skip to content

Commit 731cab1

Browse files
authored
Merge pull request #53367 from daledah/fix/52681
2 parents c049ac7 + 5252494 commit 731cab1

File tree

4 files changed

+13
-4
lines changed

4 files changed

+13
-4
lines changed

src/components/TextInput/BaseTextInput/index.native.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import Text from '@components/Text';
1616
import * as styleConst from '@components/TextInput/styleConst';
1717
import TextInputClearButton from '@components/TextInput/TextInputClearButton';
1818
import TextInputLabel from '@components/TextInput/TextInputLabel';
19+
import useHtmlPaste from '@hooks/useHtmlPaste';
1920
import useLocalize from '@hooks/useLocalize';
2021
import useMarkdownStyle from '@hooks/useMarkdownStyle';
2122
import useStyleUtils from '@hooks/useStyleUtils';
@@ -98,6 +99,7 @@ function BaseTextInput(
9899
const labelTranslateY = useRef(new Animated.Value(initialActiveLabel ? styleConst.ACTIVE_LABEL_TRANSLATE_Y : styleConst.INACTIVE_LABEL_TRANSLATE_Y)).current;
99100
const input = useRef<TextInput | null>(null);
100101
const isLabelActive = useRef(initialActiveLabel);
102+
useHtmlPaste(input, undefined, false, isMarkdownEnabled);
101103

102104
// AutoFocus which only works on mount:
103105
useEffect(() => {

src/components/TextInput/BaseTextInput/index.tsx

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {Str} from 'expensify-common';
2-
import type {ForwardedRef} from 'react';
2+
import type {ForwardedRef, MutableRefObject} from 'react';
33
import React, {forwardRef, useCallback, useEffect, useMemo, useRef, useState} from 'react';
4-
import type {GestureResponderEvent, LayoutChangeEvent, NativeSyntheticEvent, StyleProp, TextInputFocusEventData, ViewStyle} from 'react-native';
4+
import type {GestureResponderEvent, LayoutChangeEvent, NativeSyntheticEvent, StyleProp, TextInput, TextInputFocusEventData, ViewStyle} from 'react-native';
55
import {ActivityIndicator, Animated, StyleSheet, View} from 'react-native';
66
import Checkbox from '@components/Checkbox';
77
import FormHelpMessage from '@components/FormHelpMessage';
@@ -17,6 +17,7 @@ import Text from '@components/Text';
1717
import * as styleConst from '@components/TextInput/styleConst';
1818
import TextInputClearButton from '@components/TextInput/TextInputClearButton';
1919
import TextInputLabel from '@components/TextInput/TextInputLabel';
20+
import useHtmlPaste from '@hooks/useHtmlPaste';
2021
import useLocalize from '@hooks/useLocalize';
2122
import useMarkdownStyle from '@hooks/useMarkdownStyle';
2223
import useStyleUtils from '@hooks/useStyleUtils';
@@ -103,6 +104,7 @@ function BaseTextInput(
103104
const labelTranslateY = useRef(new Animated.Value(initialActiveLabel ? styleConst.ACTIVE_LABEL_TRANSLATE_Y : styleConst.INACTIVE_LABEL_TRANSLATE_Y)).current;
104105
const input = useRef<HTMLInputElement | null>(null);
105106
const isLabelActive = useRef(initialActiveLabel);
107+
useHtmlPaste(input as MutableRefObject<TextInput | null>, undefined, false, isMarkdownEnabled);
106108

107109
// AutoFocus which only works on mount:
108110
useEffect(() => {

src/hooks/useHtmlPaste/index.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import Parser from '@libs/Parser';
44
import type UseHtmlPaste from './types';
55

66
const insertByCommand = (text: string) => {
7+
// eslint-disable-next-line deprecation/deprecation
78
document.execCommand('insertText', false, text);
89
};
910

@@ -27,7 +28,7 @@ const insertAtCaret = (target: HTMLElement, text: string) => {
2728
}
2829
};
2930

30-
const useHtmlPaste: UseHtmlPaste = (textInputRef, preHtmlPasteCallback, removeListenerOnScreenBlur = false) => {
31+
const useHtmlPaste: UseHtmlPaste = (textInputRef, preHtmlPasteCallback, removeListenerOnScreenBlur = false, isMarkdownEnabled = true) => {
3132
const navigation = useNavigation();
3233

3334
/**
@@ -129,6 +130,9 @@ const useHtmlPaste: UseHtmlPaste = (textInputRef, preHtmlPasteCallback, removeLi
129130
);
130131

131132
useEffect(() => {
133+
if (!isMarkdownEnabled) {
134+
return;
135+
}
132136
// we need to re-register listener on navigation focus/blur if the component (like Composer) is not unmounting
133137
// when navigating away to different screen (report) to avoid paste event on other screen being wrongly handled
134138
// by current screen paste listener
@@ -149,7 +153,7 @@ const useHtmlPaste: UseHtmlPaste = (textInputRef, preHtmlPasteCallback, removeLi
149153
document.removeEventListener('paste', handlePaste, true);
150154
};
151155
// eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps
152-
}, []);
156+
}, [isMarkdownEnabled]);
153157
};
154158

155159
export default useHtmlPaste;

src/hooks/useHtmlPaste/types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ type UseHtmlPaste = (
55
textInputRef: MutableRefObject<(HTMLTextAreaElement & TextInput) | TextInput | null>,
66
preHtmlPasteCallback?: (event: ClipboardEvent) => boolean,
77
removeListenerOnScreenBlur?: boolean,
8+
isMarkdownEnabled?: boolean,
89
) => void;
910

1011
export default UseHtmlPaste;

0 commit comments

Comments
 (0)