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
243a49f7
Commit
243a49f7
authored
Mar 29, 2016
by
Adam Barth
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2992 from abarth/reactive_build
Reactivating a StatefulElement should imply a build
parents
66316433
b841e868
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
71 additions
and
12 deletions
+71
-12
framework.dart
packages/flutter/lib/src/widgets/framework.dart
+24
-12
reparent_state_test.dart
packages/flutter/test/widget/reparent_state_test.dart
+47
-0
No files found.
packages/flutter/lib/src/widgets/framework.dart
View file @
243a49f7
...
...
@@ -626,11 +626,11 @@ class _InactiveElements {
});
}
void
_deactivate
(
Element
element
)
{
void
_deactivate
Recursively
(
Element
element
)
{
assert
(
element
.
_debugLifecycleState
==
_ElementLifecycle
.
active
);
element
.
deactivate
();
assert
(
element
.
_debugLifecycleState
==
_ElementLifecycle
.
inactive
);
element
.
visitChildren
(
_deactivate
);
element
.
visitChildren
(
_deactivate
Recursively
);
assert
(()
{
element
.
debugDeactivated
();
return
true
;
});
}
...
...
@@ -639,7 +639,7 @@ class _InactiveElements {
assert
(!
_elements
.
contains
(
element
));
assert
(
element
.
_parent
==
null
);
if
(
element
.
_active
)
_deactivate
(
element
);
_deactivate
Recursively
(
element
);
_elements
.
add
(
element
);
}
...
...
@@ -840,12 +840,12 @@ abstract class Element implements BuildContext {
_slot
=
newSlot
;
}
void
_updateDepth
()
{
int
expectedDepth
=
_parent
.
d
epth
+
1
;
void
_updateDepth
(
int
parentDepth
)
{
int
expectedDepth
=
parentD
epth
+
1
;
if
(
_depth
<
expectedDepth
)
{
_depth
=
expectedDepth
;
visitChildren
((
Element
child
)
{
child
.
_updateDepth
();
child
.
_updateDepth
(
expectedDepth
);
});
}
}
...
...
@@ -885,7 +885,7 @@ abstract class Element implements BuildContext {
if
(
newChild
!=
null
)
{
assert
(
newChild
.
_parent
==
null
);
assert
(()
{
_debugCheckForCycles
(
newChild
);
return
true
;
});
newChild
.
activate
(
this
,
newSlot
);
newChild
.
_activateWithParent
(
this
,
newSlot
);
Element
updatedChild
=
updateChild
(
newChild
,
newWidget
,
newSlot
);
assert
(
newChild
==
updatedChild
);
return
updatedChild
;
...
...
@@ -917,16 +917,23 @@ abstract class Element implements BuildContext {
_inactiveElements
.
add
(
child
);
// this eventually calls child.deactivate()
}
void
activate
(
Element
parent
,
dynamic
newSlot
)
{
void
_activateWithParent
(
Element
parent
,
dynamic
newSlot
)
{
assert
(
_debugLifecycleState
==
_ElementLifecycle
.
inactive
);
_parent
=
parent
;
_
reactivate
(
);
_
updateDepth
(
);
_
updateDepth
(
_parent
.
depth
);
_
activateRecursively
(
this
);
attachRenderObject
(
newSlot
);
assert
(
_debugLifecycleState
==
_ElementLifecycle
.
active
);
}
void
_reactivate
()
{
static
void
_activateRecursively
(
Element
element
)
{
assert
(
element
.
_debugLifecycleState
==
_ElementLifecycle
.
inactive
);
element
.
activate
();
assert
(
element
.
_debugLifecycleState
==
_ElementLifecycle
.
active
);
element
.
visitChildren
(
_activateRecursively
);
}
void
activate
()
{
assert
(
_debugLifecycleState
==
_ElementLifecycle
.
inactive
);
assert
(
widget
!=
null
);
assert
(
depth
!=
null
);
...
...
@@ -934,7 +941,6 @@ abstract class Element implements BuildContext {
_active
=
true
;
_updateInheritance
();
assert
(()
{
_debugLifecycleState
=
_ElementLifecycle
.
active
;
return
true
;
});
visitChildren
((
Element
child
)
=>
child
.
_reactivate
());
}
void
deactivate
()
{
...
...
@@ -1430,6 +1436,12 @@ class StatefulElement extends ComponentElement {
rebuild
();
}
@override
void
activate
()
{
super
.
activate
();
markNeedsBuild
();
}
@override
void
deactivate
()
{
_state
.
deactivate
();
...
...
packages/flutter/test/widget/reparent_state_test.dart
View file @
243a49f7
...
...
@@ -26,6 +26,29 @@ class StateMarkerState extends State<StateMarker> {
}
}
class
DeactivateLogger
extends
StatefulWidget
{
DeactivateLogger
({
Key
key
,
this
.
log
})
:
super
(
key:
key
);
final
List
<
String
>
log
;
@override
DeactivateLoggerState
createState
()
=>
new
DeactivateLoggerState
();
}
class
DeactivateLoggerState
extends
State
<
DeactivateLogger
>
{
@override
void
deactivate
()
{
config
.
log
.
add
(
'deactivate'
);
super
.
deactivate
();
}
@override
Widget
build
(
BuildContext
context
)
{
config
.
log
.
add
(
'build'
);
return
new
Container
();
}
}
void
main
(
)
{
test
(
'can reparent state'
,
()
{
testWidgets
((
WidgetTester
tester
)
{
...
...
@@ -293,4 +316,28 @@ void main() {
expect
(
keyState
.
marker
,
equals
(
"marked"
));
});
});
test
(
'Deactivate implies build'
,
()
{
testWidgets
((
WidgetTester
tester
)
{
GlobalKey
key
=
new
GlobalKey
();
List
<
String
>
log
=
<
String
>[];
DeactivateLogger
logger
=
new
DeactivateLogger
(
key:
key
,
log:
log
);
tester
.
pumpWidget
(
new
Container
(
key:
new
UniqueKey
(),
child:
logger
)
);
expect
(
log
,
equals
([
'build'
]));
tester
.
pumpWidget
(
new
Container
(
key:
new
UniqueKey
(),
child:
logger
)
);
expect
(
log
,
equals
([
'build'
,
'deactivate'
,
'build'
]));
log
.
clear
();
tester
.
pump
();
expect
(
log
,
isEmpty
);
});
});
}
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