Skip to content
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

Fixed onTap(..) handler - unable to add second tap handler #715

Merged
merged 1 commit into from
Jul 17, 2020

Conversation

devpolant
Copy link
Contributor

Updates

In this pull request I'm going to fix the logic of registering new tap handlers.

Previous implementation of this method is completely wrong, because copy-on-write behaviour was not considered.

New handler was appended to copy in this line - handlers.append(handler). tapHandlers dictionary was not changes, so as a user:

  • I was not able to register second tap handler for the same node
  • I was not able to register new tap handler if I disposed previous one

This is old implementation:

    @discardableResult public func onTap(tapCount: Int = 1, f: @escaping (TapEvent) -> Void) -> Disposable {
        let handler = ChangeHandler<TapEvent>(f)
        if var handlers = tapHandlers[tapCount] { // array copy is created
            handlers.append(handler) // copy is mutated here, so changes not applied to `self.tapHandlers`
        } else {
            tapHandlers[tapCount] = [handler]
        }

        return Disposable { [weak self, unowned handler]  in
            guard let index = self?.tapHandlers[tapCount]?.firstIndex(of: handler) else {
                return
            }

            self?.tapHandlers[tapCount]?.remove(at: index)
        }
    }

Issue is fixed in new implementation.

…ed copy on write behavior, so it was not possible to register second tap hander.
@ystrot ystrot self-assigned this Jul 17, 2020
@ystrot ystrot added this to the 0.9.7 milestone Jul 17, 2020
@ystrot ystrot merged commit 2a8e6ee into exyte:master Jul 17, 2020
@ystrot
Copy link
Member

ystrot commented Jul 17, 2020

Thank you for the fix! Merged it.

@devpolant devpolant deleted the bugfix/touch-handling branch August 3, 2020 11:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants