Skip to content
This repository has been archived by the owner on Aug 13, 2021. It is now read-only.

Commit

Permalink
Implement inline properties for android.
Browse files Browse the repository at this point in the history
Summary: Fixes material-motion/material-motion#31

Reviewers: O2 Material Motion!, miguelandres, O6 Material Motion Android platform reviewers, #material_motion

Reviewed By: miguelandres, O6 Material Motion Android platform reviewers

Subscribers: featherless

Tags: #material_motion

Differential Revision: http://codereview.cc/D2171
  • Loading branch information
Mark Wei committed Dec 8, 2016
1 parent 1475da3 commit 079c346
Showing 1 changed file with 39 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,28 @@ public static abstract class Predicate<T> {
public abstract boolean evaluate(T value);
}

/**
* An inline property that can be read into a MotionObservable stream.
*/
public static abstract class InlineReadable<T> {

/**
* Reads the property's value.
*/
public abstract T read();
}

/**
* An inline property that can be written from a MotionObservable stream.
*/
public static abstract class InlineWritable<T> {

/**
* Writes the property with the given value.
*/
public abstract void write(T value);
}

/**
* A light-weight operator builder.
* <p>
Expand Down Expand Up @@ -194,7 +216,7 @@ public void next(MotionObserver<T> observer, T value) {
}

/**
* Writes the values from an Observable onto the given target and property.
* Writes the values from an Observable onto the given unscoped property.
*
* @see <a href="https://material-motion.github.io/material-motion/starmap/specifications/streams/operators/$.write">The
* write() specification</a>
Expand All @@ -208,4 +230,20 @@ public void next(MotionObserver<T> observer, T value) {
}
});
}

/**
* Writes the values from an Observable onto the given inline property.
*
* @see <a href="https://material-motion.github.io/material-motion/starmap/specifications/streams/operators/$.write">The
* write() specification</a>
*/
public <O> MotionObservable<T> write(final InlineWritable<T> property) {
return operator(new Operation<T, T>() {
@Override
public void next(MotionObserver<T> observer, T value) {
property.write(value);
observer.next(value);
}
});
}
}

0 comments on commit 079c346

Please sign in to comment.