Skip to content

Commit da9364f

Browse files
elicwhitefacebook-github-bot
authored andcommitted
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
1 parent 1470554 commit da9364f

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

Libraries/Components/TextInput/TextInputState.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616

1717
const React = require('react');
1818
const Platform = require('../../Utilities/Platform');
19-
const UIManager = require('../../ReactNative/UIManager');
2019
const {findNodeHandle} = require('../../Renderer/shims/ReactNative');
2120
import {Commands as AndroidTextInputCommands} from '../../Components/TextInput/AndroidTextInputNativeComponent';
21+
import {Commands as iOSTextInputCommands} from '../../Components/TextInput/RCTSingelineTextInputNativeComponent';
2222

2323
import type {HostComponent} from '../../Renderer/shims/ReactNativeTypes';
2424
type ComponentRef = React.ElementRef<HostComponent<mixed>>;
@@ -89,10 +89,14 @@ function focusTextInput(textField: ?ComponentRef) {
8989
}
9090

9191
if (currentlyFocusedInputRef !== textField && textField != null) {
92-
const textFieldID = findNodeHandle(textField);
9392
focusInput(textField);
9493
if (Platform.OS === 'ios') {
95-
UIManager.focus(textFieldID);
94+
// This isn't necessarily a single line text input
95+
// But commands don't actually care as long as the thing being passed in
96+
// actually has a command with that name. So this should work with single
97+
// and multiline text inputs. Ideally we'll merge them into one component
98+
// in the future.
99+
iOSTextInputCommands.focus(textField);
96100
} else if (Platform.OS === 'android') {
97101
AndroidTextInputCommands.focus(textField);
98102
}
@@ -116,10 +120,14 @@ function blurTextInput(textField: ?ComponentRef) {
116120
}
117121

118122
if (currentlyFocusedInputRef === textField && textField != null) {
119-
const textFieldID = findNodeHandle(textField);
120123
blurInput(textField);
121124
if (Platform.OS === 'ios') {
122-
UIManager.blur(textFieldID);
125+
// This isn't necessarily a single line text input
126+
// But commands don't actually care as long as the thing being passed in
127+
// actually has a command with that name. So this should work with single
128+
// and multiline text inputs. Ideally we'll merge them into one component
129+
// in the future.
130+
iOSTextInputCommands.blur(textField);
123131
} else if (Platform.OS === 'android') {
124132
AndroidTextInputCommands.blur(textField);
125133
}

0 commit comments

Comments
 (0)