Created
July 10, 2019 21:34
-
-
Save kylpo/b18f2537678ff6e5af2a8798d7e3bb23 to your computer and use it in GitHub Desktop.
Renderable
This file contains 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 UIKit | |
class Col: UIStackView { | |
override init(frame: CGRect) { | |
super.init(frame: frame) | |
axis = .vertical | |
} | |
convenience init(apply closure: (Col) -> Void) { | |
self.init(frame: .zero) | |
closure(self) | |
} | |
@available(*, unavailable) | |
required init(coder aDecoder: NSCoder) { | |
fatalError("init(coder:) has not been implemented") | |
} | |
} | |
extension UIView { | |
@discardableResult | |
func col(apply closure: (Col) -> Void) -> Col { | |
return render(Col(), apply: closure) | |
} | |
} |
This file contains 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
class EditTallyScene: ViewController { | |
override func loadView() { | |
view = View { | |
$0.backgroundColor = .blue | |
$0.accessibilityIdentifier = Id.EditTally.scene | |
$0.col { | |
$0.edgesToSuperview(usingSafeArea: true) | |
$0.distribution = .equalCentering | |
$0.row { | |
$0.height(60) | |
$0.button { | |
$0.accessibilityIdentifier = Id.EditTally.cancelButton | |
$0.setTitle(.PLACEHOLDER, for: .normal) | |
$0.onTap = onExit | |
} | |
$0.button { | |
$0.accessibilityIdentifier = Id.EditTally.saveButton | |
$0.setTitle(.PLACEHOLDER, for: .normal) | |
$0.onTap = handleUserSaved | |
} | |
} | |
$0.textField { | |
$0.accessibilityIdentifier = Id.EditTally.nameInput | |
$0.tag = 1 | |
$0.height(40) | |
$0.widthToSuperview() | |
} | |
$0.textField { | |
$0.accessibilityIdentifier = Id.EditTally.noteInput | |
$0.tag = 2 | |
$0.height(40) | |
$0.widthToSuperview() | |
} | |
} | |
} | |
} | |
// MARK: - Actions | |
func handleUserSaved() { | |
_ = tallyManager.insert(name: "Hello") | |
onExit() | |
} | |
} |
This file contains 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 UIKit | |
class Row: UIStackView { | |
override init(frame: CGRect = .zero) { | |
super.init(frame: frame) | |
axis = .horizontal | |
} | |
convenience init(apply closure: (Row) -> Void) { | |
self.init() | |
closure(self) | |
} | |
@available(*, unavailable) | |
required init(coder aDecoder: NSCoder) { | |
fatalError("init(coder:) has not been implemented") | |
} | |
} | |
extension UIView { | |
/// Inits, adds, configures, then returns subview Row | |
@discardableResult | |
func row(apply closure: (Row) -> Void) -> Row { | |
return render(Row(), apply: closure) | |
} | |
} |
This file contains 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 UIKit | |
class TextField: UITextField { | |
convenience init(apply closure: (TextField) -> Void) { | |
self.init(frame: .zero) | |
closure(self) | |
} | |
} | |
extension UIView { | |
/// Inits, adds, configures, then returns subview Row | |
@discardableResult | |
func textField(apply closure: (TextField) -> Void) -> TextField { | |
return render(TextField(), apply: closure) | |
} | |
} |
This file contains 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 UIKit | |
class View: UIView { | |
convenience init(apply closure: (View) -> Void) { | |
self.init(frame: .zero) | |
closure(self) | |
} | |
} | |
extension UIView { | |
@discardableResult | |
func view(apply closure: (View) -> Void) -> View { | |
return render(View(), apply: closure) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment