Skip to content

Commit

Permalink
add timestamp to onScroll on iOS (#46978)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #46978

changelog: [internal]

Add timestamp to onScroll event on Android.

Reviewed By: fabriziocucci

Differential Revision: D64068207

fbshipit-source-id: 3d4c31bbf43ef5f06af4933867380d3ef297b550
  • Loading branch information
sammy-SC authored and facebook-github-bot committed Oct 12, 2024
1 parent f4855d7 commit 3130f0d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,7 @@ - (BOOL)_shouldDisableScrollInteraction
metrics.contentInset = RCTEdgeInsetsFromUIEdgeInsets(_scrollView.contentInset);
metrics.containerSize = RCTSizeFromCGSize(_scrollView.bounds.size);
metrics.zoomScale = _scrollView.zoomScale;
metrics.timestamp = CACurrentMediaTime();

if (_layoutMetrics.layoutDirection == LayoutDirection::RightToLeft) {
metrics.contentOffset.x = metrics.contentSize.width - metrics.containerSize.width - metrics.contentOffset.x;
Expand Down
3 changes: 3 additions & 0 deletions packages/react-native/React/Views/ScrollView/RCTScrollEvent.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ @implementation RCTScrollEvent {
CGFloat _scrollViewZoomScale;
NSDictionary *_userData;
uint16_t _coalescingKey;
CFTimeInterval _timestamp;
}

@synthesize viewTag = _viewTag;
Expand Down Expand Up @@ -43,6 +44,7 @@ - (instancetype)initWithEventName:(NSString *)eventName
_scrollViewZoomScale = scrollViewZoomScale;
_userData = userData;
_coalescingKey = coalescingKey;
_timestamp = CACurrentMediaTime();
}
return self;
}
Expand All @@ -67,6 +69,7 @@ - (NSDictionary *)body
@"contentSize" : @{@"width" : @(_scrollViewContentSize.width), @"height" : @(_scrollViewContentSize.height)},
@"layoutMeasurement" : @{@"width" : @(_scrollViewFrame.size.width), @"height" : @(_scrollViewFrame.size.height)},
@"zoomScale" : @(_scrollViewZoomScale ?: 1),
@"timestamp" : @(_timestamp * 1000),
};

if (_userData) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ jsi::Value ScrollEvent::asJSIValue(jsi::Runtime& runtime) const {
}

payload.setProperty(runtime, "zoomScale", zoomScale);
payload.setProperty(runtime, "timestamp", timestamp * 1000);

return payload;
}
Expand All @@ -61,11 +62,12 @@ folly::dynamic ScrollEvent::asDynamic() const {
auto containerSizeObj = folly::dynamic::object("width", containerSize.width)(
"height", containerSize.height);

auto metrics = folly::dynamic::object(
"contentOffset", std::move(contentOffsetObj))(
"contentInset", std::move(contentInsetObj))(
"contentSize", std::move(contentSizeObj))(
"layoutMeasurement", std::move(containerSizeObj))("zoomScale", zoomScale);
auto metrics =
folly::dynamic::object("contentOffset", std::move(contentOffsetObj))(
"contentInset", std::move(contentInsetObj))(
"contentSize", std::move(contentSizeObj))(
"layoutMeasurement", std::move(containerSizeObj))(
"zoomScale", zoomScale)("timestamp", timestamp * 1000);

return metrics;
};
Expand All @@ -91,7 +93,7 @@ std::vector<DebugStringConvertibleObject> getDebugProps(
{"layoutMeasurement",
getDebugDescription(scrollEvent.layoutMeasurement, options)},
{"zoomScale", getDebugDescription(scrollEvent.zoomScale, options)},
};
{"timestamp", getDebugDescription(scrollEvent.timestamp, options)}};
}

#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ struct ScrollEvent : public EventPayload {
Size containerSize;
Float zoomScale{};

/*
* The time in seconds when the touch occurred or when it was last mutated.
*/
Float timestamp{};

ScrollEvent() = default;

folly::dynamic asDynamic() const;
Expand Down

0 comments on commit 3130f0d

Please sign in to comment.