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
2 changes: 1 addition & 1 deletion React/Base/macOS/RCTUIKit.m
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ - (instancetype)initWithFrame:(NSRect)frameRect
return self;
}

@end // ]TODO(macOS GH#774)
@end // ]TODO(macOS GH#774)

@implementation RCTUISwitch

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ NS_ASSUME_NONNULL_BEGIN
* resilient to other code as possible: even if something else nil the delegate, other delegates that were subscribed
* via the splitter will continue working.
*/
#if !TARGET_OS_OSX // TODO(macOS GH#774)
@property (nonatomic, strong, readonly) RCTGenericDelegateSplitter<id<UIScrollViewDelegate>> *delegateSplitter;
#endif // TODO(macOS GH#774)

@property (nonatomic, weak) id<RCTEnhancedScrollViewOverridingDelegate> overridingDelegate;
@property (nonatomic, assign) BOOL pinchGestureEnabled;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,24 @@

#import "RCTEnhancedScrollView.h"
#import <React/RCTUtils.h>

@interface RCTEnhancedScrollView () <UIScrollViewDelegate>
#import <React/RCTScrollableProtocol.h>
#import <React/RCTAutoInsetsProtocol.h>

@interface RCTEnhancedScrollView () <
#if !TARGET_OS_OSX // TODO(macOS GH#774)
UIScrollViewDelegate
#else // [TODO(macOS GH#774)
RCTScrollableProtocol, RCTAutoInsetsProtocol
#endif // ]TODO(macOS GH#774)
>
@end

@implementation RCTEnhancedScrollView {
#if !TARGET_OS_OSX // TODO(macOS GH#774)
__weak id<UIScrollViewDelegate> _publicDelegate;
#else // [TODO(macOS GH#774)
__weak id<RCTScrollableProtocol, RCTAutoInsetsProtocol> _publicDelegate;
#endif // ]TODO(macOS GH#774)
BOOL _isSetContentOffsetDisabled;
}

Expand All @@ -30,6 +42,7 @@ + (BOOL)automaticallyNotifiesObserversForKey:(NSString *)key
- (instancetype)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
#if !TARGET_OS_OSX // TODO(macOS GH#774)
// We set the default behavior to "never" so that iOS
// doesn't do weird things to UIScrollView insets automatically
// and keeps it as an opt-in behavior.
Expand All @@ -45,6 +58,7 @@ - (instancetype)initWithFrame:(CGRect)frame
[weakSelf setPrivateDelegate:delegate];
}];
[_delegateSplitter addDelegate:self];
#endif // TODO(macOS GH#774)
}

return self;
Expand Down Expand Up @@ -88,6 +102,7 @@ - (void)setContentOffset:(CGPoint)contentOffset
RCTSanitizeNaNValue(contentOffset.y, @"scrollView.contentOffset.y"));
}

#if !TARGET_OS_OSX // TODO(macOS GH#774)
- (BOOL)touchesShouldCancelInContentView:(RCTUIView *)view // TODO(macOS GH#774)
{
if ([_overridingDelegate respondsToSelector:@selector(touchesShouldCancelInContentView:)]) {
Expand Down Expand Up @@ -128,6 +143,8 @@ - (void)setDelegate:(id<UIScrollViewDelegate>)delegate
}
}

#endif // TODO(macOS GH#774)

#pragma mark - UIScrollViewDelegate

- (void)scrollViewWillEndDragging:(RCTUIScrollView *)scrollView
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ @interface RCTPullToRefreshViewComponentView () <RCTPullToRefreshViewViewProtoco
@end

@implementation RCTPullToRefreshViewComponentView {
#if !TARGET_OS_OSX // TODO(macOS GH#774)
UIRefreshControl *_refreshControl;
#endif // TODO(macOS GH#774)
RCTScrollViewComponentView *__weak _scrollViewComponentView;
}

Expand All @@ -39,10 +41,12 @@ - (instancetype)initWithFrame:(CGRect)frame
static auto const defaultProps = std::make_shared<PullToRefreshViewProps const>();
_props = defaultProps;

#if !TARGET_OS_OSX // TODO(macOS GH#774)
_refreshControl = [UIRefreshControl new];
[_refreshControl addTarget:self
action:@selector(handleUIControlEventValueChanged)
forControlEvents:UIControlEventValueChanged];
#endif // TODO(macOS GH#774)
}

return self;
Expand All @@ -61,11 +65,13 @@ - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &
auto const &newConcreteProps = *std::static_pointer_cast<PullToRefreshViewProps const>(props);

if (newConcreteProps.refreshing != oldConcreteProps.refreshing) {
#if !TARGET_OS_OSX // TODO(macOS GH#774)
if (newConcreteProps.refreshing) {
[_refreshControl beginRefreshing];
} else {
[_refreshControl endRefreshing];
}
#endif // TODO(macOS GH#774)
}

BOOL needsUpdateTitle = NO;
Expand Down Expand Up @@ -97,7 +103,9 @@ - (void)_updateTitle
auto const &concreteProps = *std::static_pointer_cast<PullToRefreshViewProps const>(_props);

if (concreteProps.title.empty()) {
#if !TARGET_OS_OSX // TODO(macOS GH#774)
_refreshControl.attributedTitle = nil;
#endif // TODO(macOS GH#774)
return;
}

Expand All @@ -106,8 +114,10 @@ - (void)_updateTitle
attributes[NSForegroundColorAttributeName] = RCTUIColorFromSharedColor(concreteProps.titleColor);
}

#if !TARGET_OS_OSX // TODO(macOS GH#774)
_refreshControl.attributedTitle =
[[NSAttributedString alloc] initWithString:RCTNSStringFromString(concreteProps.title) attributes:attributes];
#endif // TODO(macOS GH#774)
}

#pragma mark - Attaching & Detaching
Expand All @@ -132,9 +142,11 @@ - (void)_attach
return;
}

#if !TARGET_OS_OSX // TODO(macOS GH#774)
if (@available(macOS 13.0, *)) {
_scrollViewComponentView.scrollView.refreshControl = _refreshControl;
}
#endif // TODO(macOS GH#774)
}

- (void)_detach
Expand All @@ -144,11 +156,13 @@ - (void)_detach
}

// iOS requires to end refreshing before unmounting.
#if !TARGET_OS_OSX // TODO(macOS GH#774)
[_refreshControl endRefreshing];

if (@available(macOS 13.0, *)) {
_scrollViewComponentView.scrollView.refreshControl = nil;
}
#endif // TODO(macOS GH#774)
_scrollViewComponentView = nil;
}

Expand All @@ -161,11 +175,13 @@ - (void)handleCommand:(const NSString *)commandName args:(const NSArray *)args

- (void)setNativeRefreshing:(BOOL)refreshing
{
#if !TARGET_OS_OSX // TODO(macOS GH#774)
if (refreshing) {
[_refreshControl beginRefreshing];
} else {
[_refreshControl endRefreshing];
}
#endif // TODO(macOS GH#774)
}

#pragma mark - RCTRefreshableProtocol
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ NS_ASSUME_NONNULL_BEGIN
/*
* Returns a delegate splitter that can be used to subscribe for UIScrollView delegate.
*/
#if !TARGET_OS_OSX // TODO(macOS GH#774)
@property (nonatomic, strong, readonly)
RCTGenericDelegateSplitter<id<UIScrollViewDelegate>> *scrollViewDelegateSplitter;
#endif // TODO(macOS GH#774)

@end

Expand Down
Loading