Giter VIP home page Giter VIP logo

rebound's Introduction

Rebound

Build Status Android Arsenal

About

Rebound is a java library that models spring dynamics. Rebound spring models can be used to create animations that feel natural by introducing real world physics to your application.

Rebound is not a general purpose physics library; however, spring dynamics can be used to drive a wide variety of animations. The simplicity of Rebound makes it easy to integrate and use as a building block for creating more complex components like pagers, toggles, and scrollers.

For examples and usage instructions head over to:

facebook.github.io/rebound

If you are looking to build springy animations for the web, check out the Javascript version.

License

BSD License

For Rebound software

Copyright (c) 2013, Facebook, Inc. All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

rebound's People

Contributors

andraskindler avatar brianloveswords avatar bryant1410 avatar jaredpalmer avatar matthewmichihara avatar michaelevans avatar ppamorim avatar stoyan avatar vbauer avatar willbailey 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  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

rebound's Issues

GC overhead and inflate exception error occurs

Hi,

At first, I referenced rebound library to sample project of rebound in eclipse and then
I am running sample project of rebound, gc overhead occurs in the eclipse and I can not launch sample project. Console window in my eclipse logs like following link : https://gist.github.com/sarizeybek/8280388#file-rebound_error

If I add rebound library to sample project as jar, android.view.InflateException error occurs. Details of logcat : https://gist.github.com/sarizeybek/8280452#file-rebound_layout_error

How can I fix those errors?

Thanks.

support older Android versions like NineOldAndroids lib does?

I'm currently using both libraries with nineoldandroids nested inside rebound to make the animations work on older android versions.

public void onSpringUpdate(Spring spring) {
    float logoPosition = (float) SpringUtil.mapValueFromRangeToRange(spring.getCurrentValue(), 0, 1, splash_logo.getBottom(), 0);

    // this is where I nest the ObjectAnimator class from NineOldAndroids library
    ObjectAnimator.ofFloat(splash_logo, "translationY", previousPosition, logoPosition).setDuration(1).start();

    previousPosition = logoPosition;
}

Negative tension values can cause breaking behavior

I was playing around with the demo and it's a cool library. Feeling mischievous, I put some negative values in for tension to test the behavior. -1 and -10 seemed to work fine, but when I jumped up to -100 it quickly overloaded my browser's capabilities and crashed as the sample image outgrew its borders. Is it intended to accept negative values? Should there be some sort of cap or is it the developer's responsibility?

A quick Google search reveals that a negative tension may be breaking some laws of physics. Quoting an answer from a physics forum: "A negative tension, to my mind, would mean that the string should spontaneously blow itself apart."

Can a boundary be added to a spring.

I am trying to achieve something like this.
screen shot 2016-07-08 at 2 47 18 pm

When I add animation, the spring takes the object out of the frame. I want the bounce to happen with the frame. Is it possible to achieve this with rebound?

LAYER_TYPE_HARDWARE improve the performance

Second these slides, add this property to the view will increase the performance of the animations. And did!
I've an complex animation on my application, a little bit slow. After I add this property, the animation runs at 60fps smoothly.

Usage:

@Override public void onSpringActivate(Spring spring) {
  super.onSpringActivate(spring);
  happyView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
}

@Override public void onSpringUpdate(Spring spring) {
  //do something...
}

@Override public void onSpringAtRest(Spring spring) {
  super.onSpringAtRest(spring);
  happyView.setLayerType(View.LAYER_TYPE_NONE, null);
}

Or, we can use ViewCompat to support API 10 using:

ViewCompat.setLayerType();

We can advise the developers to don't forget this point.

Sample applications of rebound

I realized there aren't many samples on the inter-webs on how to integrate rebound in android applications(and the ones there are scarcely descriptive). So, i have created a repository so that anyone willing can add there an example where rebound can be used. The first example ports the Scaling animation to android. I hope this helps developers who may want to use it.

Remove Guava dependency

Guava is used for Preconditions and list/map utilities. There is no reason to force downstream consumers of this library to bundle a massive 2.1MB jar when you aren't even really using it.

Preconditions is easily inlined since they amount to just an if+throw. The list and map utilities are easily replaced by instantiating lists and maps yourself and using Collections.unmodifiableFoo(new Foo(thing)) for defensive copies.

I would have sent a pull request, but buck isn't on brew and didn't work with java 6, 7, or 8 on my system.

Rebound for RecyclerView.

Thanks for the library, it is awesome.
I'm trying to use rebound for RecyclerView so that it can over scroll and bounce back just like the SpringScrollView in the playground-example. My implementation is working so far, but the way I do is using a wrapper adapter class and add a transparent header and footer rows into the original adapter. Then I use rebound library to handle the case when the header or footer row is visible. I'm not sure if it is the best way to do it or there is a better way. Can you give me an opinion or suggestion about that?
Thanks.

Iterator allocations

Use of enhanced for loop syntax (e.g. for (SpringListener listener : mListeners) {) causes the creation of unwanted garbage every frame, in example here is a capture of Inertia Ball demo

Iterator allocations

Would you consider not using it particularly in methods which are called often like advance?

Why use mListeners rather than mListener

In the Spring:
private ReentrantCallback mListeners = new ReentrantCallback();

In the SpringSystem:

private ReentrantCallback mListeners = new ReentrantCallback();

Why use List ? Can you for example? thank you.

SequencerSpring

@willbailey What do you think about a sequencer Spring? It's similar of SpringChain but without any interaction with another springs. Look like:

SpringSquencer().create()
  .add(0, new Spring())
  .add(1, new Spring(), 1000)
  .add(2, new Spring());

The first spring(at 0 index) will run, when this animation ends, it will run the second spring(at index 1) and wait 1000 miliseconds to run the spring at index 2.

ConcurrentModificationException onRemoveListener

If you call the following consecutively it produces a Concurrent Exception, see the Stacktrace below.

Seems that ReentrantCallback is not as safe as intended.

mSpringFrom.addListener(new SimpleSpringListener() {
            @Override
            public void onSpringUpdate(final Spring spring) {
                from.setTranslationX((float) spring.getCurrentValue());
            }

            @Override
            public void onSpringAtRest(final Spring spring) {
                removeView(from);
                mSpringFrom.removeListener(this);
            }
        });
java.util.ConcurrentModificationException
            at java.util.HashMap$HashIterator.nextEntry(HashMap.java:806)
            at java.util.HashMap$KeyIterator.next(HashMap.java:833)
            at java.util.Collections$UnmodifiableCollection$1.next(Collections.java:960)
            at com.facebook.rebound.Spring.advance(Spring.java:402)
            at com.facebook.rebound.BaseSpringSystem.advance(BaseSpringSystem.java:138)
            at com.facebook.rebound.BaseSpringSystem.loop(BaseSpringSystem.java:159)
            at com.facebook.rebound.AndroidSpringLooperFactory$ChoreographerAndroidSpringLooper$1.doFrame(AndroidSpringLooperFactory.java:108)
            at android.view.Choreographer$CallbackRecord.run(Choreographer.java:759)
            at android.view.Choreographer.doCallbacks(Choreographer.java:574)
            at android.view.Choreographer.doFrame(Choreographer.java:543)
            at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
            at android.os.Handler.handleCallback(Handler.java:733)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5017)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
            at dalvik.system.NativeStart.main(Native Method)

Error:Error converting bytecode to dex:

Error:Error converting bytecode to dex:
Cause: Dex cannot parse version 52 byte code.
This is caused by library dependencies that have been compiled using Java 8 or above.
If you are using the 'java' gradle plugin in a library submodule add
targetCompatibility = '1.7'
sourceCompatibility = '1.7'
to that submodule's build.gradle file.

Use algebraic integration for better performance and accuracy

It's possible to use algebraic integration on the damped spring equation, and you get something that implements the same model as Rebound but is faster to compute, a pure function of time and more accurate than doing a numerical integration like RK4.

I did a Java implementation of this here: https://github.com/iamralpht/gravitas/blob/master/Gravitas/src/com/infinite_imagination/physics/Spring.java (the interface was inspired by Rebound, and I originally made it after playing with Rebound but wanting something fast enough that I could generate keyframes for a spring animation in a couple of ms on device).

Also I transliterated it to JavaScript here:
https://github.com/iamralpht/iamralpht.github.io/blob/master/fab/demo/fab.js (you can see it in action here: http://iamralpht.github.io/fab -- the UI was inspired by the Facebook Home menu system, which I really liked!).

It ends up being a lot less code than Rebound (but maybe Rebound does a lot more than damped springs...).

Finally, here's a link to the physics textbook I cribbed the equations from (although after playing around in Maxima I was able to reproduce them there): http://www.stewartcalculus.com/data/CALCULUS%20Concepts%20and%20Contexts/upfiles/3c3-AppsOf2ndOrders_Stu.pdf

SpringUtil question

Would you explain to me how to understand these params by your sample app

  // On each update of the spring value, we adjust the scale of the image view to match the
      // springs new value. We use the SpringUtil linear interpolation function mapValueFromRangeToRange
      // to translate the spring's 0 to 1 scale to a 100% to 50% scale range and apply that to the View
      // with setScaleX/Y. Note that rendering is an implementation detail of the application and not
      // Rebound itself. If you need Gingerbread compatibility consider using NineOldAndroids to update
      // your view properties in a backwards compatible manner.
      float mappedValue = (float) SpringUtil.mapValueFromRangeToRange(spring.getCurrentValue(), 0, 1, 1, 0.5);

At the end, I would like to apply the spring's 0 to 1 to 400dp to 100 dp in the layout height. Please let me know how to apply it into SpringUtil.mapValueFromRangeToRange(spring.getCurrentValue(), 0, 1, 1, 0.5);. Thank you so much.

JS documentation

Do you have plans to release any documentation for the JS version?

Thanks!

ListView example

Thanks you very much for this excellent library! Great work on this! I was playing around with the samples and I would like to use the rubber effect for ListViews. Do you know a way how to integrate the spring physics in a ListView?

Would be really nice if you could make a sample ;-) Thank you for you help!

Getting Error NoClassDefinationFound

E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.dixeam.millionarequotes, PID: 20997 java.lang.NoClassDefFoundError: Failed resolution of: Lcom/facebook/rebound/SpringSystem;
at com.dixeam.millionarequotes.utils.RecyclerViewAnimator.(RecyclerViewAnimator.java:51) at com.dixeam.millionarequotes.Recent$SimpleStringRecyclerViewAdapter.(Recent.java:155) at com.dixeam.millionarequotes.Recent.setupRecyclerView(Recent.java:68) at com.dixeam.millionarequotes.Recent.onCreateView(Recent.java:53)

Please help me.

setting scrollbar

I would like to use this librarySpringScrollView scrollbar,
Make it with the SpringScrollView effect, how to use

How to solve this project run with the error below?

Error:Error converting bytecode to dex:
Cause: Dex cannot parse version 52 byte code.
This is caused by library dependencies that have been compiled using Java 8 or above.
If you are using the 'java' gradle plugin in a library submodule add
targetCompatibility = '1.7'
sourceCompatibility = '1.7'
to that submodule's build.gradle file.
...while parsing com/facebook/rebound/BaseSpringSystem.class
Error:1 error; aborting
Error:Execution failed for task ':rebound-android-playground:transformClassesWithDexForDebug'.

com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: Error while executing java process with main class com.android.dx.command.Main with arguments {--dex --num-threads=4 --output /Users/huaihuhu/Desktop/rebound/rebound-0.3.8/rebound-android-playground/build/intermediates/transforms/dex/debug/folders/1000/1f/main /Users/huaihuhu/Desktop/rebound/rebound-0.3.8/rebound-core/build/libs/rebound-core.jar /Users/huaihuhu/Desktop/rebound/rebound-0.3.8/rebound-android/build/intermediates/bundles/default/classes.jar /Users/huaihuhu/Desktop/rebound/rebound-0.3.8/rebound-android-playground/build/intermediates/classes/debug}

Enhance Usage in README.md

I just try and want to enhance Usage in README.md.

Add spring.setEndValue(1) in myView OnTouchListener, otherwise onSpringUpdate won't be call.

I found out the example have this one, but on read me page didn't.

Thank you so much!

Default spring config is shared yet mutable

    SpringSystem system = SpringSystem.create();
    Spring a = system.createSpring();
    Spring b = system.createSpring();

    a.getSpringConfig().tension = 123;
    a.getSpringConfig().friction = 456;

    Log.e("REBOUND", "t: " + b.getSpringConfig().tension);
    Log.e("REBOUND", "f: " + b.getSpringConfig().friction);

In this example, both a and b share the same default SpringConfig instance. This becomes an issue when code tries to mutate the SpringConfig on a. We find that the SpringConfig on b is accidentally mutated as well.

Downloaded jar still requires guava dependency

This commit removed dependency on Guava but the downloadable jar has not been updated. It still requires Guava and crashes when it cannot find it. Either the Readme should be reverted to say that Guava is needed or the jar should be updated.

Update gradle.build

gradle.build should be updated to represent the latest Gradle tools.

This means updating the buildscript dependencies (classpath 'com.android.tools.build:gradle:0.7.1+') and the defaultConfig (minSdkVersion 14 and targetSdkVersion 19)

[feature request] calculate animation duration until at rest

To synchronise Android Animators with Springs, it would be nice to know the time it takes for a spring to be back at rest

ie

Animator fadeIn = ...;
double springDuration = spring.duration(double startValue, double endValue);
fadeIn.setStartDelay(springDuration);

How do I know that Spring is bouncing?

I want one of my widgets can animate without bouncing, but I have to rely on changes in the value of the onSpringUpdate callback method.So is there a api to know Spring is in Bouncing?

Cannot build with Java 1.8

Not sure if this is known, but installing Rebound using JDK 1.8u25 fails (both Playground and Example). It's weird because Gradle says the build succeeds until I try to push it to a device. JDK 1.7u75 has no issues, so I'm not too sure exactly what's going on. I don't see any specific build.gradle or settings.gradle files which specify a JDK version to build with either.

Error occurs during preDexDebug:

UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dx.cf.iface.ParseException: bad class file magic (cafebabe) or version (0034.0000)
at com.android.dx.cf.direct.DirectClassFile.parse0(DirectClassFile.java:472)
at com.android.dx.cf.direct.DirectClassFile.parse(DirectClassFile.java:406)
at com.android.dx.cf.direct.DirectClassFile.parseToInterfacesIfNecessary(DirectClassFile.java:388)
at com.android.dx.cf.direct.DirectClassFile.getMagic(DirectClassFile.java:251)
at com.android.dx.command.dexer.Main.processClass(Main.java:665)
at com.android.dx.command.dexer.Main.processFileBytes(Main.java:634)
at com.android.dx.command.dexer.Main.access$600(Main.java:78)
at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:572)
at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:284)
at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)
at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
at com.android.dx.command.dexer.Main.processOne(Main.java:596)
at com.android.dx.command.dexer.Main.processAllFiles(Main.java:498)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:264)
at com.android.dx.command.dexer.Main.run(Main.java:230)
at com.android.dx.command.dexer.Main.main(Main.java:199)
at com.android.dx.command.Main.main(Main.java:103)
...while parsing com/facebook/rebound/BaseSpringSystem.class

Tutorial?

Am I missing something or do I have to download and look through the code (and possibly bundled examples) to see how this works? Normally a quick tutorial / wiki page with some examples can help greatly reduce the pain of going through code examples.

slide bottom?

SpringScrollView how to judge the slide to the bottom?

Gradle/Maven support?

Any chance Gradle/Maven support will be added?

Ideally a developer could add this to their project as simply as adding this to the build.gradle:

dependencies {
    compile group: 'com.facebook.rebound', name: 'rebound', version: '1.0'
}

Possible defect in the source code

Hi.

SpringOverScroller.java#L86-L87: getCurrVelocity

  public float getCurrVelocity() {
    double velX = mSpringX.getVelocity();
    double velY = mSpringX.getVelocity();
    return (int) Math.sqrt(velX * velX + velY * velY);
  }

It is suspicious that the variables 'velX' and 'velY' are initialized with the same value.

Probably, it should be:

  public float getCurrVelocity() {
    double velX = mSpringX.getVelocity();
    double velY = mSpringY.getVelocity();
    return (int) Math.sqrt(velX * velX + velY * velY);
  }

This possible defect found by AppChecker.

help

the project of rebound run with error:
Error:Execution failed for task ':rebound-android-example:preDexDebug'.

com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java'' finished with non-zero exit value 1

who can help me?thanks!

Update published rebound.js on npm

The version of rebound.js on npm has an outdated version of createSpring:

 createSpring: function() {
      var spring = new Spring(this);
      this.registerSpring(spring);
      return spring;
    },

Instead of what is in the docs

createSpring: function(tension, friction) {
      var spring = new Spring(this);
      this.registerSpring(spring);
      if (typeof tension === 'undefined' || typeof friction === 'undefined') {
        spring.setSpringConfig(SpringConfig.DEFAULT_ORIGAMI_SPRING_CONFIG);
      } else {
        var springConfig = SpringConfig.fromOrigamiTensionAndFriction(tension, friction);
        spring.setSpringConfig(springConfig);
      }
      return spring;
    },

When following the example in the docs it throws an error since this._springConfig is never defined in the old version. *Great addition btw

I would love to see rebound.js become it's own project with it's own repo etc. I have some performance improvements to add :)

Make samples apk available

Hi, I would like to be able to download the samples apk.
I tried to compile the source code, but I just have the jdk 1.8 in my machine and #53 says it is not compatible with that..so, could you, please, make the samples apk available?

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.