Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove ScenarioContent protocol #64

Merged
merged 2 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions Playbook.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
/* Begin PBXBuildFile section */
04DAC4EBEE89D365F72AD5DB /* SnapshotSupport.swift in Sources */ = {isa = PBXBuildFile; fileRef = 023425CAEE4AA111BE174F66 /* SnapshotSupport.swift */; };
04E6DA15062197311CB80A23 /* ScenarioProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 68E1EB13B5ED8DD48245B1E8 /* ScenarioProvider.swift */; };
06CC7A9EF2AEA3FEEC75B0B3 /* ScenarioContentTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F291632484870BA6A8BA1609 /* ScenarioContentTests.swift */; };
0D0659EBE8EF0971AF40405D /* Scheduler.swift in Sources */ = {isa = PBXBuildFile; fileRef = A2C24C0BB3864D3AF550A05D /* Scheduler.swift */; };
0E1A77DB134CE41112BE7EFB /* Counter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95BDCEF4FDC1DE7D50B6E73D /* Counter.swift */; };
0FEB2071F01AF72A62527F63 /* Highlight.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA6FEAB12579B7940EA763BB /* Highlight.swift */; };
Expand Down Expand Up @@ -65,7 +64,6 @@
C0F32DC787F41414E09C37FB /* HorizontalSeparator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5576F4CB67593B259E12C387 /* HorizontalSeparator.swift */; };
C51E0AB09C31FA61FE7D90BF /* ExtraScenarios.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56D23A73BBBCC7E6D4027CDB /* ExtraScenarios.swift */; };
C6A0A71A7D1DB2BECD5B4A2D /* ScenarioSearchTree.swift in Sources */ = {isa = PBXBuildFile; fileRef = 068FE06929659477F04AA176 /* ScenarioSearchTree.swift */; };
CB15497812BC08565D686486 /* ScenarioContent.swift in Sources */ = {isa = PBXBuildFile; fileRef = B4FB169EFF0C0FF72C2E69C4 /* ScenarioContent.swift */; };
CF8244A4AB05E5ED99B68742 /* SnapshotTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9B59B5A8B33031C6AF8A049E /* SnapshotTests.swift */; };
D016FBABE74D6996F5648DDC /* SnapshotDevice.swift in Sources */ = {isa = PBXBuildFile; fileRef = B6C5F051089936C546DFBB95 /* SnapshotDevice.swift */; };
D45CD95A63FC59D24E4F5E65 /* GalleryStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = 38F7F9F34307C4DEEDF210F9 /* GalleryStore.swift */; };
Expand Down Expand Up @@ -186,7 +184,6 @@
A8FCF24068A7FDD9BAD27ECA /* ScenarioDisplaySheet.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScenarioDisplaySheet.swift; sourceTree = "<group>"; };
ABBE0D7EADE227862CB3EB1F /* TableView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TableView.swift; sourceTree = "<group>"; };
AEB78746E7DE13CB4BBD42FC /* Mocks.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Mocks.swift; sourceTree = "<group>"; };
B4FB169EFF0C0FF72C2E69C4 /* ScenarioContent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScenarioContent.swift; sourceTree = "<group>"; };
B6C5F051089936C546DFBB95 /* SnapshotDevice.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SnapshotDevice.swift; sourceTree = "<group>"; };
B6CEC4F17D84235922932498 /* ScenarioStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScenarioStore.swift; sourceTree = "<group>"; };
C65E03F37BA759FC6E55D1C2 /* Drawer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Drawer.swift; sourceTree = "<group>"; };
Expand All @@ -202,7 +199,6 @@
EA762F5B447EF9828E1F86F2 /* PlaybookCatalog.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlaybookCatalog.swift; sourceTree = "<group>"; };
EB7DE56F774FFD4DB73EBD37 /* CatalogBarItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CatalogBarItem.swift; sourceTree = "<group>"; };
EC23506D3CC07FABB1992787 /* Playbook-Tests.xctest */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = wrapper.cfbundle; path = "Playbook-Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
F291632484870BA6A8BA1609 /* ScenarioContentTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScenarioContentTests.swift; sourceTree = "<group>"; };
F49057856849F915AB692364 /* ScenarioSearchStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScenarioSearchStore.swift; sourceTree = "<group>"; };
F6B0431D91C939D181493ECC /* PlaybookGallery.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlaybookGallery.swift; sourceTree = "<group>"; };
F830987472F2FBD2C3BA7284 /* ScenarioKind.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScenarioKind.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -276,7 +272,6 @@
children = (
385C5E36DF37E9A2AF379859 /* Playbook.swift */,
6E50413A08A9CF285D97A65C /* Scenario.swift */,
B4FB169EFF0C0FF72C2E69C4 /* ScenarioContent.swift */,
D63CD111722A3B8067BFE548 /* ScenarioContext.swift */,
F830987472F2FBD2C3BA7284 /* ScenarioKind.swift */,
FF835DB024B80E2FADFFD0FC /* ScenarioLayout.swift */,
Expand Down Expand Up @@ -395,7 +390,6 @@
9BAD3FE8D577886981218938 /* GalleryScenarios.swift */,
AEB78746E7DE13CB4BBD42FC /* Mocks.swift */,
9370D44977281AAEBF6DEF44 /* PlaybookTests.swift */,
F291632484870BA6A8BA1609 /* ScenarioContentTests.swift */,
81538A32C0A57BA96700E55E /* ScenarioStoreTests.swift */,
CEB51C85B7D63CEF5DC83B60 /* ScenarioSwiftUITests.swift */,
F913250C8A5AB7148459FEC6 /* ScenarioViewControllerTests.swift */,
Expand Down Expand Up @@ -541,7 +535,6 @@
334B859A3103A83A4EC996BF /* GalleryScenarios.swift in Sources */,
F9DF0B63F62E3A7B5ED2E619 /* Mocks.swift in Sources */,
E7597D8F364FF8D2CD4DF584 /* PlaybookTests.swift in Sources */,
06CC7A9EF2AEA3FEEC75B0B3 /* ScenarioContentTests.swift in Sources */,
B945D03AD556F3F8B3161147 /* ScenarioStoreTests.swift in Sources */,
72DDF1BB8E77EF11CB9BB4FC /* ScenarioSwiftUITests.swift in Sources */,
6CF7056823EA1730746AB145 /* ScenarioViewControllerTests.swift in Sources */,
Expand All @@ -556,7 +549,6 @@
99904F2A1ECCD16DC130B51A /* OrderedStorage.swift in Sources */,
FD3C77D1442C7CAADC579CB2 /* Playbook.swift in Sources */,
BF44BEAFAA1183BE4B9952AF /* Scenario.swift in Sources */,
CB15497812BC08565D686486 /* ScenarioContent.swift in Sources */,
341406194DDF8C7A82AB96D0 /* ScenarioContext.swift in Sources */,
BE7BF04B28E47309D2D7608D /* ScenarioKind.swift in Sources */,
DDF763A23C1AE9464827CCCE /* ScenarioLayout.swift in Sources */,
Expand Down
76 changes: 73 additions & 3 deletions Sources/Playbook/Scenario.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public struct Scenario {
public var line: UInt

/// A closure that make a new content with passed context.
public var content: (ScenarioContext) -> ScenarioContent
public var content: (ScenarioContext) -> UIViewController

/// Creates a new scenario.
///
Expand All @@ -30,7 +30,7 @@ public struct Scenario {
layout: ScenarioLayout,
file: StaticString = #file,
line: UInt = #line,
content: @escaping (ScenarioContext) -> ScenarioContent
content: @escaping (ScenarioContext) -> UIViewController
) {
self.name = name
self.layout = layout
Expand All @@ -39,6 +39,32 @@ public struct Scenario {
self.content = content
}

/// Creates a new scenario.
///
/// - Parameters:
/// - name: A unique name of this scenario.
/// - layout: Represents how the component should be laid out.
/// - file: A file path where defined this scenario.
/// - line: A line number where defined this scenario in file.
/// - content: A closure that make a new content with passed context.
public init(
_ name: ScenarioName,
layout: ScenarioLayout,
file: StaticString = #file,
line: UInt = #line,
content: @escaping (ScenarioContext) -> UIView
) {
self.init(
name,
layout: layout,
file: file,
line: line,
content: { context in
UIViewHostingController(view: content(context))
}
)
}

/// Creates a new scenario.
///
/// - Parameters:
Expand All @@ -52,7 +78,7 @@ public struct Scenario {
layout: ScenarioLayout,
file: StaticString = #file,
line: UInt = #line,
content: @escaping () -> ScenarioContent
content: @escaping () -> UIViewController
) {
self.init(
name,
Expand All @@ -62,4 +88,48 @@ public struct Scenario {
content: { _ in content() }
)
}

/// Creates a new scenario.
///
/// - Parameters:
/// - name: A unique name of this scenario.
/// - layout: Represents how the component should be laid out.
/// - file: A file path where defined this scenario.
/// - line: A line number where defined this scenario in file.
/// - content: A closure that make a new content.
public init(
_ name: ScenarioName,
layout: ScenarioLayout,
file: StaticString = #file,
line: UInt = #line,
content: @escaping () -> UIView
) {
self.init(
name,
layout: layout,
file: file,
line: line,
content: { _ in
UIViewHostingController(view: content())
}
)
}
}

private final class UIViewHostingController: UIViewController {
private let _view: UIView

init(view: UIView) {
self._view = view
super.init(nibName: nil, bundle: nil)
}

@available(*, unavailable)
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

override func loadView() {
view = _view
}
}
37 changes: 0 additions & 37 deletions Sources/Playbook/ScenarioContent.swift

This file was deleted.

2 changes: 1 addition & 1 deletion Sources/Playbook/ScenarioViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ private extension ScenarioViewController {
return
}

let contentViewController = scenario.content(context).makeUIViewController()
let contentViewController = scenario.content(context)
self.contentViewController = contentViewController

contentViewController.willMove(toParent: self)
Expand Down
18 changes: 0 additions & 18 deletions Tests/ScenarioContentTests.swift

This file was deleted.

Loading