Skip to content

Commit

Permalink
iOS: Fixes textinput onscroll event payload (#43445)
Browse files Browse the repository at this point in the history
Summary:
Fixes #43428 . cc cortinico .

## Changelog:

[IOS] [FIXED] - [Fabric] iOS: Fixes textinput onscroll event payload

Pull Request resolved: #43445

Test Plan:
```
    const onInputScroll = (e) => {
      if (Platform.OS !== "web") {
        const {
          nativeEvent: {
            contentOffset: { x, y },
          },
        } = e;
        console.log('onInputScroll ====', e?.nativeEvent)
      }
    };

<TextInput
          onScroll={onInputScroll}
          // ref={inputRef}
          multiline
  />
```

Reviewed By: cortinico

Differential Revision: D54813378

Pulled By: sammy-SC

fbshipit-source-id: 76671fbb390c2fbc67a9c29b6c2a834ba699fff4
  • Loading branch information
zhongwuzw authored and cipolleschi committed Jun 3, 2024
1 parent 2375b07 commit a88a3c5
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,56 @@ 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 ? textInputMetrics.zoomScale : 1);

return payload;
};

static jsi::Value textInputMetricsContentSizePayload(
jsi::Runtime& runtime,
const TextInputMetrics& textInputMetrics) {
Expand Down Expand Up @@ -140,7 +190,9 @@ void TextInputEventEmitter::onKeyPressSync(

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

void TextInputEventEmitter::dispatchTextInputEvent(
Expand Down

0 comments on commit a88a3c5

Please sign in to comment.