Commit 0d63d6b7 authored by Adam Barth's avatar Adam Barth

Port most of scrollable.dart to fn3

parent e7bc8f57
...@@ -8,7 +8,7 @@ import 'package:sky/rendering.dart'; ...@@ -8,7 +8,7 @@ import 'package:sky/rendering.dart';
import 'package:sky/src/fn3/framework.dart'; import 'package:sky/src/fn3/framework.dart';
import 'package:sky/src/fn3/basic.dart'; import 'package:sky/src/fn3/basic.dart';
typedef List<Widget> ListBuilder(int startIndex, int count, BuildContext context); typedef List<Widget> ListBuilder(BuildContext context, int startIndex, int count);
class HomogeneousViewport extends RenderObjectWidget { class HomogeneousViewport extends RenderObjectWidget {
HomogeneousViewport({ HomogeneousViewport({
...@@ -137,7 +137,7 @@ class HomogeneousViewportElement extends RenderObjectElement<HomogeneousViewport ...@@ -137,7 +137,7 @@ class HomogeneousViewportElement extends RenderObjectElement<HomogeneousViewport
assert(_layoutItemCount != null); assert(_layoutItemCount != null);
List<Widget> newWidgets; List<Widget> newWidgets;
if (_layoutItemCount > 0) if (_layoutItemCount > 0)
newWidgets = widget.builder(_layoutFirstIndex, _layoutItemCount, this); newWidgets = widget.builder(this, _layoutFirstIndex, _layoutItemCount);
else else
newWidgets = <Widget>[]; newWidgets = <Widget>[];
_children = updateChildren(_children, newWidgets); _children = updateChildren(_children, newWidgets);
......
This diff is collapsed.
import 'package:sky/rendering.dart';
import 'package:sky/src/fn3.dart'; import 'package:sky/src/fn3.dart';
import 'package:test/test.dart'; import 'package:test/test.dart';
...@@ -9,7 +10,6 @@ void main() { ...@@ -9,7 +10,6 @@ void main() {
Key keyA = new GlobalKey(); Key keyA = new GlobalKey();
Key keyB = new GlobalKey(); Key keyB = new GlobalKey();
Key keyC = new GlobalKey();
tester.pumpFrame( tester.pumpFrame(
new Stack([ new Stack([
...@@ -34,13 +34,13 @@ void main() { ...@@ -34,13 +34,13 @@ void main() {
]) ])
); );
expect(tester.findElementByKey(keyA).renderObject.localToGlobal(const Point(0.0, 0.0)), expect((tester.findElementByKey(keyA).renderObject as RenderBox).localToGlobal(const Point(0.0, 0.0)),
equals(const Point(100.0, 100.0))); equals(const Point(100.0, 100.0)));
expect(tester.findElementByKey(keyB).renderObject.localToGlobal(const Point(0.0, 0.0)), expect((tester.findElementByKey(keyB).renderObject as RenderBox).localToGlobal(const Point(0.0, 0.0)),
equals(const Point(100.0, 200.0))); equals(const Point(100.0, 200.0)));
expect(tester.findElementByKey(keyB).renderObject.globalToLocal(const Point(110.0, 205.0)), expect((tester.findElementByKey(keyB).renderObject as RenderBox).globalToLocal(const Point(110.0, 205.0)),
equals(const Point(10.0, 5.0))); equals(const Point(10.0, 5.0)));
}); });
} }
...@@ -33,7 +33,7 @@ void main() { ...@@ -33,7 +33,7 @@ void main() {
Widget builder() { Widget builder() {
return new TestComponent(new HomogeneousViewport( return new TestComponent(new HomogeneousViewport(
builder: (int start, int count, BuildContext context) { builder: (BuildContext context, int start, int count) {
List<Widget> result = <Widget>[]; List<Widget> result = <Widget>[];
for (int index = start; index < start + count; index += 1) { for (int index = start; index < start + count; index += 1) {
callbackTracker.add(index); callbackTracker.add(index);
...@@ -52,18 +52,19 @@ void main() { ...@@ -52,18 +52,19 @@ void main() {
tester.pumpFrame(builder()); tester.pumpFrame(builder());
TestComponentState testComponent = tester.findElement((element) => element.widget is TestComponent).state; StatefulComponentElement testComponent = tester.findElement((element) => element.widget is TestComponent);
TestComponentState testComponentState = testComponent.state;
expect(callbackTracker, equals([0, 1, 2, 3, 4, 5])); expect(callbackTracker, equals([0, 1, 2, 3, 4, 5]));
callbackTracker.clear(); callbackTracker.clear();
testComponent.go(false); testComponentState.go(false);
tester.pumpFrameWithoutChange(); tester.pumpFrameWithoutChange();
expect(callbackTracker, equals([])); expect(callbackTracker, equals([]));
callbackTracker.clear(); callbackTracker.clear();
testComponent.go(true); testComponentState.go(true);
tester.pumpFrameWithoutChange(); tester.pumpFrameWithoutChange();
expect(callbackTracker, equals([0, 1, 2, 3, 4, 5])); expect(callbackTracker, equals([0, 1, 2, 3, 4, 5]));
...@@ -80,7 +81,7 @@ void main() { ...@@ -80,7 +81,7 @@ void main() {
double offset = 300.0; double offset = 300.0;
ListBuilder itemBuilder = (int start, int count, BuildContext context) { ListBuilder itemBuilder = (BuildContext context, int start, int count) {
List<Widget> result = <Widget>[]; List<Widget> result = <Widget>[];
for (int index = start; index < start + count; index += 1) { for (int index = start; index < start + count; index += 1) {
callbackTracker.add(index); callbackTracker.add(index);
...@@ -130,7 +131,7 @@ void main() { ...@@ -130,7 +131,7 @@ void main() {
double offset = 300.0; double offset = 300.0;
ListBuilder itemBuilder = (int start, int count, BuildContext context) { ListBuilder itemBuilder = (BuildContext context, int start, int count) {
List<Widget> result = <Widget>[]; List<Widget> result = <Widget>[];
for (int index = start; index < start + count; index += 1) { for (int index = start; index < start + count; index += 1) {
callbackTracker.add(index); callbackTracker.add(index);
......
import 'package:quiver/testing/async.dart';
import 'package:sky/widgets.dart'; import 'package:sky/widgets.dart';
import 'package:test/test.dart'; import 'package:test/test.dart';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment