flutter_flutter/sdk/lib/widgets/animated_component.dart
Hixie c6f0b8447d Fork some more files from the old framework, so that the transition will be easier to perform.
Summary:
  framework/animation/* -> animation/*
  framework/debug/utils.dart -> debug/utils.dart
  framework/shell.dart -> mojo/shell.dart
  framework/embedder.dart -> mojo/embedder.dart
  framework/net/* -> mojo/net/*

This should have no code changes except fixing and reordering imports.

R=abarth@chromium.org

Review URL: https://codereview.chromium.org/1189943004.
2015-06-17 19:09:28 -07:00

53 lines
1.3 KiB
Dart

// 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:async';
import '../animation/animated_value.dart';
import 'basic.dart';
typedef void SetterFunction(double value);
class _AnimationEntry {
_AnimationEntry(this.value, this.setter);
final AnimatedValue value;
final SetterFunction setter;
StreamSubscription<double> subscription;
}
abstract class AnimatedComponent extends Component {
AnimatedComponent({ String key }) : super(key: key, stateful: true);
void syncFields(AnimatedComponent source) { }
List<_AnimationEntry> _animatedFields = new List<_AnimationEntry>();
animate(AnimatedValue value, SetterFunction setter) {
assert(!mounted);
setter(value.value);
_animatedFields.add(new _AnimationEntry(value, setter));
}
void didMount() {
for (_AnimationEntry entry in _animatedFields) {
entry.subscription = entry.value.onValueChanged.listen((_) {
entry.setter(entry.value.value);
scheduleBuild();
});
}
super.didMount();
}
void didUnmount() {
for (_AnimationEntry entry in _animatedFields) {
assert(entry.subscription != null);
entry.subscription.cancel();
entry.subscription = null;
}
super.didUnmount();
}
}