- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 1k
Logic detector native gestures #3765
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: next
Are you sure you want to change the base?
Changes from 6 commits
e68928d
              5fdc74a
              b8d999f
              359402e
              02f8732
              7d591f4
              d1eaf3c
              91ea2e7
              3c2ddac
              9eb434f
              8c42422
              66e7f23
              ed852b6
              3cf56a6
              File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm curious, why did the order of attach/detach change? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you follow the logic in  There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure what is  There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I meant  There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I could not replicate the same issue on web due to how views are reused there, but I decided to add a similar fix to be safe. | 
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -160,11 +160,19 @@ - (void)attachHandlers:(const std::vector<int> &)handlerTags | |
| react_native_assert(handlerManager != nullptr && "Tried to access a non-existent handler manager") | ||
|  | ||
| NSMutableSet *handlersToDetach = [attachedHandlers mutableCopy]; | ||
|  | ||
| for (const int tag : handlerTags) { | ||
| [handlersToDetach removeObject:@(tag)]; | ||
| } | ||
|  | ||
| for (const id tag : handlersToDetach) { | ||
| [handlerManager.registry detachHandlerWithTag:tag]; | ||
| [attachedHandlers removeObject:tag]; | ||
| [_nativeHandlers removeObject:tag]; | ||
| } | ||
|  | ||
| for (const int tag : handlerTags) { | ||
| if (![attachedHandlers containsObject:@(tag)]) { | ||
| if ([self shouldAttachGestureToSubview:@(tag)]) { | ||
| if ([self shouldAttachGestureToSubview:@(tag)] && actionType != RNGestureHandlerActionTypeLogicDetector) { | ||
|         
                  j-piasecki marked this conversation as resolved.
              Outdated
          
            Show resolved
            Hide resolved          | ||
| // It might happen that `attachHandlers` will be called before children are added into view hierarchy. In that | ||
| // case we cannot attach `NativeViewGestureHandlers` here and we have to do it in `didAddSubview` method. | ||
| [_nativeHandlers addObject:@(tag)]; | ||
|  | @@ -180,12 +188,6 @@ - (void)attachHandlers:(const std::vector<int> &)handlerTags | |
| } | ||
| } | ||
|  | ||
| for (const id tag : handlersToDetach) { | ||
| [handlerManager.registry detachHandlerWithTag:tag]; | ||
| [attachedHandlers removeObject:tag]; | ||
| [_nativeHandlers removeObject:tag]; | ||
| } | ||
|  | ||
| // This covers the case where `NativeViewGestureHandlers` are attached after child views were created. | ||
| if (self.subviews[0]) { | ||
| [self tryAttachNativeHandlersToChildView]; | ||
|  | @@ -220,22 +222,24 @@ - (void)updateLogicChildren:(const std::vector<RNGestureHandlerDetectorLogicChil | |
| } | ||
|  | ||
| for (const auto &child : logicChildren) { | ||
| if (_attachedLogicHandlers.find(child.viewTag) == _attachedLogicHandlers.end()) { | ||
| _attachedLogicHandlers[child.viewTag] = [NSMutableSet set]; | ||
| } | ||
|  | ||
| [logicChildrenToDetach removeObject:@(child.viewTag)]; | ||
|  | ||
| [self attachHandlers:child.handlerTags | ||
| actionType:RNGestureHandlerActionTypeLogicDetector | ||
| viewTag:child.viewTag | ||
| attachedHandlers:_attachedLogicHandlers[child.viewTag]]; | ||
| } | ||
|  | ||
| for (const NSNumber *tag : logicChildrenToDetach) { | ||
| for (id handlerTag : _attachedLogicHandlers[tag.intValue]) { | ||
| [handlerManager.registry detachHandlerWithTag:handlerTag]; | ||
| } | ||
| _attachedLogicHandlers.erase(tag.intValue); | ||
| } | ||
|  | ||
| for (const auto &child : logicChildren) { | ||
| if (_attachedLogicHandlers.find(child.viewTag) == _attachedLogicHandlers.end()) { | ||
| _attachedLogicHandlers[child.viewTag] = [NSMutableSet set]; | ||
| } | ||
| [self attachHandlers:child.handlerTags | ||
| actionType:RNGestureHandlerActionTypeLogicDetector | ||
| viewTag:child.viewTag | ||
| attachedHandlers:_attachedLogicHandlers[child.viewTag]]; | ||
| } | ||
| } | ||
|  | ||
|  | ||
Uh oh!
There was an error while loading. Please reload this page.