fix(ios): fix tap gesture conflict handling and animation in ItemPressableModule

Signed-off-by: Innei <tukon479@gmail.com>
This commit is contained in:
Innei 2025-04-16 19:43:03 +08:00
parent 5bfcbbcb16
commit 102f66e264
No known key found for this signature in database
GPG Key ID: 0F62D33977F021F7
1 changed files with 13 additions and 9 deletions

View File

@ -39,22 +39,26 @@ class ItemPressableView: ExpoView {
}
func initizlize() {
gestureRecognizers = [UITapGestureRecognizer(target: self, action: #selector(handleTap))]
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(handleTap))
tapGesture.delegate = self
gestureRecognizers = [tapGesture]
}
@objc func handleTap() {
let bgColor = layer.backgroundColor
if touchHighlight {
UIView.animate(withDuration: 0.2, delay: 0, options: [.curveEaseIn]) {
self.layer.backgroundColor = UIColor.systemFill.cgColor
} completion: { done in
if done {
UIView.animate(withDuration: 0.2, delay: 0.2, options: [.curveEaseOut]) {
self.layer.backgroundColor = bgColor
}
}
layer.backgroundColor = UIColor.systemGray5.cgColor
UIView.animate(withDuration: 0.2, delay: 0.5, options: [.curveEaseOut]) {
self.layer.backgroundColor = bgColor
}
}
onItemPress()
}
}
extension ItemPressableView: UIGestureRecognizerDelegate {
func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {
return touch.view == gestureRecognizer.view
}
}