Skip to content

Commit

Permalink
more
Browse files Browse the repository at this point in the history
  • Loading branch information
kyleve committed Jan 22, 2021
1 parent 1725453 commit 211c3a4
Show file tree
Hide file tree
Showing 8 changed files with 342 additions and 105 deletions.
4 changes: 2 additions & 2 deletions Demo/Sources/Demos/DemosRootViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -218,12 +218,12 @@ public final class DemosRootViewController : ListViewController

section += Item(
DemoItem(text: "Tappable Row"),
selectionStyle: .selectable()
selectionStyle: .tappable
)

section += Item(
DemoItem(text: "Tappable Row (Slow Is Selected)"),
selectionStyle: .selectable(),
selectionStyle: .tappable,
onSelect: { _ in
Thread.sleep(forTimeInterval: 0.5)
}
Expand Down
53 changes: 0 additions & 53 deletions ListableUI/Sources/HeaderFooter/HeaderFooter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -104,56 +104,3 @@ extension HeaderFooter : SignpostLoggable
)
}
}


///
/// `HeaderFooterLayout` allows you to provide `ListLayout`-specific layout configuration for
/// individual headers and footers within a list. Eg, customize the layout for a list, a grid, etc.
///
/// For example, if you want to specify a custom layout for list layouts, you
/// would do the following on your header:
/// ```
/// myHeader.layouts.list = .init(
/// width: .fill
/// )
/// ```
/// And then, when the `HeaderFooter` is used within a `.list` style
/// list layout, the provided `HeaderFooter` layout will be used.
///
/// If you plan on swapping the `ListLayout` type on your list,
/// you can provide multiple layouts. The correct one will be used:
///
/// ```
/// myHeader.layouts.list = .init(
/// width: .fill
/// )
///
/// myHeader.layouts.otherLayout = .init(
/// width: 300,
/// alignment: .left
/// padding: 10
/// )
/// ```
public struct HeaderFooterLayouts {

public init(
_ configure : (inout Self) -> () = { _ in }
) {
self.storage = .init()

configure(&self)
}

private var storage : ContentLayoutsStorage

public subscript<ValueType:SectionLayoutsValue>(_ valueType : ValueType.Type) -> ValueType {
get { self.storage.get(valueType, default: ValueType.defaultValue) }
set { self.storage.set(valueType, new: newValue) }
}
}


public protocol HeaderFooterLayoutsValue {

static var defaultValue : Self { get }
}
114 changes: 114 additions & 0 deletions ListableUI/Sources/HeaderFooter/HeaderFooterLayouts.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
//
// HeaderFooterLayouts.swift
// ListableUI
//
// Created by Kyle Van Essen on 1/22/21.
//

import Foundation


///
/// `HeaderFooterLayouts` allows you to provide `ListLayout`-specific layout configuration for
/// individual headers and footers within a list. Eg, customize the layout for a header when it is in a table, a grid, etc.
///
/// For example, if you want to specify a custom layout for table layouts, you
/// would do the following on your header:
///
/// ```
/// myHeader.layouts.table = .init(
/// width: .fill
/// )
/// ```
///
/// And then, when the `HeaderFooter` is used within a `.table` style
/// list layout, the provided layout will be used.
///
/// If you plan on swapping between multiple `ListLayout` types on your list,
/// you can provide multiple layouts. The correct one will be used at the correct time:
///
/// ```
/// myHeader.layouts.table = .init(
/// width: .fill
/// )
///
/// myHeader.layouts.otherLayout = .init(
/// width: 300,
/// alignment: .left
/// padding: 10
/// )
/// ```
///
/// Note
/// ----
/// When implementing your own custom layout, you should add an extension to `HeaderFooterLayouts`,
/// to provide easier access to your layout-specific `HeaderFooterLayoutsValue` type, like so:
///
/// ```
/// extension HeaderFooterLayouts {
/// public var table : TableAppearance.HeaderFooter.Layout {
/// get { self[TableAppearance.HeaderFooter.Layout.self] }
/// set { self[TableAppearance.HeaderFooter.Layout.self] = newValue }
/// }
/// }
/// ```
public struct HeaderFooterLayouts {

/// Creates a new instance of the layouts, with an optional `configure`
/// closure, to allow you to set up styling inline.
public init(
_ configure : (inout Self) -> () = { _ in }
) {
self.storage = .init()

configure(&self)
}

private var storage : ContentLayoutsStorage

/// Allows accessing the various `HeaderFooterLayoutValue`s stored within the object.
/// This method will return the `defaultValue` for a value if none is set.
///
/// Note
/// ----
/// When implementing your own custom layout, you should add an extension to `HeaderFooterLayouts`,
/// to provide easier access to your layout-specific `HeaderFooterLayoutsValue` type.
///
/// ```
/// extension HeaderFooterLayouts {
/// public var table : TableAppearance.HeaderFooter.Layout {
/// get { self[TableAppearance.HeaderFooter.Layout.self] }
/// set { self[TableAppearance.HeaderFooter.Layout.self] = newValue }
/// }
/// }
/// ```
public subscript<ValueType:HeaderFooterLayoutsValue>(_ valueType : ValueType.Type) -> ValueType {
get { self.storage.get(valueType, default: ValueType.defaultValue) }
set { self.storage.set(valueType, new: newValue) }
}
}


///
/// The `HeaderFooterLayoutsValue` protocol provides a default value for the different layouts stored
/// within `HeaderFooterLayouts`. Provide a `defaultValue` with reasonable defaults, as the
/// developer should not need to set these values at all times when using your layout.
///
/// ```
/// public struct Layout : Equatable, HeaderFooterLayoutsValue
/// {
/// public var width : CGFloat
/// public var minHeight : CGFloat
///
/// ...
///
/// public static var defaultValue : Self {
/// ...
/// }
/// }
/// ```
public protocol HeaderFooterLayoutsValue {

/// The default value used when accessing the value, if none is set.
static var defaultValue : Self { get }
}
25 changes: 0 additions & 25 deletions ListableUI/Sources/Item/Item.swift
Original file line number Diff line number Diff line change
Expand Up @@ -181,28 +181,3 @@ extension Item : SignpostLoggable
)
}
}


public struct ItemLayouts {

public init(
_ configure : (inout Self) -> () = { _ in }
) {
self.storage = .init()

configure(&self)
}

private var storage : ContentLayoutsStorage

public subscript<ValueType:SectionLayoutsValue>(_ valueType : ValueType.Type) -> ValueType {
get { self.storage.get(valueType, default: ValueType.defaultValue) }
set { self.storage.set(valueType, new: newValue) }
}
}


public protocol ItemLayoutsValue {

static var defaultValue : Self { get }
}
File renamed without changes.
113 changes: 113 additions & 0 deletions ListableUI/Sources/Item/ItemLayouts.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
//
// ItemLayouts.swift
// ListableUI
//
// Created by Kyle Van Essen on 1/22/21.
//

import Foundation


///
/// `ItemLayouts` allows you to provide `ListLayout`-specific layout configuration for
/// individual items within a list. Eg, customize the layout for an item when it is in a table, a grid, etc.
///
/// For example, if you want to specify a custom layout for table layouts, you
/// would do the following on your item:
///
/// ```
/// myItem.layouts.table = .init(
/// width: .fill
/// )
/// ```
///
/// And then, when the `Item` is used within a `.table` style
/// list layout, the provided layout will be used.
///
/// If you plan on swapping between multiple `ListLayout` types on your list,
/// you can provide multiple layouts. The correct one will be used at the correct time:
///
/// ```
/// myItem.layouts.table = .init(
/// width: .fill
/// )
///
/// myItem.layouts.otherLayout = .init(
/// width: 300,
/// alignment: .left
/// )
/// ```
///
/// Note
/// ----
/// When implementing your own custom layout, you should add an extension to `ItemLayouts`,
/// to provide easier access to your layout-specific `ItemLayoutsValue` type, like so:
///
/// ```
/// extension ItemLayoutsValue {
/// public var table : TableAppearance.Item.Layout {
/// get { self[TableAppearance.Item.Layout.self] }
/// set { self[TableAppearance.Item.Layout.self] = newValue }
/// }
/// }
/// ```
public struct ItemLayouts {

/// Creates a new instance of the layouts, with an optional `configure`
/// closure, to allow you to set up styling inline.
public init(
_ configure : (inout Self) -> () = { _ in }
) {
self.storage = .init()

configure(&self)
}

private var storage : ContentLayoutsStorage

/// Allows accessing the various `ItemLayoutsValue`s stored within the object.
/// This method will return the `defaultValue` for a value if none is set.
///
/// Note
/// ----
/// When implementing your own custom layout, you should add an extension to `ItemLayouts`,
/// to provide easier access to your layout-specific `ItemLayoutsValue` type.
///
/// ```
/// extension ItemLayoutsValue {
/// public var table : TableAppearance.Item.Layout {
/// get { self[TableAppearance.Item.Layout.self] }
/// set { self[TableAppearance.Item.Layout.self] = newValue }
/// }
/// }
/// ```
public subscript<ValueType:ItemLayoutsValue>(_ valueType : ValueType.Type) -> ValueType {
get { self.storage.get(valueType, default: ValueType.defaultValue) }
set { self.storage.set(valueType, new: newValue) }
}
}


///
/// The `ItemLayoutsValue` protocol provides a default value for the different layouts stored
/// within `ItemLayouts`. Provide a `defaultValue` with reasonable defaults, as the
/// developer should not need to set these values at all times when using your layout.
///
/// ```
/// public struct Layout : Equatable, ItemLayoutsValue
/// {
/// public var width : CGFloat
/// public var minHeight : CGFloat
///
/// ...
///
/// public static var defaultValue : Self {
/// ...
/// }
/// }
/// ```
public protocol ItemLayoutsValue {

/// The default value used when accessing the value, if none is set.
static var defaultValue : Self { get }
}
25 changes: 0 additions & 25 deletions ListableUI/Sources/Section/Section.swift
Original file line number Diff line number Diff line change
Expand Up @@ -231,28 +231,3 @@ private struct HashableSectionInfo<Value:Hashable> : SectionInfo
return self.value != other.value
}
}


public struct SectionLayouts {

public init(
_ configure : (inout Self) -> () = { _ in }
) {
self.storage = .init()

configure(&self)
}

private var storage : ContentLayoutsStorage

public subscript<ValueType:SectionLayoutsValue>(_ valueType : ValueType.Type) -> ValueType {
get { self.storage.get(valueType, default: ValueType.defaultValue) }
set { self.storage.set(valueType, new: newValue) }
}
}


public protocol SectionLayoutsValue {

static var defaultValue : Self { get }
}
Loading

0 comments on commit 211c3a4

Please sign in to comment.