Skip to content

[ASLayoutTransition] Default transition uses snapshots, so that subnodes of each node can't animate independently. #168

Open
@garrettmoon

Description

@garrettmoon

From @ikhromov on December 19, 2016 21:0

I tried to apply animation to ASDisplayNode that has several subnodes.

  • (ASLayoutSpec )layoutSpecThatFits:(ASSizeRange)constrainedSize
    {
    /
    Layout foreground elements in horizontal stack */
    ASStackLayoutSpec *footerHorizontalStack = [ASStackLayoutSpec horizontalStackLayoutSpec];
    [footerHorizontalStack setJustifyContent:ASStackLayoutJustifyContentStart];
    [footerHorizontalStack setAlignItems:ASStackLayoutAlignItemsCenter];

    NSMutableArray *stackItems = [[NSMutableArray alloc] initWithCapacity:3];
    [stackItems addObjectsFromArray:@[__unitsCountTextNode,
    __progressPercentTextNode,
    __progressBar]];
    ....

One of the subnodes __progressBar has it's own subnodes:

  • (ASLayoutSpec *)layoutSpecThatFits:(ASSizeRange)constrainedSize
    {
    __backgroundBlueImageNode.style.width = ASDimensionMakeWithFraction([self progressPercent]);
    __backgroundBlueImageNode.style.minWidth = ASDimensionMakeWithFraction([self progressPercent]);
    __backgroundBlueImageNode.style.maxWidth = ASDimensionMakeWithFraction([self progressPercent]);

    ASRelativeLayoutSpec *relativeSpec =
    [ASRelativeLayoutSpec
    relativePositionLayoutSpecWithHorizontalPosition:ASRelativeLayoutSpecPositionStart
    verticalPosition:ASRelativeLayoutSpecPositionStart
    sizingOption:ASRelativeLayoutSpecSizingOptionDefault
    child:__backgroundBlueImageNode];

    ASOverlayLayoutSpec *overlayBlueImageSpec =
    [ASOverlayLayoutSpec overlayLayoutSpecWithChild:__backgroundGrayImageNode
    overlay:relativeSpec];
    return
    [ASBackgroundLayoutSpec backgroundLayoutSpecWithChild:__frontImageNode
    background:overlayBlueImageSpec];
    }

So when I make some changes in parent node and call
[self transitionLayoutWithAnimation:YES
shouldMeasureAsync:NO measurementCompletion:^{}];

  1. It will animate only it's own subnodes and subnodes of __progressBar are not animated.
  2. Animation will cause snapshots using for ASImageNode subnodes, that is not looks cool.

I think it's a good reason to provide mechanism to animate subnodes in hierarchy, because UIKit does it by default.

Copied from original issue: facebookarchive/AsyncDisplayKit#2804

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions