• This repository has been archived on 03/Mar/2020
  • Stars
    star
    19,716
  • Rank 1,223 (Top 0.03 %)
  • Language Objective-C++
  • License
    Other
  • Created about 10 years ago
  • Updated over 4 years ago

Reviews

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

Repository Details

An extensible iOS and OS X animation library, useful for physics-based interactions.

pop

Pop is an extensible animation engine for iOS, tvOS, and OS X. In addition to basic static animations, it supports spring and decay dynamic animations, making it useful for building realistic, physics-based interactions. The API allows quick integration with existing Objective-C or Swift codebases and enables the animation of any property on any object. It's a mature and well-tested framework that drives all the animations and transitions in Paper.

Build Status

Installation

Pop is available on CocoaPods. Just add the following to your project Podfile:

pod 'pop', '~> 1.0'

Bugs are first fixed in master and then made available via a designated release. If you tend to live on the bleeding edge, you can use Pop from master with the following Podfile entry:

pod 'pop', :git => 'https://github.com/facebook/pop.git'

Framework (manual)

By adding the project to your project and adding pop.embedded framework to the Embedded Binaries section on the General tab of your app's target, you can set up pop in seconds! This also enables @import pop syntax with header modules.

Note: because of some awkward limitations with Xcode, embedded binaries must share the same name as the module and must have .framework as an extension. This means that you'll see three pop.frameworks when adding embedded binaries (one for OS X, one for tvOS, and one for iOS). You'll need to be sure to add the right one; they appear identically in the list but note the list is populated in order of targets. You can verify the correct one was chosen by checking the path next to the framework listed, in the format <configuration>-<platform> (e.g. Debug-iphoneos).

Embedded Binaries

Note 2: this method does not currently play nicely with workspaces. Since targets can only depend on and embed products from other targets in the same project, it only works when pop.xcodeproj is added as a subproject to the current target's project. Otherwise, you'll need to manually set the build ordering in the scheme and copy in the product.

Static Library (manual)

Alternatively, you can add the project to your workspace and adopt the provided configuration files or manually copy the files under the pop subdirectory into your project. If installing manually, ensure the C++ standard library is also linked by including -lc++ to your project linker flags.

Usage

Pop adopts the Core Animation explicit animation programming model. Use by including the following import:

Objective-C

#import <pop/POP.h>

or if you're using the embedded framework:

@import pop;

Swift

import pop

Start, Stop & Update

To start an animation, add it to the object you wish to animate:

Objective-C

POPSpringAnimation *anim = [POPSpringAnimation animation];
...
[layer pop_addAnimation:anim forKey:@"myKey"];

Swift

let anim = POPSpringAnimation()
...
layer.pop_add(anim, forKey: "myKey")

To stop an animation, remove it from the object referencing the key specified on start:

Objective-C

[layer pop_removeAnimationForKey:@"myKey"];

Swift

layer.pop_removeAnimation(forKey: "myKey")

The key can also be used to query for the existence of an animation. Updating the toValue of a running animation can provide the most seamless way to change course:

Objective-C

anim = [layer pop_animationForKey:@"myKey"];
if (anim) {
  /* update to value to new destination */
  anim.toValue = @(42.0);
} else {
  /* create and start a new animation */
  ....
}

Swift

if let anim = layer.pop_animation(forKey: "myKey") as? POPSpringAnimation {
    /* update to value to new destination */
    anim.toValue = 42.0
} else {
    /* create and start a new animation */
    ....
}

While a layer was used in the above examples, the Pop interface is implemented as a category addition on NSObject. Any NSObject or subclass can be animated.

Types

There are four concrete animation types: spring, decay, basic and custom.

Spring animations can be used to give objects a delightful bounce. In this example, we use a spring animation to animate a layer's bounds from its current value to (0, 0, 400, 400):

Objective-C

POPSpringAnimation *anim = [POPSpringAnimation animationWithPropertyNamed:kPOPLayerBounds];
anim.toValue = [NSValue valueWithCGRect:CGRectMake(0, 0, 400, 400)];
[layer pop_addAnimation:anim forKey:@"size"];

Swift

if let anim = POPSpringAnimation(propertyNamed: kPOPLayerBounds) {
    anim.toValue = NSValue(cgRect: CGRect(x: 0, y: 0, width: 400, height: 400))
    layer.pop_add(anim, forKey: "size")
}

Decay animations can be used to gradually slow an object to a halt. In this example, we decay a layer's positionX from it's current value and velocity 1000pts per second:

Objective-C

POPDecayAnimation *anim = [POPDecayAnimation animationWithPropertyNamed:kPOPLayerPositionX];
anim.velocity = @(1000.);
[layer pop_addAnimation:anim forKey:@"slide"];

Swift

if let anim = POPDecayAnimation(propertyNamed: kPOPLayerPositionX) {
    anim.velocity = 1000.0
    layer.pop_add(anim, forKey: "slide")
}

Basic animations can be used to interpolate values over a specified time period. To use an ease-in ease-out animation to animate a view's alpha from 0.0 to 1.0 over the default duration:

Objective-C

POPBasicAnimation *anim = [POPBasicAnimation animationWithPropertyNamed:kPOPViewAlpha];
anim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
anim.fromValue = @(0.0);
anim.toValue = @(1.0);
[view pop_addAnimation:anim forKey:@"fade"];

Swift

if let anim = POPBasicAnimation(propertyNamed: kPOPViewAlpha) {
    anim.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
    anim.fromValue = 0.0
    anim.toValue = 1.0
    view.pop_add(anim, forKey: "fade")
}

POPCustomAnimation makes creating custom animations and transitions easier by handling CADisplayLink and associated time-step management. See header for more details.

Properties

The property animated is specified by the POPAnimatableProperty class. In this example we create a spring animation and explicitly set the animatable property corresponding to -[CALayer bounds]:

Objective-C

POPSpringAnimation *anim = [POPSpringAnimation animation];
anim.property = [POPAnimatableProperty propertyWithName:kPOPLayerBounds];

Swift

let anim = POPSpringAnimation()
if let property = POPAnimatableProperty.property(withName: kPOPLayerBounds) as? POPAnimatableProperty {
    anim.property = property
}

The framework provides many common layer and view animatable properties out of box. You can animate a custom property by creating a new instance of the class. In this example, we declare a custom volume property:

Objective-C

prop = [POPAnimatableProperty propertyWithName:@"com.foo.radio.volume" initializer:^(POPMutableAnimatableProperty *prop) {
  // read value
  prop.readBlock = ^(id obj, CGFloat values[]) {
    values[0] = [obj volume];
  };
  // write value
  prop.writeBlock = ^(id obj, const CGFloat values[]) {
    [obj setVolume:values[0]];
  };
  // dynamics threshold
  prop.threshold = 0.01;
}];

anim.property = prop;

Swift

if let prop = POPAnimatableProperty.property(withName: "com.foo.radio.volume", initializer: { prop in
    guard let prop = prop else {
        return
    }
    // read value
    prop.readBlock = { obj, values in
        guard let obj = obj as? Volumeable, let values = values else {
            return
        }

        values[0] = obj.volume
    }
    // write value
    prop.writeBlock = { obj, values in
        guard var obj = obj as? Volumeable, let values = values else {
            return
        }

        obj.volume = values[0]
    }
    // dynamics threshold
    prop.threshold = 0.01
}) as? POPAnimatableProperty {
    anim.property = prop
}

For a complete listing of provided animatable properties, as well more information on declaring custom properties see POPAnimatableProperty.h.

Debugging

Here are a few tips when debugging. Pop obeys the Simulator's Toggle Slow Animations setting. Try enabling it to slow down animations and more easily observe interactions.

Consider naming your animations. This will allow you to more easily identify them when referencing them, either via logging or in the debugger:

Objective-C

anim.name = @"springOpen";

Swift

anim.name = "springOpen"

Each animation comes with an associated tracer. The tracer allows you to record all animation-related events, in a fast and efficient manner, allowing you to query and analyze them after animation completion. The below example starts the tracer and configures it to log all events on animation completion:

Objective-C

POPAnimationTracer *tracer = anim.tracer;
tracer.shouldLogAndResetOnCompletion = YES;
[tracer start];

Swift

if let tracer = anim.tracer {
    tracer.shouldLogAndResetOnCompletion = true
    tracer.start()
}

See POPAnimationTracer.h for more details.

Testing

Pop has extensive unit test coverage. To install test dependencies, navigate to the root pop directory and type:

pod install

Assuming CocoaPods is installed, this will include the necessary OCMock dependency to the unit test targets.

SceneKit

Due to SceneKit requiring iOS 8 and OS X 10.9, POP's SceneKit extensions aren't provided out of box. Unfortunately, weakly linked frameworks cannot be used due to issues mentioned in the Xcode 6.1 Release Notes.

To remedy this, you can easily opt-in to use SceneKit! Simply add this to the Preprocessor Macros section of your Xcode Project:

POP_USE_SCENEKIT=1

Resources

A collection of links to external resources that may prove valuable:

Contributing

See the CONTRIBUTING file for how to help out.

License

Pop is released under a BSD License. See LICENSE file for details.

More Repositories

1

draft-js

A React framework for building text editors.
JavaScript
22,506
star
2

flux

Application Architecture for Building User Interfaces
JavaScript
17,397
star
3

prepack

A JavaScript bundle optimizer.
JavaScript
14,271
star
4

AsyncDisplayKit

Smooth asynchronous user interfaces for iOS apps.
Objective-C++
13,447
star
5

stetho

Stetho is a debug bridge for Android applications, enabling the powerful Chrome Developer Tools and much more.
Java
12,653
star
6

Shimmer

An easy way to add a simple, shimmering effect to any view in an iOS app.
Objective-C
9,375
star
7

react-360

Create amazing 360 and VR content using React
JavaScript
8,702
star
8

caffe2

Caffe2 is a lightweight, modular, and scalable deep learning framework.
Shell
8,420
star
9

nuclide

An open IDE for web and native mobile development, built on top of Atom
JavaScript
7,816
star
10

KVOController

Simple, modern, thread-safe key-value observing for iOS and OS X.
Objective-C
7,359
star
11

three20

Three20 is an Objective-C library for iPhone developers
Objective-C
7,265
star
12

xctool

An extension for Apple's xcodebuild that makes it easier to test iOS and macOS apps.
Objective-C
6,954
star
13

fbctf

Platform to host Capture the Flag competitions
Hack
6,495
star
14

rebound

A Java library that models spring dynamics and adds real world physics to your app.
Java
5,444
star
15

Keyframes

A library for converting Adobe AE shape based animations to a data format and playing it back on Android and iOS devices.
JavaScript
5,343
star
16

shimmer-android

An easy, flexible way to add a shimmering effect to any view in an Android app.
Java
5,265
star
17

grace

Graceful restart & zero downtime deploy for Go servers.
Go
4,899
star
18

Tweaks

An easy way to fine-tune, and adjust parameters for iOS apps in development.
Objective-C
4,751
star
19

augmented-traffic-control

Augmented Traffic Control: A tool to simulate network conditions
Python
4,331
star
20

fixed-data-table

A React table component designed to allow presenting thousands of rows of data.
JavaScript
4,314
star
21

WebDriverAgent

A WebDriver server for iOS that runs inside the Simulator.
Objective-C
4,096
star
22

huxley

A testing system for catching visual regressions in Web applications.
Python
4,086
star
23

codemod

Codemod is a tool/library to assist you with large-scale codebase refactors that can be partially automated but still require human oversight and occasional intervention. Codemod was developed at Facebook and released as open source.
Python
4,069
star
24

scribe

Scribe is a server for aggregating log data streamed in real time from a large number of servers.
C++
3,932
star
25

FBMemoryProfiler

iOS tool that helps with profiling iOS Memory usage.
Objective-C
3,417
star
26

mention-bot

Automatically mention potential reviewers on pull requests.
JavaScript
3,371
star
27

facebook-php-sdk

This SDK is deprecated. Find the new SDK here: https://github.com/facebook/facebook-php-sdk-v4
PHP
3,289
star
28

origami

A Quartz Composer framework that enables interactive design prototyping without programming.
Objective-C
3,280
star
29

RakNet

RakNet is a cross platform, open source, C++ networking engine for game programmers.
HTML
3,211
star
30

network-connection-class

Listen to current network traffic in the app and categorize the quality of the network.
Java
3,178
star
31

beringei

Beringei is a high performance, in-memory storage engine for time series data.
C++
3,159
star
32

php-graph-sdk

The Facebook SDK for PHP provides a native interface to the Graph API and Facebook Login. https://developers.facebook.com/docs/php
PHP
3,146
star
33

react-native-fbsdk

A React Native wrapper around the Facebook SDKs for Android and iOS. Provides access to Facebook login, sharing, graph requests, app events etc.
Java
2,993
star
34

python-instagram

Python Client for Instagram API
Python
2,966
star
35

conceal

Conceal provides easy Android APIs for performing fast encryption and authentication of data.
C++
2,966
star
36

webscalesql-5.6

WebScaleSQL, Version 5.6, based upon the MySQL-5.6 community releases.
C++
2,954
star
37

ios-snapshot-test-case

Snapshot view unit tests for iOS
Objective-C
2,674
star
38

device-year-class

A library that analyzes an Android device's specifications and calculates which year the device would be considered "high end”.
Java
2,581
star
39

BOLT

Binary Optimization and Layout Tool - A linux command-line utility used for optimizing performance of binaries
2,497
star
40

pfff

Tools for code analysis, visualizations, or style-preserving source transformation.
OCaml
2,439
star
41

fb.resnet.torch

Torch implementation of ResNet from http://arxiv.org/abs/1512.03385 and training scripts
Lua
2,243
star
42

redux-react-hook

React Hook for accessing state and dispatch from a Redux store
TypeScript
2,164
star
43

Surround360

Surround360 is Facebook's open source hardware and software for capturing stereoscopic 3D 360 video for VR. The repo contains hardware designs, as well as software for camera control and rendering.
C++
2,153
star
44

xcbuild

Xcode-compatible build tool.
C++
2,000
star
45

LogDevice

Distributed storage for sequential data
C++
1,888
star
46

MemNN

Memory Networks implementations
Lua
1,757
star
47

rebound-js

Spring dynamics in JavaScript.
JavaScript
1,754
star
48

redis-faina

A query analyzer that parses Redis' MONITOR command for counter/timing stats about query patterns
Python
1,749
star
49

fb-flo

A Chrome extension that lets you modify running apps without reloading them.
JavaScript
1,692
star
50

planout

PlanOut is a library and interpreter for designing online experiments.
JavaScript
1,664
star
51

libphenom

An eventing framework for building high performance and high scalability systems in C.
C
1,662
star
52

flashcache

A general purpose, write-back block cache for Linux.
C
1,601
star
53

python-nubia

A command-line and interactive shell framework.
Python
1,595
star
54

profilo

A library for performance traces from production.
C
1,577
star
55

facebook-swift-sdk

Integrate your iOS apps in Swift with Facebook Platform.
Swift
1,519
star
56

instagram-ruby-gem

The official gem for the Instagram API
Ruby
1,461
star
57

inject

Package inject provides a reflect based injector.
Go
1,393
star
58

Flicks

A unit of time defined in C++.
C++
1,388
star
59

duckling_old

Deprecated in favor of https://github.com/facebook/duckling
Clojure
1,322
star
60

connect-js

Legacy JavaScript SDK
JavaScript
1,237
star
61

atom-in-orbit

Putting Atom in the browser
JavaScript
1,183
star
62

phpsh

A read-eval-print-loop for php
Emacs Lisp
1,160
star
63

C3D

C3D is a modified version of BVLC caffe to support 3D ConvNets.
Jupyter Notebook
1,159
star
64

sublime-react

Sublime Text helpers for React. Syntax highlighting DEPRECATED in favor of babel/babel-sublime
JavaScript
1,144
star
65

fb-adb

A better shell for Android devices
C
1,139
star
66

iTorch

IPython kernel for Torch with visualization and plotting
Jupyter Notebook
1,104
star
67

FBAllocationTracker

iOS library that helps tracking all allocated Objective-C objects
Objective-C++
1,094
star
68

fbcunn

Facebook's extensions to torch/cunn.
Lua
1,069
star
69

emitter

A JS EventEmitter foundation for evented code
JavaScript
1,041
star
70

bistro

Bistro is a flexible distributed scheduler, a high-performance framework supporting multiple paradigms while retaining ease of configuration, management, and monitoring.
C++
1,040
star
71

relay-starter-kit

Barebones starting point for a Relay application.
JavaScript
1,017
star
72

torchnet

Torch on steroids
Lua
992
star
73

react-meteor

React rendering for Meteor apps
JavaScript
953
star
74

atom-ide-ui

A collection of user interfaces for Atom IDE.
JavaScript
936
star
75

NAMAS

Neural Attention Model for Abstractive Summarization
Lua
910
star
76

nifty

Thrift on Netty
Java
899
star
77

swift

An annotation-based Java library for creating Thrift serializable types and services.
Java
889
star
78

bAbI-tasks

Task generation for testing text understanding and reasoning
Lua
886
star
79

hadoop-20

Facebook's Realtime Distributed FS based on Apache Hadoop 0.20-append
Java
876
star
80

loop

A method to generate speech across multiple speakers
Python
872
star
81

IGInterfaceDataTable

A category on WKInterfaceTable that makes configuring tables with multi-dimensional data easier.
Objective-C
837
star
82

mononoke

A Mercurial source control server, specifically designed to support large monorepos.
822
star
83

react-page

Easy Application Development with React JavaScript
JavaScript
795
star
84

f8DeveloperConferenceApp

[Archive] f8 2014 Conference App
HTML
761
star
85

nailgun

Nailgun is a client, protocol, and server for running Java programs from the command line without incurring the JVM startup overhead.
Java
734
star
86

WEASEL

DNS covert channel implant for Red Teams.
Python
725
star
87

RiftDK1

Firmware, Schematics, and Mechanicals for the Oculus Rift Development Kit 1
C
688
star
88

jcommon

concurrency, collections, stats/analytics, config, testing, etc
Java
677
star
89

proguard

A fork of ProGuard.
Java
661
star
90

bootstrapped

Generate bootstrapped confidence intervals for A/B testing in Python.
Python
631
star
91

ig-lazy-module-loader

Library that implements module lazy loading.
Java
630
star
92

opencompute

A community of engineers whose mission is to design and enable the delivery of the most efficient server, storage and data center hardware designs for scalable computing.
TeX
624
star
93

flint

An open-source lint program for C++ developed by, and formerly used at Facebook.
D
622
star
94

fblualib

Facebook libraries and utilities for Lua
Lua
615
star
95

remodel

Remodel is a tool that helps iOS and OS X developers avoid repetitive code by generating Objective-C models that support coding, value comparison, and immutability.
TypeScript
609
star
96

eyescream

natural image generation using ConvNets
Lua
599
star
97

react-python

Python bridge to JSX & the React JavaScript library.
Python
576
star
98

spacetime

Experimental iOS library for live transformations on parts of layers.
Objective-C
528
star
99

warp

A fast preprocessor for C and C++
D
521
star
100

FBNotifications

Facebook Analytics In-App Notifications Framework
Objective-C
494
star