浏览代码

Merge branch 'siyaoH/1.17/material' of https://github.com/Unity-Technologies/com.unity.uiwidgets into siyaoH/1.17/material

/siyaoH-1.17-PlatformMessage
siyao 4 年前
当前提交
4a5b450e
共有 10 个文件被更改,包括 2804 次插入106 次删除
  1. 94
      com.unity.uiwidgets/Runtime/material/refresh_indicator.cs
  2. 34
      com.unity.uiwidgets/Runtime/material/reorderable_list.cs
  3. 110
      com.unity.uiwidgets/Runtime/material/scrollbar.cs
  4. 70
      com.unity.uiwidgets/Runtime/material/search.cs
  5. 4
      com.unity.uiwidgets/Runtime/material/slider_theme.cs
  6. 24
      com.unity.uiwidgets/Runtime/widgets/editable_text.cs
  7. 1001
      com.unity.uiwidgets/Runtime/material/range_slider.cs
  8. 572
      com.unity.uiwidgets/Runtime/material/selectable_text.cs
  9. 1001
      com.unity.uiwidgets/Runtime/material/time_picker.cs
  10. 0
      /com.unity.uiwidgets/Runtime/material/time.cs

94
com.unity.uiwidgets/Runtime/material/refresh_indicator.cs


using System;
using System.Collections.Generic;
using uiwidgets;
using Unity.UIWidgets.animation;
using Unity.UIWidgets.async2;
using Unity.UIWidgets.foundation;

RefreshCallback onRefresh = null,
Color color = null,
Color backgroundColor = null,
ScrollNotificationPredicate notificationPredicate = null
ScrollNotificationPredicate notificationPredicate = null,
float strokenWidth = 2.0f
) : base(key: key) {
D.assert(child != null);
D.assert(onRefresh != null);

public readonly Color backgroundColor;
public readonly ScrollNotificationPredicate notificationPredicate;
public readonly float strokeWidth;
public override State createState() {
return new RefreshIndicatorState();

return _pendingRefreshFuture;
}
GlobalKey _key = GlobalKey.key();
key: _key,
onNotification: _handleScrollNotification,
child: new NotificationListener<OverscrollIndicatorNotification>(
onNotification: _handleGlowNotification,

if (_mode == null) {
D.assert(_dragOffset == null);
D.assert(_isIndicatorAtTop == null);
return child;
}
D.assert(() => {
if (_mode == null) {
D.assert(_dragOffset == null);
D.assert(_isIndicatorAtTop == null);
}
else {
D.assert(_dragOffset != null);
D.assert(_isIndicatorAtTop != null);
}
D.assert(_dragOffset != null);
D.assert(_isIndicatorAtTop != null);
return true;
});
return new Stack(
children: new List<Widget> {
child,
new Positioned(
top: _isIndicatorAtTop == true ? 0.0f : (float?) null,
bottom: _isIndicatorAtTop != true ? 0.0f : (float?) null,
left: 0.0f,
right: 0.0f,
child: new SizeTransition(
axisAlignment: _isIndicatorAtTop == true ? 1.0f : -1.0f,
sizeFactor: _positionFactor, // this is what brings it down
child: new Container(
padding: _isIndicatorAtTop == true
? EdgeInsets.only(top: widget.displacement)
: EdgeInsets.only(bottom: widget.displacement),
alignment: _isIndicatorAtTop == true
? Alignment.topCenter
: Alignment.bottomCenter,
child: new ScaleTransition(
scale: _scaleFactor,
child: new AnimatedBuilder(
animation: _positionController,
builder: (BuildContext _context, Widget _child) => {
return new RefreshProgressIndicator(
value: showIndeterminateIndicator ? (float?) null : _value.value,
valueColor: _valueColor,
backgroundColor: widget.backgroundColor
);
}
)
List<Widget> children = new List<Widget> {child};
if (_mode != null) {
children.Add(new Positioned(
top: _isIndicatorAtTop == true ? 0.0f : (float?) null,
bottom: _isIndicatorAtTop != true ? 0.0f : (float?) null,
left: 0.0f,
right: 0.0f,
child: new SizeTransition(
axisAlignment: _isIndicatorAtTop == true ? 1.0f : -1.0f,
sizeFactor: _positionFactor, // this is what brings it down
child: new Container(
padding: _isIndicatorAtTop == true
? EdgeInsets.only(top: widget.displacement)
: EdgeInsets.only(bottom: widget.displacement),
alignment: _isIndicatorAtTop == true
? Alignment.topCenter
: Alignment.bottomCenter,
child: new ScaleTransition(
scale: _scaleFactor,
child: new AnimatedBuilder(
animation: _positionController,
builder: (BuildContext _context, Widget _child) => {
return new RefreshProgressIndicator(
value: showIndeterminateIndicator ? (float?) null : _value.value,
valueColor: _valueColor,
backgroundColor: widget.backgroundColor,
strokeWidth: widget.strokeWidth
);
}
}
));
}
return new Stack(
children: children
}
}

34
com.unity.uiwidgets/Runtime/material/reorderable_list.cs


public class ReorderableListView : StatefulWidget {
public ReorderableListView(
Key key = null,
ScrollController scrollController = null,
) {
) : base(key: key) {
D.assert(onReorder != null);
D.assert(children != null);
D.assert(

this.header = header;
this.children = children;
this.scrollController = scrollController;
this.scrollDirection = scrollDirection;
this.padding = padding;
this.onReorder = onReorder;

public readonly List<Widget> children;
public readonly Axis scrollDirection;
public readonly ScrollController scrollController;
public readonly EdgeInsets padding;

return new _ReorderableListContent(
header: widget.header,
children: widget.children,
scrollController: widget.scrollController,
scrollDirection: widget.scrollDirection,
onReorder: widget.onReorder,
padding: widget.padding,

public _ReorderableListContent(
Widget header,
List<Widget> children,
ScrollController scrollController,
Axis scrollDirection,
EdgeInsets padding,
ReorderCallback onReorder,

this.children = children;
this.scrollController = scrollController;
this.scrollDirection = scrollDirection;
this.padding = padding;
this.onReorder = onReorder;

public readonly Widget header;
public readonly List<Widget> children;
public readonly ScrollController scrollController;
public readonly Axis scrollDirection;
public readonly EdgeInsets padding;
public readonly ReorderCallback onReorder;

}
public override void didChangeDependencies() {
_scrollController = PrimaryScrollController.of(context) ?? new ScrollController();
_scrollController = widget.scrollController ?? PrimaryScrollController.of(context) ?? new ScrollController();
base.didChangeDependencies();
}

D.assert(material_.debugCheckHasMaterialLocalizations(context));
return new LayoutBuilder(builder: (BuildContext _, BoxConstraints constraints) => {
List<Widget> wrappedChildren = new List<Widget> { };
if (widget.header != null) {
wrappedChildren.Add(widget.header);
}
for (int i = 0; i < widget.children.Count; i += 1) {
wrappedChildren.Add(_wrap(widget.children[i], i, constraints));
}
Key endWidgetKey = Key.key("DraggableList - End Widget");
Widget finalDropArea;
switch (widget.scrollDirection) {

}
if (widget.reverse == true) {
wrappedChildren.Insert(0, _wrap(
wrappedChildren.Add(_wrap(
else {
if (widget.header != null) {
wrappedChildren.Add(widget.header);
}
for (int i = 0; i < widget.children.Count; i += 1) {
wrappedChildren.Add(_wrap(widget.children[i], i, constraints));
}
if (widget.reverse != true) {
wrappedChildren.Add(_wrap(
finalDropArea, widget.children.Count,
constraints)

110
com.unity.uiwidgets/Runtime/material/scrollbar.cs


using System;
using Unity.UIWidgets.animation;
using Unity.UIWidgets.async;
using Unity.UIWidgets.cupertino;
using UnityEngine;
using Color = Unity.UIWidgets.ui.Color;
namespace Unity.UIWidgets.material {
static class ScrollbarUtils {

public class Scrollbar : StatefulWidget {
public Scrollbar(
Key key = null,
Widget child = null) : base(key: key) {
Widget child = null,
ScrollController controller = null,
bool isAlwaysShown = false) : base(key: key) {
this.controller = controller;
this.isAlwaysShown = isAlwaysShown;
public readonly ScrollController controller;
public readonly bool isAlwaysShown;
public override State createState() {
return new _ScrollbarState();

public TextDirection _textDirection;
public Color _themeColor;
bool? _useCupertinoScrollbar = null;
public Animation<float> _FadeoutOpacityAnimation;
public Animation<float> _fadeoutOpacityAnimation;
public Timer _fadeoutTimer;
public override void initState() {

duration: ScrollbarUtils._kScrollbarFadeDuration
);
_FadeoutOpacityAnimation = new CurvedAnimation(
_fadeoutOpacityAnimation = new CurvedAnimation(
parent: _fadeoutAnimationController,
curve: Curves.fastOutSlowIn
);

base.didChangeDependencies();
D.assert((() => {
_useCupertinoScrollbar = null;
return true;
}));
_themeColor = theme.highlightColor.withOpacity(1.0f);
_textDirection = Directionality.of(context);
_materialPainter = _BuildMaterialScrollbarPainter();
switch (theme.platform) {
case RuntimePlatform.IPhonePlayer:
case RuntimePlatform.OSXPlayer:
case RuntimePlatform.OSXEditor:
_fadeoutTimer?.cancel();
_fadeoutTimer = null;
_fadeoutAnimationController.reset();
_useCupertinoScrollbar = true;
break;
default:
_themeColor = theme.highlightColor.withOpacity(1.0f);
_textDirection = Directionality.of(context);
_materialPainter = _buildMaterialScrollbarPainter();
_useCupertinoScrollbar = false;
WidgetsBinding.instance.addPostFrameCallback((TimeSpan duration) => {
if (widget.isAlwaysShown) {
D.assert(widget.controller != null);
widget.controller.position.didUpdateScrollPositionBy(0);
}
});
break;
}
D.assert(_useCupertinoScrollbar != null);
public ScrollbarPainter _BuildMaterialScrollbarPainter() {
public override void didUpdateWidget(StatefulWidget oldWidget) {
var _oldWidget = (Scrollbar) oldWidget;
base.didUpdateWidget(oldWidget);
if (widget.isAlwaysShown != _oldWidget.isAlwaysShown) {
D.assert(widget.controller != null);
if (widget.isAlwaysShown == false) {
_fadeoutAnimationController.reverse();
}
else {
_fadeoutAnimationController.animateTo(1.0f);
}
}
}
public ScrollbarPainter _buildMaterialScrollbarPainter() {
textDirection: _textDirection,
thickness: ScrollbarUtils._kScrollbarThickness,
fadeoutOpacityAnimation: _FadeoutOpacityAnimation
textDirection: _textDirection,
thickness: ScrollbarUtils._kScrollbarThickness,
fadeoutOpacityAnimation: _fadeoutOpacityAnimation,
padding: MediaQuery.of(context).padding
if (notification is ScrollUpdateNotification || notification is OverscrollNotification) {
ScrollMetrics metrics = notification.metrics;
if (metrics.maxScrollExtent <= metrics.minScrollExtent) {
return false;
}
if (!_useCupertinoScrollbar.Value &&
(notification is ScrollUpdateNotification ||
notification is OverscrollNotification)) {
_materialPainter.update(notification.metrics, notification.metrics.axisDirection);
_fadeoutTimer?.cancel();
_fadeoutTimer = Timer.create(ScrollbarUtils._kScrollbarTimeToFade, () => {
_fadeoutAnimationController.reverse();
_fadeoutTimer = null;
});
_materialPainter.update(
notification.metrics,
notification.metrics.axisDirection
);
if (!widget.isAlwaysShown) {
_fadeoutTimer?.cancel();
_fadeoutTimer = Timer.create(ScrollbarUtils._kScrollbarTimeToFade, () => {
_fadeoutAnimationController.reverse();
_fadeoutTimer = null;
});
}
return false;
}

}
public override Widget build(BuildContext context) {
//TODO:uncomment here when cupertino updates are merged
/*if (_useCupertinoScrollbar.Value) {
return new CupertinoScrollbar(
child: widget.child,
isAlwaysShown: widget.isAlwaysShown,
controller: widget.controller
);
}*/
return new NotificationListener<ScrollNotification>(
onNotification: _handleScrollNotification,
child: new RepaintBoundary(

70
com.unity.uiwidgets/Runtime/material/search.cs


}
public abstract class SearchDelegate<T> {
public SearchDelegate(
string searchFieldLabel = null,
TextInputType keyboardType = null,
TextInputAction textInputAction = TextInputAction.search
) {
this.searchFieldLabel = searchFieldLabel;
this.keyboardType = keyboardType;
this.textInputAction = textInputAction;
}
public abstract Widget buildSuggestions(BuildContext context);
public abstract Widget buildResults(BuildContext context);
public abstract Widget buildLeading(BuildContext context);

}
public virtual void showResults(BuildContext context) {
_focusNode.unfocus();
_focusNode?.unfocus();
FocusScope.of(context).requestFocus(_focusNode);
D.assert(_focusNode != null, () => "_focusNode must be set by route before showSuggestions is called.");
_focusNode.requestFocus();
_focusNode.unfocus();
_focusNode?.unfocus();
public readonly string searchFieldLabel;
public readonly TextInputType keyboardType;
public readonly TextInputAction textInputAction;
readonly internal FocusNode _focusNode = new FocusNode();
internal FocusNode _focusNode;
readonly internal TextEditingController _queryTextController = new TextEditingController();

public override Color barrierColor {
get { return null; }
}
public override string barrierLabel => null;
public override TimeSpan transitionDuration {
get { return new TimeSpan(0, 0, 0, 0, 300); }

}
class _SearchPageState<T> : State<_SearchPage<T>> {
FocusNode focusNode = new FocusNode();
queryTextController.addListener(_onQueryChanged);
widget.del._queryTextController.addListener(_onQueryChanged);
widget.del._focusNode.addListener(_onFocusChanged);
focusNode.addListener(_onFocusChanged);
widget.del._focusNode = focusNode;
queryTextController.removeListener(_onQueryChanged);
widget.del._queryTextController.removeListener(_onQueryChanged);
widget.del._focusNode.removeListener(_onFocusChanged);
widget.del._focusNode = null;
focusNode.dispose();
}
void _onAnimationStatusChanged(AnimationStatus status) {

widget.animation.removeStatusListener(_onAnimationStatusChanged);
if (widget.del._currentBody == _SearchBody.suggestions) {
FocusScope.of(context).requestFocus(widget.del._focusNode);
focusNode.requestFocus();
}
}
public override void didUpdateWidget(StatefulWidget oldWidget) {
var _oldWidget = (_SearchPage<T>) oldWidget;
base.didUpdateWidget(oldWidget);
if (widget.del != _oldWidget.del) {
_oldWidget.del._queryTextController.removeListener(_onQueryChanged);
widget.del._queryTextController.addListener(_onQueryChanged);
_oldWidget.del._currentBodyNotifier.removeListener(_onSearchBodyChanged);
widget.del._currentBodyNotifier.addListener(_onSearchBodyChanged);
_oldWidget.del._focusNode = null;
widget.del._focusNode = focusNode;
if (widget.del._focusNode.hasFocus && widget.del._currentBody != _SearchBody.suggestions) {
if (focusNode.hasFocus && widget.del._currentBody != _SearchBody.suggestions) {
widget.del.showSuggestions(context);
}
}

material_.debugCheckHasMaterialLocalizations(context);
ThemeData theme = widget.del.appBarTheme(context);
string searchFieldLabel = MaterialLocalizations.of(context).searchFieldLabel;
string searchFieldLabel = widget.del.searchFieldLabel ?? MaterialLocalizations.of(context).searchFieldLabel;
Widget body = null;
switch (widget.del._currentBody) {
case _SearchBody.suggestions:

string routeName;
switch (Theme.of(this.context).platform) {
case RuntimePlatform.IPhonePlayer:
case RuntimePlatform.OSXEditor:
case RuntimePlatform.OSXPlayer:
routeName = "";
break;
case RuntimePlatform.Android:

brightness: theme.primaryColorBrightness,
leading: widget.del.buildLeading(context),
title: new TextField(
controller: queryTextController,
focusNode: widget.del._focusNode,
style: theme.textTheme.title,
textInputAction: TextInputAction.search,
controller: widget.del._queryTextController,
focusNode: focusNode,
style: theme.textTheme.headline6,
textInputAction: widget.del.textInputAction,
keyboardType: widget.del.keyboardType,
hintText: searchFieldLabel
hintText: searchFieldLabel,
hintStyle: theme.inputDecorationTheme.hintStyle
)
),
actions: widget.del.buildActions(context)

4
com.unity.uiwidgets/Runtime/material/slider_theme.cs


}
}
public delegate Thumb RangeThumbSelector(TextDirection textDirection,
public delegate Thumb? RangeThumbSelector(TextDirection textDirection,
double tapValue,
float tapValue,
Size thumbSize,
Size trackSize,
float dx

24
com.unity.uiwidgets/Runtime/widgets/editable_text.cs


public class EditableText : StatefulWidget {
public EditableText(
SmartDashesType smartDashesType,
SmartQuotesType smartQuotesType,
Key key = null,
TextEditingController controller = null,
FocusNode focusNode = null,

SmartDashesType? smartDashesType = null,
SmartQuotesType? smartQuotesType = null,
bool enableSuggestions = true,
TextStyle style = null,
StrutStyle strutStyle = null,

) : base(key) {
D.assert(controller != null);
D.assert(focusNode != null);
smartDashesType = (obscureText ? SmartDashesType.disabled : SmartDashesType.enabled);
smartQuotesType = (obscureText ? SmartQuotesType.disabled : SmartQuotesType.enabled);
smartDashesType = smartDashesType ?? (obscureText ? SmartDashesType.disabled : SmartDashesType.enabled);
smartQuotesType = smartQuotesType ?? (obscureText ? SmartQuotesType.disabled : SmartQuotesType.enabled);
D.assert(enableInteractiveSelection != null);
D.assert(style != null);
D.assert(cursorColor != null);

this.obscureText = obscureText;
this.autocorrect = autocorrect;
this.style = style;
this.smartDashesType = smartDashesType;
this.smartQuotesType = smartQuotesType;
this.smartDashesType = smartDashesType.Value;
this.smartQuotesType = smartQuotesType.Value;
this.showCursor = showCursor;
this.textWidthBasis = textWidthBasis;
this.onSelectionHandleTapped = onSelectionHandleTapped;

inputType: widget.keyboardType,
obscureText: widget.obscureText,
autocorrect: widget.autocorrect,
smartDashesType: widget.obscureText ? SmartDashesType.disabled : SmartDashesType.enabled,
smartQuotesType: widget.obscureText ? SmartQuotesType.disabled : SmartQuotesType.enabled,
smartDashesType: widget.smartDashesType,
smartQuotesType: widget.smartQuotesType,
enableSuggestions: widget.enableSuggestions,
inputAction: widget.textInputAction ?? (widget.keyboardType == TextInputType.multiline
? TextInputAction.newline

Locale locale = null,
bool obscureText = false,
bool autocorrect = false,
SmartDashesType smartDashesType = SmartDashesType.disabled,
SmartQuotesType smartQuotesType = SmartQuotesType.disabled,
SmartDashesType? smartDashesType = null,
SmartQuotesType? smartQuotesType = null,
bool? enableSuggestions = null,
ViewportOffset offset = null,
SelectionChangedHandler onSelectionChanged = null,

this.textDirection = textDirection;
this.obscureText = obscureText;
this.autocorrect = autocorrect;
this.smartDashesType = smartDashesType;
this.smartQuotesType = smartQuotesType;
this.smartDashesType = smartDashesType.Value;
this.smartQuotesType = smartQuotesType.Value;
this.enableSuggestions = enableSuggestions;
this.offset = offset;
this.onSelectionChanged = onSelectionChanged;

1001
com.unity.uiwidgets/Runtime/material/range_slider.cs
文件差异内容过多而无法显示
查看文件

572
com.unity.uiwidgets/Runtime/material/selectable_text.cs


using System;
using System.Collections.Generic;
using Unity.UIWidgets.animation;
using Unity.UIWidgets.async2;
using Unity.UIWidgets.cupertino;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.gestures;
using Unity.UIWidgets.painting;
using Unity.UIWidgets.rendering;
using Unity.UIWidgets.service;
using Unity.UIWidgets.ui;
using Unity.UIWidgets.widgets;
using UnityEngine;
using Color = Unity.UIWidgets.ui.Color;
using StrutStyle = Unity.UIWidgets.painting.StrutStyle;
using TextStyle = Unity.UIWidgets.painting.TextStyle;
namespace Unity.UIWidgets.material {
public static class SelectableTextUtils {
internal const int iOSHorizontalOffset = -2;
}
class _TextSpanEditingController : TextEditingController {
public _TextSpanEditingController(TextSpan textSpan = null) : base(text: textSpan?.toPlainText()) {
D.assert(textSpan != null);
_textSpan = textSpan;
}
public readonly TextSpan _textSpan;
public override TextSpan buildTextSpan(TextStyle style = null ,bool withComposing = false) {
return new TextSpan(
style: style,
children: new List<InlineSpan> {_textSpan}
);
}
public new string text {
get { return value.text; }
set {
}
}
}
class _SelectableTextSelectionGestureDetectorBuilder : TextSelectionGestureDetectorBuilder {
public _SelectableTextSelectionGestureDetectorBuilder(
_SelectableTextState state
) : base(_delegate: state) {
_state = state;
}
public readonly _SelectableTextState _state;
protected override void onForcePressStart(ForcePressDetails details) {
base.onForcePressStart(details);
if (_delegate.selectionEnabled && shouldShowSelectionToolbar) {
editableText.showToolbar();
}
}
protected override void onForcePressEnd(ForcePressDetails details) {
// Not required.
}
protected override void onSingleLongTapMoveUpdate(LongPressMoveUpdateDetails details) {
if (_delegate.selectionEnabled) {
switch (Theme.of(_state.context).platform) {
case RuntimePlatform.IPhonePlayer:
case RuntimePlatform.OSXEditor:
case RuntimePlatform.OSXPlayer:
renderEditable.selectPositionAt(
from: details.globalPosition,
cause: SelectionChangedCause.longPress
);
break;
default:
renderEditable.selectWordsInRange(
from: details.globalPosition - details.offsetFromOrigin,
to: details.globalPosition,
cause: SelectionChangedCause.longPress
);
break;
}
}
}
protected override void onSingleTapUp(TapUpDetails details) {
editableText.hideToolbar();
if (_delegate.selectionEnabled) {
switch (Theme.of(_state.context).platform) {
case RuntimePlatform.IPhonePlayer:
case RuntimePlatform.OSXEditor:
case RuntimePlatform.OSXPlayer:
renderEditable.selectWordEdge(cause: SelectionChangedCause.tap);
break;
default:
renderEditable.selectPosition(cause: SelectionChangedCause.tap);
break;
}
}
if (_state.widget.onTap != null)
_state.widget.onTap();
}
protected override void onSingleLongTapStart(LongPressStartDetails details) {
if (_delegate.selectionEnabled) {
switch (Theme.of(_state.context).platform) {
case RuntimePlatform.IPhonePlayer:
case RuntimePlatform.OSXEditor:
case RuntimePlatform.OSXPlayer:
renderEditable.selectPositionAt(
from: details.globalPosition,
cause: SelectionChangedCause.longPress
);
break;
default:
renderEditable.selectWord(cause: SelectionChangedCause.longPress);
Feedback.forLongPress(_state.context);
break;
}
}
}
}
class SelectableText : StatefulWidget {
public SelectableText(
string data,
Key key = null,
FocusNode focusNode = null,
TextStyle style = null,
StrutStyle strutStyle = null,
TextAlign? textAlign = null,
TextDirection? textDirection = null,
float? textScaleFactor = null,
bool showCursor = false,
bool autofocus = false,
ToolbarOptions toolbarOptions = null,
int? minLines = null,
int? maxLines = null,
float cursorWidth = 2.0f,
Radius cursorRadius = null,
Color cursorColor = null,
DragStartBehavior dragStartBehavior = DragStartBehavior.start,
bool enableInteractiveSelection = true,
GestureTapCallback onTap = null,
ScrollPhysics scrollPhysics = null,
TextWidthBasis? textWidthBasis = null
) : this(
data: data,
textSpan: null,
key: key,
focusNode: focusNode,
style: style,
strutStyle: strutStyle,
textAlign: textAlign,
textDirection: textDirection,
textScaleFactor: textScaleFactor,
showCursor: showCursor,
autofocus: autofocus,
toolbarOptions: toolbarOptions,
minLines: minLines,
maxLines: maxLines,
cursorWidth: cursorWidth,
cursorRadius: cursorRadius,
cursorColor: cursorColor,
dragStartBehavior: dragStartBehavior,
enableInteractiveSelection: enableInteractiveSelection,
onTap: onTap,
scrollPhysics: scrollPhysics,
textWidthBasis: textWidthBasis
) {
D.assert(
data != null,
() => "A non-null String must be provided to a SelectableText widget."
);
}
SelectableText(
string data,
TextSpan textSpan,
Key key = null,
FocusNode focusNode = null,
TextStyle style = null,
StrutStyle strutStyle = null,
TextAlign? textAlign = null,
TextDirection? textDirection = null,
float? textScaleFactor = null,
bool showCursor = false,
bool autofocus = false,
ToolbarOptions toolbarOptions = null,
int? minLines = null,
int? maxLines = null,
float cursorWidth = 2.0f,
Radius cursorRadius = null,
Color cursorColor = null,
DragStartBehavior dragStartBehavior = DragStartBehavior.start,
bool enableInteractiveSelection = true,
GestureTapCallback onTap = null,
ScrollPhysics scrollPhysics = null,
TextWidthBasis? textWidthBasis = null
) : base(key: key) {
D.assert(maxLines == null || maxLines > 0);
D.assert(minLines == null || minLines > 0);
D.assert(
(maxLines == null) || (minLines == null) || (maxLines >= minLines),
() => "minLines can\'t be greater than maxLines"
);
toolbarOptions = toolbarOptions ??
new ToolbarOptions(
selectAll: true,
copy: true
);
this.data = data;
this.textSpan = textSpan;
this.focusNode = focusNode;
this.style = style;
this.strutStyle = strutStyle;
this.textAlign = textAlign;
this.textDirection = textDirection;
this.textScaleFactor = textScaleFactor;
this.showCursor = showCursor;
this.autofocus = autofocus;
this.toolbarOptions = toolbarOptions;
this.minLines = minLines;
this.maxLines = maxLines;
this.cursorWidth = cursorWidth;
this.cursorRadius = cursorRadius;
this.cursorColor = cursorColor;
this.dragStartBehavior = dragStartBehavior;
this.enableInteractiveSelection = enableInteractiveSelection;
this.onTap = onTap;
this.scrollPhysics = scrollPhysics;
this.textWidthBasis = textWidthBasis;
}
public static SelectableText rich(
TextSpan textSpan,
Key key = null,
FocusNode focusNode = null,
TextStyle style = null,
StrutStyle strutStyle = null,
TextAlign? textAlign = null,
TextDirection? textDirection = null,
float? textScaleFactor = null,
bool showCursor = false,
bool autofocus = false,
ToolbarOptions toolbarOptions = null,
int? minLines = null,
int? maxLines = null,
float cursorWidth = 2.0f,
Radius cursorRadius = null,
Color cursorColor = null,
DragStartBehavior dragStartBehavior = DragStartBehavior.start,
bool enableInteractiveSelection = true,
GestureTapCallback onTap = null,
ScrollPhysics scrollPhysics = null,
TextWidthBasis? textWidthBasis = null
) {
D.assert(
textSpan != null,
() => "A non-null TextSpan must be provided to a SelectableText.rich widget."
);
return new SelectableText(
data: null,
textSpan: textSpan,
key: key,
focusNode: focusNode,
style: style,
strutStyle: strutStyle,
textAlign: textAlign,
textDirection: textDirection,
textScaleFactor: textScaleFactor,
showCursor: showCursor,
autofocus: autofocus,
toolbarOptions: toolbarOptions,
minLines: minLines,
maxLines: maxLines,
cursorWidth: cursorWidth,
cursorRadius: cursorRadius,
cursorColor: cursorColor,
dragStartBehavior: dragStartBehavior,
enableInteractiveSelection: enableInteractiveSelection,
onTap: onTap,
scrollPhysics: scrollPhysics,
textWidthBasis: textWidthBasis
);
}
public readonly string data;
public readonly TextSpan textSpan;
public readonly FocusNode focusNode;
public readonly TextStyle style;
public readonly StrutStyle strutStyle;
public readonly TextAlign? textAlign;
public readonly TextDirection? textDirection;
public readonly float? textScaleFactor;
public readonly bool autofocus;
public readonly int? minLines;
public readonly int? maxLines;
public readonly bool showCursor;
public readonly float cursorWidth;
public readonly Radius cursorRadius;
public readonly Color cursorColor;
public readonly bool enableInteractiveSelection;
public readonly DragStartBehavior dragStartBehavior;
public readonly ToolbarOptions toolbarOptions;
internal bool selectionEnabled {
get { return enableInteractiveSelection; }
}
public readonly GestureTapCallback onTap;
public readonly ScrollPhysics scrollPhysics;
public readonly TextWidthBasis? textWidthBasis;
public override State createState() => new _SelectableTextState();
public override void debugFillProperties(DiagnosticPropertiesBuilder properties) {
base.debugFillProperties(properties);
properties.add( new DiagnosticsProperty<String>("data", data, defaultValue: null));
properties.add( new DiagnosticsProperty<FocusNode>("focusNode", focusNode, defaultValue: null));
properties.add( new DiagnosticsProperty<TextStyle>("style", style, defaultValue: null));
properties.add( new DiagnosticsProperty<bool>("autofocus", autofocus, defaultValue: false));
properties.add( new DiagnosticsProperty<bool>("showCursor", showCursor, defaultValue: false));
properties.add( new IntProperty("minLines", minLines, defaultValue: null));
properties.add( new IntProperty("maxLines", maxLines, defaultValue: null));
properties.add( new EnumProperty<TextAlign?>("textAlign", textAlign, defaultValue: null));
properties.add( new EnumProperty<TextDirection?>("textDirection", textDirection, defaultValue: null));
properties.add( new FloatProperty("textScaleFactor", textScaleFactor, defaultValue: null));
properties.add( new FloatProperty("cursorWidth", cursorWidth, defaultValue: 2.0f));
properties.add( new DiagnosticsProperty<Radius>("cursorRadius", cursorRadius, defaultValue: null));
properties.add( new DiagnosticsProperty<Color>("cursorColor", cursorColor, defaultValue: null));
properties.add( new FlagProperty("selectionEnabled", value: selectionEnabled, defaultValue: true, ifFalse: "selection disabled"));
properties.add( new DiagnosticsProperty<ScrollPhysics>("scrollPhysics", scrollPhysics, defaultValue: null));
}
}
class _SelectableTextState : AutomaticKeepAliveClientMixin<SelectableText>,
TextSelectionGestureDetectorBuilderDelegate {
EditableTextState _editableText => editableTextKey.currentState;
_TextSpanEditingController _controller;
FocusNode _focusNode;
FocusNode _effectiveFocusNode => widget.focusNode ?? (_focusNode = _focusNode ?? new FocusNode());
bool _showSelectionHandles = false;
_SelectableTextSelectionGestureDetectorBuilder _selectionGestureDetectorBuilder;
public bool forcePressEnabled {
get { return _forcePressEnabled; }
set { _forcePressEnabled = value; }
}
bool _forcePressEnabled;
public GlobalKey<EditableTextState> editableTextKey {
get { return _editableTextKey; }
}
readonly GlobalKey<EditableTextState> _editableTextKey = GlobalKey<EditableTextState>.key();
public bool selectionEnabled => widget.selectionEnabled;
public override void initState() {
base.initState();
_selectionGestureDetectorBuilder = new _SelectableTextSelectionGestureDetectorBuilder(state: this);
_controller = new _TextSpanEditingController(
textSpan: widget.textSpan ?? new TextSpan(text: widget.data)
);
}
public override void didUpdateWidget(StatefulWidget oldWidget) {
var _oldWidget = (SelectableText) oldWidget;
base.didUpdateWidget(oldWidget);
if (widget.data != _oldWidget.data || widget.textSpan != _oldWidget.textSpan) {
_controller = new _TextSpanEditingController(
textSpan: widget.textSpan ?? new TextSpan(text: widget.data)
);
}
if (_effectiveFocusNode.hasFocus && _controller.selection.isCollapsed) {
_showSelectionHandles = false;
}
}
public override void dispose() {
_focusNode?.dispose();
base.dispose();
}
void _handleSelectionChanged(TextSelection selection, SelectionChangedCause cause) {
bool willShowSelectionHandles = _shouldShowSelectionHandles(cause);
if (willShowSelectionHandles != _showSelectionHandles) {
setState(() => {
_showSelectionHandles = willShowSelectionHandles;
});
}
switch (Theme.of(context).platform) {
case RuntimePlatform.IPhonePlayer:
case RuntimePlatform.OSXEditor:
case RuntimePlatform.OSXPlayer:
if (cause == SelectionChangedCause.longPress) {
_editableText?.bringIntoView(selection.basePos);
}
return;
default:
// Do nothing.
break;
}
}
void _handleSelectionHandleTapped() {
if (_controller.selection.isCollapsed) {
_editableText.toggleToolbar();
}
}
bool _shouldShowSelectionHandles(SelectionChangedCause cause) {
if (!_selectionGestureDetectorBuilder.shouldShowSelectionToolbar)
return false;
if (_controller.selection.isCollapsed)
return false;
if (cause == SelectionChangedCause.keyboard)
return false;
if (cause == SelectionChangedCause.longPress)
return true;
if (_controller.text.isNotEmpty())
return true;
return false;
}
protected override bool wantKeepAlive => true;
Widget build(BuildContext context) {
base.build(context);
D.assert(() => {
return _controller._textSpan.visitChildren((InlineSpan span) => span is TextSpan);
}, () => "SelectableText only supports TextSpan; Other type of InlineSpan is not allowed");
D.assert(WidgetsD.debugCheckHasMediaQuery(context));
D.assert(WidgetsD.debugCheckHasDirectionality(context));
D.assert(
!(widget.style != null && widget.style.inherit == false &&
(widget.style.fontSize == null || widget.style.textBaseline == null)),
() => "inherit false style must supply fontSize and textBaseline"
);
ThemeData themeData = Theme.of(context);
FocusNode focusNode = _effectiveFocusNode;
TextSelectionControls textSelectionControls;
bool paintCursorAboveText;
bool cursorOpacityAnimates;
Offset cursorOffset = Offset.zero;
Color cursorColor = widget.cursorColor;
Radius cursorRadius = widget.cursorRadius;
switch (themeData.platform) {
case RuntimePlatform.IPhonePlayer:
case RuntimePlatform.OSXEditor:
case RuntimePlatform.OSXPlayer:
forcePressEnabled = true;
textSelectionControls = CupertinoTextSelectionUtils.cupertinoTextSelectionControls;
paintCursorAboveText = true;
cursorOpacityAnimates = true;
cursorColor = cursorColor ?? CupertinoTheme.of(context).primaryColor;
cursorRadius = cursorRadius?? Radius.circular(2.0f);
cursorOffset = new Offset(SelectableTextUtils.iOSHorizontalOffset / MediaQuery.of(context).devicePixelRatio, 0);
break;
default:
forcePressEnabled = false;
textSelectionControls = _MaterialTextSelectionControls.materialTextSelectionControls;
paintCursorAboveText = false;
cursorOpacityAnimates = false;
cursorColor = cursorColor ?? themeData.cursorColor;
break;
}
DefaultTextStyle defaultTextStyle = DefaultTextStyle.of(context);
TextStyle effectiveTextStyle = widget.style;
if (widget.style == null || widget.style.inherit)
effectiveTextStyle = defaultTextStyle.style.merge(widget.style);
if (MediaQuery.boldTextOverride(context))
effectiveTextStyle = effectiveTextStyle.merge(new TextStyle(fontWeight: FontWeight.bold));
Widget child = new RepaintBoundary(
child: new EditableText(
key: editableTextKey,
style: effectiveTextStyle,
readOnly: true,
textWidthBasis: widget.textWidthBasis ?? defaultTextStyle.textWidthBasis,
showSelectionHandles: _showSelectionHandles,
showCursor: widget.showCursor,
controller: _controller,
focusNode: focusNode,
strutStyle: widget.strutStyle ?? new StrutStyle(),
textAlign: widget.textAlign ?? defaultTextStyle.textAlign ?? TextAlign.start,
textDirection: widget.textDirection,
textScaleFactor: widget.textScaleFactor,
autofocus: widget.autofocus,
forceLine: false,
toolbarOptions: widget.toolbarOptions,
minLines: widget.minLines,
maxLines: widget.maxLines ?? defaultTextStyle.maxLines,
selectionColor: themeData.textSelectionColor,
selectionControls: widget.selectionEnabled ? textSelectionControls : null,
onSelectionChanged: _handleSelectionChanged,
onSelectionHandleTapped: _handleSelectionHandleTapped,
rendererIgnoresPointer: true,
cursorWidth: widget.cursorWidth,
cursorRadius: cursorRadius,
cursorColor: cursorColor,
cursorOpacityAnimates: cursorOpacityAnimates,
cursorOffset: cursorOffset,
paintCursorAboveText: paintCursorAboveText,
backgroundCursorColor: CupertinoColors.inactiveGray,
enableInteractiveSelection: widget.enableInteractiveSelection,
dragStartBehavior: widget.dragStartBehavior,
scrollPhysics: widget.scrollPhysics
)
);
return _selectionGestureDetectorBuilder.buildGestureDetector(
behavior: HitTestBehavior.translucent,
child: child
);
}
}
}

1001
com.unity.uiwidgets/Runtime/material/time_picker.cs
文件差异内容过多而无法显示
查看文件

/com.unity.uiwidgets/Runtime/material/timer.cs → /com.unity.uiwidgets/Runtime/material/time.cs

正在加载...
取消
保存