-
Notifications
You must be signed in to change notification settings - Fork 370
Animate changes to flexlayouts #1404
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
8aa64e4
Animate the flexlayouts
dbe7c61
Merge branch 'master' of github.com:flutter/devtools into tween
7b06a0d
Make the layouts animate flex changes
f557052
Cleanup
244c0c8
Cleanup
29d73b6
Respond to comments
fee3ca6
Trailing commas
63c4ff5
Fix lints
23f8f8f
Remove fixed TODO
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -105,11 +105,34 @@ class LayoutProperties { | |
| LayoutProperties(child, copyLevel: copyLevel - 1)) | ||
| ?.toList(growable: false); | ||
|
|
||
| LayoutProperties.values({ | ||
| @required this.node, | ||
| @required this.children, | ||
| @required this.constraints, | ||
| @required this.description, | ||
| @required this.flexFactor, | ||
| @required this.isFlex, | ||
| @required this.size, | ||
| }); | ||
|
|
||
| factory LayoutProperties.lerp( | ||
| LayoutProperties begin, LayoutProperties end, double t) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: trailing comma? |
||
| return LayoutProperties.values( | ||
| node: end.node, | ||
| children: end.children, | ||
| constraints: BoxConstraints.lerp(begin.constraints, end.constraints, t), | ||
| description: end.description, | ||
| flexFactor: begin.flexFactor + (begin.flexFactor - end.flexFactor) * t, | ||
| isFlex: begin.isFlex && end.isFlex, | ||
| size: Size.lerp(begin.size, end.size, t), | ||
| ); | ||
| } | ||
|
|
||
| final RemoteDiagnosticsNode node; | ||
| final List<LayoutProperties> children; | ||
| final BoxConstraints constraints; | ||
| final String description; | ||
| final int flexFactor; | ||
| final num flexFactor; | ||
albertusdev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| final bool isFlex; | ||
| final Size size; | ||
|
|
||
|
|
@@ -172,13 +195,57 @@ class LayoutProperties { | |
| double.parse(json['height']), | ||
| ); | ||
| } | ||
|
|
||
| LayoutProperties copyWith({ | ||
| List<LayoutProperties> children, | ||
| BoxConstraints constraints, | ||
| String description, | ||
| int flexFactor, | ||
| bool isFlex, | ||
| Size size, | ||
| }) { | ||
| return LayoutProperties.values( | ||
| node: node, | ||
| children: children ?? this.children, | ||
| constraints: constraints ?? this.constraints, | ||
| description: description ?? this.description, | ||
| flexFactor: flexFactor ?? this.flexFactor, | ||
| isFlex: isFlex ?? this.isFlex, | ||
| size: size ?? this.size, | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| final Expando<FlexLayoutProperties> _flexLayoutExpando = Expando(); | ||
|
|
||
| /// TODO(albertusangga): Move this to [RemoteDiagnosticsNode] once dart:html app is removed | ||
| class FlexLayoutProperties extends LayoutProperties { | ||
| FlexLayoutProperties._( | ||
| FlexLayoutProperties({ | ||
| Size size, | ||
| List<LayoutProperties> children, | ||
| RemoteDiagnosticsNode node, | ||
| BoxConstraints constraints, | ||
| bool isFlex, | ||
| String description, | ||
| num flexFactor, | ||
| this.direction, | ||
| this.mainAxisAlignment, | ||
| this.crossAxisAlignment, | ||
| this.mainAxisSize, | ||
| this.textDirection, | ||
| this.verticalDirection, | ||
| this.textBaseline, | ||
| }) : super.values( | ||
| size: size, | ||
| children: children, | ||
| node: node, | ||
| constraints: constraints, | ||
| isFlex: isFlex, | ||
| description: description, | ||
| flexFactor: flexFactor, | ||
| ); | ||
|
|
||
| FlexLayoutProperties._fromNode( | ||
| RemoteDiagnosticsNode node, { | ||
| this.direction, | ||
| this.mainAxisAlignment, | ||
|
|
@@ -197,6 +264,40 @@ class FlexLayoutProperties extends LayoutProperties { | |
| return _flexLayoutExpando[node] ??= _buildNode(node); | ||
| } | ||
|
|
||
| @override | ||
| FlexLayoutProperties copyWith({ | ||
| Size size, | ||
| List<LayoutProperties> children, | ||
| BoxConstraints constraints, | ||
| bool isFlex, | ||
| String description, | ||
| num flexFactor, | ||
| Axis direction, | ||
| MainAxisAlignment mainAxisAlignment, | ||
| MainAxisSize mainAxisSize, | ||
| CrossAxisAlignment crossAxisAlignment, | ||
| TextDirection textDirection, | ||
| VerticalDirection verticalDirection, | ||
| TextBaseline textBaseline, | ||
| }) { | ||
| return FlexLayoutProperties( | ||
| size: size ?? this.size, | ||
| children: children ?? this.children, | ||
| node: node, | ||
| constraints: constraints ?? this.constraints, | ||
| isFlex: isFlex ?? this.isFlex, | ||
| description: description ?? this.description, | ||
| flexFactor: flexFactor ?? this.flexFactor, | ||
| direction: direction ?? this.direction, | ||
| mainAxisAlignment: mainAxisAlignment ?? this.mainAxisAlignment, | ||
| mainAxisSize: mainAxisSize ?? this.mainAxisSize, | ||
| crossAxisAlignment: crossAxisAlignment ?? this.crossAxisAlignment, | ||
| textDirection: textDirection ?? this.textDirection, | ||
| verticalDirection: verticalDirection ?? this.verticalDirection, | ||
| textBaseline: textBaseline ?? this.textBaseline, | ||
| ); | ||
| } | ||
|
|
||
| static FlexLayoutProperties _buildNode(RemoteDiagnosticsNode node) { | ||
| final Map<String, Object> renderObjectJson = node?.renderObject; | ||
| if (renderObjectJson == null) return null; | ||
|
|
@@ -206,7 +307,7 @@ class FlexLayoutProperties extends LayoutProperties { | |
| key: (property) => property['name'], | ||
| value: (property) => property['description'], | ||
| ); | ||
| return FlexLayoutProperties._( | ||
| return FlexLayoutProperties._fromNode( | ||
| node, | ||
| direction: _directionUtils.enumEntry(data['direction']), | ||
| mainAxisAlignment: | ||
|
|
@@ -222,8 +323,8 @@ class FlexLayoutProperties extends LayoutProperties { | |
| } | ||
|
|
||
| final Axis direction; | ||
| MainAxisAlignment mainAxisAlignment; | ||
| CrossAxisAlignment crossAxisAlignment; | ||
| final MainAxisAlignment mainAxisAlignment; | ||
| final CrossAxisAlignment crossAxisAlignment; | ||
| final MainAxisSize mainAxisSize; | ||
| final TextDirection textDirection; | ||
| final VerticalDirection verticalDirection; | ||
|
|
@@ -245,11 +346,12 @@ class FlexLayoutProperties extends LayoutProperties { | |
|
|
||
| String get type => direction == Axis.horizontal ? 'Row' : 'Column'; | ||
|
|
||
| int get totalFlex { | ||
| num get totalFlex { | ||
| if (children?.isEmpty ?? true) return 0; | ||
| _totalFlex ??= children | ||
| .map((child) => child.flexFactor ?? 0) | ||
| .reduce((value, element) => value + element); | ||
| .reduce((value, element) => value + element) | ||
| .toInt(); | ||
| return _totalFlex; | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: add extra line before the factory constructor?