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

Bug on tap action #50

Closed
Josuepdc opened this issue Jan 7, 2019 · 19 comments
Closed

Bug on tap action #50

Josuepdc opened this issue Jan 7, 2019 · 19 comments
Labels

Comments

@Josuepdc
Copy link

Josuepdc commented Jan 7, 2019

After updating from 1.0.5 to 1.1.1, I need to hold the button to receive the IBAction in my view controller instead of just tap the button. I tested some things and found that if you remove the "if" of line 708 of file "LGButton.swift" (based on commit 3dfd991), the problem will no longer exists.

@loregr
Copy link
Owner

loregr commented Jan 14, 2019

@Josuepdc could you please provide more info on your local setup and view/gestures hierarchy? The issue doesn't seem to occur on the example project. Also, your suggestion may fix your problem but won't work if the button is inside a view with a UITapGestureRecognizer attached. Also please check the latest version of the pod that includes @l3bel fixes, it "may" be in some way related to your issue. Thanks.

@landa
Copy link

landa commented Feb 11, 2019

I have the same problem. You need to hold the button for it to publish a 'tap up' event.

@loregr
Copy link
Owner

loregr commented Feb 12, 2019

@landa could you please provide more info on your local setup and view/gestures hierarchy? The issue doesn't seem to occur on the example project. Thanks.

@landa
Copy link

landa commented Feb 12, 2019

Yes. I actually switched the pod to use @Josuepdc's fork, and it works well.

My buttons live within an MDCCard, which is in a UITableViewController subclass within a ContainerView.

@l3bel
Copy link

l3bel commented Feb 15, 2019

@loregr any particular reason why you are not calling super at the beginning of touchesBegan, touchesEnded, etc? not sure but this might also fix the issue.
@landa can you test this (switch back to the "normal" version, add calls to super at the beginning of the overridden touchesBla.. funcs) and see what gives, because with @Josuepdc's fork it is not possible to "cancel" the tap if touches end outside the button, which is why @loregr added the test in the first place (Lorenzo please correct me if I am wrong on this)

@landa
Copy link

landa commented Feb 15, 2019

@l3bel what exactly should I do? I'm not overriding a function, so there's no super to call. I'm just using a touch up inside IBAction.

@l3bel
Copy link

l3bel commented Feb 15, 2019

@landa sorry I mean to add the calls inside LGButton.swift (from the original repository, not @Josuepdc's fork)

@l3bel
Copy link

l3bel commented Feb 15, 2019

@landa
....
`

override open func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?){
    super.touchesBegan(touches, with: event)
    pressed = true
}

override open func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?){
    super.touchesEnded(touches, with: event)
    let shouldSendActions = pressed
    pressed = false
    if shouldSendActions{
        sendActions(for: .touchUpInside)
    }
}

override open func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?){
    super.touchesMoved(touches, with: event)
    if let touchLoc = touches.first?.location(in: self){
        if (touchLoc.x < -touchDisableRadius ||
            touchLoc.y < -touchDisableRadius ||
            touchLoc.x > self.bounds.size.width + touchDisableRadius ||
            touchLoc.y > self.bounds.size.height + touchDisableRadius){
            pressed = false
        }
        else if self.touchAlpha == .untouched {
            pressed = true
        }
    }
}

override open func touchesCancelled(_ touches: Set<UITouch>, with event: UIEvent?) {
    super.touchesCancelled(touches, with: event)
    pressed = false
}

`
....
Also please be aware of "bug" #56 in version 1.1.4 (FontAwesome.ttf file needs to be copied from the root of the repository to the Resources folder (through Xcode, make sure it's included in the LGButton target). Waiting for @loregr to fix)

@jmoscatiello
Copy link

Experiencing the same thing but @Josuepdc 's branch fixed it

@l3bel
Copy link

l3bel commented Feb 17, 2019

@jmoscatiello @landa without the if test in place (removed in @Josuepdc 's branch) it is not possible to "cancel" a tap (by means of lifting finger outside of the control). Have you tried what @loregr and myself suggest above (using version 1.1.3 and/or adding calls to super.touches... )?

@jmoscatiello
Copy link

I tried it out. Seems to work! Thanks guys

@l3bel
Copy link

l3bel commented Feb 17, 2019

@jmoscatiello thanks for your reply, glad it worked. Did 1.1.3 work "as is" or did you have to add the calls to super.touchesBla?

@jmoscatiello
Copy link

I had to add to the calls. Not a big deal.

@l3bel
Copy link

l3bel commented Feb 17, 2019

Perfect! Thank you very much for your feedback! If time permits and @landa and @Josuepdc confirm adding the calls to super works for them too, I will make a pull request for when @loregr is back ;)

@loregr
Copy link
Owner

loregr commented Feb 18, 2019

Hi all, sorry for the late response but I've been away for the weekend with no access to my laptop. Anyway thanks @l3bel for having followed the discussion and for having provided great suggestions. I'm still not able to replicate the issue, but I've just released v1.1.5 where I've implemented some improvements based on the discussion above. @jmoscatiello or whoever else was getting the issue, could you please check if it is now fixed in the latest release? Thanks 🌟

@loregr
Copy link
Owner

loregr commented Feb 21, 2019

I'm closing this issue since I'm pretty confident it has been fixed with the latest release. If that's not the case feel free to re-open it.

@loregr loregr closed this as completed Feb 21, 2019
@c0state
Copy link

c0state commented Feb 25, 2019

Didn't get to look into it yet, but I still see this in 1.1.5

@rachelrobynslater
Copy link

rachelrobynslater commented Jul 23, 2019

I'm also still seeing this issue.
I'm using an IBAction (touch up inside, although I've tested other variations).
As @landa said, you need to hold the button down for ~2 seconds for it to register. I simple click doesn't work.

@jmoscatiello
Copy link

@rachelrobynslater just connect touch up inside to the method to connect the click, by default it wont work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants