浏览代码

stash changes

/siyaoH-1.17-PlatformMessage
xingweizhu 4 年前
当前提交
14d97533
共有 6 个文件被更改,包括 284 次插入32 次删除
  1. 7
      com.unity.uiwidgets/Runtime/widgets/scroll_configuration.cs
  2. 9
      com.unity.uiwidgets/Runtime/widgets/scroll_metrics.cs
  3. 29
      com.unity.uiwidgets/Runtime/widgets/scroll_physics.cs
  4. 7
      com.unity.uiwidgets/Runtime/widgets/scroll_position.cs
  5. 91
      com.unity.uiwidgets/Runtime/widgets/scroll_view.cs
  6. 173
      com.unity.uiwidgets/Runtime/widgets/scrollable.cs

7
com.unity.uiwidgets/Runtime/widgets/scroll_configuration.cs


}
public virtual ScrollPhysics getScrollPhysics(BuildContext context) {
#if UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX || UNITY_IOS
#else
return new ClampingScrollPhysics();
#endif
}
public virtual bool shouldNotify(ScrollBehavior oldDelegate) {

public readonly ScrollBehavior behavior;
public static ScrollBehavior of(BuildContext context) {
ScrollConfiguration configuration =
(ScrollConfiguration) context.inheritFromWidgetOfExactType(typeof(ScrollConfiguration));
ScrollConfiguration configuration = context.dependOnInheritedWidgetOfExactType<ScrollConfiguration>();
if (configuration != null) {
return configuration.behavior;
}

9
com.unity.uiwidgets/Runtime/widgets/scroll_metrics.cs


using System;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.ui;
using UnityEngine;
namespace Unity.UIWidgets.widgets {

}
public static float extentInside(this ScrollMetrics it) {
return Mathf.Min(it.pixels, it.maxScrollExtent) -
Mathf.Max(it.pixels, it.minScrollExtent) +
Mathf.Min(it.viewportDimension, it.maxScrollExtent - it.minScrollExtent);
D.assert(it.minScrollExtent <= it.maxScrollExtent);
return it.viewportDimension
- (it.minScrollExtent - it.pixels).clamp(0, it.viewportDimension)
- (it.pixels - it.maxScrollExtent).clamp(0, it.viewportDimension);
}
public static float extentAfter(this ScrollMetrics it) {

29
com.unity.uiwidgets/Runtime/widgets/scroll_physics.cs


using System;
using System.Collections.Generic;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.gestures;
using Unity.UIWidgets.physics;

}
return parent.shouldAcceptUserOffset(position);
}
public bool recommendDeferredLoading(float velocity, ScrollMetrics metrics, BuildContext context) {
D.assert(metrics != null);
D.assert(context != null);
if (parent == null) {
float maxPhysicalPixels = WidgetsBinding.instance.window.physicalSize.longestSide;
return velocity.abs() > maxPhysicalPixels;
}
return parent.recommendDeferredLoading(velocity, metrics, context);
}
public virtual float applyBoundaryConditions(ScrollMetrics position, float value) {

public override float applyBoundaryConditions(ScrollMetrics position, float value) {
D.assert(() => {
if (value == position.pixels) {
throw new UIWidgetsError(
$"{GetType()}.applyBoundaryConditions() was called redundantly.\n" +
$"The proposed new position, {value}, is exactly equal to the current position of the " +
$"given {position.GetType()}, {position.pixels}.\n" +
"The applyBoundaryConditions method should only be called when the value is " +
"going to actually change the pixels, otherwise it is redundant.\n" +
"The physics object in question was:\n" + $" {this}\n" +
"The position object in question was:\n" + $" {position}\n");
throw new UIWidgetsError(new List<DiagnosticsNode>() {
new ErrorSummary($"{GetType()}.applyBoundaryConditions() was called redundantly."),
new ErrorDescription($"The proposed new position, {value}, is exactly equal to the current position of the " +
$"given {position.GetType()}, {position.pixels}.\n" +
"The applyBoundaryConditions method should only be called when the value is " +
"going to actually change the pixels, otherwise it is redundant."),
new DiagnosticsProperty<ScrollPhysics>("The physics object in question was", this, style: DiagnosticsTreeStyle.errorProperty),
new DiagnosticsProperty<ScrollMetrics>("The position object in question was", position, style: DiagnosticsTreeStyle.errorProperty)
});
}
return true;

7
com.unity.uiwidgets/Runtime/widgets/scroll_position.cs


if (!PhysicsUtils.nearEqual(_minScrollExtent, minScrollExtent, Tolerance.defaultTolerance.distance) ||
!PhysicsUtils.nearEqual(_maxScrollExtent, maxScrollExtent, Tolerance.defaultTolerance.distance) ||
_didChangeViewportDimensionOrReceiveCorrection) {
D.assert(minScrollExtent <= maxScrollExtent);
_minScrollExtent = minScrollExtent;
_maxScrollExtent = maxScrollExtent;
_haveDimensions = true;

new UserScrollNotification(metrics:
ScrollMetricsUtils.copyWith(this), context: context.notificationContext, direction: direction
).dispatch(context.notificationContext);
}
public bool recommendDeferredLoading(BuildContext context) {
D.assert(context != null);
D.assert(activity != null);
return physics.recommendDeferredLoading(activity.velocity, ScrollMetricsUtils.copyWith(this), context);
}
public override void dispose() {

91
com.unity.uiwidgets/Runtime/widgets/scroll_view.cs


using UnityEngine;
namespace Unity.UIWidgets.widgets {
public enum ScrollViewKeyboardDismissBehavior {
manual,
onDrag
}
public abstract class ScrollView : StatelessWidget {
protected ScrollView(
Key key = null,

Key center = null,
float anchor = 0.0f,
float? cacheExtent = null,
DragStartBehavior dragStartBehavior = DragStartBehavior.start
DragStartBehavior dragStartBehavior = DragStartBehavior.start,
ScrollViewKeyboardDismissBehavior keyboardDismissBehavior = ScrollViewKeyboardDismissBehavior.manual
) : base(key: key) {
D.assert(!(controller != null && primary == true),
() => "Primary ScrollViews obtain their ScrollController via inheritance from a PrimaryScrollController widget. " +

this.anchor = anchor;
this.cacheExtent = cacheExtent;
this.dragStartBehavior = dragStartBehavior;
this.keyboardDismissBehavior = keyboardDismissBehavior;
}
public readonly Axis scrollDirection;

public readonly float anchor;
public readonly float? cacheExtent;
public readonly DragStartBehavior dragStartBehavior;
public readonly ScrollViewKeyboardDismissBehavior keyboardDismissBehavior;
protected AxisDirection getDirection(BuildContext context) {
return LayoutUtils.getAxisDirectionFromAxisReverseAndDirectionality(

viewportBuilder: (viewportContext, offset) =>
buildViewport(viewportContext, offset, axisDirection, slivers)
);
return primary && scrollController != null
Widget scrollableResult = primary && scrollController != null
if (keyboardDismissBehavior == ScrollViewKeyboardDismissBehavior.onDrag) {
return new NotificationListener<ScrollUpdateNotification>(
child: scrollableResult,
onNotification: (ScrollUpdateNotification notification) => {
FocusScopeNode focusScope = FocusScope.of(context);
if (notification.dragDetails != null && focusScope.hasFocus) {
focusScope.unfocus();
}
return false;
}
);
}
else {
return scrollableResult;
}
}
public override void debugFillProperties(DiagnosticPropertiesBuilder properties) {

bool shrinkWrap = false,
EdgeInsets padding = null,
float? cacheExtent = null,
DragStartBehavior dragStartBehavior = DragStartBehavior.start
DragStartBehavior dragStartBehavior = DragStartBehavior.start,
ScrollViewKeyboardDismissBehavior keyboardDismissBehavior = ScrollViewKeyboardDismissBehavior.manual
) : base(
key: key,
scrollDirection: scrollDirection,

physics: physics,
shrinkWrap: shrinkWrap,
cacheExtent: cacheExtent,
dragStartBehavior: dragStartBehavior
dragStartBehavior: dragStartBehavior,
keyboardDismissBehavior: keyboardDismissBehavior
) {
this.padding = padding;
}

bool addRepaintBoundaries = true,
float? cacheExtent = null,
List<Widget> children = null,
DragStartBehavior dragStartBehavior = DragStartBehavior.start
DragStartBehavior dragStartBehavior = DragStartBehavior.start,
ScrollViewKeyboardDismissBehavior keyboardDismissBehavior = ScrollViewKeyboardDismissBehavior.manual
) : base(
key: key,
scrollDirection: scrollDirection,

shrinkWrap: shrinkWrap,
padding: padding,
cacheExtent: cacheExtent,
dragStartBehavior: dragStartBehavior
dragStartBehavior: dragStartBehavior,
keyboardDismissBehavior: keyboardDismissBehavior
) {
this.itemExtent = itemExtent;
childrenDelegate = new SliverChildListDelegate(

bool addAutomaticKeepAlives = true,
bool addRepaintBoundaries = true,
float? cacheExtent = null,
DragStartBehavior dragStartBehavior = DragStartBehavior.start
DragStartBehavior dragStartBehavior = DragStartBehavior.start,
ScrollViewKeyboardDismissBehavior keyboardDismissBehavior = ScrollViewKeyboardDismissBehavior.manual
) : base(key: key,
scrollDirection: scrollDirection,
reverse: reverse,

shrinkWrap: shrinkWrap,
padding: padding,
cacheExtent: cacheExtent,
dragStartBehavior: dragStartBehavior
dragStartBehavior: dragStartBehavior,
keyboardDismissBehavior: keyboardDismissBehavior
D.assert(itemCount == null || itemCount >= 0);
this.itemExtent = itemExtent;
childrenDelegate = new SliverChildBuilderDelegate(
itemBuilder,

bool addAutomaticKeepAlives = true,
bool addRepaintBoundaries = true,
float? cacheExtent = null,
DragStartBehavior dragStartBehavior = DragStartBehavior.start
DragStartBehavior dragStartBehavior = DragStartBehavior.start,
ScrollViewKeyboardDismissBehavior keyboardDismissBehavior = ScrollViewKeyboardDismissBehavior.manual
) {
return new ListView(
key: key,

itemCount: itemCount,
addAutomaticKeepAlives: addAutomaticKeepAlives,
addRepaintBoundaries: addRepaintBoundaries,
dragStartBehavior: dragStartBehavior
dragStartBehavior: dragStartBehavior,
keyboardDismissBehavior: keyboardDismissBehavior
);
}

bool addAutomaticKeepAlives = true,
bool addRepaintBoundaries = true,
float? cacheExtent = null,
DragStartBehavior dragStartBehavior = DragStartBehavior.start
DragStartBehavior dragStartBehavior = DragStartBehavior.start,
ScrollViewKeyboardDismissBehavior keyboardDismissBehavior = ScrollViewKeyboardDismissBehavior.manual
) : base(
key: key,
scrollDirection: scrollDirection,

shrinkWrap: shrinkWrap,
padding: padding,
cacheExtent: cacheExtent,
dragStartBehavior: dragStartBehavior
dragStartBehavior: dragStartBehavior,
keyboardDismissBehavior: keyboardDismissBehavior
) {
D.assert(itemBuilder != null);
D.assert(separatorBuilder != null);

(context, index) => {
int itemIndex = index / 2;
return index % 2 == 0
? itemBuilder(context, itemIndex)
: separatorBuilder(context, itemIndex);
Widget widget = null;
if (index % 2 == 0) {
widget = itemBuilder(context, itemIndex);
}
else {
widget = separatorBuilder(context, itemIndex);
D.assert(() => {
if (widget == null) {
throw new UIWidgetsError("separatorBuilder cannot return null.");
}
return true;
});
}
return widget;
childCount: Mathf.Max(0, itemCount * 2 - 1),
childCount: _computeActualChildCount(itemCount),
addAutomaticKeepAlives: addAutomaticKeepAlives,
addRepaintBoundaries: addRepaintBoundaries
);

int itemCount = 0,
bool addAutomaticKeepAlives = true,
bool addRepaintBoundaries = true,
float? cacheExtent = null
float? cacheExtent = null,
ScrollViewKeyboardDismissBehavior keyboardDismissBehavior = ScrollViewKeyboardDismissBehavior.manual
) {
return new ListView(
key,

itemCount,
addAutomaticKeepAlives,
addRepaintBoundaries,
cacheExtent
cacheExtent,
keyboardDismissBehavior: keyboardDismissBehavior
);
}

base.debugFillProperties(properties);
properties.add(new FloatProperty("itemExtent", itemExtent,
defaultValue: foundation_.kNullDefaultValue));
}
static int _computeActualChildCount(int itemCount) {
return Mathf.Max(0, itemCount * 2 - 1);
}
}

173
com.unity.uiwidgets/Runtime/widgets/scrollable.cs


ScrollController controller = null,
ScrollPhysics physics = null,
ViewportBuilder viewportBuilder = null,
ScrollIncrementCalculator incrementCalculator = null,
DragStartBehavior dragStartBehavior = DragStartBehavior.start
) : base(key: key) {
D.assert(viewportBuilder != null);

this.physics = physics;
this.viewportBuilder = viewportBuilder;
this.incrementCalculator = incrementCalculator;
this.dragStartBehavior = dragStartBehavior;
}

public readonly ScrollPhysics physics;
public readonly ViewportBuilder viewportBuilder;
public readonly ScrollIncrementCalculator incrementCalculator;
public readonly DragStartBehavior dragStartBehavior;

}
public static ScrollableState of(BuildContext context) {
_ScrollableScope widget = (_ScrollableScope) context.inheritFromWidgetOfExactType(typeof(_ScrollableScope));
_ScrollableScope widget = context.dependOnInheritedWidgetOfExactType<_ScrollableScope>();
}
static bool recommendDeferredLoadingForContext(BuildContext context) {
_ScrollableScope widget = context.getElementForInheritedWidgetOfExactType<_ScrollableScope>()?.widget as _ScrollableScope;
if (widget == null) {
return false;
}
return widget.position.recommendDeferredLoading(context);
}
public static Future ensureVisible(

float _targetScrollOffsetForPointerScroll(PointerScrollEvent e) {
float delta = widget.axis == Axis.horizontal ? e.delta.dx : e.delta.dy;
if (AxisUtils.axisDirectionIsReversed(widget.axisDirection)) {
delta += -1;
}
return Mathf.Min(Mathf.Max(position.pixels + delta, position.minScrollExtent),
position.maxScrollExtent);
}

void _handlePointerScroll(PointerEvent e) {
D.assert(e is PointerScrollEvent);
if (_physics != null && !_physics.shouldAcceptUserOffset(position)) {
return;
}
float targetScrollOffset = _targetScrollOffsetForPointerScroll(e as PointerScrollEvent);
if (targetScrollOffset != position.pixels) {
position.jumpTo(targetScrollOffset);

public override void debugFillProperties(DiagnosticPropertiesBuilder properties) {
base.debugFillProperties(properties);
properties.add(new DiagnosticsProperty<ScrollPosition>("position", position));
}
}
public delegate float ScrollIncrementCalculator(ScrollIncrementDetails details);
public enum ScrollIncrementType {
line,
page
}
public class ScrollIncrementDetails {
public ScrollIncrementDetails(
ScrollIncrementType type,
ScrollMetrics metrics
) {
D.assert(metrics != null);
this.type = type;
this.metrics = metrics;
}
public readonly ScrollIncrementType type;
public readonly ScrollMetrics metrics;
}
public class ScrollIntent : Intent {
public ScrollIntent(
AxisDirection direction,
ScrollIncrementType type = ScrollIncrementType.line
) : base (ScrollAction.key) {
this.direction = direction;
this.type = type;
}
public readonly AxisDirection direction;
public readonly ScrollIncrementType type;
protected bool isEnabled(BuildContext context) {
return Scrollable.of(context) != null;
}
}
public class ScrollAction : UiWidgetAction {
public ScrollAction() : base(key) {
}
public static readonly LocalKey key = new ValueKey<Type>(typeof(ScrollAction));
float _calculateScrollIncrement(ScrollableState state, ScrollIncrementType type = ScrollIncrementType.line) {
D.assert(state.position != null);
D.assert(state.position.pixels != null);
D.assert(state.widget.physics == null || state.widget.physics.shouldAcceptUserOffset(state.position));
if (state.widget.incrementCalculator != null) {
return state.widget.incrementCalculator(
new ScrollIncrementDetails(
type: type,
metrics: state.position
)
);
}
switch (type) {
case ScrollIncrementType.line:
return 50.0f;
case ScrollIncrementType.page:
return 0.8f * state.position.viewportDimension;
}
return 0.0f;
}
float _getIncrement(ScrollableState state, ScrollIntent intent) {
float increment = _calculateScrollIncrement(state, type: intent.type);
switch (intent.direction) {
case AxisDirection.down:
switch (state.axisDirection) {
case AxisDirection.up:
return -increment;
break;
case AxisDirection.down:
return increment;
break;
case AxisDirection.right:
case AxisDirection.left:
return 0.0f;
}
break;
case AxisDirection.up:
switch (state.axisDirection) {
case AxisDirection.up:
return increment;
break;
case AxisDirection.down:
return -increment;
break;
case AxisDirection.right:
case AxisDirection.left:
return 0.0f;
}
break;
case AxisDirection.left:
switch (state.axisDirection) {
case AxisDirection.right:
return -increment;
break;
case AxisDirection.left:
return increment;
break;
case AxisDirection.up:
case AxisDirection.down:
return 0.0f;
}
break;
case AxisDirection.right:
switch (state.axisDirection) {
case AxisDirection.right:
return increment;
break;
case AxisDirection.left:
return -increment;
break;
case AxisDirection.up:
case AxisDirection.down:
return 0.0f;
}
break;
}
return 0.0f;
}
public override void invoke(FocusNode node, Intent intent) {
ScrollableState state = Scrollable.of(node.context);
D.assert(state != null, () => "ScrollAction was invoked on a context that has no scrollable parent");
D.assert(state.position.pixels != null, () => "Scrollable must be laid out before it can be scrolled via a ScrollAction");
if (state.widget.physics != null && !state.widget.physics.shouldAcceptUserOffset(state.position)) {
return;
}
float increment = _getIncrement(state, intent as ScrollIntent);
if (increment == 0.0f) {
return;
}
state.position.moveTo(
state.position.pixels + increment,
duration: TimeSpan.FromMilliseconds(100),
curve: Curves.easeInOut
);
}
}
}
正在加载...
取消
保存