Commit 7dd26a7a authored by Adam Barth's avatar Adam Barth

Port some more examples to fn3

parent 9edd6550
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
import 'dart:sky' as sky; import 'dart:sky' as sky;
import 'package:sky/material.dart'; import 'package:sky/material.dart';
import 'package:sky/widgets.dart'; import 'package:sky/src/fn3.dart';
final double kTop = 10.0 + sky.view.paddingTop; final double kTop = 10.0 + sky.view.paddingTop;
final double kLeft = 10.0; final double kLeft = 10.0;
...@@ -17,10 +17,13 @@ class DragData { ...@@ -17,10 +17,13 @@ class DragData {
} }
class ExampleDragTarget extends StatefulComponent { class ExampleDragTarget extends StatefulComponent {
String _text = 'ready'; ExampleDragTargetState createState() => new ExampleDragTargetState(this);
}
void syncConstructorArguments(ExampleDragTarget source) { class ExampleDragTargetState extends ComponentState<ExampleDragTarget> {
} ExampleDragTargetState(ExampleDragTarget config) : super(config);
String _text = 'ready';
void _handleAccept(DragData data) { void _handleAccept(DragData data) {
setState(() { setState(() {
...@@ -28,10 +31,10 @@ class ExampleDragTarget extends StatefulComponent { ...@@ -28,10 +31,10 @@ class ExampleDragTarget extends StatefulComponent {
}); });
} }
Widget build() { Widget build(BuildContext context) {
return new DragTarget<DragData>( return new DragTarget<DragData>(
onAccept: _handleAccept, onAccept: _handleAccept,
builder: (List<DragData> data, _) { builder: (BuildContext context, List<DragData> data, _) {
return new Container( return new Container(
width: 100.0, width: 100.0,
height: 100.0, height: 100.0,
...@@ -52,8 +55,8 @@ class ExampleDragTarget extends StatefulComponent { ...@@ -52,8 +55,8 @@ class ExampleDragTarget extends StatefulComponent {
} }
} }
class Dot extends Component { class Dot extends StatelessComponent {
Widget build() { Widget build(BuildContext context) {
return new Container( return new Container(
width: 50.0, width: 50.0,
height: 50.0, height: 50.0,
...@@ -64,7 +67,13 @@ class Dot extends Component { ...@@ -64,7 +67,13 @@ class Dot extends Component {
} }
} }
class DragAndDropApp extends App { class DragAndDropApp extends StatefulComponent {
DragAndDropAppState createState() => new DragAndDropAppState(this);
}
class DragAndDropAppState extends ComponentState<DragAndDropApp> {
DragAndDropAppState(DragAndDropApp config) : super(config);
DragController _dragController; DragController _dragController;
Offset _displacement = Offset.zero; Offset _displacement = Offset.zero;
...@@ -99,7 +108,7 @@ class DragAndDropApp extends App { ...@@ -99,7 +108,7 @@ class DragAndDropApp extends App {
}); });
} }
Widget build() { Widget build(BuildContext context) {
List<Widget> layers = <Widget>[ List<Widget> layers = <Widget>[
new Row([ new Row([
new ExampleDragTarget(), new ExampleDragTarget(),
......
...@@ -2,14 +2,14 @@ ...@@ -2,14 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import 'package:sky/widgets.dart'; import 'package:sky/src/fn3.dart';
class Circle extends Component { class Circle extends StatelessComponent {
Circle({ this.margin: EdgeDims.zero }); Circle({ this.margin: EdgeDims.zero });
final EdgeDims margin; final EdgeDims margin;
Widget build() { Widget build(BuildContext context) {
return new Container( return new Container(
width: 50.0, width: 50.0,
margin: margin + new EdgeDims.symmetric(horizontal: 2.0), margin: margin + new EdgeDims.symmetric(horizontal: 2.0),
...@@ -21,8 +21,8 @@ class Circle extends Component { ...@@ -21,8 +21,8 @@ class Circle extends Component {
} }
} }
class HorizontalScrollingApp extends App { class HorizontalScrollingApp extends StatelessComponent {
Widget build() { Widget build(BuildContext context) {
List<Widget> circles = [ List<Widget> circles = [
new Circle(margin: new EdgeDims.only(left: 10.0)), new Circle(margin: new EdgeDims.only(left: 10.0)),
new Circle(), new Circle(),
...@@ -41,11 +41,7 @@ class HorizontalScrollingApp extends App { ...@@ -41,11 +41,7 @@ class HorizontalScrollingApp extends App {
return new Center( return new Center(
child: new Container( child: new Container(
height: 50.0, height: 50.0,
child: new Row([ child: new Block(circles, scrollDirection: ScrollDirection.horizontal)
new Block(circles, scrollDirection: ScrollDirection.horizontal)
],
justifyContent: FlexJustifyContent.end
)
) )
); );
} }
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import 'package:sky/widgets.dart'; import 'package:sky/src/fn3.dart';
List<Route> routes = [ List<Route> routes = [
new Route( new Route(
...@@ -60,21 +60,28 @@ List<Route> routes = [ ...@@ -60,21 +60,28 @@ List<Route> routes = [
) )
]; ];
class NavigationExampleApp extends App { class NavigationExampleApp extends StatefulComponent {
NavigationState _navState = new NavigationState(routes); NavigationExampleAppState createState() => new NavigationExampleAppState(this);
}
class NavigationExampleAppState extends ComponentState<NavigationExampleApp> {
NavigationExampleAppState(NavigationExampleApp config) : super(config);
NavigatorHistory _history = new NavigatorHistory(routes);
void onBack() { void onBack() {
if (_navState.hasPrevious()) { if (_history.hasPrevious()) {
setState(() { setState(() {
_navState.pop(); _history.pop();
}); });
} else { } else {
super.onBack(); // TODO(abarth): Integrate with the system navigator.
// super.onBack();
} }
} }
Widget build() { Widget build(BuildContext context) {
return new Row([new Navigator(_navState)]); return new Row([new Navigator(_history)]);
} }
} }
......
...@@ -4,7 +4,8 @@ ...@@ -4,7 +4,8 @@
import 'package:sky/animation.dart'; import 'package:sky/animation.dart';
import 'package:sky/material.dart'; import 'package:sky/material.dart';
import 'package:sky/widgets.dart'; import 'package:sky/painting.dart';
import 'package:sky/src/fn3.dart';
class CardModel { class CardModel {
CardModel(this.value, this.size, this.color); CardModel(this.value, this.size, this.color);
...@@ -15,17 +16,12 @@ class CardModel { ...@@ -15,17 +16,12 @@ class CardModel {
Key get key => new ObjectKey(this); Key get key => new ObjectKey(this);
} }
class PageableListApp extends App { class PageableListApp extends StatefulComponent {
PageableListAppState createState() => new PageableListAppState(this);
static const TextStyle cardLabelStyle = }
const TextStyle(color: Colors.white, fontSize: 18.0, fontWeight: bold);
List<CardModel> cardModels;
Size pageSize = new Size(200.0, 200.0);
ScrollDirection scrollDirection = ScrollDirection.horizontal;
bool itemsWrap = false;
void initState() { class PageableListAppState extends ComponentState<PageableListApp> {
PageableListAppState(PageableListApp config) : super(config) {
List<Size> cardSizes = [ List<Size> cardSizes = [
[100.0, 300.0], [300.0, 100.0], [200.0, 400.0], [400.0, 400.0], [300.0, 400.0] [100.0, 300.0], [300.0, 100.0], [200.0, 400.0], [400.0, 400.0], [300.0, 400.0]
] ]
...@@ -36,17 +32,23 @@ class PageableListApp extends App { ...@@ -36,17 +32,23 @@ class PageableListApp extends App {
Color color = Color.lerp(Colors.red[300], Colors.blue[900], i / cardSizes.length); Color color = Color.lerp(Colors.red[300], Colors.blue[900], i / cardSizes.length);
return new CardModel(i, cardSizes[i], color); return new CardModel(i, cardSizes[i], color);
}); });
super.initState();
} }
static const TextStyle cardLabelStyle =
const TextStyle(color: Colors.white, fontSize: 18.0, fontWeight: bold);
List<CardModel> cardModels;
Size pageSize = new Size(200.0, 200.0);
ScrollDirection scrollDirection = ScrollDirection.horizontal;
bool itemsWrap = false;
void updatePageSize(Size newSize) { void updatePageSize(Size newSize) {
setState(() { setState(() {
pageSize = newSize; pageSize = newSize;
}); });
} }
Widget buildCard(CardModel cardModel) { Widget buildCard(BuildContext context, CardModel cardModel) {
Widget card = new Card( Widget card = new Card(
color: cardModel.color, color: cardModel.color,
child: new Container( child: new Container(
...@@ -142,7 +144,7 @@ class PageableListApp extends App { ...@@ -142,7 +144,7 @@ class PageableListApp extends App {
); );
} }
Widget buildBody() { Widget buildBody(BuildContext context) {
Widget list = new PageableList<CardModel>( Widget list = new PageableList<CardModel>(
items: cardModels, items: cardModels,
itemsWrap: itemsWrap, itemsWrap: itemsWrap,
...@@ -156,12 +158,12 @@ class PageableListApp extends App { ...@@ -156,12 +158,12 @@ class PageableListApp extends App {
callback: updatePageSize, callback: updatePageSize,
child: new Container( child: new Container(
child: list, child: list,
decoration: new BoxDecoration(backgroundColor: Theme.of(this).primarySwatch[50]) decoration: new BoxDecoration(backgroundColor: Theme.of(context).primarySwatch[50])
) )
); );
} }
Widget build() { Widget build(BuildContext context) {
return new IconTheme( return new IconTheme(
data: const IconThemeData(color: IconThemeColor.white), data: const IconThemeData(color: IconThemeColor.white),
child: new Theme( child: new Theme(
...@@ -175,7 +177,7 @@ class PageableListApp extends App { ...@@ -175,7 +177,7 @@ class PageableListApp extends App {
child: new Scaffold( child: new Scaffold(
drawer: buildDrawer(), drawer: buildDrawer(),
toolbar: buildToolBar(), toolbar: buildToolBar(),
body: buildBody() body: buildBody(context)
) )
) )
) )
......
...@@ -7,7 +7,7 @@ import 'package:sky_services/media/media.mojom.dart'; ...@@ -7,7 +7,7 @@ import 'package:sky_services/media/media.mojom.dart';
import 'package:sky/material.dart'; import 'package:sky/material.dart';
import 'package:sky/rendering.dart'; import 'package:sky/rendering.dart';
import 'package:sky/services.dart'; import 'package:sky/services.dart';
import 'package:sky/widgets.dart'; import 'package:sky/src/fn3.dart';
// All of these sounds are marked as public domain at soundbible. // All of these sounds are marked as public domain at soundbible.
const String chimes = "http://soundbible.com/grab.php?id=2030&type=wav"; const String chimes = "http://soundbible.com/grab.php?id=2030&type=wav";
...@@ -38,7 +38,7 @@ class Key { ...@@ -38,7 +38,7 @@ class Key {
} }
} }
class PianoApp extends App { class PianoApp extends StatelessComponent {
final List<Key> keys = [ final List<Key> keys = [
new Key(Colors.red[500], chimes), new Key(Colors.red[500], chimes),
new Key(Colors.orange[500], chainsaw), new Key(Colors.orange[500], chainsaw),
...@@ -68,19 +68,19 @@ class PianoApp extends App { ...@@ -68,19 +68,19 @@ class PianoApp extends App {
// Are we leaking all the player connections? // Are we leaking all the player connections?
} }
Widget build() { Widget build(BuildContext context) {
List<Widget> children = []; List<Widget> children = [];
for (Key key in keys) { for (Key key in keys) {
children.add( children.add(
new Listener( new Flexible(
child: new Flexible( child: new Listener(
child: new Container( child: new Container(
decoration: new BoxDecoration(backgroundColor: key.color) decoration: new BoxDecoration(backgroundColor: key.color)
) ),
), onPointerCancel: (_) => key.up(),
onPointerCancel: (_) => key.up(), onPointerDown: (_) => key.down(),
onPointerDown: (_) => key.down(), onPointerUp: (_) => key.up()
onPointerUp: (_) => key.up() )
) )
); );
} }
......
...@@ -4,15 +4,14 @@ ...@@ -4,15 +4,14 @@
import 'package:sky/animation.dart'; import 'package:sky/animation.dart';
import 'package:sky/material.dart'; import 'package:sky/material.dart';
import 'package:sky/widgets.dart'; import 'package:sky/src/fn3.dart';
class ProgressIndicatorApp extends App { class ProgressIndicatorApp extends StatefulComponent {
ProgressIndicatorAppState createState() => new ProgressIndicatorAppState(this);
ValueAnimation<double> valueAnimation; }
Direction valueAnimationDirection = Direction.forward;
void initState() { class ProgressIndicatorAppState extends ComponentState<ProgressIndicatorApp> {
super.initState(); ProgressIndicatorAppState(ProgressIndicatorApp config) : super(config) {
valueAnimation = new ValueAnimation<double>() valueAnimation = new ValueAnimation<double>()
..duration = const Duration(milliseconds: 1500) ..duration = const Duration(milliseconds: 1500)
..variable = new AnimatedValue<double>( ..variable = new AnimatedValue<double>(
...@@ -29,6 +28,9 @@ class ProgressIndicatorApp extends App { ...@@ -29,6 +28,9 @@ class ProgressIndicatorApp extends App {
valueAnimation.play(valueAnimationDirection); valueAnimation.play(valueAnimationDirection);
} }
ValueAnimation<double> valueAnimation;
Direction valueAnimationDirection = Direction.forward;
void handleTap() { void handleTap() {
setState(() { setState(() {
// valueAnimation.isAnimating is part of our build state // valueAnimation.isAnimating is part of our build state
...@@ -46,7 +48,7 @@ class ProgressIndicatorApp extends App { ...@@ -46,7 +48,7 @@ class ProgressIndicatorApp extends App {
valueAnimation.play(valueAnimationDirection); valueAnimation.play(valueAnimationDirection);
} }
Widget buildIndicators() { Widget buildIndicators(BuildContext context) {
List<Widget> indicators = <Widget>[ List<Widget> indicators = <Widget>[
new SizedBox( new SizedBox(
width: 200.0, width: 200.0,
...@@ -76,12 +78,12 @@ class ProgressIndicatorApp extends App { ...@@ -76,12 +78,12 @@ class ProgressIndicatorApp extends App {
); );
} }
Widget build() { Widget build(BuildContext context) {
Widget body = new GestureDetector( Widget body = new GestureDetector(
onTap: handleTap, onTap: handleTap,
child: new Container( child: new Container(
padding: const EdgeDims.symmetric(vertical: 12.0, horizontal: 8.0), padding: const EdgeDims.symmetric(vertical: 12.0, horizontal: 8.0),
decoration: new BoxDecoration(backgroundColor: Theme.of(this).cardColor), decoration: new BoxDecoration(backgroundColor: Theme.of(context).cardColor),
child: new BuilderTransition( child: new BuilderTransition(
variables: [valueAnimation.variable], variables: [valueAnimation.variable],
performance: valueAnimation.view, performance: valueAnimation.view,
...@@ -103,7 +105,7 @@ class ProgressIndicatorApp extends App { ...@@ -103,7 +105,7 @@ class ProgressIndicatorApp extends App {
child: new Scaffold( child: new Scaffold(
toolbar: new ToolBar(center: new Text('Progress Indicators')), toolbar: new ToolBar(center: new Text('Progress Indicators')),
body: new DefaultTextStyle( body: new DefaultTextStyle(
style: Theme.of(this).text.title, style: Theme.of(context).text.title,
child: body child: body
) )
) )
......
...@@ -4,9 +4,17 @@ ...@@ -4,9 +4,17 @@
import 'package:sky/material.dart'; import 'package:sky/material.dart';
import 'package:sky/rendering.dart'; import 'package:sky/rendering.dart';
import 'package:sky/widgets.dart'; import 'package:sky/src/fn3.dart';
class ScaleApp extends App { class ScaleApp extends StatefulComponent {
ScaleAppState createState() => new ScaleAppState(this);
}
class ScaleAppState extends ComponentState<ScaleApp> {
ScaleAppState(ScaleApp config) : super(config) {
_offset = Offset.zero;
_zoom = 1.0;
}
Point _startingFocalPoint; Point _startingFocalPoint;
...@@ -16,11 +24,6 @@ class ScaleApp extends App { ...@@ -16,11 +24,6 @@ class ScaleApp extends App {
double _previousZoom; double _previousZoom;
double _zoom; double _zoom;
void initState() {
_offset = Offset.zero;
_zoom = 1.0;
}
void _handleScaleStart(Point focalPoint) { void _handleScaleStart(Point focalPoint) {
setState(() { setState(() {
_startingFocalPoint = focalPoint; _startingFocalPoint = focalPoint;
...@@ -48,7 +51,7 @@ class ScaleApp extends App { ...@@ -48,7 +51,7 @@ class ScaleApp extends App {
canvas.drawCircle(center, radius, paint); canvas.drawCircle(center, radius, paint);
} }
Widget build() { Widget build(BuildContext context) {
return new Theme( return new Theme(
data: new ThemeData.dark(), data: new ThemeData.dark(),
child: new Scaffold( child: new Scaffold(
......
...@@ -55,7 +55,9 @@ class GestureDetector extends StatefulComponent { ...@@ -55,7 +55,9 @@ class GestureDetector extends StatefulComponent {
} }
class GestureDetectorState extends ComponentState<GestureDetector> { class GestureDetectorState extends ComponentState<GestureDetector> {
GestureDetectorState(GestureDetector config) : super(config); GestureDetectorState(GestureDetector config) : super(config) {
didUpdateConfig(null);
}
final PointerRouter _router = SkyBinding.instance.pointerRouter; final PointerRouter _router = SkyBinding.instance.pointerRouter;
......
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