Parallax


abstract class Parallax<PropertyT : Property?>

Known direct subclasses
RecyclerViewParallax

Implementation of Parallax class for RecyclerView.

Known indirect subclasses
DetailsParallax

Subclass of Parallax object that tracks overview row's top and bottom edge in DetailsFragment or DetailsSupportFragment.


Parallax tracks a list of dynamic Propertys typically representing foreground UI element positions on screen. Parallax keeps a list of ParallaxEffect objects which define rules to mapping property values to ParallaxTarget.

Example: // when Property "var1" changes from 15 to max value, perform parallax effect to // change myView's translationY from 0 to 100. Parallaxparallax = new Parallax

To create a ParallaxEffect, user calls addEffect with a list of PropertyMarkerValue which defines the range of Parallax.IntProperty or Parallax.FloatProperty. Then user adds ParallaxTarget into ParallaxEffect.

App may subclass Parallax.IntProperty or Parallax.FloatProperty to supply additional information about how to retrieve Property value. RecyclerViewParallax is a great example of Parallax implementation tracking child view positions on screen.

Restrictions of properties

  • FloatProperty and IntProperty cannot be mixed in one Parallax
  • Values must be in ascending order.
  • If the UI element is unknown above screen, use UNKNOWN_BEFORE.
  • if the UI element is unknown below screen, use UNKNOWN_AFTER.
  • UNKNOWN_BEFORE and UNKNOWN_AFTER are not allowed to be next to each other.
These rules will be verified at runtime.

Subclass must override updateValues to update property values and perform ParallaxEffects. Subclass may call updateValues automatically e.g. RecyclerViewParallax calls updateValues in RecyclerView scrolling. App might call updateValues manually when Parallax is unaware of the value change. For example, when a slide transition is running, RecyclerViewParallax is unaware of translation value changes; it's the app's responsibility to call updateValues in every frame of animation.

Parameters
<PropertyT : Property?>

Subclass of Parallax.IntProperty or Parallax.FloatProperty

Summary

Nested types

FloatProperty provide access to an index based integer type property inside Parallax.

IntProperty provide access to an index based integer type property inside Parallax.

Class holding a fixed value for a Property in Parallax.

Public constructors

Public functions

ParallaxEffect!

Create a ParallaxEffect object that will track source variable changes within a provided set of ranges.

PropertyT!

Add a new IntProperty in the Parallax object.

abstract PropertyT!
createProperty(name: String!, index: Int)

Create a new Property object.

(Mutable)List<ParallaxEffect!>!

Returns a list of ParallaxEffect object which defines rules to perform mapping to multiple ParallaxTargets.

abstract Float

Return the max value which is typically size of parent visible area, e.g. RecyclerView's height if we are tracking Y position of a child.

(Mutable)List<PropertyT!>!
Unit

Remove all ParallaxEffect objects.

Unit

Remove the ParallaxEffect object.

Unit

Update property values and perform ParallaxEffects.

Public constructors

Parallax

Added in 1.1.0
Parallax()

Public functions

addEffect

fun addEffect(ranges: Array<Parallax.PropertyMarkerValue!>!): ParallaxEffect!

Create a ParallaxEffect object that will track source variable changes within a provided set of ranges.

Parameters
ranges: Array<Parallax.PropertyMarkerValue!>!

A list of marker values that defines the ranges.

Returns
ParallaxEffect!

Newly created ParallaxEffect object.

addProperty

Added in 1.1.0
fun addProperty(name: String!): PropertyT!

Add a new IntProperty in the Parallax object. App may override createProperty.

Parameters
name: String!

Name of the property.

Returns
PropertyT!

Newly created Property object.

See also
createProperty

createProperty

Added in 1.1.0
abstract fun createProperty(name: String!, index: Int): PropertyT!

Create a new Property object. App does not directly call this method. See addProperty.

Parameters
index: Int

Index of the property in this Parallax object.

Returns
PropertyT!

Newly created Property object.

getEffects

Added in 1.1.0
fun getEffects(): (Mutable)List<ParallaxEffect!>!

Returns a list of ParallaxEffect object which defines rules to perform mapping to multiple ParallaxTargets.

Returns
(Mutable)List<ParallaxEffect!>!

A list of ParallaxEffect object.

getMaxValue

Added in 1.1.0
abstract fun getMaxValue(): Float

Return the max value which is typically size of parent visible area, e.g. RecyclerView's height if we are tracking Y position of a child. The size can be used to calculate marker value using the provided fraction of FloatPropertyMarkerValue.

Returns
Float

Size of parent visible area.

getProperties

Added in 1.1.0
fun getProperties(): (Mutable)List<PropertyT!>!
Returns
(Mutable)List<PropertyT!>!

A unmodifiable list of properties.

removeAllEffects

Added in 1.1.0
fun removeAllEffects(): Unit

Remove all ParallaxEffect objects.

removeEffect

Added in 1.1.0
fun removeEffect(effect: ParallaxEffect!): Unit

Remove the ParallaxEffect object.

Parameters
effect: ParallaxEffect!

The ParallaxEffect object to remove.

updateValues

Added in 1.1.0
@CallSuper
fun updateValues(): Unit

Update property values and perform ParallaxEffects. Subclass may override and call super.updateValues() after updated properties values.