-
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.
Merge pull request #194 from kyleve/kve/manual-selection-management-demo
Add demo for manual selection management
- Loading branch information
Showing
4 changed files
with
99 additions
and
24 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
63 changes: 63 additions & 0 deletions
63
Demo/Sources/Demos/Demo Screens/ManualSelectionManagementViewController.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,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) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
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
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