Skip to content

Commit c7ed2d2

Browse files
committed
siimplify scrollview metrics
1 parent 4defd81 commit c7ed2d2

File tree

1 file changed

+26
-20
lines changed

1 file changed

+26
-20
lines changed

packages/react-native/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -724,24 +724,7 @@ - (void)scrollViewDidScroll:(RCTUIScrollView *)scrollView // [macOS]
724724
#if !TARGET_OS_OSX // [macOS]
725725
static_cast<const TextInputEventEmitter &>(*_eventEmitter).onScroll([self _textInputMetrics]);
726726
#else // [macOS
727-
auto metrics = [self _textInputMetrics];
728-
729-
CGPoint contentOffset = scrollView.contentOffset;
730-
metrics.contentOffset = {contentOffset.x, contentOffset.y};
731-
732-
UIEdgeInsets contentInset = scrollView.contentInset;
733-
metrics.contentInset = {contentInset.left, contentInset.top, contentInset.right, contentInset.bottom};
734-
735-
CGSize contentSize = scrollView.contentSize;
736-
metrics.contentSize = {contentSize.width, contentSize.height};
737-
738-
CGSize layoutMeasurement = scrollView.bounds.size;
739-
metrics.layoutMeasurement = {layoutMeasurement.width, layoutMeasurement.height};
740-
741-
CGFloat zoomScale = scrollView.zoomScale ?: 1;
742-
metrics.zoomScale = zoomScale;
743-
744-
static_cast<const TextInputEventEmitter &>(*_eventEmitter).onScroll(metrics);
727+
static_cast<const TextInputEventEmitter &>(*_eventEmitter).onScroll([self _textInputMetricsWithScrollView:scrollView]);
745728
#endif // macOS]
746729
}
747730
}
@@ -940,17 +923,40 @@ - (void)handleInputAccessoryDoneButton
940923
.selectionRange = [self _selectionRange],
941924
.eventCount = static_cast<int>(_mostRecentEventCount),
942925
#if !TARGET_OS_OSX // [macOS]
926+
.contentOffset = Point{},
927+
.contentInset = EdgeInsets{},
928+
#else // [macOS
943929
.contentOffset = RCTPointFromCGPoint(_backedTextInputView.contentOffset),
944930
.contentInset = RCTEdgeInsetsFromUIEdgeInsets(_backedTextInputView.contentInset),
945-
#endif // [macOS]
931+
#endif // macOS]
946932
.contentSize = RCTSizeFromCGSize(_backedTextInputView.contentSize),
947933
.layoutMeasurement = RCTSizeFromCGSize(_backedTextInputView.bounds.size),
948934
#if !TARGET_OS_OSX // [macOS]
935+
.zoomScale = 1,
936+
#else // [macOS
949937
.zoomScale = _backedTextInputView.zoomScale,
950-
#endif // [macOS]
938+
#endif // macOS]
951939
};
952940
}
953941

942+
#if TARGET_OS_OSX // [macOS
943+
- (TextInputEventEmitter::Metrics)_textInputMetricsWithScrollView:(RCTUIScrollView *)scrollView
944+
{
945+
TextInputEventEmitter::Metrics metrics = [self _textInputMetrics];
946+
947+
if (scrollView) {
948+
metrics.contentOffset = RCTPointFromCGPoint(scrollView.contentOffset);
949+
metrics.contentInset = RCTEdgeInsetsFromUIEdgeInsets(scrollView.contentInset);
950+
metrics.contentSize = RCTSizeFromCGSize(scrollView.contentSize);
951+
metrics.layoutMeasurement = RCTSizeFromCGSize(scrollView.bounds.size);
952+
metrics.zoomScale = scrollView.zoomScale ?: 1;
953+
}
954+
955+
return metrics;
956+
}
957+
#endif // macOS]
958+
959+
954960
- (void)_updateState
955961
{
956962
if (!_state) {

0 commit comments

Comments
 (0)