Skip to content

Commit

Permalink
Allow controlling the layout bounds via the Environment.
Browse files Browse the repository at this point in the history
  • Loading branch information
kyleve committed Aug 15, 2021
1 parent 600ca93 commit 322952b
Show file tree
Hide file tree
Showing 37 changed files with 397 additions and 234 deletions.
47 changes: 0 additions & 47 deletions .github/workflows/run_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -145,50 +145,3 @@ jobs:

- name: Run Tests
run: Scripts/run_ios12_tests.sh


ios_11:
name: iOS 11

runs-on: macos-10.15

steps:
- name: Switch To Xcode 12
run: sudo xcode-select -switch /Applications/Xcode_12.2.app

- name: Checkout Repository
uses: actions/checkout@v1

# Build Caching

- name: Cache Bundler
uses: actions/cache@v2
with:
path: vendor/bundle
key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}
restore-keys: |
${{ runner.os }}-gems-
- name: Cache Cocoapods
uses: actions/cache@v2
with:
path: Pods
key: ${{ runner.os }}-pods-${{ hashFiles('**/Podfile.lock') }}
restore-keys: |
${{ runner.os }}-pods-
# Install & Build

- name: Bundle Install
run: |
bundle config path vendor/bundle
bundle install --jobs 4 --retry 3
- name: Pod Install
run: bundle exec pod install --repo-update

- name: Install iOS 11.1
run: xcversion simulators --install="iOS 11.1"

- name: Run Tests
run: Scripts/run_ios11_tests.sh
83 changes: 83 additions & 0 deletions BlueprintUILists/Sources/List.Measurement.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
//
// List.Measurement.swift
// BlueprintUILists
//
// Created by Kyle Van Essen on 3/25/21.
//

import ListableUI


///
/// Provides the possible options for how to size and measure a list when its measured size is queried
/// by the layout system.
///
/// You have two options: `.fillParent` and `.measureContent`.
///
/// When using `.fillParent`, the full available fitting size will be taken up, regardless
/// of the size of the content itself.
///
/// When using `.measureContent`, the content will be measured within the provided fitting size
/// and the smallest of the two sizes will be returned.
/// ```
/// .fillParent:
/// ┌───────────┐
/// │┌─────────┐│
/// ││ ││
/// ││ ││
/// ││ ││
/// ││ ││
/// ││ ││
/// │└─────────┘│
/// └───────────┘
///
/// .measureContent
/// ┌───────────┐
/// │ │
/// │ │
/// │┌─────────┐│
/// ││ ││
/// ││ ││
/// ││ ││
/// │└─────────┘│
/// └───────────┘
/// ```
extension List {

public enum Measurement : Equatable
{
/// When using `.fillParent`, the full available space will be taken up, regardless
/// of the content size of the list itself.
///
/// Eg, if the fitting size passed to the list is (200w, 1000h), and the list's content
/// is only (200w, 500h), (200w, 1000h) will still be returned.
///
/// This is the setting you want to use when your list is being used to fill the content
/// of a screen, such as if it is being presented in a navigation controller or tab bar controller.
///
/// This option is the most performant, because no content measurement has to occur.
case fillParent

/// When using `.measureContent`, the content of the list will be measured within the provided fitting size
/// and the smallest of the two sizes will be returned.
///
/// If you are putting a list into a sheet or popover (or even another list!), this is generally the `Sizing` type
/// you will want to use, to ensure the sheet or popover takes up the minimum amount of space possible.
///
/// - parameters:
/// - cacheKey: If provided, the underlying `Element`'s `measurementCacheKey` will be set to this value.
/// Note that this value must be unique within the entire blueprint view – so please provide a sufficiently unique value,
/// or measurement collisions will occur (one element's measurement being used for another) for duplicate keys.
///
/// - itemLimit: When measuring the list, how many items should be measured to determine the height. Defaults
/// to 50, which is usually enough to fill the `fittingSize`. If you truly want to determine the entire height of all of
/// the content in the list, set this to `nil` (but you should rarely need to do this). The lower this value, the less
/// overall measurement that has to occur (if the value is less than the number of items in the list), which improvements
/// measurement and layout performance.
///
case measureContent(
cacheKey : AnyHashable? = nil,
itemLimit : Int? = ListView.defaultContentSizeItemLimit
)
}
}
18 changes: 9 additions & 9 deletions BlueprintUILists/Sources/List.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ public struct List : Element
/// it will take up all the size it is given. You can change this to
/// `.measureContent` to instead measure the optimal size.
///
/// See the `ListSizing` documentation for more.
public var sizing : ListSizing
/// See the `List.Measurement` documentation for more.
public var measurement : List.Measurement

//
// MARK: Initialization
Expand All @@ -63,10 +63,10 @@ public struct List : Element
/// Create a new list, configured with the provided properties,
/// configured with the provided `ListProperties` builder.
public init(
sizing : ListSizing = .fillParent,
measurement : List.Measurement = .fillParent,
configure : ListProperties.Configure
) {
self.sizing = sizing
self.measurement = measurement

self.properties = .default(with: configure)
}
Expand All @@ -79,7 +79,7 @@ public struct List : Element
ElementContent { size, env in
ListContent(
properties: self.properties,
sizing: self.sizing,
measurement: self.measurement,
environment: env
)
}
Expand All @@ -96,25 +96,25 @@ extension List {
fileprivate struct ListContent : Element {

var properties : ListProperties
var sizing : ListSizing
var measurement : List.Measurement

init(
properties : ListProperties,
sizing : ListSizing,
measurement : List.Measurement,
environment : Environment
) {
var properties = properties

properties.environment.blueprintEnvironment = environment

self.properties = properties
self.sizing = sizing
self.measurement = measurement
}

// MARK: Element

public var content : ElementContent {
switch self.sizing {
switch self.measurement {
case .fillParent:
return ElementContent { constraint -> CGSize in
constraint.maximum
Expand Down
80 changes: 0 additions & 80 deletions BlueprintUILists/Sources/ListSizing.swift

This file was deleted.

6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@

### Added

- [You can now provide default list bounds for participating layouts](https://github.com/kyleve/Listable/pull/317) via the `environment.listContentBounds` property. This allows your containing screen, eg, to provide default bounds to ensure content lays out correctly. The `table` and `grid` layout types have been updated to read these content bounds.

### Removed

### Changed

- [`ListSizing` was renamed to `List.Measurement`](https://github.com/kyleve/Listable/pull/317), to reflect that it affects measurement and to align with Blueprint's terminology for measurement.

### Misc

# Past Releases
Expand Down Expand Up @@ -102,7 +106,7 @@

### Changed

- [Changed how `ListView.contentSize` is implemented](https://github.com/kyleve/Listable/pull/283) in order to improve performance. An internal list is no longer used, instead we create a layout and ask it to lay out its elements. `ListSizing` also moved to `BlueprintUILists`, as that is the only place it was used.
- [Changed how `ListView.contentSize` is implemented](https://github.com/kyleve/Listable/pull/283) in order to improve performance. An internal list is no longer used, instead we create a layout and ask it to lay out its elements. `List.Measurement` also moved to `BlueprintUILists`, as that is the only place it was used.

# [0.19.0] - 2021-03-22

Expand Down
6 changes: 3 additions & 3 deletions Demo/Demo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 1110;
LastUpgradeCheck = 1220;
LastUpgradeCheck = 1300;
ORGANIZATIONNAME = "Kyle Van Essen";
TargetAttributes = {
0AE8554D2390933100F2E245 = {
Expand Down Expand Up @@ -582,7 +582,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = YES;
Expand Down Expand Up @@ -639,7 +639,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
SDKROOT = iphoneos;
Expand Down
2 changes: 1 addition & 1 deletion Demo/Demo.xcodeproj/xcshareddata/xcschemes/Demo.xcscheme
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1220"
LastUpgradeVersion = "1300"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@ extension LayoutDescription
{
static var demoLayout : Self {
.table {
$0.layout = .init(
$0.bounds = .init(
padding: UIEdgeInsets(top: 30.0, left: 20.0, bottom: 30.0, right: 20.0),
width: .atMost(600.0),
width: .atMost(600.0)
)

$0.layout = .init(
interSectionSpacingWithNoFooter: 20.0,
interSectionSpacingWithFooter: 20.0,
sectionHeaderBottomSpacing: 15.0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@ final public class CollectionViewDictionaryDemoViewController : UIViewController
self.title = "Dictionary"

self.listView.layout = .table {

$0.bounds = .init(
padding: UIEdgeInsets(top: 0.0, left: 20.0, bottom: 20.0, right: 20.0),
width: .atMost(600.0)
)

$0.layout.set {
$0.padding = UIEdgeInsets(top: 0.0, left: 20.0, bottom: 20.0, right: 20.0)
$0.width = .atMost(600.0)
$0.sectionHeaderBottomSpacing = 10.0
$0.itemSpacing = 7.0
$0.interSectionSpacingWithNoFooter = 10.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ final class HorizontalLayoutViewController : UIViewController
self.listView.configure { list in

list.layout = .table {

$0.bounds = .init(padding: UIEdgeInsets(top: 20.0, left: 20.0, bottom: 20.0, right: 20.0))

$0.layout.itemSpacing = 20.0
$0.layout.padding = UIEdgeInsets(top: 20.0, left: 20.0, bottom: 20.0, right: 20.0)
}

list.content.overscrollFooter = HeaderFooter(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ final class InvoicesPaymentScheduleDemoViewController : UIViewController
func setAppearance()
{
self.list.layout = .table {
$0.bounds = .init(padding: UIEdgeInsets(top: 20.0, left: 10.0, bottom: 20.0, right: 10.0))

$0.layout.set {
$0.padding = UIEdgeInsets(top: 20.0, left: 10.0, bottom: 20.0, right: 10.0)
$0.interSectionSpacingWithFooter = 30.0
$0.interSectionSpacingWithNoFooter = 30.0
$0.sectionHeaderBottomSpacing = 5.0
Expand Down
Loading

0 comments on commit 322952b

Please sign in to comment.