mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
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.
53 lines
1.3 KiB
Dart
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();
|
|
}
|
|
|
|
}
|