浏览代码

fix picker

/zgh-devtools
Shiyun Wen 4 年前
当前提交
5268cb6d
共有 7 个文件被更改,包括 87 次插入61 次删除
  1. 9
      com.unity.uiwidgets/Runtime/cupertino/date_picker.cs
  2. 14
      com.unity.uiwidgets/Runtime/cupertino/picker.cs
  3. 2
      com.unity.uiwidgets/Runtime/painting/matrix_utils.cs
  4. 15
      com.unity.uiwidgets/Runtime/rendering/layer.cs
  5. 19
      com.unity.uiwidgets/Runtime/rendering/list_wheel_viewport.cs
  6. 73
      com.unity.uiwidgets/Runtime/widgets/list_wheel_scroll_view.cs
  7. 16
      com.unity.uiwidgets/Runtime/widgets/scrollable.cs

9
com.unity.uiwidgets/Runtime/cupertino/date_picker.cs


_onSelectedItemChange(index);
},
itemBuilder: (BuildContext context, int index) => {
rangeStart.AddDays(index);
rangeStart = rangeStart.AddDays(index);
var rangeEnd = rangeStart.AddDays(1);

return null;
if (widget.maximumDate?.CompareTo(rangeStart) > 0)
if (widget.maximumDate?.CompareTo(rangeStart) < 0)
return null;
string dateText = rangeStart == new DateTime(now.Year, now.Month, now.Day)

DateTime _lastDayInMonth(int year, int month) {
//new DateTime(year, month + 1, 0);
var date = new DateTime(year,month,1);
date.AddMonths(1);
date.Subtract(new TimeSpan(1, 0, 0, 0));
date = date.AddMonths(1);
date = date.Subtract(new TimeSpan(1, 0, 0, 0));
return date;
}

14
com.unity.uiwidgets/Runtime/cupertino/picker.cs


public class CupertinoPicker : StatefulWidget {
public CupertinoPicker(
List<Widget> children,
float itemExtent,
Key key = null,
float? diameterRatio = null,
Color backgroundColor = null,

FixedExtentScrollController scrollController = null,
float? squeeze = null,
float? itemExtent = null,
ValueChanged<int> onSelectedItemChanged = null,
bool looping = false
) : base(key: key) {

D.assert(diameterRatio > 0.0f, ()=>RenderListWheelViewport.diameterRatioZeroMessage);
D.assert(magnification > 0);
D.assert(itemExtent != null);
D.assert(itemExtent > 0);
D.assert(squeeze > 0);
this.diameterRatio = diameterRatio;

}
public CupertinoPicker(
float itemExtent,
Key key = null,
float? diameterRatio = null,
Color backgroundColor = null,

FixedExtentScrollController scrollController = null,
float? squeeze = null,
float? itemExtent = null,
ValueChanged<int> onSelectedItemChanged = null,
IndexedWidgetBuilder itemBuilder = null,
int? childCount = null

D.assert(itemBuilder != null);
D.assert(diameterRatio > 0.0f,()=> RenderListWheelViewport.diameterRatioZeroMessage);
D.assert(magnification > 0);
D.assert(itemExtent != null);
D.assert(itemExtent > 0);
D.assert(squeeze > 0);
this.diameterRatio = diameterRatio;

public readonly bool useMagnifier;
public readonly float magnification;
public readonly FixedExtentScrollController scrollController;
public readonly float? itemExtent;
public readonly float itemExtent;
public readonly ValueChanged<int> onSelectedItemChanged;
public ListWheelChildDelegate childDelegate;
public readonly float? squeeze;

}
public override void didUpdateWidget(StatefulWidget oldWidget) {
oldWidget = (CupertinoPicker) oldWidget;
if (widget.scrollController != null && ((CupertinoPicker) oldWidget).scrollController == null) {
_controller = null;
}

child: new ListWheelScrollView(
controller: widget.scrollController ?? _controller,
physics: new FixedExtentScrollPhysics(),
diameterRatio: widget.diameterRatio ?? CupertinoPickerUtils._kDefaultDiameterRatio,
diameterRatio: widget.diameterRatio ?? RenderListWheelViewport.defaultDiameterRatio ,
itemExtent: widget.itemExtent ?? 1f,
itemExtent: widget.itemExtent ,
squeeze: widget.squeeze ?? CupertinoPickerUtils._kSqueeze,
onSelectedItemChanged: _handleSelectedItemChanged,
childDelegate: widget.childDelegate

2
com.unity.uiwidgets/Runtime/painting/matrix_utils.cs


return (e > f) ? e : f;
}
static Matrix4 createCylindricalProjectionTransform(
public static Matrix4 createCylindricalProjectionTransform(
float radius,
float angle,
float perspective = 0.001f,

15
com.unity.uiwidgets/Runtime/rendering/layer.cs


var totalOffset = offset + layerOffset;
if (totalOffset != Offset.zero) {
_lastEffectiveTransform = Matrix4.translationValues(totalOffset.dx, totalOffset.dy, 0);
_lastEffectiveTransform = Matrix4.translationValues(totalOffset.dx, totalOffset.dy, 0.0f);
_lastEffectiveTransform.multiply(transform);
}

_lastOffset = offset + layerOffset;
if (_lastOffset != Offset.zero) {
engineLayer = builder.pushTransform(
Matrix4.translationValues(_lastOffset.dx, _lastOffset.dy,0)
._m4storage,
Matrix4.translationValues(_lastOffset.dx, _lastOffset.dy,0.0f).storage,
oldLayer: engineLayer as TransformEngineLayer);
}

return null;
}
Matrix4 result = Matrix4.translationValues(-_lastOffset.dx, -_lastOffset.dy,0 );
Matrix4 result = Matrix4.translationValues(-_lastOffset.dx, -_lastOffset.dy,0.0f );
result.multiply(_lastTransform);
return result;
}

_establishTransform();
if (_lastTransform != null) {
engineLayer = builder.pushTransform(
_lastTransform._m4storage,
_lastTransform.storage,
oldLayer: engineLayer as TransformEngineLayer);
addChildrenToScene(builder);
builder.pop();

_lastOffset = null;
var matrix = Matrix4.translationValues(unlinkedOffset.dx, unlinkedOffset.dy, 0);
var matrix = Matrix4.translationValues(unlinkedOffset.dx, unlinkedOffset.dy, 0.0f);
matrix._m4storage,
matrix.storage,
oldLayer: engineLayer as TransformEngineLayer);
addChildrenToScene(builder);
builder.pop();

transform.multiply(_lastTransform);
}
else {
transform.multiply(Matrix4.translationValues(unlinkedOffset.dx, unlinkedOffset.dy, 0));
transform.multiply(Matrix4.translationValues(unlinkedOffset.dx, unlinkedOffset.dy, 0.0f));
}
}

19
com.unity.uiwidgets/Runtime/rendering/list_wheel_viewport.cs


var radius = size.height * _diameterRatio / 2.0f;
var deltaY = radius * Mathf.Sin(angle);
Matrix4 transform = Matrix4.identity();
// Matrix4x4 transform2 = MatrixUtils.createCylindricalProjectionTransform(
// radius: this.size.height * this._diameterRatio / 2.0f,
// angle: angle,
// perspective: this._perspective
// );
Matrix4 transform = MatrixUtils.createCylindricalProjectionTransform(
radius: size.height * _diameterRatio / 2.0f,
angle: angle,
perspective: _perspective
);
// Offset offsetToCenter = new Offset(untransformedPaintingCoordinates.dx, -this._topScrollMarginExtent);
// Offset that helps painting everything in the center (e.g. angle = 0).
Offset offsetToCenter = new Offset(
untransformedPaintingCoordinates.dx,
-_topScrollMarginExtent
);
Offset offsetToCenter =
new Offset(untransformedPaintingCoordinates.dx, -deltaY - _topScrollMarginExtent);
bool shouldApplyOffCenterDim = overAndUnderCenterOpacity < 1;
if (useMagnifier || shouldApplyOffCenterDim) {

73
com.unity.uiwidgets/Runtime/widgets/list_wheel_scroll_view.cs


if (children.isEmpty()) {
return null;
}
return new Container(child: children[Mathf.Abs(index % children.Count)]);
return new IndexedSemantics(child: children[Mathf.Abs(index % children.Count)]);
}
public bool shouldRebuild(ListWheelChildDelegate oldDelegate) {

public Widget build(BuildContext context, int index) {
if (childCount == null) {
Widget child = builder(context, index);
return child == null ? null : new Container(child: child);
return child == null ? null : new IndexedSemantics(child: child);
}
if (index < 0 || index >= childCount) {

return new Container(child: builder(context, index));
return new IndexedSemantics(child: builder(context, index));
}
public int trueIndexOf(int index) {

class ListWheelScrollViewUtils {
public static int _getItemFromOffset(
float? offset = null,
float? itemExtent = null,
float? minScrollExtent = null,
float? maxScrollExtent = null
float offset ,
float itemExtent ,
float minScrollExtent ,
float maxScrollExtent
var _itemExtent = itemExtent ?? 1.0f;
return (_clipOffsetToScrollableRange(offset ?? 0.0f , minScrollExtent ?? 0.0f, maxScrollExtent ?? 0.0f) / _itemExtent).round();
return (_clipOffsetToScrollableRange(offset, minScrollExtent, maxScrollExtent) / itemExtent).round();
}
public static float _clipOffsetToScrollableRange(
float offset,

() =>
"The selectedItem property cannot be read when multiple scroll views are attached to the same FixedExtentScrollController."
);
_FixedExtentScrollPosition position = (_FixedExtentScrollPosition) this.position;
_FixedExtentScrollPosition position = (_FixedExtentScrollPosition) this.position;
return position.itemIndex;
}
}

TimeSpan? duration = null,
Curve curve = null
TimeSpan duration,
Curve curve
duration: duration ?? new TimeSpan(0,0,0,0,0),
duration: duration,
return Future.wait<object>(futures);
}

public interface IFixedExtentMetrics {
int itemIndex { set; get; }
/*FixedExtentMetrics copyWith(
float? minScrollExtent = null,
float? maxScrollExtent = null,
float? pixels = null,
float? viewportDimension = null,
AxisDirection? axisDirection = null,
int? itemIndex = null
);*/
FixedExtentMetrics copyWith(
float? minScrollExtent = null,
float? maxScrollExtent = null,

}
public class FixedExtentMetrics : FixedScrollMetrics, IFixedExtentMetrics {
public FixedExtentMetrics(
/*public FixedExtentMetrics(
float? minScrollExtent = null,
float? maxScrollExtent = null,
float? pixels = null,

axisDirection: axisDirection
) {
this.itemIndex = itemIndex ?? 0;
}*/
public FixedExtentMetrics(
float minScrollExtent ,
float maxScrollExtent,
float pixels ,
float viewportDimension ,
AxisDirection axisDirection ,
int itemIndex
) : base(
minScrollExtent: minScrollExtent ,
maxScrollExtent: maxScrollExtent ,
pixels: pixels ,
viewportDimension: viewportDimension ,
axisDirection: axisDirection
) {
this.itemIndex = itemIndex;
}
public int itemIndex { get; set; }

) : base(
physics: physics,
context: context,
initialPixels: _getItemExtentFromScrollContext(context) * initialItem,
initialPixels: _getItemExtentFromScrollContext(context) * (initialItem ?? 0.0f),
keepScrollOffset: keepScrollOffset,
oldPosition: oldPosition,
debugLabel: debugLabel

static float _getItemExtentFromScrollContext(ScrollContext context) {
_FixedExtentScrollableState scrollable = (_FixedExtentScrollableState) context;
return scrollable.itemExtent ?? 0.0f;
return scrollable.itemExtent;
}
public float itemExtent {

class _FixedExtentScrollable : Scrollable {
public _FixedExtentScrollable(
float itemExtent,
ScrollPhysics physics = null,
float? itemExtent = null,
ScrollPhysics physics = null,
) : base(
key: key,
axisDirection: axisDirection,

this.itemExtent = itemExtent;
}
public readonly float? itemExtent;
public readonly float itemExtent;
public override State createState() {
return new _FixedExtentScrollableState();

class _FixedExtentScrollableState : ScrollableState {
public float? itemExtent {
public float itemExtent {
get {
_FixedExtentScrollable actualWidget = (_FixedExtentScrollable) widget;
return actualWidget.itemExtent;

public class ListWheelScrollView : StatefulWidget {
public ListWheelScrollView(
List<Widget> children,
float itemExtent,
Key key = null,
ScrollController controller = null,
ScrollPhysics physics = null,

bool useMagnifier = false,
float magnification = 1.0f,
float overAndUnderCenterOpacity = 1.0f,
float? itemExtent = null,
float squeeze = 1.0f,
ValueChanged<int> onSelectedItemChanged = null,
bool clipToSize = true,

}
public ListWheelScrollView (
float itemExtent,
Key key = null,
ScrollController controller = null,
ScrollPhysics physics = null,

bool useMagnifier = false,
float magnification = 1.0f,
float? itemExtent = null,
float squeeze = 1.0f,
ValueChanged<int> onSelectedItemChanged = null,
float overAndUnderCenterOpacity = 1.0f,

public readonly float offAxisFraction;
public readonly bool useMagnifier;
public readonly float magnification;
public readonly float? itemExtent;
public readonly float itemExtent;
public readonly float overAndUnderCenterOpacity;
public readonly float squeeze;
public readonly ValueChanged<int> onSelectedItemChanged;

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


if (widget.physics != null) {
_physics = widget.physics.applyTo(_physics);
}
ScrollController controller = widget.controller;
ScrollPosition oldPosition = position;
if (oldPosition != null) {

});
}
_position = controller == null
? null
: controller.createScrollPosition(_physics, this, oldPosition);
_position = _position
?? new ScrollPositionWithSingleContext(physics: _physics, context: this,
oldPosition: oldPosition);
if (controller == null) {
_position = new ScrollPositionWithSingleContext(physics: _physics, context: this, oldPosition: oldPosition);
}
else {
_position = controller?.createScrollPosition(_physics, this, oldPosition)
?? new ScrollPositionWithSingleContext(physics: _physics, context: this, oldPosition: oldPosition);
}
D.assert(position != null);
if (controller != null) {
controller.attach(position);

正在加载...
取消
保存