material-motion-android icon indicating copy to clipboard operation
material-motion-android copied to clipboard

Should related reactive properties update each other

Open pingpongboss opened this issue 8 years ago • 3 comments

Here's code that a user might write:

runtime.add(draggable, view);
ReactiveProperty.of(view, CENTER).subscribe( value -> {
  log(value);
})

This wouldn't work because Draggable writes to the view's TRANSLATION instead of CENTER. However, the user may expect this to work.

pingpongboss avatar Apr 18 '17 23:04 pingpongboss

In Swift we document which properties our view-based interactions affect.

jverkoey avatar Apr 18 '17 23:04 jverkoey

Would be great if android followed the same convention as iOS. I don't have to know anything about CENTER or TRANSLATION options.

runtime.get(block.layer).position.subscribeToValue { (p: CGPoint) in
  log(p.x)
}

randcode-generator avatar Apr 19 '17 02:04 randcode-generator

iOS has the same underlying problem, unfortunately. For example:

var position = runtime.get(block.layer).position
var positionX = runtime.get(block.layer).positionX

position.subscribeToValue { (p: CGPoint) in
  log(p.x)
}
positionX.write(0.5) // Error: Nothing is logged even though position's value has changed.

The iOS example you provided works because you happen to subscribe to the same property (position) that Draggable modifies (position). If you subscribed to a different property (positionX), then you would run into the same issues even though positionX and position are related. Like Jeff said, documentation is the easiest way to solve this issue on both platforms. A more involved solution would involve creating a graph of properties that are related to each other.

pingpongboss avatar Apr 19 '17 06:04 pingpongboss