Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 10 additions & 27 deletions React/Views/ScrollView/RCTScrollContentView.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,25 @@
#import "RCTScrollView.h"

@implementation RCTScrollContentView
#if TARGET_OS_OSX // [TODO(macOS GH#774)
{
BOOL _hasHorizontalScroller;
BOOL _hasVerticalScroller;
}
#endif // ]TODO(macOS GH#774)

- (void)reactSetFrame:(CGRect)frame
{
[super reactSetFrame:frame];

#if !TARGET_OS_OSX // TODO(macOS GH#774)
RCTScrollView *scrollView = (RCTScrollView *)self.superview.superview;
#else // [TODO(macOS GH#774)
// macOS also has a NSClipView in its hierarchy
RCTScrollView *scrollView = (RCTScrollView *)self.superview.superview.superview;
#endif // ]TODO(macOS GH#774)

[super reactSetFrame:frame];

if (!scrollView) {
return;
}

RCTAssert([scrollView isKindOfClass:[RCTScrollView class]], @"Unexpected view hierarchy of RCTScrollView component.");

[scrollView updateContentSizeIfNeeded];

#if TARGET_OS_OSX // [TODO(macOS GH#774)
// On macOS scroll indicators may float over the content view like they do in iOS
// or depending on system preferences they may be outside of the content view
Expand All @@ -52,24 +45,14 @@ - (void)reactSetFrame:(CGRect)frame
// the contents will overflow causing the scroll indicators to appear unnecessarily.
NSScrollView *platformScrollView = [scrollView scrollView];
if ([platformScrollView scrollerStyle] == NSScrollerStyleLegacy) {
const BOOL nextHasHorizontalScroller = [platformScrollView hasHorizontalScroller];
const BOOL nextHasVerticalScroller = [platformScrollView hasVerticalScroller];

if (_hasHorizontalScroller != nextHasHorizontalScroller ||
_hasVerticalScroller != nextHasVerticalScroller) {

_hasHorizontalScroller = nextHasHorizontalScroller;
_hasVerticalScroller = nextHasVerticalScroller;

CGFloat horizontalScrollerHeight = _hasHorizontalScroller ? NSHeight([[platformScrollView horizontalScroller] frame]) : 0;
CGFloat verticalScrollerWidth = _hasVerticalScroller ? NSWidth([[platformScrollView verticalScroller] frame]) : 0;

RCTScrollContentLocalData *localData =
[[RCTScrollContentLocalData alloc]
initWithVerticalScrollerWidth:horizontalScrollerHeight
horizontalScrollerHeight:verticalScrollerWidth];
[[[scrollView bridge] uiManager] setLocalData:localData forView:self];
}
CGFloat horizontalScrollerHeight = [platformScrollView hasHorizontalScroller] ? NSHeight([[platformScrollView horizontalScroller] frame]) : 0;
CGFloat verticalScrollerWidth = [platformScrollView hasVerticalScroller] ? NSWidth([[platformScrollView verticalScroller] frame]) : 0;

RCTScrollContentLocalData *localData =
[[RCTScrollContentLocalData alloc]
initWithVerticalScrollerWidth:horizontalScrollerHeight
horizontalScrollerHeight:verticalScrollerWidth];
[[[scrollView bridge] uiManager] setLocalData:localData forView:self];
}
#endif // ]TODO(macOS GH#774)
}
Expand Down
6 changes: 1 addition & 5 deletions React/Views/ScrollView/RCTScrollView.m
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ - (instancetype)initWithFrame:(CGRect)frame
self.scrollEnabled = YES;
self.hasHorizontalScroller = YES;
self.hasVerticalScroller = YES;
self.autohidesScrollers = YES;
self.panGestureRecognizer = [[NSPanGestureRecognizer alloc] initWithTarget:self action:@selector(handleCustomPan:)];
#else // ]TODO(macOS GH#774)
[self.panGestureRecognizer addTarget:self action:@selector(handleCustomPan:)];
Expand Down Expand Up @@ -642,11 +643,6 @@ - (void)updateClippedSubviews
[self react_updateClippedSubviewsWithClipRect:clipRect relativeToView:clipView];
_lastClippedToRect = bounds;
}

#if TARGET_OS_OSX // [TODO(macOS GH#774)
[[self scrollView] setHasHorizontalScroller:[self isHorizontal:_scrollView]];
[[self scrollView] setHasVerticalScroller:[self isVertical:_scrollView]];
#endif // ]TODO(macOS GH#774)
}

#if TARGET_OS_OSX // [TODO(macOS GH#774)
Expand Down