Skip to content

Commit

Permalink
Fix tvOS build (#2654)
Browse files Browse the repository at this point in the history
## Description

tvOS apps are not building since release 2.13.0, because `UIHoverGestureRecognizer` used in `Hover` does not exist on tvOS. This PR changes `#if` inside `RNHoverHandler` in order to avoid using this recognizer on tvOS. It means that functions inside `Hover` can be treated as `no-op`

Fixes #2647 

## Test plan

Tested that tvOS example builds when used with `Hover`
  • Loading branch information
m-bert authored Oct 26, 2023
1 parent fa721ed commit c46c158
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
29 changes: 15 additions & 14 deletions ios/Handlers/RNHoverHandler.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,17 @@
#import <React/RCTConvert.h>
#import <UIKit/UIGestureRecognizerSubclass.h>

#define CHECK_TARGET(__VERSION__) \
defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && defined(__IPHONE_##__VERSION__) && \
__IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_##__VERSION__ && !TARGET_OS_TV

typedef NS_ENUM(NSInteger, RNGestureHandlerHoverEffect) {
RNGestureHandlerHoverEffectNone = 0,
RNGestureHandlerHoverEffectLift,
RNGestureHandlerHoverEffectHightlight,
};

#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && defined(__IPHONE_13_4) && \
__IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_13_4
#if CHECK_TARGET(13_4)

API_AVAILABLE(ios(13.4))
@interface RNBetterHoverGestureRecognizer : UIHoverGestureRecognizer <UIPointerInteractionDelegate>
Expand Down Expand Up @@ -74,17 +77,19 @@ - (UIPointerStyle *)pointerInteraction:(UIPointerInteraction *)interaction style
#endif

@implementation RNHoverGestureHandler {
#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && defined(__IPHONE_13_4) && \
__IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_13_4
#if CHECK_TARGET(13_4)
UIPointerInteraction *_pointerInteraction;
#endif
}

- (instancetype)initWithTag:(NSNumber *)tag
{
#if TARGET_OS_TV
RCTLogWarn(@"Hover gesture handler is not supported on tvOS");
#endif

if ((self = [super initWithTag:tag])) {
#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && defined(__IPHONE_13_4) && \
__IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_13_4
#if CHECK_TARGET(13_4)
if (@available(iOS 13.4, *)) {
_recognizer = [[RNBetterHoverGestureRecognizer alloc] initWithGestureHandler:self];
_pointerInteraction =
Expand All @@ -97,8 +102,7 @@ - (instancetype)initWithTag:(NSNumber *)tag

- (void)bindToView:(UIView *)view
{
#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && defined(__IPHONE_13_4) && \
__IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_13_4
#if CHECK_TARGET(13_4)
if (@available(iOS 13.4, *)) {
[super bindToView:view];
[view addInteraction:_pointerInteraction];
Expand All @@ -108,8 +112,7 @@ - (void)bindToView:(UIView *)view

- (void)unbindFromView
{
#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && defined(__IPHONE_13_4) && \
__IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_13_4
#if CHECK_TARGET(13_4)
if (@available(iOS 13.4, *)) {
[super unbindFromView];
[self.recognizer.view removeInteraction:_pointerInteraction];
Expand All @@ -121,8 +124,7 @@ - (void)resetConfig
{
[super resetConfig];

#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && defined(__IPHONE_13_4) && \
__IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_13_4
#if CHECK_TARGET(13_4)
if (@available(iOS 13.4, *)) {
RNBetterHoverGestureRecognizer *recognizer = (RNBetterHoverGestureRecognizer *)_recognizer;
recognizer.hoverEffect = RNGestureHandlerHoverEffectNone;
Expand All @@ -134,8 +136,7 @@ - (void)configure:(NSDictionary *)config
{
[super configure:config];

#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && defined(__IPHONE_13_4) && \
__IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_13_4
#if CHECK_TARGET(13_4)
if (@available(iOS 13.4, *)) {
RNBetterHoverGestureRecognizer *recognizer = (RNBetterHoverGestureRecognizer *)_recognizer;
APPLY_INT_PROP(hoverEffect);
Expand Down
2 changes: 2 additions & 0 deletions ios/RNGestureHandlerButtonComponentView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ - (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &
const auto &newProps = *std::static_pointer_cast<const RNGestureHandlerButtonProps>(props);

_buttonView.userEnabled = newProps.enabled;
#if !TARGET_OS_TV
_buttonView.exclusiveTouch = newProps.exclusive;
#endif
_buttonView.hitTestEdgeInsets = UIEdgeInsetsMake(
-newProps.hitSlop.top, -newProps.hitSlop.left, -newProps.hitSlop.bottom, -newProps.hitSlop.right);

Expand Down

0 comments on commit c46c158

Please sign in to comment.