浏览代码

upgrade tab stuffs

/siyaoH-1.17-PlatformMessage
xingweizhu 4 年前
当前提交
612117a5
共有 2 个文件被更改,包括 152 次插入61 次删除
  1. 69
      com.unity.uiwidgets/Runtime/material/tab_controller.cs
  2. 144
      com.unity.uiwidgets/Runtime/material/tabs.cs

69
com.unity.uiwidgets/Runtime/material/tab_controller.cs


using Unity.UIWidgets.foundation;
using Unity.UIWidgets.scheduler2;
using Unity.UIWidgets.widgets;
using UnityEngine;
namespace Unity.UIWidgets.material {
public class TabController : ChangeNotifier {

_index = initialIndex;
_previousIndex = initialIndex;
_animationController = length < 2
? null
: new AnimationController(
value: initialIndex,
upperBound: length.Value - 1,
vsync: vsync);
_animationController = AnimationController.unbounded(value: initialIndex, vsync: vsync);
}
internal TabController(
int index = 0,
int previousIndex = 0,
AnimationController animationController = null,
int? length = null
) {
D.assert(length != null);
_index = index;
_previousIndex = index;
this.length = length.Value;
_animationController = animationController;
}
internal TabController _copyWith(
int? index = null,
int? length = null,
int? previousIndex = null
) {
return new TabController(
index: index ?? _index,
length: length ?? this.length,
animationController: _animationController,
previousIndex: previousIndex ?? _previousIndex
);
get { return _animationController?.view ?? Animations.kAlwaysCompleteAnimation; }
get { return _animationController?.view; }
readonly AnimationController _animationController;
AnimationController _animationController;
D.assert(duration == null ? curve == null : true);
D.assert(duration != null || curve == null);
D.assert(_indexIsChangingCount >= 0);
if (value == _index || length < 2) {

}
public float offset {
get { return length > 1 ? _animationController.value - _index : 0.0f; }
get { return _animationController.value - _index; }
D.assert(length > 1);
D.assert(value >= -1.0f && value <= 1.0f);
D.assert(!indexIsChanging);
if (value == offset) {

}
public override void dispose() {
_animationController?.dispose();
_animationController = null;
base.dispose();
}
}

Widget child = null
) : base(key: key) {
D.assert(length != null);
D.assert(length >= 0);
D.assert(length == 0 || (initialIndex >= 0 && initialIndex < length));
D.assert(child != null);
this.length = length;
this.initialIndex = initialIndex;

public readonly Widget child;
public static TabController of(BuildContext context) {
_TabControllerScope scope =
(_TabControllerScope) context.inheritFromWidgetOfExactType(typeof(_TabControllerScope));
_TabControllerScope scope = context.dependOnInheritedWidgetOfExactType<_TabControllerScope>();
return scope?.controller;
}

enabled: TickerMode.of(context),
child: widget.child
);
}
public override void didUpdateWidget(StatefulWidget oldWidget) {
var _oldWidget = (DefaultTabController) oldWidget;
base.didUpdateWidget(oldWidget);
if (_oldWidget.length != widget.length) {
int newIndex = 0;
int previousIndex = _controller.previousIndex;
if (_controller.index >= widget.length) {
newIndex = Mathf.Max(0, widget.length.Value - 1);
previousIndex = _controller.index;
}
_controller = _controller._copyWith(
length: widget.length,
index: newIndex,
previousIndex: previousIndex
);
}
}
}
}

144
com.unity.uiwidgets/Runtime/material/tabs.cs


Key key = null,
string text = null,
Widget icon = null,
EdgeInsets iconMargin = null,
Widget child = null
) : base(key: key) {
D.assert(text != null || child != null || icon != null);

this.child = child;
this.iconMargin = iconMargin ?? EdgeInsets.only(bottom: 10.0f);
}
public readonly string text;

public readonly Widget icon;
public readonly EdgeInsets iconMargin;
Widget _buildLabelText() {
return child ?? new Text(text, softWrap: false, overflow: TextOverflow.fade);

children: new List<Widget> {
new Container(
child: icon,
margin: EdgeInsets.only(bottom: 10.0f)
margin: iconMargin
),
_buildLabelText()
}

ThemeData themeData = Theme.of(context);
TabBarTheme tabBarTheme = TabBarTheme.of(context);
Animation<float> animation = (Animation<float>) listenable;
?? themeData.primaryTextTheme.body2).copyWith(inherit: true);
?? themeData.primaryTextTheme.bodyText1).copyWith(inherit: true);
?? tabBarTheme.unselectedLabelStyle
?? labelStyle
?? themeData.primaryTextTheme.body2).copyWith(inherit: true);
?? tabBarTheme.unselectedLabelStyle
?? labelStyle
?? themeData.primaryTextTheme.bodyText1).copyWith(inherit: true);
Color selectedColor = labelColor ?? tabBarTheme.labelColor ?? themeData.primaryTextTheme.body2.color;
Color selectedColor = labelColor ?? tabBarTheme.labelColor ?? themeData.primaryTextTheme.bodyText1.color;
Color unselectedColor = unselectedLabelColor ??
tabBarTheme.unselectedLabelColor ?? selectedColor.withAlpha(0xB2);
Color color = selected

}
static bool _tabOffsetsEqual(List<float> a, List<float> b) {
if (a?.Count != b?.Count) {
if (a == null || b == null || a.Count != b.Count) {
return false;
}

get { return controller.animation; }
}
public override void removeStatusListener(AnimationStatusListener listener) {
if (parent != null) {
base.removeStatusListener(listener);
}
}
public override void removeListener(VoidCallback listener) {
if (parent != null) {
base.removeListener(listener);
}
}
public override float value {
get { return TabsUtils._indexChangeProgress(controller); }
}

get { return controller.animation; }
}
public override void removeStatusListener(AnimationStatusListener listener) {
if (parent != null) {
base.removeStatusListener(listener);
}
}
public override void removeListener(VoidCallback listener) {
if (parent != null) {
base.removeListener(listener);
}
}
public override float value {
get {
D.assert(!controller.indexIsChanging);

foreach (Widget item in tabs) {
if (item is Tab) {
Tab tab = (Tab) item;
if (tab.text != null && tab.icon != null) {
if ((tab.text != null || tab.child != null) && tab.icon != null) {
return Size.fromHeight(TabsUtils._kTextAndIconTabHeight + indicatorWeight);
}
}

}
}
bool _controllerIsValid {
get { return _controller?.animation != null; }
}
void _updateTabController() {
TabController newController = widget.controller ?? DefaultTabController.of(context);
D.assert(() => {

return true;
});
D.assert(() => {
if (newController.length != widget.tabs.Count) {
throw new UIWidgetsError(
$"Controller's length property {newController.length} does not match the\n" +
$"number of tab elements {widget.tabs.Count} present in TabBar's tabs property."
);
}
return true;
});
if (_controller != null) {
if (_controllerIsValid) {
_controller.animation.removeListener(_handleTabControllerAnimationTick);
_controller.removeListener(_handleTabControllerTick);
}

}
void _initIndicatorPainter() {
_indicatorPainter = _controller == null
_indicatorPainter = (!_controllerIsValid)
? null
: new _IndicatorPainter(
controller: _controller,

public override void dispose() {
_indicatorPainter.dispose();
if (_controller != null) {
if (_controllerIsValid) {
_controller = null;
base.dispose();
}

public override Widget build(BuildContext context) {
D.assert(material_.debugCheckHasMaterialLocalizations(context));
D.assert(() => {
if (_controller.length != widget.tabs.Count) {
throw new UIWidgetsError(
$"Controller's length property {_controller.length} does not match the\n" +
$"number of tab elements {widget.tabs.Count} present in TabBar's tabs property."
);
}
return true;
});
if (_controller.length == 0) {
return new Container(
height: TabsUtils._kTabHeight + widget.indicatorWeight

TabController _controller;
PageController _pageController;
List<Widget> _children;
List<Widget> _childrenWithKey;
bool _controllerIsValid {
get { return _controller?.animation != null; }
}
void _updateTabController() {
TabController newController = widget.controller ?? DefaultTabController.of(context);

return true;
});
D.assert(() => {
if (newController.length != widget.children.Count) {
throw new UIWidgetsError(
$"Controller's length property {newController.length} does not match the\n" +
$"number of elements {widget.children.Count} present in TabBarView's children property."
);
}
return true;
});
if (_controller != null) {
if (_controllerIsValid) {
_controller.animation.removeListener(_handleTabControllerAnimationTick);
}

public override void initState() {
base.initState();
_children = widget.children;
_updateChildren();
}
public override void didChangeDependencies() {

}
if (widget.children != _oldWidget.children && _warpUnderwayCount == 0) {
_children = widget.children;
_updateChildren();
if (_controller != null) {
if (_controllerIsValid) {
_controller = null;
void _updateChildren() {
_children = widget.children;
_childrenWithKey = KeyedSubtree.ensureUniqueKeysForList(widget.children);
}
void _handleTabControllerAnimationTick() {
if (_warpUnderwayCount > 0 || !_controller.indexIsChanging) {
return;

}
D.assert((_currentIndex.Value - previousIndex).abs() > 1);
int initialPage = 0;
int initialPage = _currentIndex.Value > previousIndex
? _currentIndex.Value - 1
: _currentIndex.Value + 1;
List<Widget> originalChildren = _childrenWithKey;
_children = new List<Widget>(widget.children);
if (_currentIndex > previousIndex) {
_children[_currentIndex.Value - 1] = _children[previousIndex];
initialPage = _currentIndex.Value - 1;
}
else {
_children[_currentIndex.Value + 1] = _children[previousIndex];
initialPage = _currentIndex.Value + 1;
}
_childrenWithKey = new List<Widget>(_childrenWithKey);
Widget temp = _childrenWithKey[initialPage];
_childrenWithKey[initialPage] = _childrenWithKey[previousIndex];
_childrenWithKey[previousIndex] = temp;
});
_pageController.jumpToPage(initialPage);

setState(() => {
_warpUnderwayCount -= 1;
_children = widget.children;
if (widget.children != _children) {
_updateChildren();
}
else {
_childrenWithKey = originalChildren;
}
});
return Future.value();

}
public override Widget build(BuildContext context) {
D.assert(() => {
if (_controller.length != widget.children.Count) {
throw new UIWidgetsError(
$"Controller's length property {_controller.length} does not match the\n" +
$"number of tabs {widget.children.Count} present in TabBar's tabs property."
);
}
return true;
});
return new NotificationListener<ScrollNotification>(
onNotification: _handleScrollNotification,
child: new PageView(

? TabsUtils._kTabBarViewPhysics
: TabsUtils._kTabBarViewPhysics.applyTo(widget.physics),
children: _children
children: _childrenWithKey
)
);
}

正在加载...
取消
保存