Skip to content

Commit

Permalink
[Fabric] iOS: Fixes textinput onscroll event payload
Browse files Browse the repository at this point in the history
  • Loading branch information
zhongwuzw committed Mar 14, 2024
1 parent 082decb commit 91dd672
Showing 1 changed file with 53 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,53 @@ static jsi::Value textInputMetricsPayload(
return payload;
};

static jsi::Value textInputMetricsScrollPayload(
jsi::Runtime& runtime,
const TextInputMetrics& textInputMetrics) {
auto payload = jsi::Object(runtime);

{
auto contentOffset = jsi::Object(runtime);
contentOffset.setProperty(runtime, "x", textInputMetrics.contentOffset.x);
contentOffset.setProperty(runtime, "y", textInputMetrics.contentOffset.y);
payload.setProperty(runtime, "contentOffset", contentOffset);
}

{
auto contentInset = jsi::Object(runtime);
contentInset.setProperty(runtime, "top", textInputMetrics.contentInset.top);
contentInset.setProperty(
runtime, "left", textInputMetrics.contentInset.left);
contentInset.setProperty(
runtime, "bottom", textInputMetrics.contentInset.bottom);
contentInset.setProperty(
runtime, "right", textInputMetrics.contentInset.right);
payload.setProperty(runtime, "contentInset", contentInset);
}

{
auto contentSize = jsi::Object(runtime);
contentSize.setProperty(
runtime, "width", textInputMetrics.contentSize.width);
contentSize.setProperty(
runtime, "height", textInputMetrics.contentSize.height);
payload.setProperty(runtime, "contentSize", contentSize);
}

{
auto layoutMeasurement = jsi::Object(runtime);
layoutMeasurement.setProperty(
runtime, "width", textInputMetrics.layoutMeasurement.width);
layoutMeasurement.setProperty(
runtime, "height", textInputMetrics.layoutMeasurement.height);
payload.setProperty(runtime, "layoutMeasurement", layoutMeasurement);
}

payload.setProperty(runtime, "zoomScale", textInputMetrics.zoomScale ?: 1);

return payload;
};

static jsi::Value textInputMetricsContentSizePayload(
jsi::Runtime& runtime,
const TextInputMetrics& textInputMetrics) {
Expand Down Expand Up @@ -121,7 +168,12 @@ void TextInputEventEmitter::onKeyPress(

void TextInputEventEmitter::onScroll(
const TextInputMetrics& textInputMetrics) const {
dispatchTextInputEvent("scroll", textInputMetrics);
dispatchEvent(
"scroll",
[textInputMetrics](jsi::Runtime& runtime) {
return textInputMetricsScrollPayload(runtime, textInputMetrics);
},
EventPriority::AsynchronousBatched);
}

void TextInputEventEmitter::dispatchTextInputEvent(
Expand Down

0 comments on commit 91dd672

Please sign in to comment.