mirror of
https://github.com/status-im/react-native.git
synced 2025-01-17 21:11:45 +00:00
f536a0c268
Summary: ag -L --ignore __snapshots__ 'flow strict|noflow|generated|The controller you requested could not be found.' | ag '\.js$' | xargs ag -l 'flow' | sort > ~/temp cat ~/temp | xargs ag -L 'flow strict' | xargs sed -i '' 's/flow$/flow strict-local/' until flow check; do flow check --json | jq -r '.errors[].message[0].path' | sort | uniq | xargs hg revert; done allow_many_files The controller you requested could not be found. The controller you requested could not be found. Reviewed By: TheSavior Differential Revision: D9004573 fbshipit-source-id: 936bd5741706b781be06bf08b6ad805a69407dfd
92 lines
2.2 KiB
JavaScript
92 lines
2.2 KiB
JavaScript
/**
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
*
|
|
* This class is responsible for coordinating the "focused"
|
|
* state for TextInputs. All calls relating to the keyboard
|
|
* should be funneled through here
|
|
*
|
|
* @format
|
|
* @flow strict-local
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
const Platform = require('Platform');
|
|
const UIManager = require('UIManager');
|
|
|
|
let currentlyFocusedID: ?number = null;
|
|
const inputs = new Set();
|
|
|
|
/**
|
|
* Returns the ID of the currently focused text field, if one exists
|
|
* If no text field is focused it returns null
|
|
*/
|
|
function currentlyFocusedField(): ?number {
|
|
return currentlyFocusedID;
|
|
}
|
|
|
|
/**
|
|
* @param {number} TextInputID id of the text field to focus
|
|
* Focuses the specified text field
|
|
* noop if the text field was already focused
|
|
*/
|
|
function focusTextInput(textFieldID: ?number) {
|
|
if (currentlyFocusedID !== textFieldID && textFieldID !== null) {
|
|
currentlyFocusedID = textFieldID;
|
|
if (Platform.OS === 'ios') {
|
|
UIManager.focus(textFieldID);
|
|
} else if (Platform.OS === 'android') {
|
|
UIManager.dispatchViewManagerCommand(
|
|
textFieldID,
|
|
UIManager.AndroidTextInput.Commands.focusTextInput,
|
|
null,
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @param {number} textFieldID id of the text field to unfocus
|
|
* Unfocuses the specified text field
|
|
* noop if it wasn't focused
|
|
*/
|
|
function blurTextInput(textFieldID: ?number) {
|
|
if (currentlyFocusedID === textFieldID && textFieldID !== null) {
|
|
currentlyFocusedID = null;
|
|
if (Platform.OS === 'ios') {
|
|
UIManager.blur(textFieldID);
|
|
} else if (Platform.OS === 'android') {
|
|
UIManager.dispatchViewManagerCommand(
|
|
textFieldID,
|
|
UIManager.AndroidTextInput.Commands.blurTextInput,
|
|
null,
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
function registerInput(textFieldID: number) {
|
|
inputs.add(textFieldID);
|
|
}
|
|
|
|
function unregisterInput(textFieldID: number) {
|
|
inputs.delete(textFieldID);
|
|
}
|
|
|
|
function isTextInput(textFieldID: number) {
|
|
return inputs.has(textFieldID);
|
|
}
|
|
|
|
module.exports = {
|
|
currentlyFocusedField,
|
|
focusTextInput,
|
|
blurTextInput,
|
|
registerInput,
|
|
unregisterInput,
|
|
isTextInput,
|
|
};
|