Skip to content

Commit a88a3c5

Browse files
zhongwuzwcipolleschi
authored andcommitted
iOS: Fixes textinput onscroll event payload (#43445)
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
1 parent 2375b07 commit a88a3c5

File tree

1 file changed

+53
-1
lines changed
  • packages/react-native/ReactCommon/react/renderer/components/textinput/platform/ios/react/renderer/components/iostextinput

1 file changed

+53
-1
lines changed

packages/react-native/ReactCommon/react/renderer/components/textinput/platform/ios/react/renderer/components/iostextinput/TextInputEventEmitter.cpp

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,56 @@ static jsi::Value textInputMetricsPayload(
3636
return payload;
3737
};
3838

39+
static jsi::Value textInputMetricsScrollPayload(
40+
jsi::Runtime& runtime,
41+
const TextInputMetrics& textInputMetrics) {
42+
auto payload = jsi::Object(runtime);
43+
44+
{
45+
auto contentOffset = jsi::Object(runtime);
46+
contentOffset.setProperty(runtime, "x", textInputMetrics.contentOffset.x);
47+
contentOffset.setProperty(runtime, "y", textInputMetrics.contentOffset.y);
48+
payload.setProperty(runtime, "contentOffset", contentOffset);
49+
}
50+
51+
{
52+
auto contentInset = jsi::Object(runtime);
53+
contentInset.setProperty(runtime, "top", textInputMetrics.contentInset.top);
54+
contentInset.setProperty(
55+
runtime, "left", textInputMetrics.contentInset.left);
56+
contentInset.setProperty(
57+
runtime, "bottom", textInputMetrics.contentInset.bottom);
58+
contentInset.setProperty(
59+
runtime, "right", textInputMetrics.contentInset.right);
60+
payload.setProperty(runtime, "contentInset", contentInset);
61+
}
62+
63+
{
64+
auto contentSize = jsi::Object(runtime);
65+
contentSize.setProperty(
66+
runtime, "width", textInputMetrics.contentSize.width);
67+
contentSize.setProperty(
68+
runtime, "height", textInputMetrics.contentSize.height);
69+
payload.setProperty(runtime, "contentSize", contentSize);
70+
}
71+
72+
{
73+
auto layoutMeasurement = jsi::Object(runtime);
74+
layoutMeasurement.setProperty(
75+
runtime, "width", textInputMetrics.layoutMeasurement.width);
76+
layoutMeasurement.setProperty(
77+
runtime, "height", textInputMetrics.layoutMeasurement.height);
78+
payload.setProperty(runtime, "layoutMeasurement", layoutMeasurement);
79+
}
80+
81+
payload.setProperty(
82+
runtime,
83+
"zoomScale",
84+
textInputMetrics.zoomScale ? textInputMetrics.zoomScale : 1);
85+
86+
return payload;
87+
};
88+
3989
static jsi::Value textInputMetricsContentSizePayload(
4090
jsi::Runtime& runtime,
4191
const TextInputMetrics& textInputMetrics) {
@@ -140,7 +190,9 @@ void TextInputEventEmitter::onKeyPressSync(
140190

141191
void TextInputEventEmitter::onScroll(
142192
const TextInputMetrics& textInputMetrics) const {
143-
dispatchTextInputEvent("scroll", textInputMetrics);
193+
dispatchEvent("scroll", [textInputMetrics](jsi::Runtime& runtime) {
194+
return textInputMetricsScrollPayload(runtime, textInputMetrics);
195+
});
144196
}
145197

146198
void TextInputEventEmitter::dispatchTextInputEvent(

0 commit comments

Comments
 (0)