Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion Sources/FlapView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -171,7 +173,7 @@ final class FlapView: UIView, CAAnimationDelegate {
else {
tokenGenerator.currentElement = sanitizedToken

updateWithToken(sanitizedToken, animated: false)
updateWithToken(sanitizedToken, animated: true)

completionBlock?()
}
Expand Down Expand Up @@ -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
Expand Down
11 changes: 9 additions & 2 deletions Sources/Splitflap.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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] = []

Expand Down Expand Up @@ -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.
Expand Down
8 changes: 8 additions & 0 deletions Sources/SplitflapDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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){}
}