• Stars
    star
    1,690
  • Rank 26,467 (Top 0.6 %)
  • Language
    Java
  • License
    Apache License 2.0
  • Created almost 9 years ago
  • Updated 5 months ago

Reviews

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

Repository Details

A motion-driven animation framework for Android.

the backboard icon

Backboard

A motion-driven animation framework for Android.

backboard is a framework on top of rebound that makes it easier to use by coupling it to views and motions.

backboard-example is an Android app with a few demos of animations made possible by Backboard.

Javadoc

follow animation bloom animation scale animation

Table of Contents

Usage

Update your build.gradle with

repositories {
    exclusiveContent {
        forRepository {
            maven {
                url "https://a8c-libs.s3.amazonaws.com/android"
            }
        }
        filter {
            includeModule "com.tumblr", "backboard"
        }
    }
}

dependencies {
   implementation 'com.facebook.rebound:rebound:0.3.8'
   implementation 'com.tumblr:backboard:0.2.0'
}

Publishing a new version

In the following cases, the CI will publish a new version with the following format to our S3 Maven repo:

  • For each commit in an open PR: <PR-number>-<commit full SHA1>
  • Each time a PR is merged to master: master-<commit full SHA1>
  • Each time a new tag is created: {tag-name}

Getting Started

Backboard is a framework on top of rebound that manages how Springs are used and simplifies the most common use cases:

  • Actions, such as MotionEvents, are mapped to Springs via Imitators.
  • Springs are mapped to Views and view properties via Performers.

In addition, an Actor wraps the above objects and provides a simple interface for mapping touch motion to a view's position - dragging.

Performers

A Performer takes the current value of a Spring and sets it as the value of a view property.

Spring bounce = SpringSystem.create().createSpring();
Performer xMotion = new Performer(view, View.TRANSLATION_X);
bounce.addListener(xMotion);

for those saving screen space, a fluent interface is available:

Spring bounce = SpringSystem.create().createSpring().addListener(new Performer(view, View.TRANSLATION_X));

Imitators

An Imitator constantly perturbs the Spring it is attached to. This perturbation can originate a variety of sources:

  1. A MotionEvent, where the Spring can change based on the action (ACTION_DOWN, ACTION_UP), or imitate a property (x, y, etc.). These are called EventImitators.
  2. Another Spring, which leads to results similar to springs being chained together. These are called SpringImitators.

Imitating Touch

An EventImitator primarily operates with OnTouchListeners. The simplest example is a ToggleImitator, which toggles between two different values depending on the touch state:

view.setOnTouchListener(new ToggleImitator(spring, 0, 1));

when the user touches the view, a value of 1 is set on the spring, and when the user releases, a value of 0 is set.

Imitating Motion

A MotionImitator is a special type of EventImitator that maps x and y movement to a spring. This is done with MotionProperty enums, which specifies which methods to call in a MotionEvent object. For example, MotionProperty.X.getValue(MotionEvent) calls event.getX(). It also specifies the view property to animate - MotionEvent.X.getViewProperty() corresponds to View.TRANSLATION_X. This is useful for the Actor builder later on. In addition, tracking and following strategies allow for customization of how the event value is mapped to the spring.

Tracking Strategies

Two tracking strategies are available to configure how an imitator tracks its imitatee.

  • TRACK_ABSOLUTE maps the imitatee value directly to the spring.
  • TRACK_DELTA maps the change in the imitatee value (relative to the initial touch) to the spring.
Follow Strategies

Two follow strategies are available to configure how the spring is updated.

  • FOLLOW_EXACT maps the imitatee value directly to the current and end value of the spring.
  • FOLLOW_SPRING maps the imitatee value to the end value of the spring (which allows the spring to overshoot the current position)

Imitating Springs

A SpringImitator is also a SpringListener. When the Spring it is imitating updates, it updates the end value of the Spring it is controlling. Usage is simple:

SpringSystem springSystem = SpringSystem.create();

Spring leader = springSystem.createSpring();
Spring follower = springSystem.createSpring();

SpringImitator follow = new SpringImitator(follower);
leader.addListener(follow);

Actors

Even though backboard reduces a significant amount of boilerplate code, the Actor class further simplifes view motion by connecting each component together. It also manages a View.onTouchListener() (a MotionListener), which it attaches to the View automatically (this can be disabled). Here is how to create one:

Actor actor = new Actor.Builder(SpringSystem.create(), view)
  .addTranslateMotion(MotionProperty.X)
  .build();

in two dimensions:

Actor actor = new Actor.Builder(SpringSystem.create(), view)
  .addTranslateMotion(MotionProperty.X)
  .addTranslateMotion(MotionProperty.Y)
  .build();

Two calls to addTranslateMotion(MotionProperty) are needed because each axis is independent of the other. The builder will create an OnTouchListener and attach it to the View, as well as a Spring with the default settings. A Performer is also created and attached to the Spring. When there is a touch event, it is passed to the MotionImitator, which perturbs the spring, which moves the view.

It is also possible to supply your own SpringSystem, Spring, MotionImitator and Performer, and the builder will properly connect them. The first example above can also be expressed as:

SpringSystem springSystem = SpringSystem.create();
Spring spring = springSystem.createSpring();

Actor verbose = new Actor.Builder(springSystem, view)
 .addMotion(spring, new MotionImitator(spring, MotionProperty.X),
                    new Performer(view, View.TRANSLATION_X)
 .build();

The View can be also left out of the constructor of the Performer and the Spring out of the MotionImitator (using the default SpringConfig), since the builder will connect them.

Actor walk = new Actor.Builder(SpringSystem.create(), walker)
  .addMotion(
    new MotionImitator(MotionProperty.X),
    new Performer(View.TRANSLATION_X))
  .build();

which can be further simplified to

Actor run = new Actor.Builder(SpringSystem.create(), runner).addMotion(MotionProperty.X, View.TRANSLATION_X).build();

and for more sugar, the previous case:

Actor bolt = new Actor.Builder(SpringSystem.create(), bolter).addTranslateMotion(MotionProperty.X).build();

Actor Options

  • requestDisallowTouchEvent() causes the Actor to call ViewParent.requestDisallowTouchEvent(true) which is helpful when the view is inside a ListView or another view that captures touch events.
  • dontAttachMotionListener() tells the builder to not attach the MotionListener to the View, which is useful when you want to attach your own OnTouchListener to the view.

Dependencies

Contact

License

Copyright 2015-2016 Tumblr, 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 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

Graywater

An Android library for decomposing RecyclerView layouts to improve scroll performance.
Java
1,207
star
2

colossus

I/O and Microservice library for Scala
Scala
1,143
star
3

jetpants

MySQL toolkit for managing billions of rows and hundreds of database machines
Ruby
1,134
star
4

pytumblr

A Python Tumblr API v2 Client
Python
718
star
5

tumblr.js

JavaScript client for the Tumblr API
JavaScript
633
star
6

collins

groovy kind of love
Scala
571
star
7

Bookends

A UI widget for adding headers and footers to RecyclerView
Java
538
star
8

Remember

A preferences-backed key-value store
Java
522
star
9

policy

Tumblr policies and guidelines
453
star
10

laphs

Apple Live Photo support on the web, courtesy of Tumblr
JavaScript
447
star
11

TMTumblrSDK

Unopinionated and flexible library for easily integrating Tumblr data into your iOS or OS X application.
Objective-C
429
star
12

tumblr.php

Tumblr API v2 PHP Client
PHP
406
star
13

k8s-sidecar-injector

Kubernetes sidecar injection service
Go
340
star
14

kanvas-ios

Kanvas: a creation tool for iOS
Swift
302
star
15

jumblr

Tumblr API v2 Java Client
Java
276
star
16

gocircuit

Go
238
star
17

genesis

A tool for data center automation
Ruby
156
star
18

docker-registry-pruner

Tool to apply retention logic to docker images in a Docker Registry
Go
126
star
19

data-lasso

JavaScript
119
star
20

docs

Tumblr's public platform documentation.
99
star
21

XExtensionItem

Easier sharing of structured data between iOS applications and share extensions
Objective-C
86
star
22

webpack-web-app-manifest-plugin

A webpack plugin that generates a PWA manifest and integrates with the assets JSON.
JavaScript
75
star
23

PermissMe

Java
74
star
24

k8s-secret-projector

Kubernetes Secret generation from secure credential repos
Go
72
star
25

k8s-config-projector

Create Kubernetes ConfigMaps from configuration files
Go
65
star
26

go-collins

Collins API Client in Go - https://tumblr.github.io/collins
Go
41
star
27

tumblrclient.go

This is a concrete implementation of the ClientInterface with additional convenience methods defined right on the client object
Go
41
star
28

tumblr.go

This is a library which provides structs and functions for accessing the Tumblr API
Go
37
star
29

JXHTTP

you know, for networking
Objective-C
26
star
30

Spectacles

A tiny library for parsing JSON podspecs.
Objective-C
23
star
31

gulp-css-hashes

JavaScript
18
star
32

tsd_proxy

Clojure
15
star
33

tumblr-repl

REPL for the Tumblr API, built on tumblr.js
JavaScript
11
star
34

collins_shell

Ruby
3
star
35

consolr

Ruby
1
star
36

chorus-timekeeper

DI with timekeeping.
PHP
1
star
37

collins_client

Ruby
1
star
38

collins_notify

Ruby
1
star
39

collins_auth

Ruby
1
star
40

slackr_archiver

Ruby
1
star