From 9b8d99dac75868bec96d41d15428755a1458f1f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82?= Date: Thu, 13 Nov 2025 18:43:01 +0100 Subject: [PATCH 1/4] Remove dropped handlers --- .../apple/RNGestureHandlerDetector.mm | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/packages/react-native-gesture-handler/apple/RNGestureHandlerDetector.mm b/packages/react-native-gesture-handler/apple/RNGestureHandlerDetector.mm index b5e0059608..0baf3896f5 100644 --- a/packages/react-native-gesture-handler/apple/RNGestureHandlerDetector.mm +++ b/packages/react-native-gesture-handler/apple/RNGestureHandlerDetector.mm @@ -127,10 +127,28 @@ - (BOOL)shouldAttachGestureToSubview:(NSNumber *)handlerTag return [[[handlerManager registry] handlerWithTag:handlerTag] wantsToAttachDirectlyToView]; } +- (void)removeDroppedNativeHandlers +{ + RNGestureHandlerManager *handlerManager = [RNGestureHandlerModule handlerManagerForModuleId:_moduleId]; + + NSMutableSet *nativeHandlersToRemove = [NSMutableSet set]; + + for (NSNumber *handlerTag in _nativeHandlers) { + if ([[handlerManager registry] handlerWithTag:handlerTag] == nil) { + [nativeHandlersToRemove addObject:handlerTag]; + } + } + + for (NSNumber *handlerTag in nativeHandlersToRemove) { + [_nativeHandlers removeObject:handlerTag]; + } +} + - (void)didAddSubview:(RNGHUIView *)view { [super didAddSubview:view]; + [self removeDroppedNativeHandlers]; [self tryAttachNativeHandlersToChildView]; } From 56e79a6619a6cf2f850d2ddd03db980a47a55ddf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82?= Date: Fri, 14 Nov 2025 17:03:29 +0100 Subject: [PATCH 2/4] Override prepareForRecycle --- .../apple/RNGestureHandlerDetector.mm | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/packages/react-native-gesture-handler/apple/RNGestureHandlerDetector.mm b/packages/react-native-gesture-handler/apple/RNGestureHandlerDetector.mm index 0baf3896f5..849de93523 100644 --- a/packages/react-native-gesture-handler/apple/RNGestureHandlerDetector.mm +++ b/packages/react-native-gesture-handler/apple/RNGestureHandlerDetector.mm @@ -127,28 +127,17 @@ - (BOOL)shouldAttachGestureToSubview:(NSNumber *)handlerTag return [[[handlerManager registry] handlerWithTag:handlerTag] wantsToAttachDirectlyToView]; } -- (void)removeDroppedNativeHandlers +- (void)prepareForRecycle { - RNGestureHandlerManager *handlerManager = [RNGestureHandlerModule handlerManagerForModuleId:_moduleId]; - - NSMutableSet *nativeHandlersToRemove = [NSMutableSet set]; + [super prepareForRecycle]; - for (NSNumber *handlerTag in _nativeHandlers) { - if ([[handlerManager registry] handlerWithTag:handlerTag] == nil) { - [nativeHandlersToRemove addObject:handlerTag]; - } - } - - for (NSNumber *handlerTag in nativeHandlersToRemove) { - [_nativeHandlers removeObject:handlerTag]; - } + [_nativeHandlers removeAllObjects]; } - (void)didAddSubview:(RNGHUIView *)view { [super didAddSubview:view]; - [self removeDroppedNativeHandlers]; [self tryAttachNativeHandlersToChildView]; } From 767a938d0498a3aac5fdb823fb5f7a59449d5bd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82?= Date: Mon, 17 Nov 2025 10:12:52 +0100 Subject: [PATCH 3/4] Reset remaining fields --- .../apple/RNGestureHandlerDetector.mm | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/react-native-gesture-handler/apple/RNGestureHandlerDetector.mm b/packages/react-native-gesture-handler/apple/RNGestureHandlerDetector.mm index 849de93523..71e2685873 100644 --- a/packages/react-native-gesture-handler/apple/RNGestureHandlerDetector.mm +++ b/packages/react-native-gesture-handler/apple/RNGestureHandlerDetector.mm @@ -131,7 +131,12 @@ - (void)prepareForRecycle { [super prepareForRecycle]; + static const auto defaultProps = std::make_shared(); + _props = defaultProps; + _moduleId = -1; + [_nativeHandlers removeAllObjects]; + [_attachedHandlers removeAllObjects]; } - (void)didAddSubview:(RNGHUIView *)view From 4e99b77d0e0eea039c78f102c3721a911f74bb43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82?= Date: Mon, 17 Nov 2025 10:41:02 +0100 Subject: [PATCH 4/4] Extract assignments to function --- .../apple/RNGestureHandlerDetector.mm | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/packages/react-native-gesture-handler/apple/RNGestureHandlerDetector.mm b/packages/react-native-gesture-handler/apple/RNGestureHandlerDetector.mm index 71e2685873..f591fecff8 100644 --- a/packages/react-native-gesture-handler/apple/RNGestureHandlerDetector.mm +++ b/packages/react-native-gesture-handler/apple/RNGestureHandlerDetector.mm @@ -33,11 +33,7 @@ + (BOOL)shouldBeRecycled - (instancetype)initWithFrame:(CGRect)frame { if (self = [super initWithFrame:frame]) { - static const auto defaultProps = std::make_shared(); - _props = defaultProps; - _moduleId = -1; - _nativeHandlers = [NSMutableSet set]; - _attachedHandlers = [NSMutableSet set]; + [self setDefaultProps]; } return self; @@ -72,6 +68,15 @@ - (void)willMoveToWindow:(RNGHWindow *)newWindow } } +- (void)setDefaultProps +{ + static const auto defaultProps = std::make_shared(); + _props = defaultProps; + _moduleId = -1; + _nativeHandlers = [NSMutableSet set]; + _attachedHandlers = [NSMutableSet set]; +} + - (void)dispatchStateChangeEvent:(RNGestureHandlerDetectorEventEmitter::OnGestureHandlerStateChange)event { if (_eventEmitter != nullptr) { @@ -131,12 +136,7 @@ - (void)prepareForRecycle { [super prepareForRecycle]; - static const auto defaultProps = std::make_shared(); - _props = defaultProps; - _moduleId = -1; - - [_nativeHandlers removeAllObjects]; - [_attachedHandlers removeAllObjects]; + [self setDefaultProps]; } - (void)didAddSubview:(RNGHUIView *)view