LinkedInAttic / LayoutKit

LayoutKit is a fast view layout library for iOS, macOS, and tvOS.
http://layoutkit.org
Apache License 2.0
3.16k stars 267 forks source link

Subviews should be in a deterministic order, regardless of view reuse #66

Closed nicksnyder closed 8 years ago

nicksnyder commented 8 years ago

As reported by @pgherveou in #56:

If I run twice the same layout with reuseIds set on some of my views, the order of the views changes

== test 2 ==

Unmanaged<AnyObject>(_value: <UIView: 0x7f92a56022c0; frame = (0 0; 350 250); layer = <CALayer: 0x610000033a20>>
   | <UIImageView: 0x7f92a5503e70; frame = (4 4; 50 50); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x618000234ee0>>
   | <UILabel: 0x7f92a7104440; frame = (61 4; 36.5 20.5); text = 'hello'; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x60000009edc0>>
   | <UILabel: 0x7f92a5406770; frame = (58 29; 42.5 20.5); text = 'world'; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x60000009dd80>>)

== test 3x ==

Unmanaged<AnyObject>(_value: <UIView: 0x7f92a56022c0; frame = (0 0; 350 250); layer = <CALayer: 0x610000033a20>>
   | <UILabel: 0x7f92a7104440; frame = (61 4; 36.5 20.5); text = 'hello'; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x60000009edc0>>
   | <UILabel: 0x7f92a5406770; frame = (58 29; 42.5 20.5); text = 'world'; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x60000009dd80>>
   | <UIImageView: 0x7f92a560b770; frame = (4 4; 50 50); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x610000036180>>)

This could have unexpected consequences for layering and tap handling if views overlap so LayoutKit should make sure views are in a deterministic order.