Giter VIP home page Giter VIP logo

playbook-ui / playbook-ios Goto Github PK

View Code? Open in Web Editor NEW
1.2K 24.0 54.0 23.63 MB

πŸ“˜A library for isolated developing UI components and automatically taking snapshots of them.

Home Page: https://playbook-ui.github.io/playbook-ios/documentation/playbooksnapshot/

License: Apache License 2.0

Swift 99.14% Makefile 0.86%
playbook snapshot snapshot-testing visual-regression-testing uicatalog swift ios swiftui accessibility a11y

playbook-ios's Introduction

Playbook

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

playbook

Playbook

Playbook

Swift5 CI Status Lincense
Release Swift Package Manager

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

Components built by using Playbook 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 the Playbook, 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 both SwiftUI and UIKit.
Components are uniquely stored as scenarios. A Scenario 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)) {
        let view = UIView()
        view.backgroundColor = .red
        return view
    }
}

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

struct HomeScenarios: ScenarioProvider {
    static func addScenarios(into playbook: Playbook) {
        playbook.addScenarios(of: "Home") {
            Scenario("CategoryHome", layout: .fill) {
                CategoryHome().environmentObject(UserData.stub)
            }
        }
    }
}

struct AllScenarios: ScenarioProvider {
    static func addScenarios(into playbook: Playbook) {
        playbook.add(HomeScenarios.self)
    }
}

You can use the ScenarioContext 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) { context in
    MapView(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 by SwiftUI 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.

Browser Detail
Gellery LightGellery Dark Gellery Content LightGellery Content Dark

PlaybookCatalog

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

Browser Detail
Catalog Drawer LightCatalog Drawer Dark Catalog LightCatalog 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 the official document for more information.


PlaybookSnapshot

Scenarios can be tested by the instance of types conform to TestTool 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.

final class SnapshotTests: XCTestCase {
    func testTakeSnapshot() throws {
        let directory = ProcessInfo.processInfo.environment["SNAPSHOT_DIR"]!

        try Playbook.default.run(
            Snapshot(
                directory: URL(fileURLWithPath: directory),
                clean: true,
                format: .png,
                keyWindow: UIApplication.shared.windows.first { $0.isKeyWindow },
                devices: [.iPhone11Pro(.portrait)]
            )
        )
    }
}

generate images


An extension to Playbook that uses AccessibilitySnapshot 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.9+
  • Xcode 15.0+
  • iOS 13.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 menu File > 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 only iOS13 is supported.


License

Playbook is released under the Apache 2.0 License.


Playbook

playbook-ios's People

Contributors

7kris avatar a-neuses avatar akkyie avatar jollyjoester avatar kagemiku avatar ra1028 avatar spnkr avatar taoshotaro avatar yuzushioh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

playbook-ios's Issues

Sample App's layout is broken in iOS13.4 simulator

Checklist

  • This is not a Apple's bug. -> maybe a kind of Apple's bug
  • Reviewed the README and documents.
  • Searched existing issues for ensure not duplicated.

Description (Include Screenshots)

SamplePlaybook App's layout is broken in iOS13.4 simulator. The navigation title and bottom tab icons are rendered under safeArea. This is because Apple suddenly changed (or fixed) the behavior of edgesIgnoringSafeArea modifier.

The left simulator is iOS 13.3, and the right simulator is iOS 13.4

Screen Shot 2020-04-06 at 21 15 38

How to solve

This can be solved simply by deleting this line. Then everything are rendered correctly in the both iOS.

Screen Shot 2020-04-06 at 21 26 20

Steps to Reproduce

  1. Run SamplePlaybook scheme with iPhone 13.4 simulator on Xcode 11.4
  2. Check top and bottom area

Reproducible Demo Project

Environments

  • Library version: 0.1.0

  • Swift version: 5.2

  • iOS version: 13.4

  • Xcode version: 11.4

  • Devices/Simulators: iPhone 11 Simulator

  • Package manager version:

Incorrect article

Checklist

  • This is not a Apple's bug.
  • Reviewed the README and documents.
  • Searched existing issues for ensure not duplicated.

Description (Include Screenshots)

At the https://playbook-ui.github.io/playbook-ios/Playbook.html, in ScenarioStore, in the Parameters section, in the first bullet point, instead of an write a.

Steps to Reproduce

  1. Go to https://playbook-ui.github.io/playbook-ios/.
  2. Click the ScenarioStore
  3. In the Parameters section, in the first bullet point, instead of an write a.

Reproducible Demo Project

Environments

  • Library version:

  • Swift version:

  • iOS version:

  • Xcode version:

  • Devices/Simulators:

  • Package manager version:

Typing mistake

Checklist

  • This is not a Apple's bug.
  • Reviewed the README and documents.
  • Searched existing issues for ensure not duplicated.

Description (Include Screenshots)

In the playbook README and API Document, in the second paragraph where the sentence starts with 'Components built using...'; instead of writing 'can generates' write 'generate'.

Steps to Reproduce

  1. Go to https://github.com/playbook-ui/playbook-ios or https://playbook-ui.github.io/playbook-ios/.

  2. Go to the README section at https://github.com/playbook-ui/playbook-ios
    and
    Read the Introduction section at https://playbook-ui.github.io/playbook-ios/.

  3. Read the README and/or Introduction section.

  4. Read the first line of the second paragraph.

Reproducible Demo Project

Environments

  • Library version:

  • Swift version:

  • iOS version:

  • Xcode version:

  • Devices/Simulators:

  • Package manager version:

Sketch Support?

Hello, will there be a sketch plugin? Would be really nice ✌️

Scenario names containing the path separator (`/`) causes test failure

Checklist

  • This is not a Apple's bug.
  • Reviewed the README and documents.
  • Searched existing issues for ensure not duplicated.

Description (Include Screenshots)

Hi, I found that scenario names containing the path separator (/) can be problematic.

When it's used in the name of a group of scenarios, it's recognized literally as a path separator and makes additional directory structure. I couldn't figure out whether this is an intended behavior or not.

Screen Shot 2020-11-05 at 14 31 56

When it's in a scenario name, it causes the test to fail with an error "No such file or directory." I guess it's a bit confusing, and would be best to be avoided.

image

A few possible ways to improve it I have in my mind:

  • Encode the entire name in a URL safe way such as addingPercentEncoding
  • Replace only / with another (say, _)
  • Throw an error with an improved message like "You cannot use / in a scenario name"

Encoding the whole is indeed the most safe way, but will make the report generated by reg-suit ugly. What do you think?

Last but not least, thank you for sharing and maintaining this great project!

Steps to Reproduce

Contain / in names; see screenshots above.

Reproducible Demo Project

Reproducible with the example project.

Environments

  • Library version: Checked with the example in master (c8c14d7)
  • Swift version: Apple Swift version 5.3 (swiftlang-1200.0.29.2 clang-1200.0.30.1)
  • iOS version: 14
  • Xcode version: Version 12.1 (12A7403)
  • Devices/Simulators: iPhone 12
  • Package manager version: N/A

Remove 'that'

Checklist

  • This is not a Apple's bug.
  • Reviewed the README and documents.
  • Searched existing issues for ensure not duplicated.

Description (Include Screenshots)

At the https://playbook-ui.github.io/playbook-ios/Playbook.html, in Snapshot, in the second sentence of the Parameters section, remove that.

Steps to Reproduce

  1. Go to https://playbook-ui.github.io/playbook-ios/.
  2. Click Snapshot.
  3. In the Parameters section, in the second bullet point, remove that.

Reproducible Demo Project

Environments

  • Library version:

  • Swift version:

  • iOS version:

  • Xcode version:

  • Devices/Simulators:

  • Package manager version:

Incorrect sentence

Checklist

  • This is not a Apple's bug.
  • Reviewed the README and documents.
  • Searched existing issues for ensure not duplicated.

Description (Include Screenshots)

In the playbook README and API Document, in the PlaybookGallery section, correct the second sentence and rewrite as follows:
Those that are displayed on the top screen are not actually doing layout, but rather display the snapshots that are efficiently generated at runtime.

Steps to Reproduce

  1. Go to https://github.com/playbook-ui/playbook-ios or https://playbook-ui.github.io/playbook-ios/.
  2. Go to the README section at https://github.com/playbook-ui/playbook-ios.
    and
    Read the Introduction section at https://playbook-ui.github.io/playbook-ios/.
  3. Read the README and/or Introduction section.
  4. Read the second line of the PlaybookGallery section.

Reproducible Demo Project

Environments

  • Library version:

  • Swift version:

  • iOS version:

  • Xcode version:

  • Devices/Simulators:

  • Package manager version:

Set up documentation

Checklist

  • [x ] Reviewed the README and documents.
  • [x ] Searched existing issues for ensure not duplicated.

Description

It is very hard to figure out how to set Playbook up for a UIKit app

Motivation and Context

I'd like to set Playbook for my my UIKit app, but there is no documentation on how to set things up. The sample app is SwiftUi only, so it makes it hard to figure it out

Proposed Solution

Add a page in the documentation explaining how to setup the playbook target to for a UIKit app

Mention the purpose of the document

Checklist

  • This is not a Apple's bug.
  • Reviewed the README and documents.
  • Searched existing issues for ensure not duplicated.

Description (Include Screenshots)

Mention the purpose of the document located at https://playbook-ui.github.io/playbook-ios/. The document lists APIS. However, it nowhere mentions that it is an API document. Please provide an appropriate title/heading.

Steps to Reproduce

  1. Go to https://playbook-ui.github.io/playbook-ios/.
  2. In the menu on the left, read headings.
  3. Review if you can read API document anywhere.

Reproducible Demo Project

Environments

  • Library version:

  • Swift version:

  • iOS version:

  • Xcode version:

  • Devices/Simulators:

  • Package manager version:

Incorrect article

Checklist

  • This is not a Apple's bug.
  • Reviewed the README and documents.
  • Searched existing issues for ensure not duplicated.

Description (Include Screenshots)

At the https://playbook-ui.github.io/playbook-ios/Playbook.html, in Playbook, in the Parameters section, in the first bullet point, instead of an write a.

Steps to Reproduce

  1. Go to https://playbook-ui.github.io/playbook-ios/.
  2. Click the Playbook section.
  3. In the Parameters section, in the first bullet point, instead of an write a

Reproducible Demo Project

Environments

  • Library version:

  • Swift version:

  • iOS version:

  • Xcode version:

  • Devices/Simulators:

  • Package manager version:

Add `TestTool` for compare snapshot diffs without dependency

Checklist

  • Reviewed the README and documents.
  • Searched existing issues for ensure not duplicated.

Description

Add a new TestTool compare snapshot diffs without dependency like pointfreeco/swift-snapshot-testing and uber/ios-snapshot-test-case.

Motivation and Context

Visual regression tests using third-party tools such as reg-suit are powerful, but a framework that can be used more simply on unit tests is needed.

Proposed Solution

Playbook.default.run(
    SnapshotCompare(devices: [.iPhone11Pro(.portrait)])
)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.