浏览代码

[Cupertino] Add Picker & Date Picker

/main
iizzaya 5 年前
当前提交
5541420d
共有 6 个文件被更改,包括 1389 次插入11 次删除
  1. 11
      Runtime/cupertino/app.cs
  2. 9
      Runtime/material/app.cs
  3. 1001
      Runtime/cupertino/date_picker.cs
  4. 11
      Runtime/cupertino/date_picker.cs.meta
  5. 357
      Runtime/cupertino/picker.cs
  6. 11
      Runtime/cupertino/picker.cs.meta

11
Runtime/cupertino/app.cs


using System.Collections.Generic;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.material;
using Unity.UIWidgets.painting;
using Unity.UIWidgets.ui;
using Unity.UIWidgets.widgets;

}
}
// Iterable<LocalizationsDelegate<dynamic>> get _localizationsDelegates sync* {
// if (widget.localizationsDelegates != null)
// yield* widget.localizationsDelegates;
// yield DefaultCupertinoLocalizations.delegate;
// }
List<LocalizationsDelegate<CupertinoLocalizations>> _delegates =
new List<LocalizationsDelegate<CupertinoLocalizations>>();
var _delegates = new List<LocalizationsDelegate>();
_delegates.Add(DefaultMaterialLocalizations.del);
return new List<LocalizationsDelegate>(_delegates);
}
}

9
Runtime/material/app.cs


using System.Collections.Generic;
using Unity.UIWidgets.animation;
using Unity.UIWidgets.cupertino;
using Color = Unity.UIWidgets.ui.Color;
using Rect = Unity.UIWidgets.ui.Rect;
using TextStyle = Unity.UIWidgets.painting.TextStyle;
namespace Unity.UIWidgets.material {

List<LocalizationsDelegate> _localizationsDelegates {
get {
List<LocalizationsDelegate<MaterialLocalizations>> _delegates =
new List<LocalizationsDelegate<MaterialLocalizations>>();
var _delegates = new List<LocalizationsDelegate>();
_delegates.Add(DefaultCupertinoLocalizations.del);
_delegates.Add(DefaultMaterialLocalizations.del);
return new List<LocalizationsDelegate>(_delegates);
}

1001
Runtime/cupertino/date_picker.cs
文件差异内容过多而无法显示
查看文件

11
Runtime/cupertino/date_picker.cs.meta


fileFormatVersion: 2
guid: b8c8750ecccc84021b9aafc99e9ee64b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

357
Runtime/cupertino/picker.cs


using System.Collections.Generic;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.painting;
using Unity.UIWidgets.rendering;
using Unity.UIWidgets.ui;
using Unity.UIWidgets.widgets;
namespace Unity.UIWidgets.cupertino {
class CupertinoPickerUtils {
public static Color _kHighlighterBorder = new Color(0xFF7F7F7F);
public static Color _kDefaultBackground = new Color(0xFFD2D4DB);
public const float _kDefaultDiameterRatio = 1.35f;
public const float _kDefaultPerspective = 0.004f;
public const float _kForegroundScreenOpacityFraction = 0.7f;
}
public class CupertinoPicker : StatefulWidget {
public CupertinoPicker(
float itemExtent,
ValueChanged<int> onSelectedItemChanged,
List<Widget> children = null,
Key key = null,
float diameterRatio = CupertinoPickerUtils._kDefaultDiameterRatio,
Color backgroundColor = null,
float offAxisFraction = 0.0f,
bool useMagnifier = false,
float magnification = 1.0f,
FixedExtentScrollController scrollController = null,
bool looping = false,
ListWheelChildDelegate childDelegate = null
) : base(key: key) {
D.assert(children != null || childDelegate != null);
D.assert(diameterRatio > 0.0, () => RenderListWheelViewport.diameterRatioZeroMessage);
D.assert(magnification > 0);
D.assert(itemExtent > 0);
this.childDelegate = childDelegate ?? (looping
? (ListWheelChildDelegate) new ListWheelChildLoopingListDelegate(
children: children)
: (ListWheelChildDelegate) new ListWheelChildListDelegate(children: children));
this.itemExtent = itemExtent;
this.onSelectedItemChanged = onSelectedItemChanged;
this.diameterRatio = diameterRatio;
this.backgroundColor = backgroundColor ?? CupertinoPickerUtils._kDefaultBackground;
this.offAxisFraction = offAxisFraction;
this.useMagnifier = useMagnifier;
this.magnification = magnification;
this.scrollController = scrollController;
}
public static CupertinoPicker builder(
float itemExtent,
ValueChanged<int> onSelectedItemChanged,
IndexedWidgetBuilder itemBuilder,
Key key = null,
float diameterRatio = CupertinoPickerUtils._kDefaultDiameterRatio,
Color backgroundColor = null,
float offAxisFraction = 0.0f,
bool useMagnifier = false,
float magnification = 1.0f,
FixedExtentScrollController scrollController = null,
int? childCount = null
) {
D.assert(itemBuilder != null);
D.assert(diameterRatio > 0.0f, () => RenderListWheelViewport.diameterRatioZeroMessage);
D.assert(magnification > 0);
D.assert(itemExtent > 0);
return new CupertinoPicker(
itemExtent: itemExtent,
onSelectedItemChanged: onSelectedItemChanged,
key: key,
diameterRatio: diameterRatio,
backgroundColor: backgroundColor,
offAxisFraction: offAxisFraction,
useMagnifier: useMagnifier,
magnification: magnification,
scrollController: scrollController,
childDelegate: new ListWheelChildBuilderDelegate(builder: itemBuilder, childCount: childCount)
);
}
public readonly float diameterRatio;
public readonly Color backgroundColor;
public readonly float offAxisFraction;
public readonly bool useMagnifier;
public readonly float magnification;
public readonly FixedExtentScrollController scrollController;
public readonly float itemExtent;
public readonly ValueChanged<int> onSelectedItemChanged;
public readonly ListWheelChildDelegate childDelegate;
public override State createState() {
return new _CupertinoPickerState();
}
}
class _CupertinoPickerState : State<CupertinoPicker> {
int _lastHapticIndex;
FixedExtentScrollController _controller;
public override void initState() {
base.initState();
if (this.widget.scrollController == null) {
this._controller = new FixedExtentScrollController();
}
}
public override void didUpdateWidget(StatefulWidget oldWidget) {
if (this.widget.scrollController != null && ((CupertinoPicker) oldWidget).scrollController == null) {
this._controller = null;
}
else if (this.widget.scrollController == null && ((CupertinoPicker) oldWidget).scrollController != null) {
D.assert(this._controller == null);
this._controller = new FixedExtentScrollController();
}
base.didUpdateWidget(oldWidget);
}
public override void dispose() {
this._controller?.dispose();
base.dispose();
}
void _handleSelectedItemChanged(int index) {
// if (defaultTargetPlatform == TargetPlatform.iOS && index != _lastHapticIndex) {
// _lastHapticIndex = index;
// // HapticFeedback.selectionClick();
// }
this._lastHapticIndex = index;
if (this.widget.onSelectedItemChanged != null) {
this.widget.onSelectedItemChanged(index);
}
}
Widget _buildGradientScreen() {
if (this.widget.backgroundColor != null && this.widget.backgroundColor.alpha < 255) {
return new Container();
}
Color widgetBackgroundColor = this.widget.backgroundColor ?? new Color(0xFFFFFFFF);
return Positioned.fill(
child: new IgnorePointer(
child: new Container(
decoration: new BoxDecoration(
gradient: new LinearGradient(
colors: new List<Color> {
widgetBackgroundColor,
widgetBackgroundColor.withAlpha(0xF2),
widgetBackgroundColor.withAlpha(0xDD),
widgetBackgroundColor.withAlpha(0),
widgetBackgroundColor.withAlpha(0),
widgetBackgroundColor.withAlpha(0xDD),
widgetBackgroundColor.withAlpha(0xF2),
widgetBackgroundColor,
},
stops: new List<float> {
0.0f, 0.05f, 0.09f, 0.22f, 0.78f, 0.91f, 0.95f, 1.0f
},
begin: Alignment.topCenter,
end: Alignment.bottomCenter
)
)
)
)
);
}
Widget _buildMagnifierScreen() {
Color foreground = this.widget.backgroundColor?.withAlpha(
(int) (this.widget.backgroundColor.alpha * CupertinoPickerUtils._kForegroundScreenOpacityFraction)
);
return new IgnorePointer(
child: new Column(
children: new List<Widget> {
new Expanded(
child: new Container(
color: foreground
)
),
new Container(
decoration: new BoxDecoration(
border: new Border(
top: new BorderSide(width: 0.0f, color: CupertinoPickerUtils._kHighlighterBorder),
bottom: new BorderSide(width: 0.0f, color: CupertinoPickerUtils._kHighlighterBorder)
)
),
constraints: BoxConstraints.expand(
height: this.widget.itemExtent * this.widget.magnification
)
),
new Expanded(
child: new Container(
color: foreground
)
),
}
)
);
}
Widget _buildUnderMagnifierScreen() {
Color foreground = this.widget.backgroundColor?.withAlpha(
(int) (this.widget.backgroundColor.alpha * CupertinoPickerUtils._kForegroundScreenOpacityFraction)
);
return new Column(
children: new List<Widget> {
new Expanded(child: new Container()),
new Container(
color: foreground,
constraints: BoxConstraints.expand(
height: this.widget.itemExtent * this.widget.magnification
)
),
new Expanded(child: new Container())
}
);
}
Widget _addBackgroundToChild(Widget child) {
return new DecoratedBox(
decoration: new BoxDecoration(
color: this.widget.backgroundColor
),
child: child
);
}
public override Widget build(BuildContext context) {
Widget result = new Stack(
children: new List<Widget> {
Positioned.fill(
child: new _CupertinoPickerSemantics(
scrollController: this.widget.scrollController ?? this._controller,
child: ListWheelScrollView.useDelegate(
controller: this.widget.scrollController ?? this._controller,
physics: new FixedExtentScrollPhysics(),
diameterRatio: this.widget.diameterRatio,
perspective: CupertinoPickerUtils._kDefaultPerspective,
offAxisFraction: this.widget.offAxisFraction,
useMagnifier: this.widget.useMagnifier,
magnification: this.widget.magnification,
itemExtent: this.widget.itemExtent,
onSelectedItemChanged: this._handleSelectedItemChanged,
childDelegate: this.widget.childDelegate
)
)
),
this._buildGradientScreen(),
this._buildMagnifierScreen()
}
);
if (this.widget.backgroundColor != null && this.widget.backgroundColor.alpha < 255) {
result = new Stack(
children: new List<Widget> {
this._buildUnderMagnifierScreen(), this._addBackgroundToChild(result),
}
);
}
else {
result = this._addBackgroundToChild(result);
}
return result;
}
}
class _CupertinoPickerSemantics : SingleChildRenderObjectWidget {
public _CupertinoPickerSemantics(
FixedExtentScrollController scrollController,
Key key = null,
Widget child = null
) : base(key: key, child: child) {
this.scrollController = scrollController;
}
public readonly FixedExtentScrollController scrollController;
public override RenderObject createRenderObject(BuildContext context) {
return new _RenderCupertinoPickerSemantics(this.scrollController, Directionality.of(context));
}
public override void updateRenderObject(BuildContext context, RenderObject renderObject) {
((_RenderCupertinoPickerSemantics) renderObject).textDirection = Directionality.of(context);
((_RenderCupertinoPickerSemantics) renderObject).controller = this.scrollController;
}
}
class _RenderCupertinoPickerSemantics : RenderProxyBox {
public _RenderCupertinoPickerSemantics(FixedExtentScrollController controller, TextDirection _textDirection) {
this.controller = controller;
this._textDirection = _textDirection;
}
public FixedExtentScrollController controller {
get { return this._controller; }
set {
if (value == this._controller) {
return;
}
if (this._controller != null) {
this._controller.removeListener(this._handleScrollUpdate);
}
else {
this._currentIndex = value.initialItem;
}
value.addListener(this._handleScrollUpdate);
this._controller = value;
}
}
FixedExtentScrollController _controller;
public TextDirection textDirection {
get { return this._textDirection; }
set {
if (this.textDirection == value) {
return;
}
this._textDirection = value;
}
}
TextDirection _textDirection;
int _currentIndex = 0;
void _handleIncrease() {
this.controller.jumpToItem(this._currentIndex + 1);
}
void _handleDecrease() {
if (this._currentIndex == 0) {
return;
}
this.controller.jumpToItem(this._currentIndex - 1);
}
void _handleScrollUpdate() {
if (this.controller.selectedItem == this._currentIndex) {
return;
}
this._currentIndex = this.controller.selectedItem;
}
}
}

11
Runtime/cupertino/picker.cs.meta


fileFormatVersion: 2
guid: e1f9860a10b464e9da0c6258c08fa91e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存