浏览代码

Revert "Revert "temporary fix""

This reverts commit 0417671c6b9b1f0bbf71a3c1aaf26d7d7a1f08b9.
/siyaoH-1.17-PlatformMessage
guanghuispark 4 年前
当前提交
cf01be21
共有 3 个文件被更改,包括 189 次插入106 次删除
  1. 7
      com.unity.uiwidgets/Runtime/widgets/editable_text.cs
  2. 144
      com.unity.uiwidgets/Runtime/widgets/focus_scope.cs
  3. 144
      com.unity.uiwidgets/Runtime/widgets/focus_traversal.cs

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


_openInputConnection();
}
else {
widget.focusNode.requestFocus();
List<FocusScopeNode> ancestorScopes = FocusScope.ancestorsOf(context);
for (int i = ancestorScopes.Count - 1; i >= 1; i -= 1) {
ancestorScopes[i].setFirstFocus(ancestorScopes[i - 1]);
}
FocusScope.of(context).requestFocus(widget.focusNode);
}
}

144
com.unity.uiwidgets/Runtime/widgets/focus_scope.cs


}
}
public class FocusScope : Focus {
public FocusScope(
Key key = null,
FocusScopeNode node = null,
Widget child = null,
bool autofocus = false,
ValueChanged<bool> onFocusChange = null,
bool? canRequestFocus = null,
bool? skipTraversal = null,
FocusOnKeyCallback onKey = null,
string debugLabel = null
) : base(
key: key,
child: child,
focusNode: node,
autofocus: autofocus,
onFocusChange: onFocusChange,
canRequestFocus: canRequestFocus,
skipTraversal: skipTraversal,
onKey: onKey,
debugLabel: debugLabel) {
D.assert(child != null);
D.assert(autofocus != null);
public class FocusScope : StatefulWidget {
public FocusScope(FocusScopeNode node, Widget child, Key key = null, bool autofocus = false) : base(key) {
this.node = node;
this.child = child;
this.autofocus = autofocus;
public readonly FocusScopeNode node;
public readonly bool autofocus;
public readonly Widget child;
_FocusMarker marker = context.dependOnInheritedWidgetOfExactType<_FocusMarker>();
return marker?.notifier?.nearestScope ?? context.owner.focusManager.rootScope;
var scope = (_FocusScopeMarker) context.inheritFromWidgetOfExactType(typeof(_FocusScopeMarker));
if (scope != null && scope.node != null) {
return scope.node;
}
return context.owner.focusManager.rootScope;
public static List<FocusScopeNode> ancestorsOf(BuildContext context) {
D.assert(context != null);
List<FocusScopeNode> ancestors = new List<FocusScopeNode> { };
while (true) {
context = context.ancestorInheritedElementForWidgetOfExactType(typeof(_FocusScopeMarker));
if (context == null) {
return ancestors;
}
_FocusScopeMarker scope = (_FocusScopeMarker) context.widget;
ancestors.Add(scope.node);
context.visitAncestorElements((Element parent) => {
context = parent;
return false;
});
}
}
class _FocusScopeState : _FocusState {
public FocusScopeNode _createNode() {
return new FocusScopeNode(
debugLabel: widget.debugLabel,
canRequestFocus: widget.canRequestFocus ?? true,
skipTraversal: widget.skipTraversal ?? false
);
}
public override Widget build(BuildContext context) {
_focusAttachment.reparent();
return new _FocusMarker(
node: focusNode,
child: widget.child);
}
}
class _FocusMarker : InheritedNotifier<FocusNode> {
public _FocusMarker(
Key key = null,
FocusNode node = null,
Widget child = null
) : base(key: key, notifier: node, child: child) {
D.assert(node != null);
D.assert(child != null);
}
}
public class Focus : StatefulWidget {
public Focus(

}
return node;
}
public static bool isAt(BuildContext context) => Focus.of(context, nullOk: true)?.hasFocus ?? false;
//public static bool isAt(BuildContext context) => Focus.of(context, nullOk: true)?.hasFocus ?? false;
public override void debugFillProperties(DiagnosticPropertiesBuilder properties) {
base.debugFillProperties(properties);
properties.add(new StringProperty("debugLabel", debugLabel, defaultValue: null));

public class _FocusState : State<Focus> {
FocusNode _internalNode;
public FocusNode focusNode {
get {
return widget.focusNode ?? _internalNode;

base.didUpdateWidget(oldWidget);
D.assert(()=> {
if (((Focus)oldWidget).debugLabel != widget.debugLabel && _internalNode != null) {
_internalNode.debugLabel = widget.debugLabel;
}
return true;
_internalNode.debugLabel = widget.debugLabel;
}
return true;
});
if (((Focus)oldWidget).focusNode == widget.focusNode) {

}
}
/*class _FocusScopeState : State<FocusScope> {
bool _didAutofocus = false;
public override void didChangeDependencies() {
base.didChangeDependencies();
if (!_didAutofocus && widget.autofocus) {
FocusScope.of(context).setFirstFocus(widget.node);
_didAutofocus = true;
}
}
public override void dispose() {
widget.node.detach();
base.dispose();
}
public override Widget build(BuildContext context) {
FocusScope.of(context).reparentScopeIfNeeded(widget.node);
return new _FocusScopeMarker(node: widget.node, child: widget.child);
}
}*/
class _FocusScopeState : _FocusState {
public FocusScopeNode _createNode() {
return new FocusScopeNode(
debugLabel: widget.debugLabel,
canRequestFocus: widget.canRequestFocus ?? true,
skipTraversal: widget.skipTraversal ?? false
);
}
public override Widget build(BuildContext context) {
_focusAttachment.reparent();
return new _FocusMarker(
node: focusNode,
child: widget.child);
}
}
class _FocusMarker : InheritedNotifier<FocusNode> {
public _FocusMarker(
Key key = null,
FocusNode node = null,
Widget child = null
) : base(key: key, notifier: node, child: child) {
D.assert(node != null);
D.assert(child != null);
}
}
}

144
com.unity.uiwidgets/Runtime/widgets/focus_traversal.cs


using System;
using Unity.UIWidgets.widgets;
namespace Unity.UIWidgets.widgets {
public class FocusTraversalGroup : StatefulWidget {

Widget child = null
) : base(key: key) {
policy = policy ?? ReadingOrderTraversalPolicy();
policy = policy ?? new ReadingOrderTraversalPolicy();
this.child = child;
}

public override void debugFillProperties(DiagnosticPropertiesBuilder properties) {
base.debugFillProperties(properties);
properties.add(new DiagnosticsProperty<FocusTraversalPolicy>("policy", policy));
properties.add(new TextTreeRenderer.DiagnosticsProperty<FocusTraversalPolicy>("policy", policy));
}
}
public class _FocusTraversalGroupState : State<FocusTraversalGroup> {

public override bool updateShouldNotify(InheritedWidget oldWidget) => false;
}
public abstract class FocusTraversalPolicy : Diagnosticable {
public abstract class FocusTraversalPolicy : TextTreeRenderer.Diagnosticable {
public FocusTraversalPolicy() {
}

);
D.assert(
scope.traversalDescendants.toSet().difference(sortedDescendants.toSet()).isEmpty,
'sorted descendants are missing some nodes: (${scope.traversalDescendants.toSet().difference(sortedDescendants.toSet())})'
"sorted descendants are missing some nodes: (${scope.traversalDescendants.toSet().difference(sortedDescendants.toSet())})"
);
return sortedDescendants;
}

public readonly TraversalDirection direction;
public readonly FocusNode node;
}
class ReadingOrderTraversalPolicy : FocusTraversalPolicy , DirectionalFocusTraversalPolicyMixin {
class _ReadingOrderDirectionalGroupData : Diagnosticable {
public _ReadingOrderDirectionalGroupData(List<_ReadingOrderSortData> members) {
this.members = members;
}
public readonly List<_ReadingOrderSortData> members;
TextDirection directionality {
get {
return members.First().directionality;
}
}
Rect _rect;
Rect rect {
get {if (_rect == null) {
foreach(Rect rect in members.Select<Rect>(
(_ReadingOrderSortData data) => data.rect)){
_rect ??= rect;
_rect = _rect.expandToInclude(rect);
}
}
return _rect;
}
}
List<Directionality> memberAncestors {
get { if (_memberAncestors == null) {
_memberAncestors = new List<Directionality>();
foreach (_ReadingOrderSortData member in members) {
_memberAncestors.AddRange(member.directionalAncestors);
}
}
return _memberAncestors; }
}
List<Directionality> _memberAncestors;
public static void sortWithDirectionality(List<_ReadingOrderDirectionalGroupData> list, TextDirection directionality) {
mergeSort<_ReadingOrderDirectionalGroupData>(list, compare: (_ReadingOrderDirectionalGroupData a, _ReadingOrderDirectionalGroupData b) =>{
switch (directionality) {
case TextDirection.ltr:
return a.rect.left.compareTo(b.rect.left);
case TextDirection.rtl:
return b.rect.right.compareTo(a.rect.right);
}
D.assert(false, ()=>"Unhandled directionality $directionality");
return 0;
});
}
public override void debugFillProperties(TextTreeRenderer.DiagnosticPropertiesBuilder properties) {
base.debugFillProperties(properties);
properties.add(DiagnosticsProperty<TextDirection>("directionality", directionality));
properties.add(DiagnosticsProperty<Rect>("rect", rect));
properties.add(IterableProperty<String>("members", members.map<String>((_ReadingOrderSortData member) {
return ""${member.node.debugLabel}"(${member.rect})";
})));
}
}
public class ReadingOrderTraversalPolicy : FocusTraversalPolicy , DirectionalFocusTraversalPolicyMixin {
public List<_ReadingOrderDirectionalGroupData> _collectDirectionalityGroups(IEnumerable<_ReadingOrderSortData> candidates) {
TextDirection currentDirection = candidates.First().directionality;
List<_ReadingOrderSortData> currentGroup = new List<_ReadingOrderSortData>();

}
TextDirection nearestCommonDirectionality = _ReadingOrderSortData.commonDirectionalityOf(inBandOfTop);
_ReadingOrderSortData.sortWithDirectionality(inBandOfTop, nearestCommonDirectionality);
List<_ReadingOrderDirectionalGroupData> bandGroups = _collectDirectionalityGroups(inBandOfTop);
if (bandGroups.Count == 1) {
// There's only one directionality group, so just send back the first
// one in that group, since it's already sorted.
return bandGroups.First().members.first;
}
// Sort the groups based on the common directionality and bounding boxes.
_ReadingOrderDirectionalGroupData.sortWithDirectionality(bandGroups, nearestCommonDirectionality);
return bandGroups.first.members.first;
}
// Sorts the list of nodes based on their geometry into the desired reading
// order based on the directionality of the context for each node.
@override
IEnumerable<FocusNode> sortDescendants(IEnumerable<FocusNode> descendants) {
assert(descendants != null);
if (descendants.length <= 1) {
return descendants;
}
final List<_ReadingOrderSortData> data = <_ReadingOrderSortData>[
for (final FocusNode node in descendants) _ReadingOrderSortData(node),
];
final List<FocusNode> sortedList = <FocusNode>[];
final List<_ReadingOrderSortData> unplaced = data;
// Pick the initial widget as the one that is at the beginning of the band
// of the topmost, or the topmost, if there are no others in its band.
_ReadingOrderSortData current = _pickNext(unplaced);
sortedList.add(current.node);
unplaced.remove(current);
List<_ReadingOrderDirectionalGroupData> bandGroups = _collectDirectionalityGroups(inBandOfTop);
if (bandGroups.Count == 1) {
return bandGroups.First().members.first;
}
_ReadingOrderDirectionalGroupData.sortWithDirectionality(bandGroups, nearestCommonDirectionality);
return bandGroups.First().members.first;
}
// Go through each node, picking the next one after eliminating the previous
// one, since removing the previously picked node will expose a new band in
// which to choose candidates.
while (unplaced.isNotEmpty) {
final _ReadingOrderSortData next = _pickNext(unplaced);
current = next;
sortedList.add(current.node);
unplaced.remove(current);
public override IEnumerable<FocusNode> sortDescendants(IEnumerable<FocusNode> descendants) {
D.assert(descendants != null);
if (descendants.Count() <= 1) {
return descendants;
}
List<_ReadingOrderSortData> data = new List<_ReadingOrderSortData>(){
foreach ( FocusNode node in descendants)
_ReadingOrderSortData(node),
};
List<FocusNode> sortedList = new List<FocusNode>();
List<_ReadingOrderSortData> unplaced = data;
_ReadingOrderSortData current = _pickNext(unplaced);
sortedList.Add(current.node);
unplaced.Remove(current);
while (unplaced.isNotEmpty()) {
_ReadingOrderSortData next = _pickNext(unplaced);
current = next;
sortedList.Add(current.node);
unplaced.Remove(current);
}
return sortedList;
}
return sortedList;
}
}
}
正在加载...
取消
保存