material-motion / material-motion-swift

A toolkit for building responsive motion using Core Animation.
Apache License 2.0
1.42k stars 79 forks source link

runtime.get may lead to unexpected behavior when working with subclasses #46

Closed jverkoey closed 7 years ago

jverkoey commented 7 years ago

runtime.get is currently making use of function overloading to create and cache reactive versions of non-reactive objects. This will create problems when working with sub-types, such as CAShapeLayer, because now the sub-type has its own cache. Consider the following example:

let shapeLayer = CAShapeLayer()
let layer: CALayer = shapeLayer
let reactiveShapeLayer = runtime.get(shapeLayer)
let reactiveLayer = runtime.get(layer)
// reactiveShapeLayer !== reactiveLayer

Note that even though we're using the same shape layer instance, we get a different reacitve object instance depending on the type of the variable we pass to runtime.get. This will lead to unexpected behavior in practice and we should consider alternative solutions to this.

jverkoey commented 7 years ago

🎊 My diff is ready for review at http://codereview.cc/D2862