Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

📘A library for isolated developing UI components and automatically taking snapshots of them.

License

NotificationsYou must be signed in to change notification settings

playbook-ui/playbook-ios

Repository files navigation

Playbook

A library for isolated developing UI components and automatically taking snapshots of them.

playbook

Playbook

Playbook

Swift5CI StatusLincense
ReleaseSwift Package Manager

Playbook is a library that provides a sandbox for building UI components without having to worry about application-specific dependencies, strongly inspired byStorybook for JavaScript in web-frontend development.

Components built by usingPlaybook can generate a standalone app as living styleguide.
This allows you to not only review UI quickly but also deliver more robust designs by separating business logics out of components.

Besides, snapshots of each component can be automatically generated by unit tests, and visual regression testing can be performed using arbitrary third-party tools.

For complex modern app development, it’s important to catch UI changes more sensitively and keep improving them faster.
With thePlaybook, you don't have to struggle through preparing the data and spend human resources for manual testings.



Usage


Playbook

Playbook is a framework that provides the basic functionality for managing components. It supports bothSwiftUI andUIKit.
Components are uniquely stored as scenarios. AScenario has the way to layout component. Please check the API Doc for the variety of layouts.

Playbook.default.addScenarios(of:"Home"){Scenario("CategoryHome", layout:.fill){CategoryHome().environmentObject(UserData.stub)}Scenario("LandmarkList", layout:.fill){NavigationView{LandmarkList().environmentObject(UserData.stub)}}Scenario("UIView red", layout:.fixed(length:100)){letview=UIView()        view.backgroundColor=.redreturn view}}

ScenarioProvider allows you to isolate additional scenarios and keep your playbook building clean.

structHomeScenarios:ScenarioProvider{staticfunc addScenarios(into playbook:Playbook){        playbook.addScenarios(of:"Home"){Scenario("CategoryHome", layout:.fill){CategoryHome().environmentObject(UserData.stub)}}}}structAllScenarios:ScenarioProvider{staticfunc addScenarios(into playbook:Playbook){        playbook.add(HomeScenarios.self)}}

You can use theScenarioContext passed to the closure that creates the component to get the screen size in snapshot, or wait before generating a snapshot.

Scenario("MapView", layout:.fill){ contextinMapView(coordinate:landmarkData[10].locationCoordinate){        // This closure will called after the map has completed to render.        context.snapshotWaiter.fulfill()}.onAppear(perform: context.snapshotWaiter.wait)}

PlaybookUI

PlaybookUI is a framework that provides user interfaces made bySwiftUI for browsing a list of scenarios.

PlaybookGallery

The component visuals are listed and displayed.
Those that are displayed on the top screen are not actually doing layout, but rather display the snapshots that are efficiently generated at runtime.

BrowserDetail
Gellery LightGellery DarkGellery Content LightGellery Content Dark

PlaybookCatalog

The UI that search and select a scenario in a drawer. It's more similar toStorybook.
If you have too many scenarios, this may be more efficient thanPlaybookCatalog.

BrowserDetail
Catalog LightCatalog DarkCatalog Detail LightCatalog Detail Dark

How to Save Snapshot Images

To save snapshot images to the photo library from the share button on each UI,NSPhotoLibraryAddUsageDescription must be supported. See theofficial document for more information.


PlaybookSnapshot

Scenarios can be tested by the instance of types conform toTestTool protocol.
Snapshot is one of them, which can generate the snapshots of all scenarios with simulate the screen size and safe area of the given devices.
Since Playbook doesn't depend on XCTest, it doesn't necessarily need to be run on Unit-test.

finalclassSnapshotTests:XCTestCase{func testTakeSnapshot()throws{letdirectory=ProcessInfo.processInfo.environment["SNAPSHOT_DIR"]!tryPlaybook.default.run(Snapshot(                directory:URL(fileURLWithPath: directory),                clean:true,                format:.png,                devices:[.iPhone15Pro(.portrait)]))}}

Generated Images


An extension toPlaybook that usesAccessibilitySnapshot to produce snapshots with accessibility information such as activation points and labels.

Accessibility Snapshot


Integration with Third-party Tools

The generated snapshot images can be used for more advanced visual regression testing by using a variety of third party tools.

percy

reg-suit


Requirements

  • Swift 5.10
  • Xcode 15.4
  • iOS 13.0+ (PlaybookUI: iOS 15.0+)

Installation

Playbook features are separated into the following frameworks.

  • Playbook: Core system of component management.
  • PlaybookSnapshot: Generates snapshots of all components.
  • PlaybookUI: Products a browsing UI for components managed by Playbook.

Select Xcode menuFile > Swift Packages > Add Package Dependency... and enter repository URL with GUI.

Repository: https://github.com/playbook-ui/playbook-ios

Note: Currently, SwiftPM doesn't support specifying the OS version for each library, so onlyiOS13 is supported.


License

Playbook is released under theApache 2.0 License.


Playbook

Contributors10

Languages


[8]ページ先頭

©2009-2025 Movatter.jp