Skip to content

Commit

Permalink
Merge pull request #286 from xmartlabs/feature/genericCellSelectors
Browse files Browse the repository at this point in the history
Selector row now requires generic cell parameter
  • Loading branch information
mats-claassen committed Feb 25, 2016
2 parents 3aada43 + 54fb29f commit 10e8090
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 40 deletions.
16 changes: 15 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
# Change Log
All notable changes to this project will be documented in this file.

### Master branch
### [1.4.1](https://github.com/xmartlabs/Eureka/releases/tag/1.4.1)
Released on 2016-02-25.

##### Breaking Changes

* `SelectorRow` now requires the cell among its generic values. This means it is easier to change the cell for a selector row.
* `_AlertRow` and `_ActionSheetRow` require generic cell parameter

If you are using custom rows that inherit from SelectorRow then you might want to change them as follows (or use your custom cell):
```
// before
// public final class LocationRow : SelectorRow<CLLocation, MapViewController>, RowType
// now
public final class LocationRow : SelectorRow<CLLocation, MapViewController, PushSelectorCell<CLLocation>>, RowType
```


### [1.4.0](https://github.com/xmartlabs/Eureka/releases/tag/1.4.0)
Expand Down
2 changes: 1 addition & 1 deletion Eureka.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'Eureka'
s.version = '1.4.0'
s.version = '1.4.1'
s.license = 'MIT'
s.summary = 'Elegant iOS Forms in pure Swift 2'
s.homepage = 'https://github.com/xmartlabs/Eureka'
Expand Down
2 changes: 1 addition & 1 deletion Example/Example/CustomCells.swift
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ public final class EmailFloatLabelRow: FloatFieldRow<String, EmailFloatLabelCell

//MARK: LocationRow

public final class LocationRow : SelectorRow<CLLocation, MapViewController>, RowType {
public final class LocationRow : SelectorRow<CLLocation, MapViewController, PushSelectorCell<CLLocation>>, RowType {
public required init(tag: String?) {
super.init(tag: tag)
presentationMode = .Show(controllerProvider: ControllerProvider.Callback { return MapViewController(){ _ in } }, completionCallback: { vc in vc.navigationController?.popViewControllerAnimated(true) })
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,9 @@ public protocol FormatterProtocol {

This row will push to a new controller from where to choose options listed using Check rows.

+ **PopoverSelectorRow**
+ **PopoverSelectorRow**

This row will show a popover from where to choose options listed using Check rows.
This row will show a popover from where to choose options listed using Check rows.

+ **ImageRow**

Expand Down
8 changes: 4 additions & 4 deletions Source/Core.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1683,7 +1683,7 @@ public class Row<T: Equatable, Cell: CellType where Cell: BaseCell, Cell.Value =
}

/// Generic row type where a user must select a value among several options.
public class SelectorRow<T: Equatable, VCType: TypedRowControllerType where VCType: UIViewController, VCType.RowValue == T>: OptionsRow<T, PushSelectorCell<T>>, PresenterRowType {
public class SelectorRow<T: Equatable, VCType: TypedRowControllerType, Cell: CellType where VCType: UIViewController, VCType.RowValue == T, Cell: BaseCell, Cell.Value == T >: OptionsRow<T, Cell>, PresenterRowType {

/// Defines how the view controller will be presented, pushed, etc.
public var presentationMode: PresentationMode<VCType>?
Expand All @@ -1695,7 +1695,7 @@ public class SelectorRow<T: Equatable, VCType: TypedRowControllerType where VCTy
super.init(tag: tag)
}

public required convenience init(_ tag: String, @noescape _ initializer: (SelectorRow<T, VCType> -> ()) = { _ in }) {
public required convenience init(_ tag: String, @noescape _ initializer: (SelectorRow<T, VCType, Cell> -> ()) = { _ in }) {
self.init(tag:tag)
RowDefaults.rowInitialization["\(self.dynamicType)"]?(self)
initializer(self)
Expand Down Expand Up @@ -1743,7 +1743,7 @@ public class SelectorRow<T: Equatable, VCType: TypedRowControllerType where VCTy
}

/// Generic options selector row that allows multiple selection.
public class GenericMultipleSelectorRow<T: Hashable, VCType: TypedRowControllerType where VCType: UIViewController, VCType.RowValue == Set<T>>: Row<Set<T>, PushSelectorCell<Set<T>>>, PresenterRowType {
public class GenericMultipleSelectorRow<T: Hashable, VCType: TypedRowControllerType, Cell: CellType where VCType: UIViewController, VCType.RowValue == Set<T>, Cell: BaseCell, Cell.Value == Set<T>>: Row<Set<T>, Cell>, PresenterRowType {

/// Defines how the view controller will be presented, pushed, etc.
public var presentationMode: PresentationMode<VCType>?
Expand All @@ -1765,7 +1765,7 @@ public class GenericMultipleSelectorRow<T: Hashable, VCType: TypedRowControllerT
presentationMode = .Show(controllerProvider: ControllerProvider.Callback { return VCType() }, completionCallback: { vc in vc.navigationController?.popViewControllerAnimated(true) })
}

public required convenience init(_ tag: String, @noescape _ initializer: (GenericMultipleSelectorRow<T, VCType> -> ()) = { _ in }) {
public required convenience init(_ tag: String, @noescape _ initializer: (GenericMultipleSelectorRow<T, VCType, Cell> -> ()) = { _ in }) {
self.init(tag:tag)
RowDefaults.rowInitialization["\(self.dynamicType)"]?(self)
initializer(self)
Expand Down
59 changes: 28 additions & 31 deletions Source/Rows.swift
Original file line number Diff line number Diff line change
Expand Up @@ -531,15 +531,15 @@ public class _SwitchRow: Row<Bool, SwitchCell> {
}
}

public class _PushRow<T: Equatable> : SelectorRow<T, SelectorViewController<T>> {
public class _PushRow<T: Equatable, Cell: CellType where Cell: BaseCell, Cell.Value == T> : SelectorRow<T, SelectorViewController<T>, Cell> {

public required init(tag: String?) {
super.init(tag: tag)
presentationMode = .Show(controllerProvider: ControllerProvider.Callback { return SelectorViewController<T>(){ _ in } }, completionCallback: { vc in vc.navigationController?.popViewControllerAnimated(true) })
}
}

public class _PopoverSelectorRow<T: Equatable> : SelectorRow<T, SelectorViewController<T>> {
public class _PopoverSelectorRow<T: Equatable, Cell: CellType where Cell: BaseCell, Cell.Value == T> : SelectorRow<T, SelectorViewController<T>, Cell> {

public required init(tag: String?) {
super.init(tag: tag)
Expand Down Expand Up @@ -607,7 +607,7 @@ public class OptionsRow<T: Equatable, Cell: CellType where Cell: BaseCell, Cell.
}
}

public class _ActionSheetRow<T: Equatable>: OptionsRow<T, AlertSelectorCell<T>>, PresenterRowType {
public class _ActionSheetRow<T: Equatable, Cell: CellType where Cell: BaseCell, Cell.Value == T>: OptionsRow<T, Cell>, PresenterRowType {

public var onPresentCallback : ((FormViewController, SelectorAlertController<T>)->())?
lazy public var presentationMode: PresentationMode<SelectorAlertController<T>>? = {
Expand Down Expand Up @@ -646,7 +646,7 @@ public class _ActionSheetRow<T: Equatable>: OptionsRow<T, AlertSelectorCell<T>>,
}
}

public class _AlertRow<T: Equatable>: OptionsRow<T, AlertSelectorCell<T>>, PresenterRowType {
public class _AlertRow<T: Equatable, Cell: CellType where Cell: BaseCell, Cell.Value == T>: OptionsRow<T, Cell>, PresenterRowType {

public var onPresentCallback : ((FormViewController, SelectorAlertController<T>)->())?
lazy public var presentationMode: PresentationMode<SelectorAlertController<T>>? = {
Expand Down Expand Up @@ -694,13 +694,12 @@ public struct ImageRowSourceTypes : OptionSetType {
public static let All: ImageRowSourceTypes = [Camera, PhotoLibrary, SavedPhotosAlbum]
}

public class _ImageRow : SelectorRow<UIImage, ImagePickerController> {
public enum ImageClearAction {
case No
case Yes(style: UIAlertActionStyle)
}

public enum ImageClearAction {
case No
case Yes(style: UIAlertActionStyle)
}

public class _ImageRow<Cell: CellType where Cell: BaseCell, Cell.Value == UIImage> : SelectorRow<UIImage, ImagePickerController, Cell> {

public var sourceTypes: ImageRowSourceTypes
public internal(set) var imageURL: NSURL?
Expand Down Expand Up @@ -740,20 +739,18 @@ public class _ImageRow : SelectorRow<UIImage, ImagePickerController> {
super.customDidSelect()
return
}
deselect()
var availableSources: ImageRowSourceTypes {
var result: ImageRowSourceTypes = []

if UIImagePickerController.isSourceTypeAvailable(.PhotoLibrary) {
result.insert(.PhotoLibrary)
}
if UIImagePickerController.isSourceTypeAvailable(.Camera) {
result.insert(.Camera)
}
if UIImagePickerController.isSourceTypeAvailable(.SavedPhotosAlbum) {
result.insert(.SavedPhotosAlbum)
}
return result
deselect()

var availableSources: ImageRowSourceTypes = []

if UIImagePickerController.isSourceTypeAvailable(.PhotoLibrary) {
availableSources.insert(.PhotoLibrary)
}
if UIImagePickerController.isSourceTypeAvailable(.Camera) {
availableSources.insert(.Camera)
}
if UIImagePickerController.isSourceTypeAvailable(.SavedPhotosAlbum) {
availableSources.insert(.SavedPhotosAlbum)
}

sourceTypes.intersectInPlace(availableSources)
Expand Down Expand Up @@ -843,7 +840,7 @@ public class _ImageRow : SelectorRow<UIImage, ImagePickerController> {
}
}

public class _MultipleSelectorRow<T: Hashable> : GenericMultipleSelectorRow<T, MultipleSelectorViewController<T>> {
public class _MultipleSelectorRow<T: Hashable, Cell: CellType where Cell: BaseCell, Cell.Value == Set<T>> : GenericMultipleSelectorRow<T, MultipleSelectorViewController<T>, Cell> {
public required init(tag: String?) {
super.init(tag: tag)
self.displayValueFor = {
Expand Down Expand Up @@ -1319,42 +1316,42 @@ public final class SegmentedRow<T: Equatable>: OptionsRow<T, SegmentedCell<T>>,
}

/// An options row where the user can select an option from an ActionSheet
public final class ActionSheetRow<T: Equatable>: _ActionSheetRow<T>, RowType {
public final class ActionSheetRow<T: Equatable>: _ActionSheetRow<T, AlertSelectorCell<T>>, RowType {
required public init(tag: String?) {
super.init(tag: tag)
}
}

/// An options row where the user can select an option from a modal Alert
public final class AlertRow<T: Equatable>: _AlertRow<T>, RowType {
public final class AlertRow<T: Equatable>: _AlertRow<T, AlertSelectorCell<T>>, RowType {
required public init(tag: String?) {
super.init(tag: tag)
}
}

/// A selector row where the user can pick an image
public final class ImageRow : _ImageRow, RowType {
public final class ImageRow : _ImageRow<PushSelectorCell<UIImage>>, RowType {
public required init(tag: String?) {
super.init(tag: tag)
}
}

/// A selector row where the user can pick an option from a pushed view controller
public final class PushRow<T: Equatable> : _PushRow<T>, RowType {
public final class PushRow<T: Equatable> : _PushRow<T, PushSelectorCell<T>>, RowType {
public required init(tag: String?) {
super.init(tag: tag)
}
}

public final class PopoverSelectorRow<T: Equatable> : _PopoverSelectorRow<T>, RowType {
public final class PopoverSelectorRow<T: Equatable> : _PopoverSelectorRow<T, PushSelectorCell<T>>, RowType {
public required init(tag: String?) {
super.init(tag: tag)
}
}


/// A selector row where the user can pick several options from a pushed view controller
public final class MultipleSelectorRow<T: Hashable> : _MultipleSelectorRow<T>, RowType {
public final class MultipleSelectorRow<T: Hashable> : _MultipleSelectorRow<T, PushSelectorCell<Set<T>>>, RowType {
public required init(tag: String?) {
super.init(tag: tag)
}
Expand Down

0 comments on commit 10e8090

Please sign in to comment.