From 7a8e10dac83b6a43e4cea7e92df0dcfbcf3ad3ac Mon Sep 17 00:00:00 2001 From: Samuel Susla Date: Mon, 20 Jan 2020 03:06:14 -0800 Subject: [PATCH] Use commands to send focus and blur to TextInput Summary: Migrate to Native commands with Blur and Focus on TextInput. Changelog: [Internal] Reviewed By: TheSavior, shergin Differential Revision: D19412085 fbshipit-source-id: 33b29b2699bc74d31ef1b4b0e585daffd88c4140 --- .../RCTMultilineTextInputNativeComponent.js | 33 +++++++++++++++++++ .../RCTSingelineTextInputNativeComponent.js | 33 +++++++++++++++++++ Libraries/Components/TextInput/TextInput.js | 10 +++--- 3 files changed, 70 insertions(+), 6 deletions(-) create mode 100644 Libraries/Components/TextInput/RCTMultilineTextInputNativeComponent.js create mode 100644 Libraries/Components/TextInput/RCTSingelineTextInputNativeComponent.js diff --git a/Libraries/Components/TextInput/RCTMultilineTextInputNativeComponent.js b/Libraries/Components/TextInput/RCTMultilineTextInputNativeComponent.js new file mode 100644 index 00000000000..0dcd904baa7 --- /dev/null +++ b/Libraries/Components/TextInput/RCTMultilineTextInputNativeComponent.js @@ -0,0 +1,33 @@ +/** + * Copyright (c) Facebook, Inc. and its 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-local + * @format + */ + +'use strict'; + +import type {HostComponent} from '../../Renderer/shims/ReactNativeTypes'; +import requireNativeComponent from '../../ReactNative/requireNativeComponent'; +import codegenNativeCommands from '../../Utilities/codegenNativeCommands'; +import * as React from 'react'; + +type NativeType = HostComponent; + +interface NativeCommands { + +focus: (viewRef: React.ElementRef) => void; + +blur: (viewRef: React.ElementRef) => void; +} + +export const Commands: NativeCommands = codegenNativeCommands({ + supportedCommands: ['focus', 'blur'], +}); + +const SinglelineTextInputNativeComponent: HostComponent = requireNativeComponent( + 'RCTMultilineTextInputView', +); + +export default SinglelineTextInputNativeComponent; diff --git a/Libraries/Components/TextInput/RCTSingelineTextInputNativeComponent.js b/Libraries/Components/TextInput/RCTSingelineTextInputNativeComponent.js new file mode 100644 index 00000000000..bd600e2698f --- /dev/null +++ b/Libraries/Components/TextInput/RCTSingelineTextInputNativeComponent.js @@ -0,0 +1,33 @@ +/** + * Copyright (c) Facebook, Inc. and its 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-local + * @format + */ + +'use strict'; + +import type {HostComponent} from '../../Renderer/shims/ReactNativeTypes'; +import requireNativeComponent from '../../ReactNative/requireNativeComponent'; +import codegenNativeCommands from '../../Utilities/codegenNativeCommands'; +import * as React from 'react'; + +type NativeType = HostComponent; + +interface NativeCommands { + +focus: (viewRef: React.ElementRef) => void; + +blur: (viewRef: React.ElementRef) => void; +} + +export const Commands: NativeCommands = codegenNativeCommands({ + supportedCommands: ['focus', 'blur'], +}); + +const SinglelineTextInputNativeComponent: HostComponent = requireNativeComponent( + 'RCTSinglelineTextInputView', +); + +export default SinglelineTextInputNativeComponent; diff --git a/Libraries/Components/TextInput/TextInput.js b/Libraries/Components/TextInput/TextInput.js index 02e1db674af..dd3d5667afa 100644 --- a/Libraries/Components/TextInput/TextInput.js +++ b/Libraries/Components/TextInput/TextInput.js @@ -43,12 +43,10 @@ let RCTSinglelineTextInputView; if (Platform.OS === 'android') { AndroidTextInput = require('./AndroidTextInputNativeComponent').default; } else if (Platform.OS === 'ios') { - RCTMultilineTextInputView = requireNativeComponent( - 'RCTMultilineTextInputView', - ); - RCTSinglelineTextInputView = requireNativeComponent( - 'RCTSinglelineTextInputView', - ); + RCTMultilineTextInputView = require('./RCTMultilineTextInputNativeComponent.js') + .default; + RCTSinglelineTextInputView = require('./RCTSingelineTextInputNativeComponent.js') + .default; } export type ChangeEvent = SyntheticEvent<