mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
ce9cf3795a
Summary: This is C++ part of the implementation of Fabric-compatible <TextInput> component on iOS. Changelog: [Internal] Fabric-specific internal change. Reviewed By: JoshuaGross Differential Revision: D19169987 fbshipit-source-id: e2eac9beac6d1e124b5176b4a23676b8e05490c3
97 lines
2.7 KiB
C++
97 lines
2.7 KiB
C++
/*
|
|
* 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.
|
|
*/
|
|
|
|
#include "TextInputEventEmitter.h"
|
|
|
|
namespace facebook {
|
|
namespace react {
|
|
|
|
static jsi::Value textInputMetricsPayload(
|
|
jsi::Runtime &runtime,
|
|
TextInputMetrics const &textInputMetrics) {
|
|
auto payload = jsi::Object(runtime);
|
|
|
|
payload.setProperty(
|
|
runtime,
|
|
"text",
|
|
jsi::String::createFromUtf8(runtime, textInputMetrics.text));
|
|
|
|
{
|
|
auto selection = jsi::Object(runtime);
|
|
selection.setProperty(
|
|
runtime, "start", textInputMetrics.selectionRange.location);
|
|
selection.setProperty(
|
|
runtime,
|
|
"end",
|
|
textInputMetrics.selectionRange.location +
|
|
textInputMetrics.selectionRange.length);
|
|
payload.setProperty(runtime, "selection", selection);
|
|
}
|
|
|
|
return payload;
|
|
};
|
|
|
|
void TextInputEventEmitter::onFocus(
|
|
TextInputMetrics const &textInputMetrics) const {
|
|
dispatchTextInputEvent("focus", textInputMetrics);
|
|
}
|
|
|
|
void TextInputEventEmitter::onBlur(
|
|
TextInputMetrics const &textInputMetrics) const {
|
|
dispatchTextInputEvent("blur", textInputMetrics);
|
|
}
|
|
|
|
void TextInputEventEmitter::onChange(
|
|
TextInputMetrics const &textInputMetrics) const {
|
|
dispatchTextInputEvent("change", textInputMetrics);
|
|
}
|
|
|
|
void TextInputEventEmitter::onChangeText(
|
|
TextInputMetrics const &textInputMetrics) const {
|
|
dispatchTextInputEvent("changeText", textInputMetrics);
|
|
}
|
|
|
|
void TextInputEventEmitter::onContentSizeChange(
|
|
TextInputMetrics const &textInputMetrics) const {
|
|
dispatchTextInputEvent("contentSizeChange", textInputMetrics);
|
|
}
|
|
|
|
void TextInputEventEmitter::onSelectionChange(
|
|
TextInputMetrics const &textInputMetrics) const {
|
|
dispatchTextInputEvent("selectionChange", textInputMetrics);
|
|
}
|
|
|
|
void TextInputEventEmitter::onEndEditing(
|
|
TextInputMetrics const &textInputMetrics) const {
|
|
dispatchTextInputEvent("endEditing", textInputMetrics);
|
|
}
|
|
|
|
void TextInputEventEmitter::onSubmitEditing(
|
|
TextInputMetrics const &textInputMetrics) const {
|
|
dispatchTextInputEvent("submitEditing", textInputMetrics);
|
|
}
|
|
|
|
void TextInputEventEmitter::onKeyPress(
|
|
TextInputMetrics const &textInputMetrics) const {
|
|
dispatchTextInputEvent("keyPress", textInputMetrics);
|
|
}
|
|
|
|
void TextInputEventEmitter::dispatchTextInputEvent(
|
|
std::string const &name,
|
|
TextInputMetrics const &textInputMetrics,
|
|
EventPriority priority) const {
|
|
dispatchEvent(
|
|
name,
|
|
[textInputMetrics](jsi::Runtime &runtime) {
|
|
return textInputMetricsPayload(runtime, textInputMetrics);
|
|
},
|
|
priority);
|
|
}
|
|
|
|
} // namespace react
|
|
} // namespace facebook
|