• Stars
    star
    126
  • Rank 274,525 (Top 6 %)
  • Language
    Swift
  • License
    Apache License 2.0
  • Created over 4 years ago
  • Updated 21 days ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Modern, type-safe API for building animations on iOS

Stagehand

CI Status Version License Platform

Stagehand provides a modern, type-safe API for building animations on iOS. Stagehand is designed around a set of core ideas:

  • Composition of Structures - Stagehand makes it easy to build complex, multi-part animations that are built from small, reusable pieces that are easier to reason about.
  • Separation of Construction and Execution - Stagehand provides separate mechanisms for the construction and execution, which increases the flexibility of animations and makes concepts like queuing a series of animations work straight out of the box.
  • Compile-Time Safety - Stagehand uses modern Swift features to provide a compile-time safe API for defining animations.
  • Testability - Stagehand builds on the concept of snapshot testing to introduce a visual testing paradigm for animations.

Installation

CocoaPods

To install Stagehand via CocoaPods, simply add the following line to your Podfile:

pod 'Stagehand'

To install StagehandTesting, the animation snapshot testing utilities, add the following line to your test target definition in your Podfile:

pod 'StagehandTesting'

By default, this will use Point-Free's SnapshotTesting to record snapshots and perform comparisons. To instead use Uber's iOSSnapshotTestCase as the snapshotting engine, set your test target dependency to use the iOSSnapshotTestCase subspec.

pod 'StagehandTesting/iOSSnapshotTestCase'

Swift Package Manager

To install Stagehand via Swift Package Manager, add the following to your Package.swift:

dependencies: [
    .package(url: "https://github.com/cashapp/stagehand", from: "4.0.0"),
],

Getting Started with Stagehand

An animation begins with the construction of an Animation. An Animation is generic over a type of element and acts as a definition of how that element should be animated.

As an example, we can write an animation that highlights a view by fading its alpha to 0.8 and back:

var highlightAnimation = Animation<UIView>()
highlightAnimation.addKeyframe(for: \.alpha, at: 0, value: 1)
highlightAnimation.addKeyframe(for: \.alpha, at: 0.5, value: 0.8)
highlightAnimation.addKeyframe(for: \.alpha, at: 1, value: 1)

Let's say we've defined a view, which we'll call BinaryView, that has two subviews, leftView and rightView, and we want to highlight each of the subviews in sequence. We can define an animation for our BinaryView with two child animations:

var binaryAnimation = Animation<BinaryView>()
binaryAnimation.addChild(highlightAnimation, for: \.leftView, startingAt: 0, relativeDuration: 0.5)
binaryAnimation.addChild(highlightAnimation, for: \.rightView, startingAt: 0.5, relativeDuration: 0.5)

Once we've set up our view and we're ready to execute our animation, we can call the perform method to start animating:

let view = BinaryView()
// ...

binaryAnimation.perform(on: view)

Running the Demo App

Stagehand ships with a demo app that shows examples of many of the features provided by Stagehand. To run the demo app, open the Example directory and run:

bundle install
bundle exec pod install
open Stagehand.xcworkspace

From here, you can run the demo app and see a variety of examples for how to use the framework. In that workspace, there is also a playground that includes documentation and tutorials for how each feature works.

Contributing

We’re glad you’re interested in Stagehand, and we’d love to see where you take it. Please read our contributing guidelines prior to submitting a Pull Request.

License

Copyright 2020 Square, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

More Repositories

1

sqldelight

SQLDelight - Generates typesafe Kotlin APIs from SQL
Kotlin
5,918
star
2

turbine

A small testing library for kotlinx.coroutines Flow
Kotlin
2,323
star
3

paparazzi

Render your Android screens without a physical device or emulator
Kotlin
2,164
star
4

zipline

Run Kotlin/JS libraries in Kotlin/JVM and Kotlin/Native programs
C
1,914
star
5

molecule

Build a StateFlow stream using Jetpack Compose
Kotlin
1,710
star
6

contour

Layouts with lambdas 😎
Kotlin
1,522
star
7

redwood

Multiplatform reactive UI for Android, iOS, and web using Kotlin and Jetpack Compose
Kotlin
1,458
star
8

InflationInject

Constructor-inject views during XML layout inflation
Kotlin
908
star
9

pranadb

Go
615
star
10

licensee

Gradle plugin which validates the licenses of your dependency graph match what you expect
Kotlin
599
star
11

hermit

🐚 Hermit manages isolated, self-bootstrapping sets of tools in software projects.
Go
557
star
12

AccessibilitySnapshot

Easy regression testing for iOS accessibility
Swift
522
star
13

exhaustive

An annotation and Kotlin compiler plugin for enforcing a when statement is exhaustive
Kotlin
465
star
14

multiplatform-paging

A library that packages AndroidX Paging for Kotlin/Multiplatform.
Kotlin
452
star
15

misk

Microservice Kontainer
Kotlin
386
star
16

copper

A content provider wrapper for reactive queries
Kotlin
300
star
17

barber

Barber πŸ’ˆ A type safe Kotlin JVM library for building up localized, fillable, themed documents using Mustache templating
Kotlin
157
star
18

paraphrase

A Gradle plugin that generates type-safe formatters for Android string resources in the ICU message format.
Kotlin
157
star
19

hermit-packages

Hermit manages isolated, self-bootstrapping sets of tools in software projects.
HCL
111
star
20

quiver

Quiver is a collection of extension methods and handy functions to make the wonderful functional programming Kotlin library, Arrow, even better.
Kotlin
95
star
21

spirit

Online Schema Change Tool for MySQL 8.0
Go
87
star
22

pivit

Go
82
star
23

tempest

Typesafe DynamoDB for Kotlin and Java.
Kotlin
80
star
24

better-dynamic-features

Making dynamic feature modules better
Kotlin
70
star
25

misk-web

Micro-Frontends React + Redux + Typescript Framework
TypeScript
65
star
26

blip

Sublime MySQL monitoring
Go
59
star
27

logquacious

Logquacious (lq) is a fast and simple log viewer.
TypeScript
58
star
28

wisp

Wisp is a collection of kotlin modules providing various features and utilities, including config, logging, feature flags and more.
Kotlin
58
star
29

certifikit

Kotlin Certificate processing library.
Kotlin
40
star
30

backfila

Service that manages backfill state, calling into other services to do batched work
Kotlin
30
star
31

cash-app-pay-android-sdk

Cash Android PayKit SDK for merchant integrations with Cash App Pay
Kotlin
29
star
32

nostrino

A Kotlin SDK for Nostr
Kotlin
28
star
33

transflect

Kubernetes operator using Istio to set up Envoy's gRPC-JSON transcoding.
Go
24
star
34

cmmc

K8S ConfigMap Merging Controller
Go
20
star
35

cloner

Go
20
star
36

kfsm

Finite state machinery in Kotlin
Kotlin
19
star
37

yet-another-aws-exporter

A Prometheus metrics exporter for AWS that fills in gaps CloudWatch doesn't cover
Go
17
star
38

cash-app-pay-ios-sdk

Swift
14
star
39

protosync

ProtoSync synchronises remote .proto files to a local directory
Go
13
star
40

cash-pay-pay-sdk-android-sample-app

Cash App Pay Kit SDK Sample app for Android.
Kotlin
12
star
41

trifle

Security functionality for interoperability/interaction with core services.
Swift
11
star
42

AardvarkReveal

Generate and attach a Reveal file to your Aardvark bug reports
Swift
10
star
43

ln-invoice

Parse lightning network payment requests (invoices) in Kotlin.
Kotlin
10
star
44

kfactories

Set of factories and utils to create effective and lightweight property-based testing strategies.
Kotlin
9
star
45

jooq-encryption

Kotlin
9
star
46

hermit-ij-plugin

Kotlin
8
star
47

cash-app-pay-sdk-ios-sample-app

Swift
7
star
48

AardvarkCrashReport

AardvarkCrashReport makes it easy to provide high quality data about crashes in your bug reports
Swift
7
star
49

awsu

su for aws roles
Go
7
star
50

check-signature-action

Shell
6
star
51

csop

Go
6
star
52

activate-hermit

Github Action to activate a Hermit environment.
Shell
6
star
53

kruit

TypeScript
4
star
54

chronicler

Kotlin
3
star
55

hermit-build

Relocatable/static builds for Hermit packages
Makefile
3
star
56

s3-copy-gradle-plugin

1
star
57

.github

1
star
58

hermit-package-version

Shell
1
star
59

cash-app-pay-sandbox-releases

1
star