fn3: Add a binding for fn3 and sky.

- I extracted the BuildScheduler into a separate binding.dart file.
- Various changes to expose private members that are needed by
  binding.dart.
- Registering the render objects for event dispatch.
- Convert the tests to use the new binding mechanism.

This doesn't yet have a RenderView or event handling.
This commit is contained in:
Hixie
2015-09-22 12:29:41 -07:00
parent 8eb8c47a2d
commit b73b06e4ad
6 changed files with 178 additions and 83 deletions

View File

@@ -8,6 +8,12 @@ final BoxDecoration kBoxDecorationA = new BoxDecoration();
final BoxDecoration kBoxDecorationB = new BoxDecoration();
final BoxDecoration kBoxDecorationC = new BoxDecoration();
class TestComponent extends StatelessComponent {
const TestComponent({ this.child });
final Widget child;
Widget build() => child;
}
void main() {
test('RenderObjectWidget smoke test', () {
WidgetTester tester = new WidgetTester();

View File

@@ -78,7 +78,8 @@ void main() {
checkTree(kBoxDecorationB);
flipStatefulComponent(tester);
Element.flushBuild();
tester.pumpFrameWithoutChange();
checkTree(kBoxDecorationA);
@@ -105,7 +106,8 @@ void main() {
expect(TestBuildCounter.buildCount, equals(1));
flipStatefulComponent(tester);
Element.flushBuild();
tester.pumpFrameWithoutChange();
expect(TestBuildCounter.buildCount, equals(1));
});

View File

@@ -1,15 +1,34 @@
import 'package:sky/src/fn3/framework.dart';
import 'package:sky/src/fn3.dart';
class TestComponent extends StatelessComponent {
TestComponent({ this.child });
final Widget child;
class RootComponent extends StatefulComponent {
RootComponentState createState() => new RootComponentState(this);
}
class RootComponentState extends ComponentState<RootComponent> {
RootComponentState(RootComponent widget) : super(widget);
Widget _child = new DecoratedBox(decoration: new BoxDecoration());
Widget get child => _child;
void set child(Widget value) {
if (value != _child) {
setState(() {
_child = value;
});
}
}
Widget build() => child;
}
final Object _rootSlot = new Object();
const Object _rootSlot = const Object();
class WidgetTester {
StatelessComponentElement _rootElement;
WidgetTester() {
WidgetSkyBinding.initWidgetSkyBinding();
_rootElement = new StatefulComponentElement(new RootComponent());
_rootElement.mount(null, _rootSlot);
}
StatefulComponentElement _rootElement;
void walkElements(ElementVisitor visitor) {
void walk(Element element) {
@@ -35,12 +54,12 @@ class WidgetTester {
}
void pumpFrame(Widget widget) {
if (_rootElement == null) {
_rootElement = new StatelessComponentElement(new TestComponent(child: widget));
_rootElement.mount(null, _rootSlot);
} else {
_rootElement.update(new TestComponent(child: widget));
}
(_rootElement.state as RootComponentState).child = widget;
WidgetSkyBinding.instance.beginFrame(0.0); // TODO(ianh): https://github.com/flutter/engine/issues/1084
}
void pumpFrameWithoutChange() {
WidgetSkyBinding.instance.beginFrame(0.0); // TODO(ianh): https://github.com/flutter/engine/issues/1084
}
}