diff --git a/BlueprintUILists/Sources/BlueprintHeaderFooterContent.swift b/BlueprintUILists/Sources/BlueprintHeaderFooterContent.swift index c31f55f39..b28e258a1 100644 --- a/BlueprintUILists/Sources/BlueprintHeaderFooterContent.swift +++ b/BlueprintUILists/Sources/BlueprintHeaderFooterContent.swift @@ -119,24 +119,19 @@ public extension BlueprintHeaderFooterContent views.pressed.element = self.pressedBackground?.wrapInBlueprintEnvironmentFrom(environment: info.environment) } - static func createReusableContentView(frame: CGRect) -> ContentView - { - let view = BlueprintView(frame: frame) - view.backgroundColor = .clear - - return view + static func createReusableContentView(frame: CGRect) -> ContentView { + self.newBlueprintView(with: frame) } - static func createReusableBackgroundView(frame: CGRect) -> BackgroundView - { - let view = BlueprintView(frame: frame) - view.backgroundColor = .clear - - return view + static func createReusableBackgroundView(frame: CGRect) -> BackgroundView { + self.newBlueprintView(with: frame) + } + + static func createReusablePressedBackgroundView(frame: CGRect) -> PressedBackgroundView { + self.newBlueprintView(with: frame) } - static func createReusablePressedBackgroundView(frame: CGRect) -> PressedBackgroundView - { + private static func newBlueprintView(with frame : CGRect) -> BlueprintView { let view = BlueprintView(frame: frame) view.backgroundColor = .clear diff --git a/BlueprintUILists/Sources/BlueprintItemContent.swift b/BlueprintUILists/Sources/BlueprintItemContent.swift index abd982183..e097fdb56 100644 --- a/BlueprintUILists/Sources/BlueprintItemContent.swift +++ b/BlueprintUILists/Sources/BlueprintItemContent.swift @@ -131,24 +131,23 @@ public extension BlueprintItemContent } /// Creates the `BlueprintView` used to render the content of the item. - static func createReusableContentView(frame: CGRect) -> ContentView - { - let view = BlueprintView(frame: frame) - view.backgroundColor = .clear - - return view + static func createReusableContentView(frame: CGRect) -> ContentView { + self.newBlueprintView(with: frame) } /// Creates the `BlueprintView` used to render the background of the item. - static func createReusableBackgroundView(frame: CGRect) -> BackgroundView - { + static func createReusableBackgroundView(frame: CGRect) -> BackgroundView { + self.newBlueprintView(with: frame) + } + + static func createReusableSelectedBackgroundView(frame: CGRect) -> SelectedBackgroundView { + self.newBlueprintView(with: frame) + } + + private static func newBlueprintView(with frame : CGRect) -> BlueprintView { let view = BlueprintView(frame: frame) view.backgroundColor = .clear return view } - - static func createReusableSelectedBackgroundView(frame: CGRect) -> SelectedBackgroundView { - self.createReusableBackgroundView(frame: frame) - } } diff --git a/Demo/Sources/Demos/Demo Screens/CustomLayoutsViewController.swift b/Demo/Sources/Demos/Demo Screens/CustomLayoutsViewController.swift index df8ac9834..9584810d8 100644 --- a/Demo/Sources/Demos/Demo Screens/CustomLayoutsViewController.swift +++ b/Demo/Sources/Demos/Demo Screens/CustomLayoutsViewController.swift @@ -73,7 +73,7 @@ final class CustomLayoutsViewController : UIViewController self.gridOn.toggle() if self.gridOn { - self.listView.set(layout: .grid_experimental(), animated: true) + self.listView.set(layout: .experimental_grid(), animated: true) } else { self.listView.set(layout: .demoLayout, animated: true) } diff --git a/ListableUI/Sources/Layout/Grid/GridListLayout.swift b/ListableUI/Sources/Layout/Grid/GridListLayout.swift index 3295c77b2..78cd9bb97 100644 --- a/ListableUI/Sources/Layout/Grid/GridListLayout.swift +++ b/ListableUI/Sources/Layout/Grid/GridListLayout.swift @@ -7,9 +7,9 @@ import Foundation -public extension LayoutDescription +extension LayoutDescription { - static func grid_experimental(_ configure : @escaping (inout GridAppearance) -> () = { _ in }) -> Self + public static func experimental_grid(_ configure : @escaping (inout GridAppearance) -> () = { _ in }) -> Self { GridListLayout.describe(appearance: configure) } @@ -133,6 +133,76 @@ public struct GridAppearance : ListLayoutAppearance } +extension GridAppearance { + + public struct ItemLayout : ItemLayoutsValue { + + public static var defaultValue: Self { + .init() + } + + public init() { + + } + } + + + public struct HeaderFooterLayout : HeaderFooterLayoutsValue { + + public var width : CustomWidth + + public static var defaultValue: Self { + .init() + } + + public init( + width : CustomWidth = .default + ) { + self.width = width + } + } + + + public struct SectionLayout : SectionLayoutsValue { + + public var width : CustomWidth + + public static var defaultValue: Self { + .init() + } + + public init( + width : CustomWidth = .default + ) { + self.width = width + } + } +} + + +extension ItemLayouts { + public var grid : GridAppearance.ItemLayout { + get { self[GridAppearance.ItemLayout.self] } + set { self[GridAppearance.ItemLayout.self] = newValue } + } +} + + +extension HeaderFooterLayouts { + public var grid : GridAppearance.HeaderFooterLayout { + get { self[GridAppearance.HeaderFooterLayout.self] } + set { self[GridAppearance.HeaderFooterLayout.self] = newValue } + } +} + +extension SectionLayouts { + public var grid : GridAppearance.SectionLayout { + get { self[GridAppearance.SectionLayout.self] } + set { self[GridAppearance.SectionLayout.self] = newValue } + } +} + + final class GridListLayout : ListLayout { typealias LayoutAppearance = GridAppearance @@ -222,7 +292,7 @@ final class GridListLayout : ListLayout performLayout(for: self.content.header) { header in let hasListHeader = self.content.header.isPopulated - let position = header.layouts.table.width.position(with: viewSize, defaultWidth: rootWidth) + let position = header.layouts.grid.width.position(with: viewSize, defaultWidth: rootWidth) let measureInfo = Sizing.MeasureInfo( sizeConstraint: CGSize(width: position.width, height: .greatestFiniteMagnitude), @@ -257,7 +327,7 @@ final class GridListLayout : ListLayout self.content.sections.forEachWithIndex { sectionIndex, isLast, section in - let sectionPosition = section.layouts.table.width.position(with: viewSize, defaultWidth: rootWidth) + let sectionPosition = section.layouts.grid.width.position(with: viewSize, defaultWidth: rootWidth) // // Section Header @@ -267,7 +337,7 @@ final class GridListLayout : ListLayout let hasSectionFooter = section.footer.isPopulated performLayout(for: section.header) { header in - let width = header.layouts.table.width.merge(with: section.layouts.table.width) + let width = header.layouts.grid.width.merge(with: section.layouts.grid.width) let position = width.position(with: viewSize, defaultWidth: sectionPosition.width) let measureInfo = Sizing.MeasureInfo( @@ -315,7 +385,7 @@ final class GridListLayout : ListLayout // performLayout(for: section.footer) { footer in - let width = footer.layouts.table.width.merge(with: section.layouts.table.width) + let width = footer.layouts.grid.width.merge(with: section.layouts.grid.width) let position = width.position(with: viewSize, defaultWidth: sectionPosition.width) let measureInfo = Sizing.MeasureInfo( @@ -357,7 +427,7 @@ final class GridListLayout : ListLayout performLayout(for: self.content.footer) { footer in let hasFooter = footer.isPopulated - let position = footer.layouts.table.width.position(with: viewSize, defaultWidth: rootWidth) + let position = footer.layouts.grid.width.position(with: viewSize, defaultWidth: rootWidth) let measureInfo = Sizing.MeasureInfo( sizeConstraint: CGSize(width: position.width, height: .greatestFiniteMagnitude), @@ -383,7 +453,7 @@ final class GridListLayout : ListLayout performLayout(for: self.content.overscrollFooter) { footer in - let position = footer.layouts.table.width.position(with: viewSize, defaultWidth: rootWidth) + let position = footer.layouts.grid.width.position(with: viewSize, defaultWidth: rootWidth) let measureInfo = Sizing.MeasureInfo( sizeConstraint: CGSize(width: position.width, height: .greatestFiniteMagnitude), diff --git a/Podfile.lock b/Podfile.lock index b59846041..c59683520 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -1,6 +1,6 @@ PODS: - - BlueprintUI (0.19.0) - - BlueprintUICommonControls (0.19.0): + - BlueprintUI (0.20.0) + - BlueprintUICommonControls (0.20.0): - BlueprintUI - BlueprintUILists (0.14.2): - BlueprintUI @@ -43,8 +43,8 @@ EXTERNAL SOURCES: :path: Internal Pods/Snapshot/Snapshot.podspec SPEC CHECKSUMS: - BlueprintUI: 0a86c26f7f51bfc8dd37ead2c41d53b72995d318 - BlueprintUICommonControls: c177a134b6112a7e08db91b893f0164f49a75a25 + BlueprintUI: d26766f3e006d1f9348cba6a7f15efc64da74cb3 + BlueprintUICommonControls: b7b6a10581203f4bd6283c9d2a9b810d513d804b BlueprintUILists: afcc5b470731c70d1c2952ee4c24e6bcd566a2bd EnglishDictionary: f03968b9382ddc5c8dd63535efbf783c6cd45f1c ListableUI: 40e95b6299084145f04b421353612efbf9f50672