Skip to content

Commit

Permalink
Merge pull request #194 from kyleve/kve/manual-selection-management-demo
Browse files Browse the repository at this point in the history
Add demo for manual selection management
  • Loading branch information
kyleve authored Aug 13, 2020
2 parents ed6a8ba + 71adbb6 commit 0b5fc16
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 24 deletions.
10 changes: 7 additions & 3 deletions Demo/Demo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
/* Begin PBXBuildFile section */
0A07119324BA798400CDF65D /* ListStateViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A07119224BA798400CDF65D /* ListStateViewController.swift */; };
0A0E070423870A5700DDD27D /* README.md in Resources */ = {isa = PBXBuildFile; fileRef = 0A0E070323870A5700DDD27D /* README.md */; };
0A793B5824E4B53500850139 /* ManualSelectionManagementViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A793B5724E4B53500850139 /* ManualSelectionManagementViewController.swift */; };
0A87BA652463567B0047C3B5 /* CHANGELOG.md in Resources */ = {isa = PBXBuildFile; fileRef = 0A87BA642463567B0047C3B5 /* CHANGELOG.md */; };
0AA4D9B9248064A300CF95A5 /* CustomLayoutsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0AA4D9A8248064A200CF95A5 /* CustomLayoutsViewController.swift */; };
0AA4D9BA248064A300CF95A5 /* FlowLayoutViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0AA4D9A9248064A200CF95A5 /* FlowLayoutViewController.swift */; };
Expand Down Expand Up @@ -44,6 +45,7 @@
06908B38E59ACD7502B5332F /* Pods-Demo.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Demo.release.xcconfig"; path = "Target Support Files/Pods-Demo/Pods-Demo.release.xcconfig"; sourceTree = "<group>"; };
0A07119224BA798400CDF65D /* ListStateViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListStateViewController.swift; sourceTree = "<group>"; };
0A0E070323870A5700DDD27D /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; name = README.md; path = ../README.md; sourceTree = "<group>"; };
0A793B5724E4B53500850139 /* ManualSelectionManagementViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ManualSelectionManagementViewController.swift; sourceTree = "<group>"; };
0A87BA642463567B0047C3B5 /* CHANGELOG.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; name = CHANGELOG.md; path = ../CHANGELOG.md; sourceTree = "<group>"; };
0AA4D9A8248064A200CF95A5 /* CustomLayoutsViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CustomLayoutsViewController.swift; sourceTree = "<group>"; };
0AA4D9A9248064A200CF95A5 /* FlowLayoutViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FlowLayoutViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -123,18 +125,19 @@
0AA4D9B0248064A300CF95A5 /* CoordinatorViewController.swift */,
0AA4D9A8248064A200CF95A5 /* CustomLayoutsViewController.swift */,
0AA4D9A9248064A200CF95A5 /* FlowLayoutViewController.swift */,
0A07119224BA798400CDF65D /* ListStateViewController.swift */,
0AA4D9B1248064A300CF95A5 /* HorizontalLayoutViewController.swift */,
0AA4D9AF248064A300CF95A5 /* InvoicesPaymentScheduleDemoViewController.swift */,
0ACF96D524A0094D0090EAC4 /* ItemInsertAndRemoveAnimationsViewController.swift */,
0AA4D9B3248064A300CF95A5 /* ItemizationEditorViewController.swift */,
0AA4D9AB248064A300CF95A5 /* KeyboardTestingViewController.swift */,
0A07119224BA798400CDF65D /* ListStateViewController.swift */,
0AC2A1952489F93E00779459 /* PagedViewController.swift */,
0AA4D9B7248064A300CF95A5 /* ReorderingViewController.swift */,
0AA4D9AA248064A200CF95A5 /* ScrollViewEdgesPlaygroundViewController.swift */,
0A793B5724E4B53500850139 /* ManualSelectionManagementViewController.swift */,
2B8804642490844A003BB351 /* SpacingCustomizationViewController.swift */,
0AA4D9B5248064A300CF95A5 /* SwipeActionsViewController.swift */,
0ACF96D524A0094D0090EAC4 /* ItemInsertAndRemoveAnimationsViewController.swift */,
0AA4D9AE248064A300CF95A5 /* WidthCustomizationViewController.swift */,
2B8804642490844A003BB351 /* SpacingCustomizationViewController.swift */,
);
path = "Demo Screens";
sourceTree = "<group>";
Expand Down Expand Up @@ -422,6 +425,7 @@
0A07119324BA798400CDF65D /* ListStateViewController.swift in Sources */,
0AA4D9C0248064A300CF95A5 /* InvoicesPaymentScheduleDemoViewController.swift in Sources */,
0AEB96E222FBCC1D00341DFF /* AppDelegate.swift in Sources */,
0A793B5824E4B53500850139 /* ManualSelectionManagementViewController.swift in Sources */,
0AA4D9C9248064A300CF95A5 /* CollectionViewBasicDemoViewController.swift in Sources */,
0AA4D9BC248064A300CF95A5 /* KeyboardTestingViewController.swift in Sources */,
0AA4D9C1248064A300CF95A5 /* CoordinatorViewController.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
//
// ManualSelectionManagementViewController.swift
// Demo
//
// Created by Kyle Van Essen on 8/12/20.
// Copyright © 2020 Kyle Van Essen. All rights reserved.
//

import Listable
import UIKit


final class ManualSelectionManagementViewController : ListViewController
{
var selectedIndex : Int? = nil

override func viewDidLoad() {
super.viewDidLoad()

self.navigationItem.rightBarButtonItems = [
UIBarButtonItem(title: "Deselect", style: .plain, target: self, action: #selector(deselect)),
UIBarButtonItem(title: "Change", style: .plain, target: self, action: #selector(change)),
]
}

@objc private func deselect() {
self.selectedIndex = nil
self.reload(animated: true)
}

@objc private func change() {

if self.selectedIndex ?? 0 < 10 {
self.selectedIndex = (self.selectedIndex ?? 0) + 1
} else {
self.selectedIndex = 1
}

self.reload(animated: true)
}

override func configure(list: inout ListProperties) {

list.behavior.selectionMode = .single(clearsSelectionOnViewWillAppear: false)

list.appearance = .demoAppearance
list.layout = .demoLayout

list("content") { section in

section += (1...10).map { index in
Item(DemoItem(text: "\(index)")) { item in
item.selectionStyle = .selectable(isSelected: index == selectedIndex)

item.onSelect = { _ in
self.selectedIndex = index
self.reload(animated: true)
}
}
}
}
}
}
48 changes: 28 additions & 20 deletions Demo/Sources/Demos/DemosRootViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,22 @@ public final class DemosRootViewController : ListViewController

section += Item(
DemoItem(text: "Blueprint Integration"),
selectionStyle: .tappable,
selectionStyle: .selectable(),
onSelect : { _ in
self.push(BlueprintListDemoViewController())
})

section += Item(
DemoItem(text: "Auto Scrolling (Bottom Pin)"),
selectionStyle: .tappable,
selectionStyle: .selectable(),
onSelect : { _ in
self.push(AutoScrollingViewController())
})

if #available(iOS 13.0, *) {
section += Item(
DemoItem(text: "List State & State Reader"),
selectionStyle: .tappable,
selectionStyle: .selectable(),
onSelect: { _ in
self.push(ListStateViewController())
}
Expand All @@ -70,59 +70,67 @@ public final class DemosRootViewController : ListViewController

section += Item(
DemoItem(text: "Itemization Editor"),
selectionStyle: .tappable,
selectionStyle: .selectable(),
onSelect : { _ in
self.push(ItemizationEditorViewController())
})

section += Item(
DemoItem(text: "English Dictionary Search"),
selectionStyle: .tappable,
selectionStyle: .selectable(),
onSelect : { _ in
self.push(CollectionViewDictionaryDemoViewController())
})

section += Item(
DemoItem(text: "Keyboard Testing"),
selectionStyle: .tappable,
selectionStyle: .selectable(),
onSelect : { _ in
self.push(KeyboardTestingViewController())
})

section += Item(
DemoItem(text: "Reordering (Experimental)"),
selectionStyle: .tappable,
selectionStyle: .selectable(),
onSelect : { _ in
self.push(ReorderingViewController())
})

section += Item(
DemoItem(text: "Invoices Payment Schedule"),
selectionStyle: .tappable,
selectionStyle: .selectable(),
onSelect : { _ in
self.push(InvoicesPaymentScheduleDemoViewController())
})

section += Item(
DemoItem(text: "Swipe Actions"),
selectionStyle: .tappable,
selectionStyle: .selectable(),
onSelect : { _ in
self.push(SwipeActionsViewController())
})

section += Item(
DemoItem(text: "Item Content Coordinator"),
selectionStyle: .tappable,
selectionStyle: .selectable(),
onSelect : { _ in
self.push(CoordinatorViewController())
})

section += Item(
DemoItem(text: "Item Insert & Remove Animations"),
selectionStyle: .tappable,
selectionStyle: .selectable(),
onSelect: { _ in
self.push(ItemInsertAndRemoveAnimationsViewController())
})

section += Item(
DemoItem(text: "Manual Selection Management"),
selectionStyle: .selectable(),
onSelect: { _ in
self.push(ManualSelectionManagementViewController())
}
)
}

list("layouts") { section in
Expand All @@ -133,35 +141,35 @@ public final class DemosRootViewController : ListViewController

section += Item(
DemoItem(text: "Grid Layout"),
selectionStyle: .tappable,
selectionStyle: .selectable(),
onSelect : { _ in
self.push(CustomLayoutsViewController())
})

section += Item(
DemoItem(text: "Paged Layout"),
selectionStyle: .tappable,
selectionStyle: .selectable(),
onSelect : { _ in
self.push(PagedViewController())
})

section += Item(
DemoItem(text: "Horizontal Layout"),
selectionStyle: .tappable,
selectionStyle: .selectable(),
onSelect : { _ in
self.push(HorizontalLayoutViewController())
})

section += Item(
DemoItem(text: "Width Customization"),
selectionStyle: .tappable,
selectionStyle: .selectable(),
onSelect : { _ in
self.push(WidthCustomizationViewController())
})

section += Item(
DemoItem(text: "Spacing Customization"),
selectionStyle: .tappable,
selectionStyle: .selectable(),
onSelect : { _ in
self.push(SpacingCustomizationViewController())
})
Expand All @@ -175,12 +183,12 @@ public final class DemosRootViewController : ListViewController

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

section += Item(
DemoItem(text: "Tappable Row (Slow Is Selected)"),
selectionStyle: .tappable,
selectionStyle: .selectable(),
onSelect: { _ in
Thread.sleep(forTimeInterval: 0.5)
}
Expand All @@ -195,7 +203,7 @@ public final class DemosRootViewController : ListViewController

section += Item(
DemoItem(text: "Flow Layout"),
selectionStyle: .tappable,
selectionStyle: .selectable(),
onSelect : { _ in
self.push(FlowLayoutViewController())
})
Expand All @@ -209,7 +217,7 @@ public final class DemosRootViewController : ListViewController

section += Item(
DemoItem(text: "Edges Playground"),
selectionStyle: .tappable,
selectionStyle: .selectable(),
onSelect : { _ in
self.push(ScrollViewEdgesPlaygroundViewController())
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class EnglishDictionary
public let wordsByLetter : [Letter]
public let allWords : [Word]

init()
public init()
{
let main = Bundle(for: EnglishDictionary.self)
let bundle = Bundle(url: main.url(forResource: "EnglishDictionaryResources", withExtension: "bundle")!)!
Expand Down

0 comments on commit 0b5fc16

Please sign in to comment.