Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
82afe3ea
Unverified
Commit
82afe3ea
authored
May 06, 2022
by
xubaolin
Committed by
GitHub
May 06, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clear the cached data of `RenderBox` if its parent re-layout (#101493)
parent
55881f7a
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
87 additions
and
6 deletions
+87
-6
box.dart
packages/flutter/lib/src/rendering/box.dart
+21
-6
cached_intrinsics_test.dart
packages/flutter/test/rendering/cached_intrinsics_test.dart
+66
-0
No files found.
packages/flutter/lib/src/rendering/box.dart
View file @
82afe3ea
...
...
@@ -2348,8 +2348,7 @@ abstract class RenderBox extends RenderObject {
}());
}
@override
void
markNeedsLayout
()
{
bool
_clearCachedData
()
{
if
((
_cachedBaselines
!=
null
&&
_cachedBaselines
!.
isNotEmpty
)
||
(
_cachedIntrinsicDimensions
!=
null
&&
_cachedIntrinsicDimensions
!.
isNotEmpty
)
||
(
_cachedDryLayoutSizes
!=
null
&&
_cachedDryLayoutSizes
!.
isNotEmpty
))
{
...
...
@@ -2361,14 +2360,30 @@ abstract class RenderBox extends RenderObject {
_cachedBaselines
?.
clear
();
_cachedIntrinsicDimensions
?.
clear
();
_cachedDryLayoutSizes
?.
clear
();
if
(
parent
is
RenderObject
)
{
return
true
;
}
return
false
;
}
@override
void
markNeedsLayout
()
{
if
(
_clearCachedData
()
&&
parent
is
RenderObject
)
{
markParentNeedsLayout
();
return
;
}
}
super
.
markNeedsLayout
();
}
@override
void
layout
(
Constraints
constraints
,
{
bool
parentUsesSize
=
false
})
{
if
(
hasSize
&&
constraints
!=
this
.
constraints
&&
_cachedBaselines
!=
null
&&
_cachedBaselines
!.
isNotEmpty
)
{
// The cached baselines data may need update if the constraints change.
_cachedBaselines
?.
clear
();
}
super
.
layout
(
constraints
,
parentUsesSize:
parentUsesSize
);
}
/// {@macro flutter.rendering.RenderObject.performResize}
///
/// By default this method sets [size] to the result of [computeDryLayout]
...
...
packages/flutter/test/rendering/cached_intrinsics_test.dart
View file @
82afe3ea
...
...
@@ -5,7 +5,11 @@
import
'package:flutter/rendering.dart'
;
import
'package:flutter_test/flutter_test.dart'
;
import
'rendering_tester.dart'
;
class
RenderTestBox
extends
RenderBox
{
late
Size
boxSize
;
int
calls
=
0
;
double
value
=
0.0
;
double
next
()
{
value
+=
1.0
;
...
...
@@ -19,9 +23,23 @@ class RenderTestBox extends RenderBox {
double
computeMinIntrinsicHeight
(
double
width
)
=>
next
();
@override
double
computeMaxIntrinsicHeight
(
double
width
)
=>
next
();
@override
void
performLayout
()
{
size
=
constraints
.
biggest
;
boxSize
=
size
;
}
@override
double
?
computeDistanceToActualBaseline
(
TextBaseline
baseline
)
{
calls
+=
1
;
return
boxSize
.
height
/
2.0
;
}
}
void
main
(
)
{
TestRenderingFlutterBinding
.
ensureInitialized
();
test
(
'Intrinsics cache'
,
()
{
final
RenderBox
test
=
RenderTestBox
();
...
...
@@ -68,4 +86,52 @@ void main() {
expect
(
test
.
getMinIntrinsicWidth
(
0.0
),
equals
(
1.0
));
});
// Regression test for https://github.com/flutter/flutter/issues/101179
test
(
'Cached baselines should be cleared if its parent re-layout'
,
()
{
double
viewHeight
=
200.0
;
final
RenderTestBox
test
=
RenderTestBox
();
final
RenderBox
baseline
=
RenderBaseline
(
baseline:
0.0
,
baselineType:
TextBaseline
.
alphabetic
,
child:
test
,
);
final
RenderConstrainedBox
root
=
RenderConstrainedBox
(
additionalConstraints:
BoxConstraints
.
tightFor
(
width:
200.0
,
height:
viewHeight
),
child:
baseline
,
);
layout
(
RenderPositionedBox
(
child:
root
,
));
BoxParentData
?
parentData
=
test
.
parentData
as
BoxParentData
?;
expect
(
parentData
!.
offset
.
dy
,
-(
viewHeight
/
2.0
));
expect
(
test
.
calls
,
1
);
// Trigger the root render re-layout.
viewHeight
=
300.0
;
root
.
additionalConstraints
=
BoxConstraints
.
tightFor
(
width:
200.0
,
height:
viewHeight
);
pumpFrame
();
parentData
=
test
.
parentData
as
BoxParentData
?;
expect
(
parentData
!.
offset
.
dy
,
-(
viewHeight
/
2.0
));
expect
(
test
.
calls
,
2
);
// The layout constraints change will clear the cached data.
final
RenderObject
parent
=
test
.
parent
!
as
RenderObject
;
expect
(
parent
.
debugNeedsLayout
,
false
);
// Do not forget notify parent dirty after the cached data be cleared by `layout()`
test
.
markNeedsLayout
();
expect
(
parent
.
debugNeedsLayout
,
true
);
pumpFrame
();
expect
(
parent
.
debugNeedsLayout
,
false
);
expect
(
test
.
calls
,
3
);
// Self dirty will clear the cached data.
parent
.
markNeedsLayout
();
pumpFrame
();
expect
(
test
.
calls
,
3
);
// Use the cached data if the layout constraints do not change.
});
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment