-
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.
Updates to ItemCoordinator to properly support animations driven by B…
…lueprint-backed item content.
- Loading branch information
Showing
17 changed files
with
260 additions
and
138 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
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
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
112 changes: 112 additions & 0 deletions
112
Demo/Sources/Demos/Demo Screens/OnTapItemAnimationViewController.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,112 @@ | ||
// | ||
// OnTapItemAnimationViewController.swift | ||
// Demo | ||
// | ||
// Created by Kyle Van Essen on 3/2/21. | ||
// Copyright © 2021 Kyle Van Essen. All rights reserved. | ||
// | ||
|
||
import ListableUI | ||
import BlueprintUI | ||
import BlueprintUICommonControls | ||
import BlueprintUILists | ||
|
||
final class OnTapItemAnimationViewController : ListViewController { | ||
|
||
override func configure(list: inout ListProperties) { | ||
|
||
list.layout = .demoLayout | ||
|
||
list("items") { section in | ||
|
||
section += items.map { item in | ||
Item(item) { item in | ||
item.selectionStyle = .tappable | ||
} | ||
} | ||
|
||
} | ||
} | ||
} | ||
|
||
fileprivate struct ItemRow : BlueprintItemContent, Equatable { | ||
|
||
var name : String | ||
var price : String | ||
var onTapText : String = "Added" | ||
|
||
var isShowingPrice : Bool = true | ||
|
||
var identifier: Identifier<ItemRow> { | ||
.init(name) | ||
} | ||
|
||
func element(with info: ApplyItemContentInfo) -> Element { | ||
|
||
Row { row in | ||
row.verticalAlignment = .center | ||
|
||
row.addFlexible(child: Label(text: self.name) { label in | ||
label.font = .systemFont(ofSize: 18.0, weight: .semibold) | ||
}) | ||
|
||
row.addFlexible(child: Overlay { overlay in | ||
overlay.add( | ||
Label(text: self.price) { label in | ||
label.font = .systemFont(ofSize: 16.0, weight: .semibold) | ||
} | ||
.opacity(isShowingPrice ? 1 : 0) | ||
) | ||
|
||
overlay.add( | ||
Label(text: self.onTapText) { label in | ||
label.font = .systemFont(ofSize: 16.0, weight: .semibold) | ||
} | ||
.opacity(isShowingPrice ? 0 : 1) | ||
) | ||
}) | ||
} | ||
.inset(uniform: 10.0) | ||
.box(background: .white(0.95), corners: .rounded(radius: 10)) | ||
} | ||
|
||
func makeCoordinator( | ||
actions: CoordinatorActions, | ||
info: CoordinatorInfo | ||
) -> OnTapCoordinator | ||
{ | ||
OnTapCoordinator(actions: actions, info: info) | ||
} | ||
} | ||
|
||
fileprivate final class OnTapCoordinator : ItemContentCoordinator { | ||
var actions: ItemRow.CoordinatorActions | ||
var info: ItemRow.CoordinatorInfo | ||
|
||
init(actions: ItemRow.CoordinatorActions, info: ItemRow.CoordinatorInfo) { | ||
self.actions = actions | ||
self.info = info | ||
} | ||
|
||
typealias ItemContentType = ItemRow | ||
|
||
func wasSelected() { | ||
self.actions.update { item in | ||
item.content.isShowingPrice = false | ||
} | ||
|
||
self.actions.update(after: 1.0) { item in | ||
item.content.isShowingPrice = true | ||
} | ||
} | ||
} | ||
|
||
|
||
fileprivate let items : [ItemRow] = [ | ||
.init(name: "Coffee", price: "$4.00"), | ||
.init(name: "Cold Brew", price: "$5.00"), | ||
.init(name: "Espresso", price: "$6.00"), | ||
.init(name: "Flat White", price: "$5.00"), | ||
.init(name: "Iced Coffee", price: "$5.00"), | ||
.init(name: "Latte", price: "$6.00") | ||
] |
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
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
Oops, something went wrong.