Skip to content

Commit

Permalink
Add ListStateObserver and ListActions for listening to and performing…
Browse files Browse the repository at this point in the history
… list actions.
  • Loading branch information
kyleve committed Jul 17, 2020
1 parent 94966e9 commit 5e2b394
Show file tree
Hide file tree
Showing 21 changed files with 1,062 additions and 256 deletions.
4 changes: 4 additions & 0 deletions Demo/Demo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* 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 */; };
0A87BA652463567B0047C3B5 /* CHANGELOG.md in Resources */ = {isa = PBXBuildFile; fileRef = 0A87BA642463567B0047C3B5 /* CHANGELOG.md */; };
0AA4D9B9248064A300CF95A5 /* CustomLayoutsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0AA4D9A8248064A200CF95A5 /* CustomLayoutsViewController.swift */; };
Expand Down Expand Up @@ -41,6 +42,7 @@

/* Begin PBXFileReference section */
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>"; };
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>"; };
Expand Down Expand Up @@ -121,6 +123,7 @@
0AA4D9B0248064A300CF95A5 /* CoordinatorViewController.swift */,
0AA4D9A8248064A200CF95A5 /* CustomLayoutsViewController.swift */,
0AA4D9A9248064A200CF95A5 /* FlowLayoutViewController.swift */,
0A07119224BA798400CDF65D /* ListStateViewController.swift */,
0AA4D9B1248064A300CF95A5 /* HorizontalLayoutViewController.swift */,
0AA4D9AF248064A300CF95A5 /* InvoicesPaymentScheduleDemoViewController.swift */,
0AA4D9B3248064A300CF95A5 /* ItemizationEditorViewController.swift */,
Expand Down Expand Up @@ -416,6 +419,7 @@
0AA4D9C6248064A300CF95A5 /* SwipeActionsViewController.swift in Sources */,
0AA4D9BF248064A300CF95A5 /* WidthCustomizationViewController.swift in Sources */,
0AA4D9C8248064A300CF95A5 /* ReorderingViewController.swift in Sources */,
0A07119324BA798400CDF65D /* ListStateViewController.swift in Sources */,
0AA4D9C0248064A300CF95A5 /* InvoicesPaymentScheduleDemoViewController.swift in Sources */,
0AEB96E222FBCC1D00341DFF /* AppDelegate.swift in Sources */,
0AA4D9C9248064A300CF95A5 /* CollectionViewBasicDemoViewController.swift in Sources */,
Expand Down
82 changes: 82 additions & 0 deletions Demo/Sources/Demos/Demo Screens/ListStateViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
//
// ListStateViewController.swift
// Demo
//
// Created by Kyle Van Essen on 7/11/20.
// Copyright © 2020 Kyle Van Essen. All rights reserved.
//

import BlueprintLists
import BlueprintUICommonControls
import Combine

/// Includes combine examples, so only available on iOS 13.0+.
@available(iOS 13.0, *)
final class ListStateViewController : ListViewController
{
let actions = ListActions()

@Published var index : Int = 1

override func configure(list : inout ListProperties)
{
list.appearance = .demoAppearance
list.layout = .demoLayout

list("1") { section in
(1...100).forEach { count in
section += DemoItem(text: "Item #\(count)")
}
}

list.actions = self.actions

list.stateObserver = ListStateObserver { observer in
observer.onDidScroll { info in
print("Did Scroll: Scroll Type: \(info.scrollType)")
}

observer.onVisibilityChanged { info in
print("Displayed: \(info.displayed.map { $0.identifier })")
print("Ended Display: \(info.endedDisplay.map { $0.identifier })")
}
}
}

var cancel : AnyCancellable? = nil

override func viewDidLoad() {
super.viewDidLoad()

/// Example of how to use the `actions` within a reactive framwork like Combine or ReactiveSwift.

cancel = $index.sink { [weak self] value in
self?.actions.scrolling.scrollTo(
item: Identifier<DemoItem>("Item #\(value)"),
position: .init(position: .top, ifAlreadyVisible: .scrollToPosition),
animated: true
)
}

self.navigationItem.rightBarButtonItems = [
UIBarButtonItem(title: "Up", style: .plain, target: self, action: #selector(scrollUp)),
UIBarButtonItem(title: "Down", style: .plain, target: self, action: #selector(scrollDown)),
UIBarButtonItem(title: "Signal", style: .plain, target: self, action: #selector(doSignal))
]
}

@objc private func scrollUp()
{
self.actions.scrolling.scrollToTop(animated: true)
}

@objc private func scrollDown()
{
self.actions.scrolling.scrollToLastItem(animated: true)
}

@objc private func doSignal()
{
self.index += 1
}
}
Loading

0 comments on commit 5e2b394

Please sign in to comment.