From 5e8b3653857e4ce31b7cc641f10693ee26e1cd7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Egemen=20T=C3=BCrk?= Date: Wed, 30 Aug 2023 20:31:05 +0300 Subject: [PATCH] fix for issue 15 --- .DS_Store | Bin 0 -> 6148 bytes Example/.DS_Store | Bin 0 -> 6148 bytes Sources/.DS_Store | Bin 0 -> 6148 bytes Sources/SwipyCell/SwipyCell.swift | 52 +++++++++++++++++++----------- 4 files changed, 33 insertions(+), 19 deletions(-) create mode 100644 .DS_Store create mode 100644 Example/.DS_Store create mode 100644 Sources/.DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..f32cfa4cccd7a48aece10028d413466f99b50ad8 GIT binary patch literal 6148 zcmeHKU5nE|6ur}}Hg#F4py-Pb@U_(LhYO1@-F`eQsK`e2L8UfL+zriUO4C}U6!NP6 z2mgYP{uBR;PkQdmtTd@U3A)JKGIQ?C+|y*vWo9x&B-*oJo2W)a4hm!W3aVcik8@eG zlIht53iTgjiYYvb<(O>*=9HrA{^Q$OrlrLSbIF7UFy!1}x+?x)jv$Q>!Jm=OEDP#ZKANWtBaNe(7 z@5p32h>~!k2vHCswy3O literal 0 HcmV?d00001 diff --git a/Example/.DS_Store b/Example/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..96af85908793b13e1a1f0d926c051a11689c4b2b GIT binary patch literal 6148 zcmeHKO>fgc5S>j^YOAW`LlG4xOI)jxeo7S=la>QljNm{~uxqO|xZWrqxG0L`Yx`$7 z@=y3X@Md?5+6I(Er3zIu(d?U@of&JN9j}LoRCkO$GJo`u#hngwEhADSut+&C@{KcEzm-4LA7iJ@*@E99ead-unFy?OaYdok*U7aA7>pY!DD{as@9h0UEf0{lG zV12$t^>@^{PBo??!hkR!4BVXo_pS4a@bfjuMP~R1pxAA zq!HNMOK?u;Fml*f#0o^&RG>{&uEkI`9sbb8MGhN_Hl37fK9sw%avh2?S4aKOgp-Oa z$|wv712-91u+xCgfAs7B>i=&h$xIj!1|Adxs(lzAcCjUQw$5yh&)N|B3ChB8jm1AH jFw9YmSU!r^phn;i*#Jfk8;kHj5sCUmjn=ZUz8Eebgxf6ac_MC(O7w%rTlLpRtV1WD$iv$0IbL3lT&| z(M&Zb{-Of(?p*L8fe?D|>HVqeAW{L&(x-8NzWt^Rqq&SA8T2gUCFn)rU|1@>icB`Q zw7lXtPTslnZ&l(C+r!bI-tM2%(TP$~Fpb;6Y1mC#g|&u?hwU)#_BA2wbg|^(EQ~uU zsjE@k8ECF=CLGswTZN7BxLhmBYNa$O%JE*MRFt*q?quRR>svef$E~~QK2}fq) zs%_Qc6rM4dBgKQ?k0TY|;Ovw+WiYY=tN<&ppbFUK%*ik4{qt?J0<6H#DM0IkL?`qt zrUv!WfrD-V5ObK;hB5sx5=UC}ET#r=22B_$qM-`gVhBUWytH+m#nhmogRsqquvZqg zLlOGwcz&tNL3jpvWCd7(uL@A_hgP8d|M2_%Ul;Mf3a|qIQvs1{`pr5%o84Pyo|5)j tiGGDnMs=yd4+;i)E5=&diZ{`yl! literal 0 HcmV?d00001 diff --git a/Sources/SwipyCell/SwipyCell.swift b/Sources/SwipyCell/SwipyCell.swift index 3771dd1..ba23299 100644 --- a/Sources/SwipyCell/SwipyCell.swift +++ b/Sources/SwipyCell/SwipyCell.swift @@ -53,7 +53,7 @@ open class SwipyCell: UITableViewCell, SwipyCellTriggerPointEditable { var firstLeftTrigger: CGFloat! var firstRightTrigger: CGFloat! -// MARK: - Initialization + // MARK: - Initialization override public init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { super.init(style: style, reuseIdentifier: reuseIdentifier) @@ -113,10 +113,11 @@ open class SwipyCell: UITableViewCell, SwipyCellTriggerPointEditable { addSubview(contentScreenshotView!) } -// MARK: - Public Interface + // MARK: - Public Interface public func addSwipeTrigger(forState state: SwipyCellState, withMode mode: SwipyCellMode, swipeView view: UIView, swipeColor color: UIColor, completion block: SwipyCellTriggerBlock?) { triggers[state] = SwipyCellTrigger(mode: mode, color: color, view: view, block: block) + checkEmptyTrigger() } public func setCompletionBlock(forState state: SwipyCellState, _ block: @escaping SwipyCellTriggerBlock) { @@ -130,9 +131,9 @@ open class SwipyCell: UITableViewCell, SwipyCellTriggerPointEditable { triggers[trigger.key]?.block = block } } - -// MARK: - Prepare reuse + + // MARK: - Prepare reuse override open func prepareForReuse() { super.prepareForReuse() @@ -155,8 +156,8 @@ open class SwipyCell: UITableViewCell, SwipyCellTriggerPointEditable { contentScreenshotView!.removeFromSuperview() contentScreenshotView = nil } - -// MARK: - Gesture Recognition + + // MARK: - Gesture Recognition @objc func handlePanGesture(_ gesture: UIPanGestureRecognizer) { if shouldDrag == false || isExited == true { @@ -229,8 +230,8 @@ open class SwipyCell: UITableViewCell, SwipyCellTriggerPointEditable { return false } - -// MARK: - Percentage calculations + + // MARK: - Percentage calculations func swipeOffset(withPercentage percentage: CGFloat, relativeToWidth width: CGFloat) -> CGFloat { var offset = percentage * width @@ -255,8 +256,8 @@ open class SwipyCell: UITableViewCell, SwipyCellTriggerPointEditable { return percentage } - -// MARK: - Animation calculations + + // MARK: - Animation calculations func viewAnimationDuration(withVelocity velocity: CGPoint) -> TimeInterval { let width = bounds.width @@ -271,8 +272,8 @@ open class SwipyCell: UITableViewCell, SwipyCellTriggerPointEditable { return TimeInterval(SwipyCellConstants.durationHighLimit + SwipyCellConstants.durationLowLimit - fabs(Double(horizontalVelocity / width) * animationDurationDiff)) } - -// MARK: - State calculations + + // MARK: - State calculations func swipeDirection(withPercentage percentage: CGFloat) -> SwipyCellDirection { if percentage < 0 { @@ -342,7 +343,7 @@ open class SwipyCell: UITableViewCell, SwipyCellTriggerPointEditable { return alpha } -// MARK: - Trigger handling + // MARK: - Trigger handling func updateTriggerDirections() { triggerDirections = [] @@ -363,7 +364,7 @@ open class SwipyCell: UITableViewCell, SwipyCellTriggerPointEditable { firstRightTrigger = firstTrigger(forDirection: .right) } -// MARK: - Animations / View movement + // MARK: - Animations / View movement func animate(withOffset offset: CGFloat) { let percentage = swipePercentage(withOffset: offset, relativeToWidth: bounds.width) @@ -379,7 +380,7 @@ open class SwipyCell: UITableViewCell, SwipyCellTriggerPointEditable { let color = swipeColor(withSwipeState: state) colorIndicatorView.backgroundColor = color } - + func slideSwipeView(withPercentage percentage: CGFloat, view: UIView?, isDragging: Bool) { guard let view = view else { return } @@ -412,7 +413,7 @@ open class SwipyCell: UITableViewCell, SwipyCellTriggerPointEditable { } else if direction == .left { position.x = min(position.x, bounds.width - view.bounds.width - swipeViewPadding / 2.0) } - + let activeViewSize = view.bounds.size var activeViewFrame = CGRect(x: position.x - activeViewSize.width / 2.0, y: position.y - activeViewSize.height / 2.0, @@ -470,7 +471,7 @@ open class SwipyCell: UITableViewCell, SwipyCellTriggerPointEditable { }) } -// MARK: - View setup + // MARK: - View setup func setView(ofSlidingView view: UIView) { let subviews = slidingView.subviews @@ -479,8 +480,8 @@ open class SwipyCell: UITableViewCell, SwipyCellTriggerPointEditable { } slidingView.addSubview(view) } - -// MARK: - Utilities + + // MARK: - Utilities func image(withView view: UIView) -> UIImage { let scale = UIScreen.main.scale @@ -522,4 +523,17 @@ open class SwipyCell: UITableViewCell, SwipyCellTriggerPointEditable { return false } + + // MARK: - Empty Trigger Configure + func checkEmptyTrigger() { + if triggers[SwipyCellState.state(1, .left)]?.view != nil, + triggers[SwipyCellState.state(0, .left)]?.view == nil { + triggers[SwipyCellState.state(0, .left)] = triggers[SwipyCellState.state(1, .left)] + } + + if triggers[SwipyCellState.state(0, .right)]?.view != nil, + triggers[SwipyCellState.state(1, .right)]?.view == nil { + triggers[SwipyCellState.state(1, .right)] = triggers[SwipyCellState.state(0, .right)] + } + } }