浏览代码

[Clean] Remove Semantics&TextDirection Parameters

/main
iizzaya 5 年前
当前提交
5921e8ce
共有 2 个文件被更改,包括 37 次插入174 次删除
  1. 94
      Runtime/cupertino/date_picker.cs
  2. 117
      Runtime/cupertino/picker.cs

94
Runtime/cupertino/date_picker.cs


public class _DatePickerLayoutDelegate : MultiChildLayoutDelegate {
public _DatePickerLayoutDelegate(
List<float> columnWidths,
int textDirectionFactor
List<float> columnWidths
this.textDirectionFactor = textDirectionFactor;
public readonly int textDirectionFactor;
public override void performLayout(Size size) {
float remainingWidth = size.width;

float currentHorizontalOffset = 0.0f;
for (int i = 0; i < this.columnWidths.Count; i++) {
int index = this.textDirectionFactor == 1 ? i : this.columnWidths.Count - i - 1;
float childWidth = this.columnWidths[index] + CupertinoDatePickerUtils._kDatePickerPadSize * 2;
if (index == 0 || index == this.columnWidths.Count - 1) {
float childWidth = this.columnWidths[i] + CupertinoDatePickerUtils._kDatePickerPadSize * 2;
if (i == 0 || i == this.columnWidths.Count - 1) {
this.layoutChild(index, BoxConstraints.tight(new Size(childWidth, size.height)));
this.positionChild(index, new Offset(currentHorizontalOffset, 0.0f));
this.layoutChild(i, BoxConstraints.tight(new Size(childWidth, size.height)));
this.positionChild(i, new Offset(currentHorizontalOffset, 0.0f));
return this.columnWidths != ((_DatePickerLayoutDelegate) oldDelegate).columnWidths
|| this.textDirectionFactor != ((_DatePickerLayoutDelegate) oldDelegate).textDirectionFactor;
return this.columnWidths != ((_DatePickerLayoutDelegate) oldDelegate).columnWidths;
}
}

text: new TextSpan(
style: DefaultTextStyle.of(context).style,
text: longestText
),
textDirection: Directionality.of(context)
)
);

delegate Widget _ColumnBuilder(float offAxisFraction, TransitionBuilder itemPositioningBuilder);
class _CupertinoDatePickerDateTimeState : State<CupertinoDatePicker> {
public int textDirectionFactor;
public CupertinoLocalizations localizations;
public Alignment alignCenterLeft;
public Alignment alignCenterRight;

public override void didChangeDependencies() {
base.didChangeDependencies();
this.textDirectionFactor = Directionality.of(this.context) == TextDirection.ltr ? 1 : -1;
this.alignCenterLeft = this.textDirectionFactor == 1 ? Alignment.centerLeft : Alignment.centerRight;
this.alignCenterRight = this.textDirectionFactor == 1 ? Alignment.centerRight : Alignment.centerLeft;
this.alignCenterLeft = Alignment.centerLeft;
this.alignCenterRight = Alignment.centerRight;
estimatedColumnWidths.Clear();
}

var _i = i;
float offAxisFraction = 0.0f;
if (_i == 0) {
offAxisFraction = -0.5f * this.textDirectionFactor;
offAxisFraction = -0.5f;
offAxisFraction = 0.5f * this.textDirectionFactor;
offAxisFraction = 0.5f;
padding = padding.flipped;
}
if (this.textDirectionFactor == -1) {
padding = padding.flipped;
}

style: CupertinoDatePickerUtils._kDefaultPickerTextStyle,
child: new CustomMultiChildLayout(
layoutDelegate: new _DatePickerLayoutDelegate(
columnWidths: columnWidths,
textDirectionFactor: this.textDirectionFactor
columnWidths: columnWidths
),
children: pickers
)

}
class _CupertinoDatePickerDateState : State<CupertinoDatePicker> {
int textDirectionFactor;
CupertinoLocalizations localizations;
Alignment alignCenterLeft;

public override void didChangeDependencies() {
base.didChangeDependencies();
this.textDirectionFactor = Directionality.of(this.context) == TextDirection.ltr ? 1 : -1;
this.alignCenterLeft = this.textDirectionFactor == 1 ? Alignment.centerLeft : Alignment.centerRight;
this.alignCenterRight = this.textDirectionFactor == 1 ? Alignment.centerRight : Alignment.centerLeft;
this.alignCenterLeft = Alignment.centerLeft;
this.alignCenterRight = Alignment.centerRight;
this.estimatedColumnWidths[(int) _PickerColumnType.dayOfMonth] = CupertinoDatePicker._getColumnWidth(
_PickerColumnType.dayOfMonth, this.localizations, this.context);

List<Widget> pickers = new List<Widget>();
for (int i = 0; i < columnWidths.Count; i++) {
var _i = i;
float offAxisFraction = (_i - 1) * 0.3f * this.textDirectionFactor;
float offAxisFraction = (_i - 1) * 0.3f;
if (this.textDirectionFactor == -1) {
padding = EdgeInsets.only(left: CupertinoDatePickerUtils._kDatePickerPadSize);
}
pickers.Add(new LayoutId(
id: _i,

style: CupertinoDatePickerUtils._kDefaultPickerTextStyle,
child: new CustomMultiChildLayout(
layoutDelegate: new _DatePickerLayoutDelegate(
columnWidths: columnWidths,
textDirectionFactor: this.textDirectionFactor
columnWidths: columnWidths
),
children:
pickers

}
class _CupertinoTimerPickerState : State<CupertinoTimerPicker> {
int textDirectionFactor;
CupertinoLocalizations localizations;
Alignment alignCenterLeft;
Alignment alignCenterRight;

public override void didChangeDependencies() {
base.didChangeDependencies();
this.textDirectionFactor = Directionality.of(this.context) == TextDirection.ltr ? 1 : -1;
this.alignCenterLeft = this.textDirectionFactor == 1 ? Alignment.centerLeft : Alignment.centerRight;
this.alignCenterRight = this.textDirectionFactor == 1 ? Alignment.centerRight : Alignment.centerLeft;
this.alignCenterLeft = Alignment.centerLeft;
this.alignCenterRight = Alignment.centerRight;
offAxisFraction: -0.5f * this.textDirectionFactor,
offAxisFraction: -0.5f,
itemExtent: CupertinoDatePickerUtils._kItemExtent,
backgroundColor: CupertinoDatePickerUtils._kBackgroundColor,
onSelectedItemChanged: (int index) => {

float hourLabelWidth = this.widget.mode == CupertinoTimerPickerMode.hm
? CupertinoDatePickerUtils._kPickerWidth / 4
: CupertinoDatePickerUtils._kPickerWidth / 6;
string semanticsLabel = this.textDirectionFactor == 1
? this.localizations.timerPickerHour(index) + this.localizations.timerPickerHourLabel(index)
: this.localizations.timerPickerHourLabel(index) + this.localizations.timerPickerHour(index);
padding: this.textDirectionFactor == 1
? EdgeInsets.only(right: hourLabelWidth)
: EdgeInsets.only(left: hourLabelWidth),
padding: EdgeInsets.only(right: hourLabelWidth),
child: new Container(
alignment: this.alignCenterRight,
padding: EdgeInsets.symmetric(horizontal: 2.0f),

Widget _buildMinutePicker() {
float offAxisFraction;
if (this.widget.mode == CupertinoTimerPickerMode.hm) {
offAxisFraction = 0.5f * this.textDirectionFactor;
offAxisFraction = 0.5f;
offAxisFraction = -0.5f * this.textDirectionFactor;
offAxisFraction = -0.5f;
}
return new CupertinoPicker(

},
children: CupertinoDatePickerUtils.listGenerate(60 / this.widget.minuteInterval, (int index) => {
int minute = index * this.widget.minuteInterval;
string semanticsLabel = this.textDirectionFactor == 1
? this.localizations.timerPickerMinute(minute) +
this.localizations.timerPickerMinuteLabel(minute)
: this.localizations.timerPickerMinuteLabel(minute) +
this.localizations.timerPickerMinute(minute);
padding: this.textDirectionFactor == 1
? EdgeInsets.only(right: CupertinoDatePickerUtils._kPickerWidth / 4)
: EdgeInsets.only(left: CupertinoDatePickerUtils._kPickerWidth / 4),
padding: EdgeInsets.only(right: CupertinoDatePickerUtils._kPickerWidth / 4),
child: new Container(
alignment: this.alignCenterRight,
padding: EdgeInsets.symmetric(horizontal: 2.0f),

minuteLabel = new IgnorePointer(
child: new Container(
alignment: this.alignCenterLeft,
padding: this.textDirectionFactor == 1
? EdgeInsets.only(left: CupertinoDatePickerUtils._kPickerWidth / 10)
: EdgeInsets.only(right: CupertinoDatePickerUtils._kPickerWidth / 10),
padding: EdgeInsets.only(left: CupertinoDatePickerUtils._kPickerWidth / 10),
child: new Container(
alignment: this.alignCenterLeft,
padding: EdgeInsets.symmetric(horizontal: 2.0f),

}
Widget _buildSecondPicker() {
float offAxisFraction = 0.5f * this.textDirectionFactor;
float offAxisFraction = 0.5f;
float secondPickerWidth = this.widget.mode == CupertinoTimerPickerMode.ms
? CupertinoDatePickerUtils._kPickerWidth / 10
: CupertinoDatePickerUtils._kPickerWidth / 6;

},
children: CupertinoDatePickerUtils.listGenerate(60 / this.widget.secondInterval, (int index) => {
int second = index * this.widget.secondInterval;
string semanticsLabel = this.textDirectionFactor == 1
? this.localizations.timerPickerSecond(second) +
this.localizations.timerPickerSecondLabel(second)
: this.localizations.timerPickerSecondLabel(second) +
this.localizations.timerPickerSecond(second);
return new Container(
alignment: this.alignCenterLeft,
child: new Container(

Widget secondLabel = new IgnorePointer(
child: new Container(
alignment: this.alignCenterLeft,
padding: this.textDirectionFactor == 1
? EdgeInsets.only(left: secondPickerWidth)
: EdgeInsets.only(right: secondPickerWidth),
padding: EdgeInsets.only(left: secondPickerWidth),
child: new Container(
alignment: this.alignCenterLeft,
padding: EdgeInsets.symmetric(horizontal: 2.0f),

117
Runtime/cupertino/picker.cs


}
class _CupertinoPickerState : State<CupertinoPicker> {
int _lastHapticIndex;
FixedExtentScrollController _controller;
public override void initState() {

}
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 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
)
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(),

}
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;
}
}
}
正在加载...
取消
保存