From da9364fa3e2e78ed3e06d469af8414933611501b Mon Sep 17 00:00:00 2001 From: Eli White Date: Wed, 19 Feb 2020 15:26:09 -0800 Subject: [PATCH] Switch iOS focus/blur calls to use new commands Summary: Make iOS use Commands instead of UIManager.{focus,blur}. This makes these apis compatible with Fabric and paper at the same time. Changelog: [Internal] Switch iOS focus/blur calls to use new commands Reviewed By: mdvacca Differential Revision: D19458995 fbshipit-source-id: 8c4aacd41941f54a887aeec1a17d9ce0b6878ab1 --- .../Components/TextInput/TextInputState.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/Libraries/Components/TextInput/TextInputState.js b/Libraries/Components/TextInput/TextInputState.js index 9f3c08af6ab..3a45d647457 100644 --- a/Libraries/Components/TextInput/TextInputState.js +++ b/Libraries/Components/TextInput/TextInputState.js @@ -16,9 +16,9 @@ const React = require('react'); const Platform = require('../../Utilities/Platform'); -const UIManager = require('../../ReactNative/UIManager'); const {findNodeHandle} = require('../../Renderer/shims/ReactNative'); import {Commands as AndroidTextInputCommands} from '../../Components/TextInput/AndroidTextInputNativeComponent'; +import {Commands as iOSTextInputCommands} from '../../Components/TextInput/RCTSingelineTextInputNativeComponent'; import type {HostComponent} from '../../Renderer/shims/ReactNativeTypes'; type ComponentRef = React.ElementRef>; @@ -89,10 +89,14 @@ function focusTextInput(textField: ?ComponentRef) { } if (currentlyFocusedInputRef !== textField && textField != null) { - const textFieldID = findNodeHandle(textField); focusInput(textField); if (Platform.OS === 'ios') { - UIManager.focus(textFieldID); + // This isn't necessarily a single line text input + // But commands don't actually care as long as the thing being passed in + // actually has a command with that name. So this should work with single + // and multiline text inputs. Ideally we'll merge them into one component + // in the future. + iOSTextInputCommands.focus(textField); } else if (Platform.OS === 'android') { AndroidTextInputCommands.focus(textField); } @@ -116,10 +120,14 @@ function blurTextInput(textField: ?ComponentRef) { } if (currentlyFocusedInputRef === textField && textField != null) { - const textFieldID = findNodeHandle(textField); blurInput(textField); if (Platform.OS === 'ios') { - UIManager.blur(textFieldID); + // This isn't necessarily a single line text input + // But commands don't actually care as long as the thing being passed in + // actually has a command with that name. So this should work with single + // and multiline text inputs. Ideally we'll merge them into one component + // in the future. + iOSTextInputCommands.blur(textField); } else if (Platform.OS === 'android') { AndroidTextInputCommands.blur(textField); }