Skip to content

Commit

Permalink
Merge pull request #47110 from Expensify/Rory-RevertImagePasting
Browse files Browse the repository at this point in the history
Revert PR #45722

(cherry picked from commit aa1430f) (CP triggered by roryabraham)
  • Loading branch information
marcaaron authored and OSBotify committed Aug 8, 2024
1 parent 6a3cec5 commit 4c7edb4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
19 changes: 17 additions & 2 deletions src/components/Composer/index.native.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import type {MarkdownStyle} from '@expensify/react-native-live-markdown';
import type {ForwardedRef} from 'react';
<<<<<<< HEAD
import React, {useCallback, useEffect, useMemo, useRef} from 'react';
import type {NativeSyntheticEvent, TextInput, TextInputPasteEventData} from 'react-native';
=======
import React, {useCallback, useMemo, useRef} from 'react';
import type {NativeSyntheticEvent, TextInput, TextInputChangeEventData} from 'react-native';
>>>>>>> aa1430f (Merge pull request #47110 from Expensify/Rory-RevertImagePasting)
import {StyleSheet} from 'react-native';
import type {FileObject} from '@components/AttachmentModal';
import type {AnimatedMarkdownTextInputRef} from '@components/RNMarkdownTextInput';
import RNMarkdownTextInput from '@components/RNMarkdownTextInput';
import useMarkdownStyle from '@hooks/useMarkdownStyle';
Expand All @@ -20,9 +24,13 @@ const excludeReportMentionStyle: Array<keyof MarkdownStyle> = ['mentionReport'];

function Composer(
{
<<<<<<< HEAD
shouldClear = false,
onClear = () => {},
onPasteFile = () => {},
=======
onClear: onClearProp = () => {},
>>>>>>> aa1430f (Merge pull request #47110 from Expensify/Rory-RevertImagePasting)
isDisabled = false,
maxLines,
isComposerFullSize = false,
Expand Down Expand Up @@ -66,6 +74,7 @@ function Composer(
// eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps
}, []);

<<<<<<< HEAD
const pasteFile = useCallback(
(e: NativeSyntheticEvent<TextInputPasteEventData>) => {
const clipboardContent = e.nativeEvent.items[0];
Expand All @@ -78,6 +87,13 @@ function Composer(
onPasteFile(file);
},
[onPasteFile],
=======
const onClear = useCallback(
({nativeEvent}: NativeSyntheticEvent<TextInputChangeEventData>) => {
onClearProp(nativeEvent.text);
},
[onClearProp],
>>>>>>> aa1430f (Merge pull request #47110 from Expensify/Rory-RevertImagePasting)
);

useEffect(() => {
Expand Down Expand Up @@ -108,7 +124,6 @@ function Composer(
/* eslint-disable-next-line react/jsx-props-no-spreading */
{...props}
readOnly={isDisabled}
onPaste={pasteFile}
onBlur={(e) => {
if (!isFocused) {
// eslint-disable-next-line react-compiler/react-compiler
Expand Down
3 changes: 1 addition & 2 deletions src/components/Composer/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type {NativeSyntheticEvent, StyleProp, TextInputProps, TextInputSelectionChangeEventData, TextStyle} from 'react-native';
import type {FileObject} from '@components/AttachmentModal';

type TextSelection = {
start: number;
Expand Down Expand Up @@ -32,7 +31,7 @@ type ComposerProps = TextInputProps & {
onChangeText?: (numberOfLines: string) => void;

/** Callback method to handle pasting a file */
onPasteFile?: (file: FileObject) => void;
onPasteFile?: (file: File) => void;

/** General styles to apply to the text input */
// eslint-disable-next-line react/forbid-prop-types
Expand Down
5 changes: 2 additions & 3 deletions src/stories/Composer.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import type {Meta} from '@storybook/react';
import {ExpensiMark} from 'expensify-common';
import React, {useState} from 'react';
import {Image, View} from 'react-native';
import type {FileObject} from '@components/AttachmentModal';
import Composer from '@components/Composer';
import type {ComposerProps} from '@components/Composer/types';
import RenderHTML from '@components/RenderHTML';
Expand All @@ -30,7 +29,7 @@ const parser = new ExpensiMark();

function Default(props: ComposerProps) {
const StyleUtils = useStyleUtils();
const [pastedFile, setPastedFile] = useState<FileObject | null>(null);
const [pastedFile, setPastedFile] = useState<File | null>(null);
const [comment, setComment] = useState(props.defaultValue);
const renderedHTML = parser.replace(comment ?? '');

Expand All @@ -54,7 +53,7 @@ function Default(props: ComposerProps) {
<View style={[defaultStyles.p5, defaultStyles.borderBottom, defaultStyles.borderRight, defaultStyles.borderTop, defaultStyles.flex1]}>
<Text style={[defaultStyles.mb2, defaultStyles.textLabelSupporting]}>Rendered Comment</Text>
{!!renderedHTML && <RenderHTML html={renderedHTML} />}
{!!pastedFile && pastedFile instanceof File && (
{!!pastedFile && (
<View style={defaultStyles.mv3}>
<Image
source={{uri: URL.createObjectURL(pastedFile)}}
Expand Down

0 comments on commit 4c7edb4

Please sign in to comment.