提交 1d78945c 编写于 作者: H Hixie

Fix theme changing: turns out we were not reparenting stateful surviving nodes...

Fix theme changing: turns out we were not reparenting stateful surviving nodes when their parents changed identity

This also makes the optimistic/pessimistic mode switch change the active theme, because why not.

While I was at it I also provided a debug boolean argument to runApp() to make it possible to profile more easily.

R=abarth@chromium.org

Review URL: https://codereview.chromium.org/1215023002.
上级 de574c74
......@@ -61,22 +61,35 @@ class StocksApp extends App {
});
}
Widget build() {
return new Theme(
data: new ThemeData.light(
Widget build() {
ThemeData theme;
if (stockMode == StockMode.optimistic) {
theme = new ThemeData.light(
primary: colors.Purple,
accent: colors.RedAccent,
darkToolbar: true),
child: new Navigator(_navigationState)
);
}
darkToolbar: true
);
} else {
theme = new ThemeData.dark(
primary: colors.Red,
accent: colors.PurpleAccent
);
}
return new Theme(
data: theme,
child: new Navigator(_navigationState)
);
}
}
void main() {
print("starting stocks app!");
runApp(new StocksApp());
runApp(new StocksApp(), enableProfilingLoop: true);
// set enableProfilingLoop to true to make the app rebuild continually every 20ms
SkyBinding.instance.onFrame = () {
// uncomment this for debugging:
// uncomment this to print the RenderObject tree every frame:
// SkyBinding.instance.debugDumpRenderTree();
};
}
......@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:math' as math;
import 'dart:sky' as sky;
import 'dart:sky' show Point, Offset, Size, Rect, Color, Paint, Path;
......
......@@ -50,6 +50,8 @@ abstract class Widget {
void setParent(Widget newParent) {
assert(!_notifyingMountStatus);
if (_parent == newParent)
return;
_parent = newParent;
if (newParent == null) {
if (_mounted) {
......@@ -146,6 +148,7 @@ abstract class Widget {
if (node._retainStatefulNodeIfPossible(oldNode)) {
assert(oldNode.mounted);
assert(!node.mounted);
oldNode.setParent(this);
oldNode._sync(node, slot);
assert(oldNode.root is RenderObject);
return oldNode;
......@@ -957,9 +960,14 @@ class AppContainer extends AbstractWidgetRoot {
Widget build() => new RenderViewWrapper(child: app);
}
void runApp(App app, { RenderView renderViewOverride }) {
void runApp(App app, { RenderView renderViewOverride, bool enableProfilingLoop: false }) {
WidgetSkyBinding.initWidgetSkyBinding(renderViewOverride: renderViewOverride);
new AppContainer(app);
if (enableProfilingLoop) {
new Timer.periodic(const Duration(milliseconds: 20), (_) {
app.scheduleBuild();
});
}
}
typedef Widget Builder();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册