From 7ca9452d5f49b8c6ad8bb928dc7e2f70b31628a2 Mon Sep 17 00:00:00 2001 From: Jakub Piasecki Date: Tue, 28 May 2024 18:34:35 +0200 Subject: [PATCH 1/3] Remove button component view --- ...dlerButton.m => RNGestureHandlerButton.mm} | 40 ++++++++++++ apple/RNGestureHandlerButtonComponentView.h | 17 ----- apple/RNGestureHandlerButtonComponentView.mm | 64 ------------------- 3 files changed, 40 insertions(+), 81 deletions(-) rename apple/{RNGestureHandlerButton.m => RNGestureHandlerButton.mm} (67%) delete mode 100644 apple/RNGestureHandlerButtonComponentView.h delete mode 100644 apple/RNGestureHandlerButtonComponentView.mm diff --git a/apple/RNGestureHandlerButton.m b/apple/RNGestureHandlerButton.mm similarity index 67% rename from apple/RNGestureHandlerButton.m rename to apple/RNGestureHandlerButton.mm index e16f07e8e3..8199b7bdcf 100644 --- a/apple/RNGestureHandlerButton.m +++ b/apple/RNGestureHandlerButton.mm @@ -12,6 +12,19 @@ #import #endif +#ifdef RCT_NEW_ARCH_ENABLED +#import +#import +#import + +#import +#import +#import +#import + +using namespace facebook::react; +#endif // RCT_NEW_ARCH_ENABLED + /** * Gesture Handler Button components overrides standard mechanism used by RN * to determine touch target, which normally would reurn the UIView that is placed @@ -82,4 +95,31 @@ - (RNGHUIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event } #endif +#ifdef RCT_NEW_ARCH_ENABLED ++ (ComponentDescriptorProvider)componentDescriptorProvider +{ + return concreteComponentDescriptorProvider(); +} + +- (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &)oldProps +{ + const auto &newProps = *std::static_pointer_cast(props); + + self.userEnabled = newProps.enabled; +#if !TARGET_OS_TV + self.exclusiveTouch = newProps.exclusive; +#endif + self.hitTestEdgeInsets = UIEdgeInsetsMake( + -newProps.hitSlop.top, -newProps.hitSlop.left, -newProps.hitSlop.bottom, -newProps.hitSlop.right); + + [super updateProps:props oldProps:oldProps]; +} + +Class RNGestureHandlerButtonCls(void) +{ + return RNGestureHandlerButton.class; +} + +#endif // RCT_NEW_ARCH_ENABLED + @end diff --git a/apple/RNGestureHandlerButtonComponentView.h b/apple/RNGestureHandlerButtonComponentView.h deleted file mode 100644 index f1cbdd9ed5..0000000000 --- a/apple/RNGestureHandlerButtonComponentView.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifdef RCT_NEW_ARCH_ENABLED - -#import - -#import - -#import "RNGestureHandlerButton.h" - -NS_ASSUME_NONNULL_BEGIN - -@interface RNGestureHandlerButtonComponentView : RCTViewComponentView - -@end - -NS_ASSUME_NONNULL_END - -#endif // RCT_NEW_ARCH_ENABLED diff --git a/apple/RNGestureHandlerButtonComponentView.mm b/apple/RNGestureHandlerButtonComponentView.mm deleted file mode 100644 index c4cdc99d8c..0000000000 --- a/apple/RNGestureHandlerButtonComponentView.mm +++ /dev/null @@ -1,64 +0,0 @@ -#ifdef RCT_NEW_ARCH_ENABLED - -#import "RNGestureHandlerButtonComponentView.h" - -#import -#import - -#import -#import -#import -#import - -#import "RNGestureHandlerButton.h" - -using namespace facebook::react; - -@interface RNGestureHandlerButtonComponentView () -@end - -@implementation RNGestureHandlerButtonComponentView { - RNGestureHandlerButton *_buttonView; -} - -- (instancetype)initWithFrame:(CGRect)frame -{ - if (self = [super initWithFrame:frame]) { - static const auto defaultProps = std::make_shared(); - _props = defaultProps; - _buttonView = [[RNGestureHandlerButton alloc] initWithFrame:self.bounds]; - - self.contentView = _buttonView; - } - - return self; -} - -#pragma mark - RCTComponentViewProtocol - -+ (ComponentDescriptorProvider)componentDescriptorProvider -{ - return concreteComponentDescriptorProvider(); -} - -- (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &)oldProps -{ - const auto &newProps = *std::static_pointer_cast(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); - - [super updateProps:props oldProps:oldProps]; -} -@end - -Class RNGestureHandlerButtonCls(void) -{ - return RNGestureHandlerButtonComponentView.class; -} - -#endif // RCT_NEW_ARCH_ENABLED From 3155d51381e3b307cda75a52d5c0a93bc73720f4 Mon Sep 17 00:00:00 2001 From: Jakub Piasecki Date: Wed, 29 May 2024 15:35:56 +0200 Subject: [PATCH 2/3] Revert "Remove button component view" This reverts commit 7ca9452d5f49b8c6ad8bb928dc7e2f70b31628a2. --- ...dlerButton.mm => RNGestureHandlerButton.m} | 40 ------------ apple/RNGestureHandlerButtonComponentView.h | 17 +++++ apple/RNGestureHandlerButtonComponentView.mm | 64 +++++++++++++++++++ 3 files changed, 81 insertions(+), 40 deletions(-) rename apple/{RNGestureHandlerButton.mm => RNGestureHandlerButton.m} (67%) create mode 100644 apple/RNGestureHandlerButtonComponentView.h create mode 100644 apple/RNGestureHandlerButtonComponentView.mm diff --git a/apple/RNGestureHandlerButton.mm b/apple/RNGestureHandlerButton.m similarity index 67% rename from apple/RNGestureHandlerButton.mm rename to apple/RNGestureHandlerButton.m index 8199b7bdcf..e16f07e8e3 100644 --- a/apple/RNGestureHandlerButton.mm +++ b/apple/RNGestureHandlerButton.m @@ -12,19 +12,6 @@ #import #endif -#ifdef RCT_NEW_ARCH_ENABLED -#import -#import -#import - -#import -#import -#import -#import - -using namespace facebook::react; -#endif // RCT_NEW_ARCH_ENABLED - /** * Gesture Handler Button components overrides standard mechanism used by RN * to determine touch target, which normally would reurn the UIView that is placed @@ -95,31 +82,4 @@ - (RNGHUIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event } #endif -#ifdef RCT_NEW_ARCH_ENABLED -+ (ComponentDescriptorProvider)componentDescriptorProvider -{ - return concreteComponentDescriptorProvider(); -} - -- (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &)oldProps -{ - const auto &newProps = *std::static_pointer_cast(props); - - self.userEnabled = newProps.enabled; -#if !TARGET_OS_TV - self.exclusiveTouch = newProps.exclusive; -#endif - self.hitTestEdgeInsets = UIEdgeInsetsMake( - -newProps.hitSlop.top, -newProps.hitSlop.left, -newProps.hitSlop.bottom, -newProps.hitSlop.right); - - [super updateProps:props oldProps:oldProps]; -} - -Class RNGestureHandlerButtonCls(void) -{ - return RNGestureHandlerButton.class; -} - -#endif // RCT_NEW_ARCH_ENABLED - @end diff --git a/apple/RNGestureHandlerButtonComponentView.h b/apple/RNGestureHandlerButtonComponentView.h new file mode 100644 index 0000000000..f1cbdd9ed5 --- /dev/null +++ b/apple/RNGestureHandlerButtonComponentView.h @@ -0,0 +1,17 @@ +#ifdef RCT_NEW_ARCH_ENABLED + +#import + +#import + +#import "RNGestureHandlerButton.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface RNGestureHandlerButtonComponentView : RCTViewComponentView + +@end + +NS_ASSUME_NONNULL_END + +#endif // RCT_NEW_ARCH_ENABLED diff --git a/apple/RNGestureHandlerButtonComponentView.mm b/apple/RNGestureHandlerButtonComponentView.mm new file mode 100644 index 0000000000..c4cdc99d8c --- /dev/null +++ b/apple/RNGestureHandlerButtonComponentView.mm @@ -0,0 +1,64 @@ +#ifdef RCT_NEW_ARCH_ENABLED + +#import "RNGestureHandlerButtonComponentView.h" + +#import +#import + +#import +#import +#import +#import + +#import "RNGestureHandlerButton.h" + +using namespace facebook::react; + +@interface RNGestureHandlerButtonComponentView () +@end + +@implementation RNGestureHandlerButtonComponentView { + RNGestureHandlerButton *_buttonView; +} + +- (instancetype)initWithFrame:(CGRect)frame +{ + if (self = [super initWithFrame:frame]) { + static const auto defaultProps = std::make_shared(); + _props = defaultProps; + _buttonView = [[RNGestureHandlerButton alloc] initWithFrame:self.bounds]; + + self.contentView = _buttonView; + } + + return self; +} + +#pragma mark - RCTComponentViewProtocol + ++ (ComponentDescriptorProvider)componentDescriptorProvider +{ + return concreteComponentDescriptorProvider(); +} + +- (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &)oldProps +{ + const auto &newProps = *std::static_pointer_cast(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); + + [super updateProps:props oldProps:oldProps]; +} +@end + +Class RNGestureHandlerButtonCls(void) +{ + return RNGestureHandlerButtonComponentView.class; +} + +#endif // RCT_NEW_ARCH_ENABLED From dad58b5ad6d8e978f44ca186278f0950f1f31926 Mon Sep 17 00:00:00 2001 From: Jakub Piasecki Date: Wed, 29 May 2024 16:33:08 +0200 Subject: [PATCH 3/3] Redirect children to the actual button --- apple/RNGestureHandlerButtonComponentView.mm | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/apple/RNGestureHandlerButtonComponentView.mm b/apple/RNGestureHandlerButtonComponentView.mm index c4cdc99d8c..f9bf4ccf3b 100644 --- a/apple/RNGestureHandlerButtonComponentView.mm +++ b/apple/RNGestureHandlerButtonComponentView.mm @@ -34,6 +34,16 @@ - (instancetype)initWithFrame:(CGRect)frame return self; } +- (void)mountChildComponentView:(UIView *)childComponentView index:(NSInteger)index +{ + [_buttonView mountChildComponentView:childComponentView index:index]; +} + +- (void)unmountChildComponentView:(UIView *)childComponentView index:(NSInteger)index +{ + [_buttonView unmountChildComponentView:childComponentView index:index]; +} + #pragma mark - RCTComponentViewProtocol + (ComponentDescriptorProvider)componentDescriptorProvider