Skip to content

Commit

Permalink
Merge pull request #53675 from Expensify/revert-53367-fix/52681
Browse files Browse the repository at this point in the history
Revert "fix: enable paste html in compose box"
  • Loading branch information
srikarparsi authored Dec 6, 2024
2 parents 36b9b44 + f5849f9 commit a9bf599
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 13 deletions.
2 changes: 0 additions & 2 deletions src/components/TextInput/BaseTextInput/index.native.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import Text from '@components/Text';
import * as styleConst from '@components/TextInput/styleConst';
import TextInputClearButton from '@components/TextInput/TextInputClearButton';
import TextInputLabel from '@components/TextInput/TextInputLabel';
import useHtmlPaste from '@hooks/useHtmlPaste';
import useLocalize from '@hooks/useLocalize';
import useMarkdownStyle from '@hooks/useMarkdownStyle';
import useStyleUtils from '@hooks/useStyleUtils';
Expand Down Expand Up @@ -99,7 +98,6 @@ function BaseTextInput(
const labelTranslateY = useRef(new Animated.Value(initialActiveLabel ? styleConst.ACTIVE_LABEL_TRANSLATE_Y : styleConst.INACTIVE_LABEL_TRANSLATE_Y)).current;
const input = useRef<TextInput | null>(null);
const isLabelActive = useRef(initialActiveLabel);
useHtmlPaste(input, undefined, false, isMarkdownEnabled);

// AutoFocus which only works on mount:
useEffect(() => {
Expand Down
6 changes: 2 additions & 4 deletions src/components/TextInput/BaseTextInput/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {Str} from 'expensify-common';
import type {ForwardedRef, MutableRefObject} from 'react';
import type {ForwardedRef} from 'react';
import React, {forwardRef, useCallback, useEffect, useMemo, useRef, useState} from 'react';
import type {GestureResponderEvent, LayoutChangeEvent, NativeSyntheticEvent, StyleProp, TextInput, TextInputFocusEventData, ViewStyle} from 'react-native';
import type {GestureResponderEvent, LayoutChangeEvent, NativeSyntheticEvent, StyleProp, TextInputFocusEventData, ViewStyle} from 'react-native';
import {ActivityIndicator, Animated, StyleSheet, View} from 'react-native';
import Checkbox from '@components/Checkbox';
import FormHelpMessage from '@components/FormHelpMessage';
Expand All @@ -17,7 +17,6 @@ import Text from '@components/Text';
import * as styleConst from '@components/TextInput/styleConst';
import TextInputClearButton from '@components/TextInput/TextInputClearButton';
import TextInputLabel from '@components/TextInput/TextInputLabel';
import useHtmlPaste from '@hooks/useHtmlPaste';
import useLocalize from '@hooks/useLocalize';
import useMarkdownStyle from '@hooks/useMarkdownStyle';
import useStyleUtils from '@hooks/useStyleUtils';
Expand Down Expand Up @@ -104,7 +103,6 @@ function BaseTextInput(
const labelTranslateY = useRef(new Animated.Value(initialActiveLabel ? styleConst.ACTIVE_LABEL_TRANSLATE_Y : styleConst.INACTIVE_LABEL_TRANSLATE_Y)).current;
const input = useRef<HTMLInputElement | null>(null);
const isLabelActive = useRef(initialActiveLabel);
useHtmlPaste(input as MutableRefObject<TextInput | null>, undefined, false, isMarkdownEnabled);

// AutoFocus which only works on mount:
useEffect(() => {
Expand Down
8 changes: 2 additions & 6 deletions src/hooks/useHtmlPaste/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import Parser from '@libs/Parser';
import type UseHtmlPaste from './types';

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

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

const useHtmlPaste: UseHtmlPaste = (textInputRef, preHtmlPasteCallback, removeListenerOnScreenBlur = false, isMarkdownEnabled = true) => {
const useHtmlPaste: UseHtmlPaste = (textInputRef, preHtmlPasteCallback, removeListenerOnScreenBlur = false) => {
const navigation = useNavigation();

/**
Expand Down Expand Up @@ -130,9 +129,6 @@ const useHtmlPaste: UseHtmlPaste = (textInputRef, preHtmlPasteCallback, removeLi
);

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

export default useHtmlPaste;
1 change: 0 additions & 1 deletion src/hooks/useHtmlPaste/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ type UseHtmlPaste = (
textInputRef: MutableRefObject<(HTMLTextAreaElement & TextInput) | TextInput | null>,
preHtmlPasteCallback?: (event: ClipboardEvent) => boolean,
removeListenerOnScreenBlur?: boolean,
isMarkdownEnabled?: boolean,
) => void;

export default UseHtmlPaste;

0 comments on commit a9bf599

Please sign in to comment.