-
Notifications
You must be signed in to change notification settings - Fork 1
Present selector as modal #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
0a13d79
53312e8
f04a8b0
ccd09f6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,43 +5,60 @@ import Eureka | |
| import Foundation | ||
|
|
||
| public final class LocationCell: PushSelectorCell<CLPlacemark> { | ||
| @IBOutlet public var clearButton: UIButton! { | ||
| didSet { | ||
| clearButton.setImage(UIImage(named: "Clear", in: Bundle.current, compatibleWith: nil)?.withRenderingMode(.alwaysTemplate), for: .normal) | ||
| clearButton.tintColor = .lightGray | ||
| } | ||
| } | ||
| @IBOutlet public weak var clearButton: UIButton! | ||
|
|
||
| required init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { | ||
| super.init(style: style, reuseIdentifier: reuseIdentifier) | ||
|
|
||
| let clearButton = UIButton(frame: CGRect(x: 0, y: 0, width: 18, height: 18)) | ||
| clearButton.setImage(UIImage(named: "Clear", in: Bundle.current, compatibleWith: nil)?.withRenderingMode(.alwaysTemplate), for: .normal) | ||
| clearButton.tintColor = .lightGray | ||
|
|
||
| self.clearButton = clearButton | ||
|
|
||
| accessoryView = clearButton | ||
| editingAccessoryView = accessoryView | ||
| } | ||
|
|
||
| required init?(coder aDecoder: NSCoder) { | ||
| super.init(coder: aDecoder) | ||
| } | ||
|
|
||
| deinit { | ||
| clearButton?.removeTarget(self, action: nil, for: .allEvents) | ||
| } | ||
|
|
||
| public override func setup() { | ||
| super.setup() | ||
|
|
||
| clearButton.addTarget(self, action: #selector(LocationCell.clear), for: .touchUpInside) | ||
| } | ||
|
|
||
| public override func update() { | ||
| super.update() | ||
|
|
||
| detailTextLabel?.text = nil | ||
| accessoryType = .none | ||
|
|
||
| guard let row = self.row as? LocationRow else { return } | ||
|
|
||
| let isEmpty = row.value?.name?.isEmpty ?? true | ||
|
|
||
| textLabel?.text = row.value?.name ?? row.placeholder | ||
| textLabel?.textColor = row.value?.name != nil ? .black : UIColor(red: 198 / 255, green: 198 / 255, blue: 204 / 255, alpha: 1) | ||
| textLabel?.textColor = isEmpty ? UIColor(red: 198 / 255, green: 198 / 255, blue: 204 / 255, alpha: 1) : row.isDisabled ? .gray : .black | ||
|
|
||
| clearButton.isHidden = row.value?.name == nil | ||
| clearButton.isHidden = isEmpty | ||
| clearButton.isEnabled = !row.isDisabled | ||
| } | ||
|
|
||
| @IBAction func clear(_: Any) { | ||
| @objc | ||
| func clear() { | ||
| row.value = nil | ||
| update() | ||
| } | ||
| } | ||
|
|
||
| public final class LocationRow: Row<LocationCell>, RowType, PresenterRowType { | ||
| public typealias PresenterRow = LocationViewController | ||
| public typealias PresenterRow = LocationNavigationController | ||
|
|
||
| public var presentationMode: PresentationMode<PresenterRow>? | ||
| public var onPresentCallback: ((FormViewController, PresenterRow) -> Void)? | ||
|
|
@@ -50,35 +67,34 @@ public final class LocationRow: Row<LocationCell>, RowType, PresenterRowType { | |
|
|
||
| public required init(tag: String?) { | ||
| super.init(tag: tag) | ||
|
|
||
| cellProvider = CellProvider<LocationCell>(nibName: "LocationCell", bundle: Bundle.current) | ||
| } | ||
|
|
||
| public override func customDidSelect() { | ||
| super.customDidSelect() | ||
|
|
||
| guard let controller = makeController() else { return } | ||
| guard !isDisabled else { return } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we can allow the user to set up a title and use the detailTextView as the value. By doing that the user can opt by leaving empty the title and we will get the same result as now. I would recommend to add the cell clear button as cell accessoryView. We also have to change cell color title when row is disabled in order to indicate that. Take a look at switchCell to see how we do it.
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Done in f04a8b0
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Done in ccd09f6
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
@mtnbarreto There are a couple of reasons I would prefer the leave this as is (at least for the moment), where only the
Let me know if these reasonings are acceptable. |
||
|
|
||
| presentationMode = PresentationMode.show(controllerProvider: ControllerProvider.callback { | ||
| controller | ||
| }, onDismiss: { viewController in | ||
| _ = viewController.navigationController?.popViewController(animated: true) | ||
| presentationMode = PresentationMode.presentModally(controllerProvider: ControllerProvider.callback { | ||
chamitha marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| let bar = LocationViewController(nibName: "LocationViewController", bundle: Bundle.current) | ||
| return LocationNavigationController(rootViewController: bar) | ||
| }, onDismiss: { viewController in | ||
| viewController.presentingViewController?.dismiss(animated: true) | ||
| }) | ||
|
|
||
| guard let presentationMode = presentationMode, !isDisabled else { return } | ||
|
|
||
| if let controller = presentationMode.makeController() { | ||
| controller.row = self | ||
|
|
||
| onPresentCallback?(cell.formViewController()!, controller) | ||
|
|
||
| controller.topViewController?.title = controller.title | ||
|
|
||
| presentationMode.present(controller, row: self, presentingController: cell.formViewController()!) | ||
| } else { | ||
| presentationMode.present(nil, row: self, presentingController: cell.formViewController()!) | ||
| } | ||
| } | ||
|
|
||
| private func makeController() -> LocationViewController? { | ||
| return LocationViewController(nibName: "LocationViewController", bundle: Bundle.current) | ||
| } | ||
| } | ||
|
|
||
| private extension Bundle { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.