mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
remove sync events from TextInput (#43429)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/43429 changelog: [internal] these experimental props have served their purpose and can be deleted. Reviewed By: rubennorte Differential Revision: D54682805 fbshipit-source-id: aee5072e2aa056c862f369426617d0d51c98997f
This commit is contained in:
committed by
Facebook GitHub Bot
parent
9e2bb4efc3
commit
2ed1e9ad28
-8
@@ -79,18 +79,12 @@ const RCTTextInputViewConfig = {
|
||||
topTextInput: {
|
||||
registrationName: 'onTextInput',
|
||||
},
|
||||
topKeyPressSync: {
|
||||
registrationName: 'onKeyPressSync',
|
||||
},
|
||||
topScroll: {
|
||||
registrationName: 'onScroll',
|
||||
},
|
||||
topSelectionChange: {
|
||||
registrationName: 'onSelectionChange',
|
||||
},
|
||||
topChangeSync: {
|
||||
registrationName: 'onChangeSync',
|
||||
},
|
||||
topContentSizeChange: {
|
||||
registrationName: 'onContentSizeChange',
|
||||
},
|
||||
@@ -159,8 +153,6 @@ const RCTTextInputViewConfig = {
|
||||
onSelectionChange: true,
|
||||
onContentSizeChange: true,
|
||||
onScroll: true,
|
||||
onChangeSync: true,
|
||||
onKeyPressSync: true,
|
||||
onTextInput: true,
|
||||
}),
|
||||
},
|
||||
|
||||
@@ -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
|
||||
@@ -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.
|
||||
*/
|
||||
@@ -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);
|
||||
|
||||
@@ -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.
|
||||
@@ -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}
|
||||
|
||||
+1
-18
@@ -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,
|
||||
@@ -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);
|
||||
@@ -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);
|
||||
|
||||
@@ -183,7 +171,6 @@ describe('TextInput tests', () => {
|
||||
mostRecentEventCount={0}
|
||||
onBlur={[Function]}
|
||||
onChange={[Function]}
|
||||
onChangeSync={null}
|
||||
onClick={[Function]}
|
||||
onFocus={[Function]}
|
||||
onResponderGrant={[Function]}
|
||||
@@ -229,7 +216,6 @@ describe('TextInput', () => {
|
||||
mostRecentEventCount={0}
|
||||
onBlur={[Function]}
|
||||
onChange={[Function]}
|
||||
onChangeSync={null}
|
||||
onClick={[Function]}
|
||||
onFocus={[Function]}
|
||||
onResponderGrant={[Function]}
|
||||
@@ -275,7 +261,6 @@ describe('TextInput compat with web', () => {
|
||||
nativeID="id"
|
||||
onBlur={[Function]}
|
||||
onChange={[Function]}
|
||||
onChangeSync={null}
|
||||
onClick={[Function]}
|
||||
onFocus={[Function]}
|
||||
onResponderGrant={[Function]}
|
||||
@@ -407,7 +392,6 @@ describe('TextInput compat with web', () => {
|
||||
mostRecentEventCount={0}
|
||||
onBlur={[Function]}
|
||||
onChange={[Function]}
|
||||
onChangeSync={null}
|
||||
onClick={[Function]}
|
||||
onFocus={[Function]}
|
||||
onResponderGrant={[Function]}
|
||||
@@ -450,7 +434,6 @@ describe('TextInput compat with web', () => {
|
||||
mostRecentEventCount={0}
|
||||
onBlur={[Function]}
|
||||
onChange={[Function]}
|
||||
onChangeSync={null}
|
||||
onClick={[Function]}
|
||||
onFocus={[Function]}
|
||||
onResponderGrant={[Function]}
|
||||
|
||||
-2
@@ -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]}
|
||||
@@ -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]}
|
||||
|
||||
@@ -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,
|
||||
|
||||
+2
-11
@@ -341,11 +341,7 @@ using namespace facebook::react;
|
||||
keyPressMetrics.eventCount = _mostRecentEventCount;
|
||||
|
||||
const auto &textInputEventEmitter = static_cast<const TextInputEventEmitter &>(*_eventEmitter);
|
||||
if (props.onKeyPressSync) {
|
||||
textInputEventEmitter.onKeyPressSync(keyPressMetrics);
|
||||
} else {
|
||||
textInputEventEmitter.onKeyPress(keyPressMetrics);
|
||||
}
|
||||
textInputEventEmitter.onKeyPress(keyPressMetrics);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -391,12 +387,7 @@ using namespace facebook::react;
|
||||
|
||||
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]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
-16
@@ -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(
|
||||
@@ -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);
|
||||
|
||||
-2
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user