Skip to content

Commit

Permalink
add onTouchStart (#499)
Browse files Browse the repository at this point in the history
  • Loading branch information
christianwen authored Sep 18, 2024
1 parent bd20d84 commit caee52f
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/MarkdownTextInput.web.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import type {
TextInputKeyPressEventData,
TextInputFocusEventData,
TextInputContentSizeChangeEventData,
GestureResponderEvent,
} from 'react-native';
import React, {useEffect, useRef, useCallback, useMemo, useLayoutEffect} from 'react';
import type {CSSProperties, MutableRefObject, ReactEventHandler, FocusEventHandler, MouseEvent, KeyboardEvent, SyntheticEvent, ClipboardEventHandler} from 'react';
import type {CSSProperties, MutableRefObject, ReactEventHandler, FocusEventHandler, MouseEvent, KeyboardEvent, SyntheticEvent, ClipboardEventHandler, TouchEvent} from 'react';
import {StyleSheet} from 'react-native';
import {updateInputStructure} from './web/utils/parserUtils';
import InputHistory from './web/InputHistory';
Expand Down Expand Up @@ -98,6 +99,7 @@ const MarkdownTextInput = React.forwardRef<TextInput, MarkdownTextInputProps>(
onContentSizeChange,
id,
inputMode,
onTouchStart,
},
ref,
) => {
Expand Down Expand Up @@ -590,6 +592,14 @@ const MarkdownTextInput = React.forwardRef<TextInput, MarkdownTextInputProps>(
divRef.current = r as MarkdownTextInputElement;
};

const handleTouchStart = (event: TouchEvent<HTMLDivElement>) => {
if (!onTouchStart) {
return;
}
const e = event as unknown as GestureResponderEvent;
onTouchStart(e);
};

useClientEffect(
function parseAndStyleValue() {
if (!divRef.current || value === divRef.current.value) {
Expand Down Expand Up @@ -676,6 +686,7 @@ const MarkdownTextInput = React.forwardRef<TextInput, MarkdownTextInputProps>(
dir={dir}
inputMode={inputMode}
onSelect={updateSelection}
onTouchStart={handleTouchStart}
/>
);
},
Expand Down

0 comments on commit caee52f

Please sign in to comment.