Created
July 26, 2017 02:43
-
-
Save mokagio/c167af2bfe3f47dca121dced57c89c7e to your computer and use it in GitHub Desktop.
TitleAndValueRowWithPresenter.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Eureka | |
/// This row is build based on the implementation of `ButtonRowWithPresent`, and | |
/// allows consurmers to set a detail value for the row, which is not possible | |
/// in the other. | |
/// | |
/// To set the value use `$0.cellUpdate { cell, _ in cell.detailLabel?.text = "value" }`. | |
/// | |
/// - See: https://github.com/xmartlabs/Eureka/blob/master/Source/Rows/ButtonRowWithPresent.swift | |
open class _TitleAndValueRowWithPresenter<VCType: TypedRowControllerType>: Row<LabelCellOf<VCType.RowValue>>, PresenterRowType where VCType: UIViewController { | |
open var presentationMode: PresentationMode<VCType>? | |
open var onPresentCallback : ((FormViewController, VCType)->())? | |
required public init(tag: String?) { | |
super.init(tag: tag) | |
displayValueFor = nil | |
cellStyle = .value1 | |
} | |
open override func customUpdateCell() { | |
super.customUpdateCell() | |
cell.accessoryType = isDisabled ? .none : .disclosureIndicator | |
} | |
open override func customDidSelect() { | |
super.customDidSelect() | |
if let presentationMode = presentationMode, !isDisabled { | |
if let controller = presentationMode.makeController(){ | |
controller.row = self | |
onPresentCallback?(cell.formViewController()!, controller) | |
presentationMode.present(controller, row: self, presentingController: cell.formViewController()!) | |
} | |
else{ | |
presentationMode.present(nil, row: self, presentingController: cell.formViewController()!) | |
} | |
} | |
} | |
open override func prepare(for segue: UIStoryboardSegue) { | |
super.prepare(for: segue) | |
guard let rowVC = segue.destination as? VCType else { | |
return | |
} | |
if let callback = presentationMode?.onDismissCallback{ | |
rowVC.onDismissCallback = callback | |
} | |
rowVC.row = self | |
onPresentCallback?(cell.formViewController()!, rowVC) | |
} | |
} | |
/// A generic row with a button that presents a view controller when tapped | |
public final class TitleAndValueRowWithWithPresenter<VCType: TypedRowControllerType> : _TitleAndValueRowWithPresenter<VCType>, RowType where VCType: UIViewController { | |
public required init(tag: String?) { | |
super.init(tag: tag) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just dumping it here because I know that I'll forget about having written this in an app from which I'm now stripping Eureka, but it might come handy in the future.
Of course I'll have to remember having made this gist...