-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ListStateObserver and ListActions for listening to and performing…
… list actions.
- Loading branch information
Showing
21 changed files
with
1,062 additions
and
256 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
Demo/Sources/Demos/Demo Screens/ListStateViewController.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
Oops, something went wrong.