Commit 67f97b45 authored by Adam Barth's avatar Adam Barth Committed by GitHub

Remove ChildView widget (#6195)

This widget now lives in Mozart:

https://fuchsia.googlesource.com/mozart/+/master/lib/flutter/child_view.dart
parent 8071a82d
// Copyright 2015 The Chromium Authors. All rights reserved.
// 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 'package:flutter/material.dart';
class LauncherData {
const LauncherData({ this.url, this.title });
final String url;
final String title;
}
final List<LauncherData> _kLauncherData = <LauncherData>[
const LauncherData(
url: 'mojo:noodles_view',
title: 'Noodles'
),
const LauncherData(
url: 'mojo:shapes_view',
title: 'Shapes'
),
new LauncherData(
url: Uri.base.resolve('../../../examples/stocks/build/app.flx').toString(),
title: 'Stocks'
),
];
const Size _kInitialWindowSize = const Size(200.0, 200.0);
const double _kWindowPadding = 10.0;
enum WindowSide {
topCenter,
topRight,
bottomRight,
}
class WindowDecoration extends StatelessWidget {
WindowDecoration({
Key key,
this.side,
this.color,
this.onTap,
this.onPanUpdate
}) : super(key: key);
final WindowSide side;
final Color color;
final GestureTapCallback onTap;
final GestureDragUpdateCallback onPanUpdate;
@override
Widget build(BuildContext context) {
double top, right, bottom, left, width, height;
height = _kWindowPadding * 2.0;
if (side == WindowSide.topCenter || side == WindowSide.topRight)
top = 0.0;
if (side == WindowSide.topRight || side == WindowSide.bottomRight) {
right = 0.0;
width = _kWindowPadding * 2.0;
}
if (side == WindowSide.topCenter) {
left = _kWindowPadding;
right = _kWindowPadding;
}
if (side == WindowSide.bottomRight)
bottom = 0.0;
return new Positioned(
top: top,
right: right,
bottom: bottom,
left: left,
width: width,
height: height,
child: new GestureDetector(
onTap: onTap,
onPanUpdate: onPanUpdate,
child: new Container(
decoration: new BoxDecoration(
backgroundColor: color
)
)
)
);
}
}
class Window extends StatefulWidget {
Window({ Key key, this.child, this.onClose }) : super(key: key);
final ChildViewConnection child;
final ValueChanged<ChildViewConnection> onClose;
@override
_WindowState createState() => new _WindowState();
}
class _WindowState extends State<Window> {
Offset _offset = Offset.zero;
Size _size = _kInitialWindowSize;
void _handleResizerDrag(DragUpdateDetails details) {
setState(() {
_size = new Size(
math.max(0.0, _size.width + details.delta.dx),
math.max(0.0, _size.height + details.delta.dy)
);
});
}
void _handleRepositionDrag(DragUpdateDetails details) {
setState(() {
_offset += details.delta;
});
}
void _handleClose() {
config.onClose(config.child);
}
@override
Widget build(BuildContext context) {
return new Positioned(
left: _offset.dx,
top: _offset.dy,
width: _size.width + _kWindowPadding * 2.0,
height: _size.height + _kWindowPadding * 2.0,
child: new Stack(
children: <Widget>[
new WindowDecoration(
side: WindowSide.topCenter,
onPanUpdate: _handleRepositionDrag,
color: Colors.green[200]
),
new WindowDecoration(
side: WindowSide.topRight,
onTap: _handleClose,
color: Colors.red[200]
),
new WindowDecoration(
side: WindowSide.bottomRight,
onPanUpdate: _handleResizerDrag,
color: Colors.blue[200]
),
new Container(
padding: const EdgeInsets.all(_kWindowPadding),
child: new Material(
elevation: 8,
child: new ChildView(child: config.child)
)
)
]
)
);
}
}
class LauncherItem extends StatelessWidget {
LauncherItem({
Key key,
this.url,
this.child,
this.onLaunch
}) : super(key: key);
final String url;
final Widget child;
final ValueChanged<ChildViewConnection> onLaunch;
@override
Widget build(BuildContext context) {
return new RaisedButton(
onPressed: () { onLaunch(new ChildViewConnection(url: url)); },
child: child
);
}
}
class Launcher extends StatelessWidget {
Launcher({ Key key, this.items }) : super(key: key);
final List<Widget> items;
@override
Widget build(BuildContext context) {
return new ButtonBar(
alignment: MainAxisAlignment.center,
children: items
);
}
}
class WindowManager extends StatefulWidget {
@override
_WindowManagerState createState() => new _WindowManagerState();
}
class _WindowManagerState extends State<WindowManager> {
List<ChildViewConnection> _windows = <ChildViewConnection>[];
void _handleLaunch(ChildViewConnection child) {
setState(() {
_windows.add(child);
});
}
void _handleClose(ChildViewConnection child) {
setState(() {
_windows.remove(child);
});
}
@override
Widget build(BuildContext context) {
return new Material(
child: new Stack(
children: <Widget>[
new Positioned(
left: 0.0,
right: 0.0,
bottom: 0.0,
child: new Launcher(items: _kLauncherData.map((LauncherData data) {
return new LauncherItem(
url: data.url,
onLaunch: _handleLaunch,
child: new Text(data.title)
);
}).toList())
)
]..addAll(_windows.map((ChildViewConnection child) {
return new Window(
key: new ObjectKey(child),
onClose: _handleClose,
child: child
);
}))
)
);
}
}
void main() {
runApp(new MaterialApp(
title: 'Mozart',
home: new WindowManager()
));
}
......@@ -27,7 +27,6 @@ export 'src/rendering/auto_layout.dart';
export 'src/rendering/binding.dart';
export 'src/rendering/block.dart';
export 'src/rendering/box.dart';
export 'src/rendering/child_view.dart';
export 'src/rendering/custom_layout.dart';
export 'src/rendering/debug.dart';
export 'src/rendering/editable_line.dart';
......
This diff is collapsed.
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/rendering.dart';
import 'framework.dart';
import 'media_query.dart';
export 'package:flutter/rendering.dart' show ChildViewConnection;
/// (mojo-only) A widget that is replaced by content from another process.
///
/// Requires a [MediaQuery] ancestor to provide appropriate media information to
/// the child.
class ChildView extends StatelessWidget {
/// Creates a widget that is replaced by content from another process.
ChildView({ Key key, this.child }) : super(key: key);
/// A connection to the child whose content will replace this widget.
final ChildViewConnection child;
@override
Widget build(BuildContext context) {
return new _ChildViewWidget(
child: child,
scale: MediaQuery.of(context).devicePixelRatio
);
}
}
class _ChildViewWidget extends LeafRenderObjectWidget {
_ChildViewWidget({
ChildViewConnection child,
this.scale
}) : child = child, super(key: new GlobalObjectKey(child)) {
assert(scale != null);
}
final ChildViewConnection child;
final double scale;
@override
RenderChildView createRenderObject(BuildContext context) => new RenderChildView(child: child, scale: scale);
@override
void updateRenderObject(BuildContext context, RenderChildView renderObject) {
renderObject
..child = child
..scale = scale;
}
}
......@@ -15,7 +15,6 @@ export 'src/widgets/auto_layout.dart';
export 'src/widgets/banner.dart';
export 'src/widgets/basic.dart';
export 'src/widgets/binding.dart';
export 'src/widgets/child_view.dart';
export 'src/widgets/clamp_overscrolls.dart';
export 'src/widgets/container.dart';
export 'src/widgets/debug.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