Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Physics UI - Droidcon London 2015

Sponsored · SiteGround - Reliable hosting with speed, security, and support you can count on. →
Avatar for fabrantes fabrantes
October 30, 2015

Physics UI - Droidcon London 2015

Avatar for fabrantes

fabrantes

October 30, 2015

Other Decks in Technology

Transcript

  1. public void translatePre11(@NonNull View view, @NonNull PointF to) {
 TranslateAnimation

    translateAnimation =
 new TranslateAnimation(view.getLeft(), view.getTop(),
 to.x, to.y);
 // translateAnimation.setFillAfter(true);
 translateAnimation.setDuration(300);
 translateAnimation.setInterpolator(new OvershootInterpolator());
 view.setAnimation(translateAnimation);
 translateAnimation.start();
 }
  2. public void translate(@NonNull View view, @NonNull PointF to) {
 view.animate()


    .x(to.x)
 .setDuration(300)
 .setInterpolator(new OvershootInterpolator());
 }
  3. Overview • What is UI physics? • Why do UI

    physics matter? • Theory • Practical Implementation • Designing motion
  4. “Hooke's law: the force F needed to extend or compress

    a spring by some distance X is proportional to that distance.”
  5. “Hooke's law: the force F needed to extend or compress

    a spring by some distance X is proportional to that distance.”
  6. “Damping: is an influence within or upon an oscillatory system

    that has the effect of reducing, restricting or preventing its oscillations. In physical systems, damping is produced by processes that dissipate the energy stored in the oscillation.”
  7. “Damping: is an influence within or upon an oscillatory system

    that has the effect of reducing, restricting or preventing its oscillations. In physical systems, damping is produced by processes that dissipate the energy stored in the oscillation.”
  8. Interpolator • Use the analytical solver as the base •

    Calculate a time multiplier so it fits in a 0…1 interval • position < 1px away from target • velocity < 1px/16msec 0 1
  9. A simple library that accurately models spring dynamics for the

    purpose of driving physical animations.
  10. Design Goals • Not a full physics engine (springs!) •

    Lightweight and easy to integrate • Focus on the model, not opinionated about rendering • Low level building block
  11. What can it help you build? ▪ delightful transitions ▪

    toggles ▪ pagers ▪ scrollers ▪ anything that involves goal driven animation with physics driven motion…
  12. SpringSystem Spring SpringSystemListener SpringListener creates/observes observes observes SpringLooper drives Concrete

    Classes SteppingLooper SynchronousLooper ChoreographerAndroidSpringLooper LegacyAndroidSpringLooper Methods onSpringActivate onSpringUpdate onSpringAtRest onSpringEndStateChange Methods onBeforeIntegrate onAfterIntegrate SpringConfig SpringConfigRegistry holds has Methods setCurrentValue setEndValue setVelocity
  13. @Override
 public void onAfterIntegrate(BaseSpringSystem springSystem) {
 if (!mTouching) {
 //

    If we are free scrolling then check to see if we have 
 // moved out of bounds and trigger the appropriate 
 // rubber-banding.
 constrainToBounds(true);
 }
 }
  14. Other Interesting Libraries • Gravitas (physics engine built for Letterplex)


    https://github.com/iamralpht/gravitas • Backboard (API around Rebound from Tumblr)
 https://github.com/tumblr/Backboard • POP (iOS)
 https://github.com/facebook/pop