From 7095fc026c1c5f0067c01d513c7aeeaf0cc1ccd7 Mon Sep 17 00:00:00 2001 From: PradyumnaRout <102755963+PradyumnaRout@users.noreply.github.com> Date: Fri, 6 Oct 2023 12:56:34 +0530 Subject: [PATCH 1/3] Update Splitflap Delegate.swift Add new delegate to get the current displaying text in the view. --- Sources/SplitflapDelegate.swift | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Sources/SplitflapDelegate.swift b/Sources/SplitflapDelegate.swift index 3faf44a..1291d08 100644 --- a/Sources/SplitflapDelegate.swift +++ b/Sources/SplitflapDelegate.swift @@ -57,6 +57,11 @@ public protocol SplitflapDelegate: class { - returns: A FlapView builder object to create custom flaps. */ func splitflap(_ splitflap: Splitflap, builderForFlapAtIndex index: Int) -> FlapViewBuilder + + /** + Called when the text in the count down view changes. + **/ + func splitflap(_ splitflap: Splitflap, currentText value: String) } /// Default implementation of SplitflapDelegate @@ -70,4 +75,7 @@ public extension SplitflapDelegate { func splitflap(_ splitflap: Splitflap, builderForFlapAtIndex index: Int) -> FlapViewBuilder { return FlapViewBuilder() } + + /// Get call when text changes + func splitflap(_ splitflap: Splitflap, currentText value: String){} } From a377bb41c0df728d658ec4372a7c61154ebd3039 Mon Sep 17 00:00:00 2001 From: PradyumnaRout <102755963+PradyumnaRout@users.noreply.github.com> Date: Fri, 6 Oct 2023 12:59:03 +0530 Subject: [PATCH 2/3] Update Splitflap.swift return delegate --- Sources/Splitflap.swift | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Sources/Splitflap.swift b/Sources/Splitflap.swift index 74b9e77..ae189dd 100644 --- a/Sources/Splitflap.swift +++ b/Sources/Splitflap.swift @@ -132,7 +132,7 @@ import UIKit open func setText(_ text: String?, animated: Bool, completionBlock: (() -> Void)? = nil) { let completionGroup = DispatchGroup() let target = (delegate ?? self) - let delay = animated ? 0.181 : 0 + let delay = animated ? 0.181 : 0.281 var tokens: [String] = [] @@ -195,7 +195,14 @@ import UIKit for (index, flap) in flaps.enumerated() { let fIndex = CGFloat(index) flap.frame = CGRect(x: fIndex * widthPerFlap + flapSpacing * fIndex, y: 0, width: widthPerFlap, height: bounds.height) - } + } + + for flap in flaps { + flap.getBackCurrentValue = { value in + // print("find the current vlaue ::: \(value)") + self.delegate?.splitflap(self, currentText: value) + } + } } /// Rebuild and layout the split-flap view. From 77466c0163bb2e648e03d747ae7c3aaccc7702eb Mon Sep 17 00:00:00 2001 From: PradyumnaRout <102755963+PradyumnaRout@users.noreply.github.com> Date: Fri, 6 Oct 2023 13:02:21 +0530 Subject: [PATCH 3/3] Update FlapView.swift closure add to return the current value --- Sources/FlapView.swift | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Sources/FlapView.swift b/Sources/FlapView.swift index 3b0d5c2..170531e 100644 --- a/Sources/FlapView.swift +++ b/Sources/FlapView.swift @@ -38,6 +38,8 @@ final class FlapView: UIView, CAAnimationDelegate { fileprivate let topTacTile: TileView fileprivate let bottomTacTile: TileView + var getBackCurrentValue: ((String) -> Void)? + // MARK: - Working With Tokens let tokens: [String] @@ -171,7 +173,7 @@ final class FlapView: UIView, CAAnimationDelegate { else { tokenGenerator.currentElement = sanitizedToken - updateWithToken(sanitizedToken, animated: false) + updateWithToken(sanitizedToken, animated: true) completionBlock?() } @@ -224,6 +226,12 @@ final class FlapView: UIView, CAAnimationDelegate { animationTime = animationTime == .tic ? .tac : .tic } + + DispatchQueue.main.asyncAfter(deadline: .now() + 1.0, execute: { [weak self] in + if let getBackValue = self?.getBackCurrentValue { + getBackValue(token ?? "") + } + }) } // MARK: - CAAnimation Delegate Methods