Skip to content
Draft
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
4 changes: 2 additions & 2 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2690,9 +2690,9 @@ SPEC CHECKSUMS:
ReactAppDependencyProvider: 77a7129540c0e06ab6be9a2bcb887d3d2e594431
ReactCodegen: b62625187ce853918021a7a9178cc406e9820d56
ReactCommon: d07170f92e0e853091a70b2741b7c43f5dfdea73
ReactNativeEnriched: b11d66700889cd36c9938a825736de1929349b24
ReactNativeEnriched: ce7a893fdefce993826a3177da6811b513e26526
SocketRocket: d4aabe649be1e368d1318fdf28a022d714d65748
Yoga: 6af5d1e0290903c82b3e0cb6836a5f898c1c4634
Yoga: 47264cc34431da6b66b3687348be283084924f46

PODFILE CHECKSUM: 1b876ae6d1ea0597d954f2089c1213dd3ade28bc

Expand Down
8 changes: 7 additions & 1 deletion example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
Text,
type NativeSyntheticEvent,
ScrollView,
Keyboard,
} from 'react-native';
import {
EnrichedTextInput,
Expand Down Expand Up @@ -62,7 +63,7 @@ const DEFAULT_LINK_STATE = {
end: 0,
};

const DEBUG_SCROLLABLE = false;
const DEBUG_SCROLLABLE = true;

// Enabling this prop fixes input flickering while auto growing.
// However, it's still experimental and not tested well.
Expand Down Expand Up @@ -293,6 +294,11 @@ export default function App() {
onPress={openValueModal}
style={styles.valueButton}
/>
<Button
title="Dismiss keyboard"
onPress={Keyboard.dismiss}
style={styles.valueButton}
/>
<HtmlSection currentHtml={currentHtml} />
{DEBUG_SCROLLABLE && <View style={styles.scrollPlaceholder} />}
</ScrollView>
Expand Down
31 changes: 29 additions & 2 deletions src/EnrichedTextInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
type Component,
type RefObject,
useImperativeHandle,
useLayoutEffect,
useMemo,
useRef,
} from 'react';
Expand Down Expand Up @@ -32,6 +33,9 @@
} from 'react-native';
import { normalizeHtmlStyle } from './normalizeHtmlStyle';

//@ts-ignore
import TextInputState from 'react-native/Libraries/Components/TextInput/TextInputState';

Check warning on line 37 in src/EnrichedTextInput.tsx

View workflow job for this annotation

GitHub Actions / lint

'react-native/Libraries/Components/TextInput/TextInputState' React Native deep imports are deprecated. Please use the top level import instead

export interface EnrichedTextInputInstance extends NativeMethods {
// General commands
focus: () => void;
Expand Down Expand Up @@ -297,6 +301,19 @@
},
}));

useLayoutEffect(() => {
const inputRef = nativeRef.current;
TextInputState.registerInput(inputRef);

return () => {
TextInputState.unregisterInput(inputRef);

if (TextInputState.currentlyFocusedInput() === inputRef) {
inputRef?.blur();
}
};
}, []);

const handleMentionEvent = (e: NativeSyntheticEvent<OnMentionEvent>) => {
const mentionText = e.nativeEvent.text;
const mentionIndicator = e.nativeEvent.indicator;
Expand Down Expand Up @@ -325,6 +342,16 @@
onMentionDetected?.({ text, indicator, attributes });
};

const _onFocus = () => {
TextInputState.focusInput(nativeRef?.current);
onFocus?.();
};

const _onBlur = () => {
TextInputState.blurInput(nativeRef?.current);
onBlur?.();
};

return (
<EnrichedTextInputNativeComponent
ref={nativeRef}
Expand All @@ -339,8 +366,8 @@
style={style}
autoCapitalize={autoCapitalize}
htmlStyle={normalizedHtmlStyle}
onInputFocus={onFocus}
onInputBlur={onBlur}
onInputFocus={_onFocus}
onInputBlur={_onBlur}
onChangeText={onChangeText}
onChangeHtml={onChangeHtml}
isOnChangeHtmlSet={onChangeHtml !== undefined}
Expand Down
Loading