提交 4ce574a1 编写于 作者: H Hixie

Abstract out the AppView logic in fn so that it can also be used in non-pure-fn apps.

This lays the groundwork for using fn widgets in static environments.

R=abarth@chromium.org

Review URL: https://codereview.chromium.org/1178703002
上级 4811d497
...@@ -46,8 +46,6 @@ class StocksApp extends App { ...@@ -46,8 +46,6 @@ class StocksApp extends App {
_drawerController = new DrawerController(_handleDrawerStatusChanged); _drawerController = new DrawerController(_handleDrawerStatusChanged);
} }
void syncFields(StocksApp source) { }
bool _isSearching = false; bool _isSearching = false;
String _searchQuery; String _searchQuery;
......
...@@ -16,7 +16,10 @@ class PointerState { ...@@ -16,7 +16,10 @@ class PointerState {
class AppView { class AppView {
AppView(RenderBox root) { AppView([RenderBox root = null]) {
assert(_app == null);
_app = this;
sky.view.setEventCallback(_handleEvent); sky.view.setEventCallback(_handleEvent);
sky.view.setMetricsChangedCallback(_handleMetricsChanged); sky.view.setMetricsChangedCallback(_handleMetricsChanged);
scheduler.init(); scheduler.init();
...@@ -26,8 +29,12 @@ class AppView { ...@@ -26,8 +29,12 @@ class AppView {
_renderView.attach(); _renderView.attach();
_renderView.rootConstraints = _viewConstraints; _renderView.rootConstraints = _viewConstraints;
_renderView.scheduleInitialLayout(); _renderView.scheduleInitialLayout();
assert(_app == this);
} }
static AppView _app; // used to enforce that we're a singleton
RenderView _renderView; RenderView _renderView;
ViewConstraints get _viewConstraints => ViewConstraints get _viewConstraints =>
......
...@@ -767,6 +767,13 @@ class Paragraph extends RenderObjectWrapper { ...@@ -767,6 +767,13 @@ class Paragraph extends RenderObjectWrapper {
} }
class Text extends Component {
Text(this.data) : super(key: '*text*');
final String data;
bool get interchangeable => true;
UINode build() => new Paragraph(text: data);
}
class Flex extends MultiChildRenderObjectWrapper { class Flex extends MultiChildRenderObjectWrapper {
Flex(List<UINode> children, { Flex(List<UINode> children, {
...@@ -1059,11 +1066,20 @@ class Container extends Component { ...@@ -1059,11 +1066,20 @@ class Container extends Component {
} }
class _AppView extends AppView { class UINodeAppView extends AppView {
_AppView() : super(null); UINodeAppView() {
assert(_appView == null);
}
static UINodeAppView _appView;
static void initUINodeAppView() {
if (_appView == null)
_appView = new UINodeAppView();
}
void dispatchEvent(sky.Event event, HitTestResult result) { void dispatchEvent(sky.Event event, HitTestResult result) {
assert(_appView == this);
super.dispatchEvent(event, result); super.dispatchEvent(event, result);
for (HitTestEntry entry in result.path.reversed) { for (HitTestEntry entry in result.path.reversed) {
UINode target = RenderObjectWrapper._getMounted(entry.target); UINode target = RenderObjectWrapper._getMounted(entry.target);
...@@ -1080,31 +1096,86 @@ class _AppView extends AppView { ...@@ -1080,31 +1096,86 @@ class _AppView extends AppView {
} }
abstract class App extends Component { abstract class AbstractUINodeRoot extends Component {
App() : super(stateful: true) { AbstractUINodeRoot() : super(stateful: true) {
_appView = new _AppView(); UINodeAppView.initUINodeAppView();
_scheduleComponentForRender(this);
_mounted = true; _mounted = true;
_scheduleComponentForRender(this);
} }
AppView _appView; void syncFields(AbstractUINodeRoot source) {
AppView get appView => _appView; assert(false);
// if we get here, it implies that we have a parent
}
void _buildIfDirty() { void _buildIfDirty() {
assert(_dirty); assert(_dirty);
assert(_mounted); assert(_mounted);
assert(parent == null);
_sync(null, null); _sync(null, null);
if (root.parent == null) }
_appView.root = root;
}
abstract class App extends AbstractUINodeRoot {
App();
AppView get appView => UINodeAppView._appView;
void _buildIfDirty() {
super._buildIfDirty();
if (root.parent == null) {
// we haven't attached it yet
UINodeAppView._appView.root = root;
}
assert(root.parent is RenderView); assert(root.parent is RenderView);
} }
} }
class Text extends Component { typedef UINode Builder();
Text(this.data) : super(key: '*text*');
final String data; class RenderNodeToUINodeAdapter extends AbstractUINodeRoot {
bool get interchangeable => true;
UINode build() => new Paragraph(text: data); RenderNodeToUINodeAdapter(
RenderObjectWithChildMixin<RenderBox> container,
this.builder
) : _container = container {
assert(builder != null);
}
RenderObjectWithChildMixin<RenderBox> _container;
RenderObjectWithChildMixin<RenderBox> get container => _container;
void set container(RenderObjectWithChildMixin<RenderBox> value) {
if (_container != value) {
assert(value.child == null);
if (root != null) {
assert(_container.child == root);
_container.child = null;
}
_container = value;
if (root != null) {
_container.child = root;
assert(_container.child == root);
}
}
}
final Builder builder;
void _buildIfDirty() {
super._buildIfDirty();
if (root.parent == null) {
// we haven't attached it yet
assert(_container.child == null);
_container.child = root;
}
assert(root.parent == _container);
}
UINode build() => builder();
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册