Skip to content

Commit

Permalink
Update storybook (#112)
Browse files Browse the repository at this point in the history
  • Loading branch information
muukii committed Sep 7, 2023
1 parent 0633ee1 commit ed5211e
Show file tree
Hide file tree
Showing 11 changed files with 152 additions and 131 deletions.
19 changes: 11 additions & 8 deletions Demo/Book.HStackLayout.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import StorybookKit
import StorybookKitTextureSupport
import TextureSwiftSupport
import SwiftUISupport

extension Book {

Expand All @@ -13,13 +14,13 @@ extension Book {
}

@MainActor
static func hStackLayout() -> BookView {
static func hStackLayout() -> BookPage {

BookNavigationLink(title: "HStackLayout") {
BookPage(title: "HStackLayout") {

BookForEach(data: [.start, .center, .end, .spaceBetween, .spaceAround] as [ASStackLayoutJustifyContent]) { justifyContent in
ForEach.inefficient(items: [.start, .center, .end, .spaceBetween, .spaceAround] as [ASStackLayoutJustifyContent]) { justifyContent in

BookNodePreview(expandsWidth: true) {
BookNodePreview(title: "\(justifyContent.rawValue)") { _ in
AnyDisplayNode { _, _ in
LayoutSpec {
HStackLayout(spacing: 20, justifyContent: justifyContent) {
Expand All @@ -40,12 +41,13 @@ extension Book {
}

}
.title("\(justifyContent.rawValue)")
.frame(maxWidth: .greatestFiniteMagnitude)

}

BookForEach(data: [.start, .center, .end, .spaceBetween, .spaceAround] as [ASStackLayoutJustifyContent]) { justifyContent in
ForEach.inefficient(items: [.start, .center, .end, .spaceBetween, .spaceAround] as [ASStackLayoutJustifyContent]) { justifyContent in

BookNodePreview(expandsWidth: false) {
BookNodePreview(title: "\(justifyContent.rawValue)") { _ in
AnyDisplayNode { _, _ in
LayoutSpec {
HStackLayout(spacing: 20, justifyContent: justifyContent) {
Expand All @@ -66,7 +68,8 @@ extension Book {
}

}
.title("\(justifyContent.rawValue)")
.frame(maxWidth: .greatestFiniteMagnitude)

}

}
Expand Down
79 changes: 39 additions & 40 deletions Demo/Book.ImageNode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,51 +11,50 @@ extension Book {
}

@MainActor
static func bookImageNode() -> BookView {

BookNavigationLink(title: "ImageNode") {

BookPage(title: "ASImageNode") {
BookSection(title: "ContentMode - .center") {
BookNodePreview(expandsWidth: true) {
let node = Self.makeImageNode()
node.contentMode = .center
return node
}

BookNodePreview(expandsWidth: true) {
let node = Self.makeImageNode()
node.contentMode = .center
node.style.maxWidth = .init(unit: .points, value: 60)
return node
}
.title("Width: 60")

BookNodePreview(expandsWidth: true) {
let node = Self.makeImageNode()
node.contentMode = .center
node.style.maxWidth = .init(unit: .points, value: 200)
return node
}
.title("Width: 200")
static func bookImageNode() -> BookPage {

BookPage(title: "ASImageNode") {
BookSection(title: "ContentMode - .center") {
BookNodePreview { _ in
let node = Self.makeImageNode()
node.contentMode = .center
return node
}
.frame(maxWidth: .greatestFiniteMagnitude)

BookSection(title: "ContentMode - .scaleAspectFit") {
BookNodePreview(expandsWidth: true) {
let node = Self.makeImageNode()
node.contentMode = .scaleAspectFit
return node
}

BookNodePreview(expandsWidth: true) {
let node = Self.makeImageNode()
node.contentMode = .scaleAspectFit
node.style.maxWidth = .init(unit: .points, value: 60)
return node
}
BookNodePreview(title: "Width: 60") { _ in
let node = Self.makeImageNode()
node.contentMode = .center
node.style.maxWidth = .init(unit: .points, value: 60)
return node
}
.frame(maxWidth: .greatestFiniteMagnitude)

BookNodePreview(title: "Width: 200") { _ in
let node = Self.makeImageNode()
node.contentMode = .center
node.style.maxWidth = .init(unit: .points, value: 200)
return node
}
.frame(maxWidth: .greatestFiniteMagnitude)
}

BookSection(title: "ContentMode - .scaleAspectFit") {
BookNodePreview { _ in
let node = Self.makeImageNode()
node.contentMode = .scaleAspectFit
return node
}
.frame(maxWidth: .greatestFiniteMagnitude)

BookNodePreview { _ in
let node = Self.makeImageNode()
node.contentMode = .scaleAspectFit
node.style.maxWidth = .init(unit: .points, value: 60)
return node
}
.frame(maxWidth: .greatestFiniteMagnitude)
}
}

}
Expand Down
16 changes: 7 additions & 9 deletions Demo/Book.InteractiveNode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,42 +23,40 @@ extension Book {
}

@MainActor
static func bookInteractiveNode() -> BookView {
BookNavigationLink(title: "InteractiveNode") {
BookNodePreview {
static func bookInteractiveNode() -> BookPage {
BookPage(title: "InteractiveNode") {
BookNodePreview { _ in
InteractiveNode(animation: .translucent) {
makeBody()
}
}

BookSection(title: "With Haptics") {

BookForEach(data: [.light, .medium, .heavy] as [UIImpactFeedbackGenerator.FeedbackStyle]) {
ForEach.inefficient(items: [.light, .medium, .heavy] as [UIImpactFeedbackGenerator.FeedbackStyle]) {
style in
BookNodePreview {
BookNodePreview(title: "Impact style:\(style.localizedDescription)") { _ in
InteractiveNode(
animation: .translucent,
haptics: .impactOnTouchUpInside(style: style)
) {
makeBody()
}
}
.title("Impact style:\(style.localizedDescription)")
}

if #available(iOS 13, *) {

BookForEach(data: [.soft, .rigid] as [UIImpactFeedbackGenerator.FeedbackStyle]) {
ForEach.inefficient(items: [.soft, .rigid] as [UIImpactFeedbackGenerator.FeedbackStyle]) {
style in
BookNodePreview {
BookNodePreview(title: "Impact style:\(style.localizedDescription)") { _ in
InteractiveNode(
animation: .translucent,
haptics: .impactOnTouchUpInside(style: style)
) {
makeBody()
}
}
.title("Impact style:\(style.localizedDescription)")
}

}
Expand Down
8 changes: 4 additions & 4 deletions Demo/Book.LayerBacking.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import TextureSwiftSupport
extension Book {

@MainActor
static func layerBacked() -> BookView {
static func layerBacked() -> BookPage {

BookNavigationLink(title: "LayerBacking") {
BookPage(title: "LayerBacking") {

BookNodePreview {
BookNodePreview { _ in
AnyDisplayNode { node, _ in
LayoutSpec {
VStackLayout {
Expand All @@ -24,7 +24,7 @@ extension Book {
}
}

BookNodePreview {
BookNodePreview { _ in
AnyDisplayNode { node, _ in
LayoutSpec {
VStackLayout {
Expand Down
18 changes: 9 additions & 9 deletions Demo/Book.StyledEdgeNode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import TextureSwiftSupport
extension Book {

@MainActor
static func bookStyledEdgeNode() -> BookView {
BookNavigationLink(title: "StyledEdgeNode") {
BookNodePreview {
static func bookStyledEdgeNode() -> BookPage {
BookPage(title: "StyledEdgeNode") {
BookNodePreview { _ in
let bodyNode = ASDisplayNode()
bodyNode.backgroundColor = .red

Expand All @@ -20,9 +20,9 @@ extension Book {
node.style.preferredSize = .init(width: 60, height: 60)
return node
}
.backgroundColor(.orange)
.background(Color.orange)

BookNodePreview {
BookNodePreview { _ in
let bodyNode = ASDisplayNode()
bodyNode.backgroundColor = .red

Expand All @@ -36,9 +36,9 @@ extension Book {
node.style.preferredSize = .init(width: 60, height: 60)
return node
}
.backgroundColor(.orange)
.background(Color.orange)

BookNodePreview {
BookNodePreview(title: "Mask") { _ in
let bodyNode = ASDisplayNode()
bodyNode.backgroundColor = .red

Expand All @@ -52,8 +52,8 @@ extension Book {
node.style.preferredSize = .init(width: 60, height: 60)
return node
}
.backgroundColor(.orange)
.title("Mask")
.background(Color.orange)


}

Expand Down
37 changes: 21 additions & 16 deletions Demo/Book.TiledLayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import UIKit
extension Book {

@MainActor
static func tiledLayer() -> BookView {
static func tiledLayer() -> BookPage {

BookNavigationLink(title: "Tile") {
BookPage(title: "Tile") {

BookNavigationLink(title: "TiledLayerView") {
BookPage(title: "TiledLayerView") {

BookForEach(data: 0..<50) { i in
BookPreview {
ForEach(0..<50) { i in
BookPreview { _ in
with(TiledLayerView(identifier: i)) { view in
view.backgroundColor = .systemYellow
Mondrian.layout {
Expand All @@ -24,10 +24,10 @@ extension Book {

}

BookNavigationLink(title: "TiledLayerView - transparent") {
BookPage(title: "TiledLayerView - transparent") {

BookForEach(data: 0..<50) { i in
BookPreview {
ForEach(0..<50) { i in
BookPreview { _ in

ZStackView(views: [
with(UIButton(type: .system)) {
Expand All @@ -47,11 +47,11 @@ extension Book {

}

BookNavigationLink(title: "TiledLayerView - hiding") {
BookPage(title: "TiledLayerView - hiding") {

BookForEach(data: 0..<50) { i in
BookPreview {
ZStackView(views: [
ForEach(0..<50) { i in
BookPreview { context in
let view = ZStackView(views: [
with(TiledLayerView(identifier: i)) { view in
view.backgroundColor = .systemYellow
Mondrian.layout {
Expand All @@ -65,10 +65,15 @@ extension Book {
}
},
])
}
.addButton("On") { view in
view.subviews[1].isHidden = true
}

context.control {
Button("On") {
view.subviews[1].isHidden = true
}
}

return view
}
}

}
Expand Down

0 comments on commit ed5211e

Please sign in to comment.