Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small changes required by the coming layout debugger #337

Merged
merged 3 commits into from
Jun 8, 2017

Conversation

nguyenhuy
Copy link
Member

@nguyenhuy nguyenhuy commented Jun 6, 2017

  • ASDisplayNode can be told to not flatten its layout immediately but later on. The unflattened layout is also stored in a separate property. It's needed for inspecting not only display nodes but also layout specs used to compute a layout tree.
  • ASLayout can be told to always retain its sublayout elements. This is needed especially for layout specs since they are usually not retained after an ASLayout is computed.

@nguyenhuy nguyenhuy force-pushed the HNLayoutDebugger-CoreChanges branch from 5adbb8d to 1c98eaa Compare June 6, 2017 20:04
@ghost
Copy link

ghost commented Jun 6, 2017

🚫 CI failed with log

@ghost
Copy link

ghost commented Jun 6, 2017

🚫 CI failed with log

@nguyenhuy nguyenhuy force-pushed the HNLayoutDebugger-CoreChanges branch from e42f6c9 to a8f1bbf Compare June 6, 2017 20:09
@@ -554,6 +554,19 @@ extern NSInteger const ASDefaultDrawingPriority;
@interface ASDisplayNode (Debugging) <ASDebugNameProvider>

/**
* Whether ASDisplayNode should store their unflattened layouts. The layout can be accessed via `-unflattenedCalculatedLayout`.
* Flattened layouts use less memory and are faster to lookup, while unflattened ones are useful for debugging
* because they reserve original information.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: typo reserve should be preserve

*
* Defaults to NO.
*/
+ (void)setShouldStoreUnflattenedLayouts:(BOOL)shouldStore;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason this isn't also a property?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nm, I see now that this is a class method :)

@@ -3286,6 +3294,21 @@ - (UIView *)preferredFocusedView

@implementation ASDisplayNode (Debugging)

+ (void)setShouldStoreUnflattenedLayouts:(BOOL)shouldStore
{
storesUnflattenedLayouts = shouldStore;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These don't appear to be thread safe. Should we use OSAtomic at least here? I wouldn't be surprised if setting BOOLs is actually atomic on most architectures but we probably shouldn't at least have a comment about that or fix it?


- (ASLayout *)unflattenedCalculatedLayout
{
return _unflattenedLayout;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs a lock?

@@ -76,6 +76,13 @@ @implementation ASLayout

@dynamic frame, type;

static BOOL static_retainsSublayoutLayoutElements = NO;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason to have the prepended static here? Seems like a newish convention? Is there an existing one we can use?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is because ASLayout also has an instance variable called retainSublayoutLayoutElements here.


+ (void)setShouldRetainSublayoutLayoutElements:(BOOL)shouldRetain
{
static_retainsSublayoutLayoutElements = shouldRetain;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem thread safe either.

- `ASDisplayNode` can be told to not flatten its layout immediately but later on. The unflattened layout is also stored in a separate property. It's needed for inspecting not only display nodes but also layout specs used to compute a layout tree.
- `ASLayout` can be told to always retain its sublayout elements. This is needed especially for layout specs since they are usually not retained after an ASLayout was computed.
@nguyenhuy nguyenhuy force-pushed the HNLayoutDebugger-CoreChanges branch from 061e5ee to 3dcf125 Compare June 6, 2017 22:51
@nguyenhuy
Copy link
Member Author

@garrettmoon Ready for another round of review. Thanks!

@@ -76,6 +76,18 @@ @implementation ASLayout

@dynamic frame, type;

static std::atomic_bool static_retainsSublayoutLayoutElements = ATOMIC_VAR_INIT(NO);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added static prefix because ASLayout also has an instance variable called retainSublayoutLayoutElements here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Member

@garrettmoon garrettmoon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@@ -82,6 +82,7 @@ @implementation ASDisplayNode
@synthesize threadSafeBounds = _threadSafeBounds;

static BOOL suppressesInvalidCollectionUpdateExceptions = NO;
static std::atomic_bool storesUnflattenedLayouts = ATOMIC_VAR_INIT(NO);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh man, this is way nicer than objc!

@@ -76,6 +76,18 @@ @implementation ASLayout

@dynamic frame, type;

static std::atomic_bool static_retainsSublayoutLayoutElements = ATOMIC_VAR_INIT(NO);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@nguyenhuy
Copy link
Member Author

Awesome. Thanks, @garrettmoon!

@nguyenhuy nguyenhuy merged commit 05e9bdd into master Jun 8, 2017
bernieperez pushed a commit to AtomTickets/Texture that referenced this pull request Apr 25, 2018
* Small changes required by the layout debugger
- `ASDisplayNode` can be told to not flatten its layout immediately but later on. The unflattened layout is also stored in a separate property. It's needed for inspecting not only display nodes but also layout specs used to compute a layout tree.
- `ASLayout` can be told to always retain its sublayout elements. This is needed especially for layout specs since they are usually not retained after an ASLayout was computed.

* Update CHANGELOG

* Address comments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants