|
@ -14,7 +14,25 @@ struct TablePresenterConfiguration { |
|
|
var closeButtonTitle: String |
|
|
var closeButtonTitle: String |
|
|
var notFoundTitle: String |
|
|
var notFoundTitle: String |
|
|
var searchBarPlaceHolder: String |
|
|
var searchBarPlaceHolder: String |
|
|
var isUseSearchBar: Bool |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
init(presenterTitle: String) { |
|
|
|
|
|
self.presenterTitle = presenterTitle |
|
|
|
|
|
closeButtonTitle = "penny_test_close_text".localized() |
|
|
|
|
|
notFoundTitle = "no_result_found_text".localized() |
|
|
|
|
|
searchBarPlaceHolder = "search_text".localized() |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
init( |
|
|
|
|
|
presenterTitle: String, |
|
|
|
|
|
closeButtonTitle: String, |
|
|
|
|
|
notFoundTitle: String, |
|
|
|
|
|
searchBarPlaceHolder: String |
|
|
|
|
|
) { |
|
|
|
|
|
self.presenterTitle = presenterTitle |
|
|
|
|
|
self.closeButtonTitle = closeButtonTitle |
|
|
|
|
|
self.notFoundTitle = notFoundTitle |
|
|
|
|
|
self.searchBarPlaceHolder = searchBarPlaceHolder |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
protocol TablePresenterDelegate: class { |
|
|
protocol TablePresenterDelegate: class { |
|
@ -41,6 +59,9 @@ class TablePresenterViewController: UIViewController { |
|
|
|
|
|
|
|
|
private let impact = UISelectionFeedbackGenerator() |
|
|
private let impact = UISelectionFeedbackGenerator() |
|
|
private var isFirst = true |
|
|
private var isFirst = true |
|
|
|
|
|
|
|
|
|
|
|
private lazy var originPoint = CGPoint(x: 0, y: 0) |
|
|
|
|
|
private lazy var isDismissAnimation = false |
|
|
// MARK: Computed Properties |
|
|
// MARK: Computed Properties |
|
|
var model: [TablePresenterProtocol]? { |
|
|
var model: [TablePresenterProtocol]? { |
|
|
didSet { |
|
|
didSet { |
|
@ -99,6 +120,12 @@ class TablePresenterViewController: UIViewController { |
|
|
impact.selectionChanged() |
|
|
impact.selectionChanged() |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override func viewDidAppear(_ animated: Bool) { |
|
|
|
|
|
super.viewDidAppear(animated) |
|
|
|
|
|
|
|
|
|
|
|
originPoint = mainView.frame.origin |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
override func viewWillDisappear(_ animated: Bool) { |
|
|
override func viewWillDisappear(_ animated: Bool) { |
|
|
super.viewWillDisappear(animated) |
|
|
super.viewWillDisappear(animated) |
|
|
IQKeyboardManager.shared.enable = true |
|
|
IQKeyboardManager.shared.enable = true |
|
@ -109,7 +136,7 @@ class TablePresenterViewController: UIViewController { |
|
|
@IBAction func touchCloseButton(_ sender: UIButton) { |
|
|
@IBAction func touchCloseButton(_ sender: UIButton) { |
|
|
presentingViewController?.view.endEditing(true) |
|
|
presentingViewController?.view.endEditing(true) |
|
|
mainView.originToBottom { |
|
|
mainView.originToBottom { |
|
|
self.delegate?.tablePresenterView(self, didSelectModel: nil) |
|
|
|
|
|
|
|
|
// self.delegate?.tablePresenterView(self, didSelectModel: nil) |
|
|
self.dismiss(animated: true) |
|
|
self.dismiss(animated: true) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
@ -154,12 +181,11 @@ extension TablePresenterViewController { |
|
|
|
|
|
|
|
|
transparentView.backgroundColor = .themeBackgroundGray |
|
|
transparentView.backgroundColor = .themeBackgroundGray |
|
|
|
|
|
|
|
|
// searchBar.searchBarStyle = .default |
|
|
|
|
|
// searchBar.set(textColor: .black) |
|
|
|
|
|
// searchBar.setTextField(color: .themeWhite) |
|
|
|
|
|
// searchBar.setPlaceholder(textColor: .themeTextColor) |
|
|
|
|
|
// searchBar.setSearchImage(color: .themeTextColor) |
|
|
|
|
|
// searchBar.setClearButton(color: .themeTextColor) |
|
|
|
|
|
|
|
|
// let panGesture = UIPanGestureRecognizer(target: self,action: #selector(onDrag(_:))) |
|
|
|
|
|
// panGesture.delegate = self |
|
|
|
|
|
// |
|
|
|
|
|
// tableView.bounces = false |
|
|
|
|
|
// tableView.addGestureRecognizer(panGesture) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private func setConfiguration() { |
|
|
private func setConfiguration() { |
|
@ -172,6 +198,52 @@ extension TablePresenterViewController { |
|
|
// searchBar.isHidden = !(configuration?.isUseSearchBar ?? true) |
|
|
// searchBar.isHidden = !(configuration?.isUseSearchBar ?? true) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@objc func onDrag(_ sender: UIPanGestureRecognizer) { |
|
|
|
|
|
if tableView.contentOffset.y == 0 && sender.velocity(in: tableView).y > 0 { |
|
|
|
|
|
isDismissAnimation = true |
|
|
|
|
|
let percentThreshold: CGFloat = 0.5 |
|
|
|
|
|
let translation = sender.translation(in: mainView) |
|
|
|
|
|
|
|
|
|
|
|
let newY = ensureRange( |
|
|
|
|
|
value: mainView.frame.minY + translation.y, |
|
|
|
|
|
minimum: 0, |
|
|
|
|
|
maximum: mainView.frame.maxY |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
let progress = progressAlongAxis(newY, mainView.bounds.height) |
|
|
|
|
|
|
|
|
|
|
|
mainView.frame.origin.y = newY |
|
|
|
|
|
|
|
|
|
|
|
if sender.state == .ended { |
|
|
|
|
|
let velocity = sender.velocity(in: mainView) |
|
|
|
|
|
if velocity.y >= 200 || progress > percentThreshold { |
|
|
|
|
|
self.touchCloseButton(UIButton()) |
|
|
|
|
|
} else { |
|
|
|
|
|
UIView.animate(withDuration: 0.2, animations: { |
|
|
|
|
|
self.mainView.frame.origin.y = self.originPoint.y |
|
|
|
|
|
}) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
sender.setTranslation(.zero, in: mainView) |
|
|
|
|
|
} else if isDismissAnimation { |
|
|
|
|
|
isDismissAnimation = false |
|
|
|
|
|
UIView.animate(withDuration: 0.2, animations: { |
|
|
|
|
|
self.mainView.frame.origin.y = self.originPoint.y |
|
|
|
|
|
}) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func progressAlongAxis(_ pointOnAxis: CGFloat, _ axisLength: CGFloat) -> CGFloat { |
|
|
|
|
|
let movementOnAxis = pointOnAxis / axisLength |
|
|
|
|
|
let positiveMovementOnAxis = fmaxf(Float(movementOnAxis), 0.0) |
|
|
|
|
|
let positiveMovementOnAxisPercent = fminf(positiveMovementOnAxis, 1.0) |
|
|
|
|
|
return CGFloat(positiveMovementOnAxisPercent) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func ensureRange<T>(value: T, minimum: T, maximum: T) -> T where T : Comparable { |
|
|
|
|
|
return min(max(value, minimum), maximum) |
|
|
|
|
|
} |
|
|
@objc private func tapGesture(_ sender: UITapGestureRecognizer) { |
|
|
@objc private func tapGesture(_ sender: UITapGestureRecognizer) { |
|
|
touchCloseButton(UIButton()) |
|
|
touchCloseButton(UIButton()) |
|
|
} |
|
|
} |
|
@ -216,7 +288,17 @@ extension TablePresenterViewController: UITableViewDelegate { |
|
|
// MARK: - UIGestureRecognizerDelegate |
|
|
// MARK: - UIGestureRecognizerDelegate |
|
|
extension TablePresenterViewController: UIGestureRecognizerDelegate { |
|
|
extension TablePresenterViewController: UIGestureRecognizerDelegate { |
|
|
func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool { |
|
|
func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool { |
|
|
return touch.view == gestureRecognizer.view |
|
|
|
|
|
|
|
|
guard let tapRecognizer = gestureRecognizer as? UITapGestureRecognizer else { |
|
|
|
|
|
return true |
|
|
|
|
|
} |
|
|
|
|
|
return touch.view == tapRecognizer.view |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func gestureRecognizer( |
|
|
|
|
|
_ gestureRecognizer: UIGestureRecognizer, |
|
|
|
|
|
shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer |
|
|
|
|
|
) -> Bool { |
|
|
|
|
|
return true |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|