浏览代码

upgrade scaffold

/siyaoH-1.17-PlatformMessage
xingweizhu 4 年前
当前提交
cc497058
共有 3 个文件被更改,包括 569 次插入209 次删除
  1. 416
      com.unity.uiwidgets/Runtime/material/scaffold.cs
  2. 360
      com.unity.uiwidgets/Runtime/widgets/draggable_scrollable_sheet.cs
  3. 2
      com.unity.uiwidgets/Runtime/widgets/scroll_position_with_single_context.cs

416
com.unity.uiwidgets/Runtime/material/scaffold.cs


using Unity.UIWidgets.async2;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.gestures;
using Unity.UIWidgets.material;
using Unity.UIWidgets.painting;
using Unity.UIWidgets.rendering;
using Unity.UIWidgets.scheduler2;

}
public class ScaffoldFeatureController<T, U> where T : Widget {
public ScaffoldFeatureController(
T _widget,
Completer _completer,
VoidCallback close,
StateSetter setState) {
this._widget = _widget;
this._completer = _completer;
this.close = close;
this.setState = setState;
}
public class ScaffoldFeatureController<T, U> where T : Widget {
public ScaffoldFeatureController(
T _widget,
Completer _completer,
VoidCallback close,
StateSetter setState) {
this._widget = _widget;
this._completer = _completer;
this.close = close;
this.setState = setState;
}
public readonly T _widget;
public readonly T _widget;
public readonly Completer _completer;
public readonly Completer _completer;
public Completer closed {
get { return _completer; }
public Completer closed {
get { return _completer; }
}
public readonly VoidCallback close;
public readonly StateSetter setState;
public readonly VoidCallback close;
class _BottomSheetSuspendedCurve : ParametricCurve<float> {
public _BottomSheetSuspendedCurve(
float startingPoint,
Curve curve = null
) {
curve = curve ?? Curves.easeOutCubic;
this.startingPoint = startingPoint;
this.curve = curve;
}
public readonly StateSetter setState;
}
public readonly float startingPoint;
class _BottomSheetSuspendedCurve : ParametricCurve<float> {
public _BottomSheetSuspendedCurve(
float startingPoint,
Curve curve = null
) {
curve = curve ?? Curves.easeOutCubic;
this.startingPoint = startingPoint;
this.curve = curve;
}
public readonly float startingPoint;
public readonly Curve curve;
public readonly Curve curve;
public override float transform(float t) {
D.assert(t >= 0.0f && t <= 1.0f);
D.assert(startingPoint >= 0.0 && startingPoint <= 1.0);
public override float transform(float t) {
D.assert(t >= 0.0f && t <= 1.0f);
D.assert(startingPoint >= 0.0 && startingPoint <= 1.0);
if (t < startingPoint) {
return t;
}
if (t < startingPoint) {
return t;
}
if (t == 1.0f) {
return t;
if (t == 1.0f) {
return t;
}
float curveProgress = (t - startingPoint) / (1 - startingPoint);
float transformed = curve.transform(curveProgress);
return Mathf.Lerp(startingPoint, 1, transformed);
float curveProgress = (t - startingPoint) / (1 - startingPoint);
float transformed = curve.transform(curveProgress);
return Mathf.Lerp(startingPoint, 1, transformed);
public override string ToString() {
return $"{foundation_.describeIdentity(this)}({startingPoint}, {curve})";
}
public override string ToString() {
return $"{foundation_.describeIdentity(this)}({startingPoint}, {curve})";
}
}
public class _StandardBottomSheet : StatefulWidget {
public _StandardBottomSheet(
Key key = null,
AnimationController animationController = null,
bool enableDrag = true,
VoidCallback onClosing = null,
VoidCallback onDismissed = null,
WidgetBuilder builder = null,
bool isPersistent = false,
Color backgroundColor = null,
float? elevation = null,
ShapeBorder shape = null,
Clip? clipBehavior = null
) : base(key: key) {
this.animationController = animationController;
this.enableDrag = enableDrag;
this.onClosing = onClosing;
this.onDismissed = onDismissed;
this.builder = builder;
this.isPersistent = isPersistent;
this.backgroundColor = backgroundColor;
this.elevation = elevation;
this.shape = shape;
this.clipBehavior = clipBehavior;
}
public class _StandardBottomSheet : StatefulWidget {
public _StandardBottomSheet(
Key key = null,
AnimationController animationController = null,
bool enableDrag = true,
VoidCallback onClosing = null,
VoidCallback onDismissed = null,
WidgetBuilder builder = null,
bool isPersistent = false,
Color backgroundColor = null,
float? elevation = null,
ShapeBorder shape = null,
Clip? clipBehavior = null
) : base ( key: key ) {
this.animationController = animationController;
this.enableDrag = enableDrag;
this.onClosing = onClosing;
this.onDismissed = onDismissed;
this.builder = builder;
this.isPersistent = isPersistent;
this.backgroundColor = backgroundColor;
this.elevation = elevation;
this.shape = shape;
this.clipBehavior = clipBehavior;
public readonly AnimationController animationController;
public readonly bool enableDrag;
public readonly VoidCallback onClosing;
public readonly VoidCallback onDismissed;
public readonly WidgetBuilder builder;
public readonly bool isPersistent;
public readonly Color backgroundColor;
public readonly float? elevation;
public readonly ShapeBorder shape;
public readonly Clip? clipBehavior;
public override State createState() {
return new _StandardBottomSheetState();
}
public readonly AnimationController animationController;
public readonly bool enableDrag;
public readonly VoidCallback onClosing;
public readonly VoidCallback onDismissed;
public readonly WidgetBuilder builder;
public readonly bool isPersistent;
public readonly Color backgroundColor;
public readonly float? elevation;
public readonly ShapeBorder shape;
public readonly Clip? clipBehavior;
public override State createState() => new _StandardBottomSheetState();
}
class _StandardBottomSheetState : State<_StandardBottomSheet> {
ParametricCurve<float> animationCurve = ScaffoldUtils._standardBottomSheetCurve;
public override void initState() {
base.initState();
D.assert(widget.animationController != null);
D.assert(widget.animationController.status == AnimationStatus.forward
|| widget.animationController.status == AnimationStatus.completed);
widget.animationController.addStatusListener(_handleStatusChange);
}
class _StandardBottomSheetState : State<_StandardBottomSheet> {
ParametricCurve<float> animationCurve = ScaffoldUtils._standardBottomSheetCurve;
public override void initState() {
base.initState();
D.assert(widget.animationController != null);
D.assert(widget.animationController.status == AnimationStatus.forward
|| widget.animationController.status == AnimationStatus.completed);
widget.animationController.addStatusListener(_handleStatusChange);
}
public override void didUpdateWidget(StatefulWidget oldWidget) {
base.didUpdateWidget(oldWidget);
_StandardBottomSheet _oldWidget = (_StandardBottomSheet) oldWidget;
D.assert(widget.animationController == _oldWidget.animationController);
}
public override void didUpdateWidget(StatefulWidget oldWidget) {
base.didUpdateWidget(oldWidget);
_StandardBottomSheet _oldWidget = (_StandardBottomSheet) oldWidget;
D.assert(widget.animationController == _oldWidget.animationController);
}
public Future close() {
D.assert(widget.animationController != null);
widget.animationController.reverse();
if (widget.onClosing != null) {
widget.onClosing();
}
public Future close() {
D.assert(widget.animationController != null);
widget.animationController.reverse();
if (widget.onClosing != null) {
widget.onClosing();
return null;
return null;
}
void _handleDragStart(DragStartDetails details) {
animationCurve = Curves.linear;
}
void _handleDragEnd(DragEndDetails details, bool? isClosing = null) {
// Allow the bottom sheet to animate smoothly from its current position.
animationCurve = new _BottomSheetSuspendedCurve(
widget.animationController.value,
curve: ScaffoldUtils._standardBottomSheetCurve
);
}
void _handleDragStart(DragStartDetails details) {
animationCurve = Curves.linear;
}
void _handleStatusChange(AnimationStatus status) {
if (status == AnimationStatus.dismissed && widget.onDismissed != null) {
widget.onDismissed();
void _handleDragEnd(DragEndDetails details, bool? isClosing = null) {
// Allow the bottom sheet to animate smoothly from its current position.
animationCurve = new _BottomSheetSuspendedCurve(
widget.animationController.value,
curve: ScaffoldUtils._standardBottomSheetCurve
);
}
bool extentChanged(DraggableScrollableNotification notification) {
float extentRemaining = 1.0f - notification.extent;
ScaffoldState scaffold = Scaffold.of(context);
if (extentRemaining < ScaffoldUtils._kBottomSheetDominatesPercentage) {
scaffold._floatingActionButtonVisibilityValue = extentRemaining * ScaffoldUtils._kBottomSheetDominatesPercentage * 10;
scaffold.showBodyScrim(true, Mathf.Max(
ScaffoldUtils._kMinBottomSheetScrimOpacity,
ScaffoldUtils._kMaxBottomSheetScrimOpacity - scaffold._floatingActionButtonVisibilityValue
));
} else {
scaffold._floatingActionButtonVisibilityValue = 1.0f;
scaffold.showBodyScrim(false, 0.0f);
void _handleStatusChange(AnimationStatus status) {
if (status == AnimationStatus.dismissed && widget.onDismissed != null) {
widget.onDismissed();
}
if (notification.extent == notification.minExtent && scaffold.widget.bottomSheet == null) {
close();
bool extentChanged(DraggableScrollableNotification notification) {
float extentRemaining = 1.0f - notification.extent;
ScaffoldState scaffold = Scaffold.of(context);
if (extentRemaining < ScaffoldUtils._kBottomSheetDominatesPercentage) {
scaffold._floatingActionButtonVisibilityValue =
extentRemaining * ScaffoldUtils._kBottomSheetDominatesPercentage * 10;
scaffold.showBodyScrim(true, Mathf.Max(
ScaffoldUtils._kMinBottomSheetScrimOpacity,
ScaffoldUtils._kMaxBottomSheetScrimOpacity - scaffold._floatingActionButtonVisibilityValue
));
}
else {
scaffold._floatingActionButtonVisibilityValue = 1.0f;
scaffold.showBodyScrim(false, 0.0f);
}
if (notification.extent == notification.minExtent && scaffold.widget.bottomSheet == null) {
close();
}
return false;
return false;
}
Widget _wrapBottomSheet(Widget bottomSheet) {
return new NotificationListener<DraggableScrollableNotification>(
Widget _wrapBottomSheet(Widget bottomSheet) {
return new NotificationListener<DraggableScrollableNotification>(
);
}
);
}
public override Widget build(BuildContext context) {
if (widget.animationController != null) {
return new AnimatedBuilder(
animation: widget.animationController,
builder: (BuildContext subContext, Widget subChild) => {
return new Align(
alignment: AlignmentDirectional.topStart,
heightFactor: animationCurve.transform(widget.animationController.value),
child: subChild
);
},
child: _wrapBottomSheet(
new BottomSheet(
animationController: widget.animationController,
enableDrag: widget.enableDrag,
onDragStart: _handleDragStart,
onDragEnd: _handleDragEnd,
onClosing: widget.onClosing,
builder: widget.builder,
backgroundColor: widget.backgroundColor,
elevation: widget.elevation,
shape: widget.shape,
clipBehavior: widget.clipBehavior
public override Widget build(BuildContext context) {
if (widget.animationController != null) {
return new AnimatedBuilder(
animation: widget.animationController,
builder: (BuildContext subContext, Widget subChild) => {
return new Align(
alignment: AlignmentDirectional.topStart,
heightFactor: animationCurve.transform(widget.animationController.value),
child: subChild
);
},
child: _wrapBottomSheet(
new BottomSheet(
animationController: widget.animationController,
enableDrag: widget.enableDrag,
onDragStart: _handleDragStart,
onDragEnd: _handleDragEnd,
onClosing: widget.onClosing,
builder: widget.builder,
backgroundColor: widget.backgroundColor,
elevation: widget.elevation,
shape: widget.shape,
clipBehavior: widget.clipBehavior
)
)
}
return _wrapBottomSheet(
new BottomSheet(
onClosing: widget.onClosing,
builder: widget.builder,
backgroundColor: widget.backgroundColor
)
);
return _wrapBottomSheet(
new BottomSheet(
onClosing: widget.onClosing,
builder: widget.builder,
backgroundColor: widget.backgroundColor
)
);
}
public class PersistentBottomSheetController<T> : ScaffoldFeatureController<_StandardBottomSheet, T> {
public PersistentBottomSheetController(
_StandardBottomSheet widget,
Completer completer,
VoidCallback close,
StateSetter setState,
bool _isLocalHistoryEntry
) : base(widget, completer, close, setState) {
this._isLocalHistoryEntry = _isLocalHistoryEntry;
public class PersistentBottomSheetController<T> : ScaffoldFeatureController<_StandardBottomSheet, T> {
public PersistentBottomSheetController(
_StandardBottomSheet widget,
Completer completer,
VoidCallback close,
StateSetter setState,
bool _isLocalHistoryEntry
) : base(widget, completer, close, setState) {
this._isLocalHistoryEntry = _isLocalHistoryEntry;
}
public readonly bool _isLocalHistoryEntry;
public readonly bool _isLocalHistoryEntry;
}
class _ScaffoldScope : InheritedWidget {
public _ScaffoldScope(
Key key = null,
bool? hasDrawer = null,
_ScaffoldGeometryNotifier geometryNotifier = null,
Widget child = null
) : base(key: key, child: child) {
D.assert(hasDrawer != null);
this.hasDrawer = hasDrawer.Value;
this.geometryNotifier = geometryNotifier;
}
class _ScaffoldScope : InheritedWidget {
public _ScaffoldScope(
Key key = null,
bool? hasDrawer = null,
_ScaffoldGeometryNotifier geometryNotifier = null,
Widget child = null
) : base(key: key, child: child) {
D.assert(hasDrawer != null);
this.hasDrawer = hasDrawer.Value;
this.geometryNotifier = geometryNotifier;
}
public readonly bool hasDrawer;
public readonly _ScaffoldGeometryNotifier geometryNotifier;
public readonly bool hasDrawer;
public readonly _ScaffoldGeometryNotifier geometryNotifier;
public override bool updateShouldNotify(InheritedWidget oldWidget) {
_ScaffoldScope _oldWidget = (_ScaffoldScope) oldWidget;
return hasDrawer != _oldWidget.hasDrawer;
public override bool updateShouldNotify(InheritedWidget oldWidget) {
_ScaffoldScope _oldWidget = (_ScaffoldScope) oldWidget;
return hasDrawer != _oldWidget.hasDrawer;
}
}
}

360
com.unity.uiwidgets/Runtime/widgets/draggable_scrollable_sheet.cs


using System;
using System.Collections.Generic;
using Unity.UIWidgets.animation;
using Unity.UIWidgets.gestures;
using Unity.UIWidgets.painting;
using Unity.UIWidgets.physics;
using Unity.UIWidgets.rendering;
using Unity.UIWidgets.ui;
// TODO: complete this file
public delegate Widget ScrollableWidgetBuilder(
BuildContext context,
ScrollController scrollController
);
public class DraggableScrollableSheet : StatefulWidget {
public DraggableScrollableSheet(
Key key = null,
float initialChildSize = 0.5f,
float minChildSize = 0.25f,
bool expand = true,
ScrollableWidgetBuilder builder = null
) : base(key: key) {
D.assert(builder != null);
this.initialChildSize = initialChildSize;
this.minChildSize = minChildSize;
this.expand = expand;
this.builder = builder;
}
public readonly float initialChildSize;
public readonly float minChildSize;
public readonly float maxChildSize;
public readonly bool expand;
public readonly ScrollableWidgetBuilder builder;
public override State createState() {
return new _DraggableScrollableSheetState();
}
}
public class DraggableScrollableNotification : ViewportNotificationMixinNotification {
public DraggableScrollableNotification(
float extent,

D.assert(extent <= maxExtent);
D.assert(initialExtent <= maxExtent);
D.assert(context != null);
this.extent = extent;
this.minExtent = minExtent;
this.maxExtent = maxExtent;
this.initialExtent = initialExtent;
this.context = context;
}
public readonly float extent;

public readonly BuildContext context;
protected override void debugFillDescription(List<String> description) {
protected override void debugFillDescription(List<string> description) {
}
}
class _DraggableSheetExtent {
public _DraggableSheetExtent(
float minExtent,
float maxExtent,
float initialExtent,
VoidCallback listener
) {
D.assert(minExtent >= 0);
D.assert(maxExtent <= 1);
D.assert(minExtent <= initialExtent);
D.assert(initialExtent <= maxExtent);
this.minExtent = minExtent;
this.maxExtent = maxExtent;
this.initialExtent = initialExtent;
_currentExtent = new ValueNotifier<float>(initialExtent);
_currentExtent.addListener(listener);
availablePixels = float.PositiveInfinity;
}
float minExtent;
float maxExtent;
internal float initialExtent;
internal ValueNotifier<float> _currentExtent;
internal float availablePixels;
public bool isAtMin {
get { return minExtent >= _currentExtent.value; }
}
public bool isAtMax {
get { return maxExtent <= _currentExtent.value; }
}
public float currentExtent {
get { return _currentExtent.value; }
set { _currentExtent.value = value.clamp(minExtent, maxExtent); }
}
public float additionalMinExtent {
get { return isAtMin ? 0.0f : 1.0f; }
}
public float additionalMaxExtent {
get { return isAtMax ? 0.0f : 1.0f; }
}
public void addPixelDelta(float delta, BuildContext context) {
if (availablePixels == 0) {
return;
}
currentExtent += delta / availablePixels * maxExtent;
new DraggableScrollableNotification(
minExtent: minExtent,
maxExtent: maxExtent,
extent: currentExtent,
initialExtent: initialExtent,
context: context
).dispatch(context);
}
}
class _DraggableScrollableSheetState : State<DraggableScrollableSheet> {
_DraggableScrollableSheetScrollController _scrollController;
_DraggableSheetExtent _extent;
public override void initState() {
base.initState();
_extent = new _DraggableSheetExtent(
minExtent: widget.minChildSize,
maxExtent: widget.maxChildSize,
initialExtent: widget.initialChildSize,
listener: _setExtent
);
_scrollController = new _DraggableScrollableSheetScrollController(extent: _extent);
}
public override void didChangeDependencies() {
base.didChangeDependencies();
if (_InheritedResetNotifier.shouldReset(context)) {
if (_scrollController.offset != 0.0f) {
_scrollController.animateTo(
0.0f,
duration: new TimeSpan(0, 0, 0, 0, 1),
curve: Curves.linear
);
}
_extent._currentExtent.value = _extent.initialExtent;
}
}
void _setExtent() {
setState(() => { });
}
public override Widget build(BuildContext context) {
return new LayoutBuilder(
builder: (BuildContext subContext, BoxConstraints subConstraints) => {
_extent.availablePixels = widget.maxChildSize * subConstraints.biggest.height;
Widget sheet = new FractionallySizedBox(
heightFactor: _extent.currentExtent,
child: widget.builder(subContext, _scrollController),
alignment: Alignment.bottomCenter
);
return widget.expand ? SizedBox.expand(child: sheet) : sheet;
}
);
}
public override void dispose() {
_scrollController.dispose();
base.dispose();
}
}
class _DraggableScrollableSheetScrollController : ScrollController {
public _DraggableScrollableSheetScrollController(
float initialScrollOffset = 0.0f,
string debugLabel = null,
_DraggableSheetExtent extent = null
) : base(debugLabel: debugLabel, initialScrollOffset: initialScrollOffset) {
D.assert(extent != null);
this.extent = extent;
}
public readonly _DraggableSheetExtent extent;
public override ScrollPosition createScrollPosition(
ScrollPhysics physics,
ScrollContext context,
ScrollPosition oldPosition
) {
return new _DraggableScrollableSheetScrollPosition(
physics: physics,
context: context,
oldPosition: oldPosition,
extent: extent
);
}
protected override void debugFillDescription(List<string> description) {
base.debugFillDescription(description);
description.Add($"extent: {extent}");
}
}
class _DraggableScrollableSheetScrollPosition : ScrollPositionWithSingleContext {
public _DraggableScrollableSheetScrollPosition(
ScrollPhysics physics = null,
ScrollContext context = null,
float initialPixels = 0.0f,
bool keepScrollOffset = true,
ScrollPosition oldPosition = null,
string debugLabel = null,
_DraggableSheetExtent extent = null
) : base(physics: physics,
context: context,
initialPixels: initialPixels,
keepScrollOffset: keepScrollOffset,
oldPosition: oldPosition,
debugLabel: debugLabel) {
D.assert(extent != null);
this.extent = extent;
}
VoidCallback _dragCancelCallback;
public readonly _DraggableSheetExtent extent;
bool listShouldScroll {
get { return pixels > 0.0f; }
}
public override bool applyContentDimensions(float minScrollExtent, float maxScrollExtent) {
return base.applyContentDimensions(
minScrollExtent - extent.additionalMinExtent,
maxScrollExtent + extent.additionalMaxExtent
);
}
public override void applyUserOffset(float delta) {
if (!listShouldScroll &&
(!(extent.isAtMin || extent.isAtMax) ||
(extent.isAtMin && delta < 0) ||
(extent.isAtMax && delta > 0))) {
extent.addPixelDelta(-delta, context.notificationContext);
}
else {
base.applyUserOffset(delta);
}
}
public override void goBallistic(float velocity) {
if (velocity == 0.0f ||
(velocity < 0.0f && listShouldScroll) ||
(velocity > 0.0f && extent.isAtMax)) {
base.goBallistic(velocity);
return;
}
_dragCancelCallback?.Invoke();
_dragCancelCallback = null;
Simulation simulation = new ClampingScrollSimulation(
position: extent.currentExtent,
velocity: velocity,
tolerance: physics.tolerance
);
AnimationController ballisticController = AnimationController.unbounded(
debugLabel: $"{GetType()}",
vsync: context.vsync
);
float lastDelta = 0;
void _tick() {
float delta = ballisticController.value - lastDelta;
lastDelta = ballisticController.value;
extent.addPixelDelta(delta, context.notificationContext);
if ((velocity > 0 && extent.isAtMax) || (velocity < 0 && extent.isAtMin)) {
velocity = ballisticController.velocity +
(physics.tolerance.velocity * ballisticController.velocity.sign());
base.goBallistic(velocity);
ballisticController.stop();
}
else if (ballisticController.isCompleted) {
base.goBallistic(0);
}
}
ballisticController.addListener(_tick);
ballisticController.animateWith(simulation).whenCompleteOrCancel(
ballisticController.dispose
);
}
public override Drag drag(DragStartDetails details, VoidCallback dragCancelCallback) {
_dragCancelCallback = dragCancelCallback;
return base.drag(details, dragCancelCallback);
}
}
public class DraggableScrollableActuator : StatelessWidget {
public DraggableScrollableActuator(
Key key = null,
Widget child = null
) : base(key: key) {
D.assert(child != null);
this.child = child;
}
public readonly Widget child;
readonly _ResetNotifier _notifier = new _ResetNotifier();
public static bool reset(BuildContext context) {
_InheritedResetNotifier notifier = context.dependOnInheritedWidgetOfExactType<_InheritedResetNotifier>();
if (notifier == null) {
return false;
}
return notifier._sendReset();
}
public override Widget build(BuildContext context) {
return new _InheritedResetNotifier(child: child, notifier: _notifier);
}
}
class _ResetNotifier : ChangeNotifier {
internal bool _wasCalled = false;
internal bool sendReset() {
if (!hasListeners) {
return false;
}
_wasCalled = true;
notifyListeners();
return true;
}
}
class _InheritedResetNotifier : InheritedNotifier<_ResetNotifier> {
public _InheritedResetNotifier(
Key key = null,
Widget child = null,
_ResetNotifier notifier = null
) : base(key: key, child: child, notifier: notifier) {
}
internal bool _sendReset() {
return notifier.sendReset();
}
public static bool shouldReset(BuildContext context) {
InheritedWidget widget = context.dependOnInheritedWidgetOfExactType<_InheritedResetNotifier>();
if (widget == null) {
return false;
}
_InheritedResetNotifier inheritedNotifier = widget as _InheritedResetNotifier;
bool wasCalled = inheritedNotifier.notifier._wasCalled;
inheritedNotifier.notifier._wasCalled = false;
return wasCalled;
}
}
}

2
com.unity.uiwidgets/Runtime/widgets/scroll_position_with_single_context.cs


beginActivity(new IdleScrollActivity(this));
}
public void goBallistic(float velocity) {
public virtual void goBallistic(float velocity) {
D.assert(_pixels != null);
Simulation simulation = physics.createBallisticSimulation(this, velocity);
if (simulation != null) {

正在加载...
取消
保存