@@ -151,7 +151,7 @@ - (instancetype)initWithFrame:(CGRect)frame
151151 _containerView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
152152 [_scrollView setDocumentView: _containerView];
153153#endif // macOS]
154-
154+
155155#if !TARGET_OS_OSX // [macOS]
156156 [self .scrollViewDelegateSplitter addDelegate: self ];
157157#endif // [macOS]
@@ -279,6 +279,19 @@ static inline UIViewAnimationOptions animationOptionsWithCurve(UIViewAnimationCu
279279}
280280#endif
281281
282+ #if TARGET_OS_OSX // [macOS
283+ - (void )setContentInset : (UIEdgeInsets)contentInset
284+ {
285+ if (UIEdgeInsetsEqualToEdgeInsets (contentInset, _contentInset)) {
286+ return ;
287+ }
288+
289+ _contentInset = contentInset;
290+ _scrollView.contentInset = contentInset;
291+ _scrollView.scrollIndicatorInsets = contentInset;
292+ }
293+ #endif // macOS]
294+
282295- (RCTGenericDelegateSplitter<id<RCTUIScrollViewDelegate>> *)scrollViewDelegateSplitter
283296{
284297 return ((RCTEnhancedScrollView *)_scrollView).delegateSplitter ;
@@ -408,7 +421,11 @@ - (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &
408421 MAP_SCROLL_VIEW_PROP (zoomScale);
409422
410423 if (oldScrollViewProps.contentInset != newScrollViewProps.contentInset ) {
424+ #if !TARGET_OS_OSX // [macOS]
411425 _scrollView.contentInset = RCTUIEdgeInsetsFromEdgeInsets (newScrollViewProps.contentInset );
426+ #else // [macOS
427+ self.contentInset = RCTUIEdgeInsetsFromEdgeInsets (newScrollViewProps.contentInset );
428+ #endif // macOS]
412429 }
413430
414431 RCTEnhancedScrollView *scrollView = (RCTEnhancedScrollView *)_scrollView;
@@ -452,7 +469,7 @@ - (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &
452469 _shouldUpdateContentInsetAdjustmentBehavior = NO ;
453470 }
454471#endif // [macOS]
455-
472+
456473 MAP_SCROLL_VIEW_PROP (disableIntervalMomentum);
457474 MAP_SCROLL_VIEW_PROP (snapToInterval);
458475
@@ -673,6 +690,22 @@ - (void)prepareForRecycle
673690 _firstVisibleView = nil ;
674691}
675692
693+ #if TARGET_OS_OSX // [macOS
694+ #pragma mark - NSScrollView scroll notification
695+
696+ - (void )scrollViewDocumentViewBoundsDidChange:(__unused NSNotification *)notification
697+ {
698+ RCTEnhancedScrollView *scrollView = _scrollView;
699+
700+ if (scrollView.centerContent ) {
701+ // Update content centering through contentOffset setter
702+ [scrollView setContentOffset: scrollView.contentOffset];
703+ }
704+
705+ [self scrollViewDidScroll: scrollView];
706+ }
707+ #endif // macOS]
708+
676709#pragma mark - UIScrollViewDelegate
677710
678711#if !TARGET_OS_OSX // [macOS]
@@ -812,9 +845,25 @@ - (void)didMoveToWindow
812845 [super didMoveToWindow ];
813846#else // [macOS
814847- (void )viewDidMoveToWindow // [macOS]
848+ #endif // [macOS]
815849{
816850 [super viewDidMoveToWindow ];
817- #endif // [macOS]
851+
852+ #if TARGET_OS_OSX // [macOS
853+ NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter ];
854+ if (self.window == nil ) {
855+ // Unregister scrollview's clipview bounds change notifications
856+ [defaultCenter removeObserver: self
857+ name: NSViewBoundsDidChangeNotification
858+ object: _scrollView.contentView];
859+ } else {
860+ // Register for scrollview's clipview bounds change notifications so we can track scrolling
861+ [defaultCenter addObserver: self
862+ selector: @selector (scrollViewDocumentViewBoundsDidChange: )
863+ name: NSViewBoundsDidChangeNotification
864+ object: _scrollView.contentView]; // NSClipView
865+ }
866+ #endif // macOS]
818867
819868 if (!self.window ) {
820869 // The view is being removed, ensure that the scroll end event is dispatched
@@ -898,6 +947,8 @@ - (void)flashScrollIndicators
898947{
899948#if !TARGET_OS_OSX // [macOS]
900949 [_scrollView flashScrollIndicators ];
950+ #else // [macOS
951+ [(RCTEnhancedScrollView *)_scrollView flashScrollers ];
901952#endif // [macOS]
902953}
903954
@@ -997,7 +1048,11 @@ - (void)scrollToOffset:(CGPoint)offset animated:(BOOL)animated
9971048
9981049 [self _forceDispatchNextScrollEvent ];
9991050
1051+ #if !TARGET_OS_OSX // [macOS]
10001052 [_scrollView setContentOffset: offset animated: animated];
1053+ #else // [macOS
1054+ [(RCTEnhancedScrollView *)_scrollView setContentOffset: offset animated: animated];
1055+ #endif // macOS]
10011056
10021057 if (!animated) {
10031058 // When not animated, the expected workflow in ``scrollViewDidEndScrollingAnimation`` after scrolling is not going
@@ -1010,6 +1065,8 @@ - (void)zoomToRect:(CGRect)rect animated:(BOOL)animated
10101065{
10111066#if !TARGET_OS_OSX // [macOS]
10121067 [_scrollView zoomToRect: rect animated: animated];
1068+ #else // [macOS
1069+ [(RCTEnhancedScrollView *)_scrollView zoomToRect: rect animated: animated];
10131070#endif // [macOS]
10141071}
10151072
0 commit comments