Skip to content

Commit

Permalink
Dynamic loading of BookProvider conformers + new #StorybookPage m…
Browse files Browse the repository at this point in the history
…acro (#35)

## `#StorybookPage` macro:
```swift
#StorybookPage<Namespace.MyView> {
  VStack {
    MyView()
    Text("test")
  }
  .tint(.accentColor)
}
```
```swift
#StorybookPage(title: "My View") {
  VStack {
    MyView()
    Text("test")
  }
  .tint(.accentColor)
}
```


## Dynamically loading of all `BookProvider`
### Search only `#StorybookPage` macro usages
```swift
struct RootView: View {
  var body: some View {
    StorybookDisplayRootView(
      bookStore: .init(
        book: .init(title: "#StorybookPage macro") {
          Book.allStorybookPages()
            .map({ $0.bookBody })
        }
      )
    )
  }
}
```
### Search all `BookProvider` conformances, including `#StorybookPage`
macro usages
```swift
struct RootView: View {
  var body: some View {
    StorybookDisplayRootView(
      bookStore: .init(
        book: .init(title: "All BookProviders") {
          Book.allBookProviders()
            .map({ $0.bookBody })
        }
      )
    )
  }
}
```

## Other changes
- Updated Demo app to include both uses of previous `Book` declaring
methods and the new `#StorybookPage` usage
- Changed `#file` usages to `#fileID` to hide machine usernames in paths
- Reorganized source file directories
  • Loading branch information
JohnEstropia authored Feb 20, 2024
1 parent 8985fa9 commit 8c716b5
Show file tree
Hide file tree
Showing 20 changed files with 931 additions and 104 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ on: [push]

jobs:
build-storybook-kit:
runs-on: macos-13
runs-on: macos-14
steps:
- uses: maxim-lobanov/[email protected]
with:
xcode-version: "14.3"
xcode-version: "15.0"
- uses: actions/checkout@v2
- name: xcodebuild
run: xcodebuild -scheme StorybookKit -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 8,OS=16.2'
run: xcodebuild -scheme StorybookKit -sdk iphonesimulator -destination 'generic/platform=iOS Simulator'
build-storybook-kit-texture-support:
runs-on: macos-13
runs-on: macos-14
steps:
- uses: maxim-lobanov/[email protected]
with:
xcode-version: "14.3"
xcode-version: "15.0"
- uses: actions/checkout@v2
- name: xcodebuild
run: xcodebuild -scheme StorybookKitTextureSupport -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 8,OS=16.2'
run: xcodebuild -scheme StorybookKitTextureSupport -sdk iphonesimulator -destination 'generic/platform=iOS Simulator'
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1520"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
shouldAutocreateTestPlan = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "StorybookMacrosTests"
BuildableName = "StorybookMacrosTests"
BlueprintName = "StorybookMacrosTests"
ReferencedContainer = "container:">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
131 changes: 61 additions & 70 deletions Development/Demo/MyBook.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import StorybookKit
import SwiftUISupport

@MainActor
let myBook2 = Book.init(
let myBook = Book.init(
title: "MyUI",
contents: {

Expand Down Expand Up @@ -135,100 +135,91 @@ let myBook2 = Book.init(
}
)

private func labelExpandingTestBook() -> some View {
#StorybookPage(title: "UILabel updating text") {
BookPreview { context in
let label = UILabel()
label.text = "Test"

BookSection(title: "UILabel updating text") {
BookPreview { context in
let label = UILabel()
label.text = ""

context.control {
HStack {
Button("Empty") {
label.text = ""
}
Button("Short") {
label.text = "Hello"
}
Button("Long Text") {
label.text = "Hello, Hello,"
}
context.control {
HStack {
Button("Empty") {
label.text = ""
}
Button("Short") {
label.text = "Hello"
}
Button("Long Text") {
label.text = "Hello, Hello,"
}
}

return label
}
}

return label
}
}

extension MyLabel {

fileprivate static func makeBookView() -> some View {
Group {
BookPreview(title: "Short Text") { _ in
self.init(title: "Hello")
}
#StorybookPage<MyLabel> {
BookPreview(title: "Short Text") { _ in
MyLabel(title: "Hello")
}
.previewFrame(width: nil, height: 100)

BookPreview(title: "Long Text") { _ in
self.init(title: "HelloHelloHelloHello")
}
BookPreview(title: "Long Text") { _ in
MyLabel(title: "HelloHelloHelloHello")
}
.previewFrame(width: nil, height: 100)

BookPreview { context in
let view = self.init(title: "HelloHelloHelloHello")
BookPreview { context in
let view = MyLabel(title: "HelloHelloHelloHello")

context.control {
Button("Delete") {
view.label.text = ""
}
}

return view
context.control {
Button("Delete") {
view.label.text = ""
}
}

return view
}
.previewFrame(width: nil, height: 100)
}

fileprivate static func makeBookView_1() -> some View {
BookPreview { _ in
self.init(title: "")
}
#StorybookPage<MyLabel> {
BookPreview { _ in
MyLabel(title: "Test")
}
}

fileprivate static func makeBookView_2() -> some View {
Group {
BookPreview { _ in
self.init(title: "")
}
BookPreview { _ in
self.init(title: "")
}
}
#StorybookPage<MyLabel> {
BookPreview { _ in
MyLabel(title: "Test")
}
BookPreview { _ in
MyLabel(title: "Test")
}
}

fileprivate static func makeBookView_3() -> some View {
Group {
#StorybookPage<MyLabel> {
BookPreview { _ in
MyLabel(title: "Test")
}
BookPreview { _ in
MyLabel(title: "Test")
}
BookPage(title: "Nested") {
BookPreview { _ in
MyLabel(title: "Test")
}
BookPage(title: "Nested") {
BookPreview { _ in
self.init(title: "")
MyLabel(title: "Test")
}
BookPreview { _ in
self.init(title: "")
MyLabel(title: "Test")
}
BookPage(title: "Nested") {
BookPreview { _ in
self.init(title: "")
}
BookPage(title: "Nested") {
BookPreview { _ in
self.init(title: "")
}
BookPreview { _ in
self.init(title: "")
}
BookPage(title: "Nested") {
BookPreview { _ in
self.init(title: "")
}
}
MyLabel(title: "Test")
}
}
}
Expand Down
18 changes: 11 additions & 7 deletions Development/Demo/RootView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,18 @@ import SwiftUISupport
struct RootView: View {

var body: some View {
VStack {
StorybookDisplayRootView(
bookStore: .init(
book: .init(title: "Storybook Demo") {

// StorybookDisplayRootView(
// book: myBook
// )
myBook

StorybookDisplayRootView(bookStore: .init(book: myBook2))

}
Book(title: "#StorybookPage macro") {
Book.allStorybookPages()
.map({ $0.bookBody })
}
}
)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,33 @@
"version" : "1.3.0"
}
},
{
"identity" : "swift-macro-testing",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-macro-testing.git",
"state" : {
"branch" : "main",
"revision" : "15916c0c328339f54c15d616465d79700e3f7de8"
}
},
{
"identity" : "swift-snapshot-testing",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-snapshot-testing",
"state" : {
"revision" : "e7b77228b34057041374ebef00c0fd7739d71a2b",
"version" : "1.15.3"
}
},
{
"identity" : "swift-syntax",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-syntax.git",
"state" : {
"revision" : "64889f0c732f210a935a0ad7cda38f77f876262d",
"version" : "509.1.1"
}
},
{
"identity" : "swiftui-gesture-velocity",
"kind" : "remoteSourceControl",
Expand All @@ -50,8 +77,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/FluidGroup/Texture.git",
"state" : {
"branch" : "spm",
"revision" : "17e0b467fe7360cfb29f2612785acf60e86775e9"
"revision" : "68df47f0d26522da76b06f22e9a97e4d4ab58dad",
"version" : "3.0.2"
}
},
{
Expand All @@ -60,7 +87,7 @@
"location" : "https://github.com/FluidGroup/TextureBridging.git",
"state" : {
"branch" : "main",
"revision" : "ed8d3ac84c3fda90832c793fdeb8972154bd15fe"
"revision" : "4383f8a9846a0507d2c22ee9fac22153f9b86fed"
}
},
{
Expand All @@ -69,7 +96,7 @@
"location" : "https://github.com/FluidGroup/TextureSwiftSupport.git",
"state" : {
"branch" : "main",
"revision" : "5ebbc98ddfdac136620a95b7cf01894f4863f811"
"revision" : "5bae50cab3798dccb8b98c3ffbc70320ae66b45a"
}
}
],
Expand Down
Loading

0 comments on commit 8c716b5

Please sign in to comment.