optonaut / ActiveLabel.swift

UILabel drop-in replacement supporting Hashtags (#), Mentions (@) and URLs (http://) written in Swift
MIT License
4.47k stars 686 forks source link

Not working properly tap event #255

Closed albetoetecnia closed 5 years ago

albetoetecnia commented 6 years ago

Hi! I'm having problems to get tap event on customType, neither working mentions, hashtags... This is my code:

   ```
    let text = "remember_pwd".localized
    let customType = ActiveType.custom(pattern: "\\s" + "click_here".localized + "\\b")
    label_password_remember.numberOfLines = 0
    label_password_remember.isUserInteractionEnabled  = true
    label_password_remember.isMultipleTouchEnabled  = true
    label_password_remember.enabledTypes = [.mention, .hashtag, .url, customType]
    label_password_remember.textColor = .white
    label_password_remember.text = text
    label_password_remember.customColor[customType] = UIColor.white
    label_password_remember.customSelectedColor[customType] = Common.UIColorFromRGB(Common.Color.APP_COLOR_ACCENT)

    label_password_remember.handleCustomTap(for: customType) { (element) in
        print("Custom type tapped: \(element)")
        self.performSegue(withIdentifier: "action_remember_password", sender: nil)
    }

Only enter on handleCustomTap a few time (random). The label is created in storyboard. Swift 4.
I hope you can reproduce, it's very easy I think.

Regards
fpena commented 5 years ago

I think this happens with multiline labels. Having same issue here.

unknown-undefined commented 5 years ago

you should call ActiveLabel.text.setter at last @albetoetecnia


    let text = "remember_pwd".localized
    let customType = ActiveType.custom(pattern: "\\s" + "click_here".localized + "\\b")
    label_password_remember.numberOfLines = 0
    label_password_remember.isUserInteractionEnabled  = true
    label_password_remember.isMultipleTouchEnabled  = true
    label_password_remember.enabledTypes = [.mention, .hashtag, .url, customType]
    label_password_remember.textColor = .white
    label_password_remember.text = text // remove this line
    label_password_remember.customColor[customType] = UIColor.white
    label_password_remember.customSelectedColor[customType] = Common.UIColorFromRGB(Common.Color.APP_COLOR_ACCENT)

    label_password_remember.handleCustomTap(for: customType) { (element) in
        print("Custom type tapped: \(element)")
        self.performSegue(withIdentifier: "action_remember_password", sender: nil)
    }
    label_password_remember.text = text // add here
rakkang commented 5 years ago

Env:

Use source integration instead of cocoapod, modify func onTouch(_ touch: UITouch)

...

case .ended, .cancelled:
    guard let selectedElement = selectedElement else { return avoidSuperCall }

    ...

// case .cancelled:
//  updateAttributesWhenSelected(false)
//  selectedElement = nil

...

It's working!

vani2 commented 5 years ago

If someone want you can use my fork .

pod 'ActiveLabel' , :git => 'git@github.com:RedMadRobot/ActiveLabel.swift.git', :branch => 'master'
maziyarpanahi commented 5 years ago

Hi! If this is a real issue that needs to be fixed, please feel free to create a pull request. I'll merge it after a test for the next release.

Thanks everyone.

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

adiahuja07 commented 4 years ago

Any updates. I am also facing the same issue. If the user taps for a little longer then it gets registered otherwise it is skipped.

vani2 commented 4 years ago

@adiahuja07 did you tried my fork?