Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,12 @@ const RCTTextInputViewConfig = {
topTextInput: {
registrationName: 'onTextInput',
},
topKeyPressSync: {
registrationName: 'onKeyPressSync',
},
topScroll: {
registrationName: 'onScroll',
},
topSelectionChange: {
registrationName: 'onSelectionChange',
},
topChangeSync: {
registrationName: 'onChangeSync',
},
topContentSizeChange: {
registrationName: 'onContentSizeChange',
},
Expand Down Expand Up @@ -159,8 +153,6 @@ const RCTTextInputViewConfig = {
onSelectionChange: true,
onContentSizeChange: true,
onScroll: true,
onChangeSync: true,
onKeyPressSync: true,
onTextInput: true,
}),
},
Expand Down
62 changes: 0 additions & 62 deletions packages/react-native/Libraries/Components/TextInput/TextInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -741,33 +741,12 @@ export type Props = $ReadOnly<{|
*/
onChange?: ?(e: ChangeEvent) => mixed,

/**
* DANGER: this API is not stable and will change in the future.
*
* Callback will be called on the main thread and may result in dropped frames.
* Callback that is called when the text input's text changes.
*
* @platform ios
*/
unstable_onChangeSync?: ?(e: ChangeEvent) => mixed,

/**
* Callback that is called when the text input's text changes.
* Changed text is passed as an argument to the callback handler.
*/
onChangeText?: ?(text: string) => mixed,

/**
* DANGER: this API is not stable and will change in the future.
*
* Callback will be called on the main thread and may result in dropped frames.
* Callback that is called when the text input's text changes.
* Changed text is passed as an argument to the callback handler.
*
* @platform ios
*/
unstable_onChangeTextSync?: ?(text: string) => mixed,

/**
* Callback that is called when the text input's content size changes.
* This will be called with
Expand Down Expand Up @@ -796,21 +775,6 @@ export type Props = $ReadOnly<{|
*/
onKeyPress?: ?(e: KeyPressEvent) => mixed,

/**
* DANGER: this API is not stable and will change in the future.
*
* Callback will be called on the main thread and may result in dropped frames.
*
* Callback that is called when a key is pressed.
* This will be called with `{ nativeEvent: { key: keyValue } }`
* where `keyValue` is `'Enter'` or `'Backspace'` for respective keys and
* the typed-in character otherwise including `' '` for space.
* Fires before `onChange` callbacks.
*
* @platform ios
*/
unstable_onKeyPressSync?: ?(e: KeyPressEvent) => mixed,

/**
* Called when a single tap gesture is detected.
*/
Expand Down Expand Up @@ -1308,26 +1272,6 @@ function InternalTextInput(props: Props): React.Node {
setMostRecentEventCount(event.nativeEvent.eventCount);
};

const _onChangeSync = (event: ChangeEvent) => {
const currentText = event.nativeEvent.text;
props.unstable_onChangeSync && props.unstable_onChangeSync(event);
props.unstable_onChangeTextSync &&
props.unstable_onChangeTextSync(currentText);

if (inputRef.current == null) {
// calling `props.onChange` or `props.onChangeText`
// may clean up the input itself. Exits here.
return;
}

setLastNativeText(currentText);
// This must happen last, after we call setLastNativeText.
// Different ordering can cause bugs when editing AndroidTextInputs
// with multiple Fragments.
// We must update this so that controlled input updates work.
setMostRecentEventCount(event.nativeEvent.eventCount);
};

const _onSelectionChange = (event: SelectionChangeEvent) => {
props.onSelectionChange && props.onSelectionChange(event);

Expand Down Expand Up @@ -1470,10 +1414,6 @@ function InternalTextInput(props: Props): React.Node {
style.paddingVertical == null &&
style.paddingTop == null));

const useOnChangeSync =
(props.unstable_onChangeSync || props.unstable_onChangeTextSync) &&
!(props.onChange || props.onChangeText);

textInput = (
<RCTTextInputView
// $FlowFixMe[incompatible-type] - Figure out imperative + forward refs.
Expand All @@ -1489,9 +1429,7 @@ function InternalTextInput(props: Props): React.Node {
mostRecentEventCount={mostRecentEventCount}
nativeID={id ?? props.nativeID}
onBlur={_onBlur}
onKeyPressSync={props.unstable_onKeyPressSync}
onChange={_onChange}
onChangeSync={useOnChangeSync === true ? _onChangeSync : null}
onContentSizeChange={props.onContentSizeChange}
onFocus={_onFocus}
onScroll={_onScroll}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,3 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow-strict
* @format
* @oncall react_native
*/

const ReactNative = require('../../../ReactNative/RendererProxy');
const {
enter,
Expand Down Expand Up @@ -51,7 +40,7 @@ describe('TextInput tests', () => {
input = renderTree.root.findByType(TextInput);
});
it('has expected instance functions', () => {
expect(inputRef.current.isFocused).toBeInstanceOf(Function); // Would have prevented S168585
expect(inputRef.current.isFocused).toBeInstanceOf(Function); // Would have prevented S168585
expect(inputRef.current.clear).toBeInstanceOf(Function);
expect(inputRef.current.focus).toBeInstanceOf(jest.fn().constructor);
expect(inputRef.current.blur).toBeInstanceOf(jest.fn().constructor);
Expand Down Expand Up @@ -89,7 +78,6 @@ describe('TextInput tests', () => {

it('focus() should not do anything if the TextInput is not editable', () => {
const textInputRef = createTextInput({editable: false});
// currentProps is the property actually containing props at runtime
textInputRef.current.currentProps = textInputRef.current.props;
expect(textInputRef.current.isFocused()).toBe(false);

Expand Down Expand Up @@ -183,7 +171,6 @@ describe('TextInput tests', () => {
mostRecentEventCount={0}
onBlur={[Function]}
onChange={[Function]}
onChangeSync={null}
onClick={[Function]}
onFocus={[Function]}
onResponderGrant={[Function]}
Expand Down Expand Up @@ -229,7 +216,6 @@ describe('TextInput', () => {
mostRecentEventCount={0}
onBlur={[Function]}
onChange={[Function]}
onChangeSync={null}
onClick={[Function]}
onFocus={[Function]}
onResponderGrant={[Function]}
Expand Down Expand Up @@ -275,7 +261,6 @@ describe('TextInput compat with web', () => {
nativeID="id"
onBlur={[Function]}
onChange={[Function]}
onChangeSync={null}
onClick={[Function]}
onFocus={[Function]}
onResponderGrant={[Function]}
Expand Down Expand Up @@ -407,7 +392,6 @@ describe('TextInput compat with web', () => {
mostRecentEventCount={0}
onBlur={[Function]}
onChange={[Function]}
onChangeSync={null}
onClick={[Function]}
onFocus={[Function]}
onResponderGrant={[Function]}
Expand Down Expand Up @@ -450,7 +434,6 @@ describe('TextInput compat with web', () => {
mostRecentEventCount={0}
onBlur={[Function]}
onChange={[Function]}
onChangeSync={null}
onClick={[Function]}
onFocus={[Function]}
onResponderGrant={[Function]}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ exports[`TextInput tests should render as expected: should deep render when mock
mostRecentEventCount={0}
onBlur={[Function]}
onChange={[Function]}
onChangeSync={null}
onClick={[Function]}
onFocus={[Function]}
onResponderGrant={[Function]}
Expand Down Expand Up @@ -38,7 +37,6 @@ exports[`TextInput tests should render as expected: should deep render when not
mostRecentEventCount={0}
onBlur={[Function]}
onChange={[Function]}
onChangeSync={null}
onClick={[Function]}
onFocus={[Function]}
onResponderGrant={[Function]}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3041,14 +3041,11 @@ export type Props = $ReadOnly<{|
multiline?: ?boolean,
onBlur?: ?(e: BlurEvent) => mixed,
onChange?: ?(e: ChangeEvent) => mixed,
unstable_onChangeSync?: ?(e: ChangeEvent) => mixed,
onChangeText?: ?(text: string) => mixed,
unstable_onChangeTextSync?: ?(text: string) => mixed,
onContentSizeChange?: ?(e: ContentSizeChangeEvent) => mixed,
onEndEditing?: ?(e: EditingEvent) => mixed,
onFocus?: ?(e: FocusEvent) => mixed,
onKeyPress?: ?(e: KeyPressEvent) => mixed,
unstable_onKeyPressSync?: ?(e: KeyPressEvent) => mixed,
onPress?: ?(event: PressEvent) => mixed,
onPressIn?: ?(event: PressEvent) => mixed,
onPressOut?: ?(event: PressEvent) => mixed,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,11 +341,7 @@ - (NSString *)textInputShouldChangeText:(NSString *)text inRange:(NSRange)range
keyPressMetrics.eventCount = _mostRecentEventCount;

const auto &textInputEventEmitter = static_cast<const TextInputEventEmitter &>(*_eventEmitter);
if (props.onKeyPressSync) {
textInputEventEmitter.onKeyPressSync(keyPressMetrics);
} else {
textInputEventEmitter.onKeyPress(keyPressMetrics);
}
textInputEventEmitter.onKeyPress(keyPressMetrics);
}
}

Expand Down Expand Up @@ -391,12 +387,7 @@ - (void)textInputDidChange

if (_eventEmitter) {
const auto &textInputEventEmitter = static_cast<const TextInputEventEmitter &>(*_eventEmitter);
const auto &props = static_cast<const TextInputProps &>(*_props);
if (props.onChangeSync) {
textInputEventEmitter.onChangeSync([self _textInputMetrics]);
} else {
textInputEventEmitter.onChange([self _textInputMetrics]);
}
textInputEventEmitter.onChange([self _textInputMetrics]);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,6 @@ void TextInputEventEmitter::onChange(
dispatchTextInputEvent("change", textInputMetrics);
}

void TextInputEventEmitter::onChangeSync(
const TextInputMetrics& textInputMetrics) const {
dispatchTextInputEvent(
"changeSync", textInputMetrics, EventPriority::SynchronousBatched);
}

void TextInputEventEmitter::onContentSizeChange(
const TextInputMetrics& textInputMetrics) const {
dispatchTextInputContentSizeChangeEvent(
Expand Down Expand Up @@ -128,16 +122,6 @@ void TextInputEventEmitter::onKeyPress(
EventPriority::AsynchronousBatched);
}

void TextInputEventEmitter::onKeyPressSync(
const KeyPressMetrics& keyPressMetrics) const {
dispatchEvent(
"keyPressSync",
[keyPressMetrics](jsi::Runtime& runtime) {
return keyPressMetricsPayload(runtime, keyPressMetrics);
},
EventPriority::SynchronousBatched);
}

void TextInputEventEmitter::onScroll(
const TextInputMetrics& textInputMetrics) const {
dispatchTextInputEvent("scroll", textInputMetrics);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,11 @@ class TextInputEventEmitter : public ViewEventEmitter {
void onFocus(const TextInputMetrics& textInputMetrics) const;
void onBlur(const TextInputMetrics& textInputMetrics) const;
void onChange(const TextInputMetrics& textInputMetrics) const;
void onChangeSync(const TextInputMetrics& textInputMetrics) const;
void onContentSizeChange(const TextInputMetrics& textInputMetrics) const;
void onSelectionChange(const TextInputMetrics& textInputMetrics) const;
void onEndEditing(const TextInputMetrics& textInputMetrics) const;
void onSubmitEditing(const TextInputMetrics& textInputMetrics) const;
void onKeyPress(const KeyPressMetrics& keyPressMetrics) const;
void onKeyPressSync(const KeyPressMetrics& keyPressMetrics) const;
void onScroll(const TextInputMetrics& textInputMetrics) const;

private:
Expand Down