Shiyun Wen
4 年前
当前提交
81794ba6
共有 54 个文件被更改,包括 117 次插入 和 7552 次删除
-
132Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsExample.cs
-
4com.unity.uiwidgets/Runtime/rendering/error.cs
-
6com.unity.uiwidgets/Runtime/ui2/painting.cs
-
2com.unity.uiwidgets/Runtime/widgets/automatic_keep_alive.cs
-
7com.unity.uiwidgets/Runtime/widgets/localizations.cs
-
4com.unity.uiwidgets/Runtime/widgets/sliver.cs
-
52Samples/UIWidgetsSamples_2019_4/Assets/Plugins/x86_64/libUIWidgets_d.dll.meta
-
1001com.unity.uiwidgets/Runtime/cupertino/action_Sheet.cs
-
11com.unity.uiwidgets/Runtime/cupertino/action_Sheet.cs.meta
-
130com.unity.uiwidgets/Runtime/cupertino/activity_indicator.cs
-
11com.unity.uiwidgets/Runtime/cupertino/activity_indicator.cs.meta
-
181com.unity.uiwidgets/Runtime/cupertino/app.cs
-
11com.unity.uiwidgets/Runtime/cupertino/app.cs.meta
-
204com.unity.uiwidgets/Runtime/cupertino/bottom_app_bar.cs
-
11com.unity.uiwidgets/Runtime/cupertino/bottom_app_bar.cs.meta
-
245com.unity.uiwidgets/Runtime/cupertino/button.cs
-
11com.unity.uiwidgets/Runtime/cupertino/button.cs.meta
-
25com.unity.uiwidgets/Runtime/cupertino/color.cs
-
11com.unity.uiwidgets/Runtime/cupertino/color.cs.meta
-
1001com.unity.uiwidgets/Runtime/cupertino/date_picker.cs
-
11com.unity.uiwidgets/Runtime/cupertino/date_picker.cs.meta
-
1001com.unity.uiwidgets/Runtime/cupertino/dialog.cs
-
11com.unity.uiwidgets/Runtime/cupertino/dialog.cs.meta
-
142com.unity.uiwidgets/Runtime/cupertino/icons.cs
-
11com.unity.uiwidgets/Runtime/cupertino/icons.cs.meta
-
247com.unity.uiwidgets/Runtime/cupertino/localization.cs
-
11com.unity.uiwidgets/Runtime/cupertino/localization.cs.meta
-
11com.unity.uiwidgets/Runtime/cupertino/nav_bar.cs.meta
-
11com.unity.uiwidgets/Runtime/cupertino/page_scaffold.cs.meta
-
262com.unity.uiwidgets/Runtime/cupertino/picker.cs
-
11com.unity.uiwidgets/Runtime/cupertino/picker.cs.meta
-
11com.unity.uiwidgets/Runtime/cupertino/route.cs.meta
-
140com.unity.uiwidgets/Runtime/cupertino/scrollbar.cs
-
11com.unity.uiwidgets/Runtime/cupertino/scrollbar.cs.meta
-
380com.unity.uiwidgets/Runtime/cupertino/slider.cs
-
11com.unity.uiwidgets/Runtime/cupertino/slider.cs.meta
-
495com.unity.uiwidgets/Runtime/cupertino/switch.cs
-
11com.unity.uiwidgets/Runtime/cupertino/switch.cs.meta
-
221com.unity.uiwidgets/Runtime/cupertino/tab_scaffold.cs
-
11com.unity.uiwidgets/Runtime/cupertino/tab_scaffold.cs.meta
-
141com.unity.uiwidgets/Runtime/cupertino/tab_view.cs
-
11com.unity.uiwidgets/Runtime/cupertino/tab_view.cs.meta
-
575com.unity.uiwidgets/Runtime/cupertino/text_field.cs
-
11com.unity.uiwidgets/Runtime/cupertino/text_field.cs.meta
-
316com.unity.uiwidgets/Runtime/cupertino/text_selection.cs
-
11com.unity.uiwidgets/Runtime/cupertino/text_selection.cs.meta
-
191com.unity.uiwidgets/Runtime/cupertino/text_theme.cs
-
11com.unity.uiwidgets/Runtime/cupertino/text_theme.cs.meta
-
242com.unity.uiwidgets/Runtime/cupertino/theme.cs
-
11com.unity.uiwidgets/Runtime/cupertino/theme.cs.meta
-
42com.unity.uiwidgets/Runtime/cupertino/thumb_painter.cs
-
11com.unity.uiwidgets/Runtime/cupertino/thumb_painter.cs.meta
-
8com.unity.uiwidgets/Runtime/cupertino.meta
-
8com.unity.uiwidgets/Runtime/ui33.meta
|
|||
fileFormatVersion: 2 |
|||
guid: ef8445888386d7f479b700d769b35a63 |
|||
PluginImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
iconMap: {} |
|||
executionOrder: {} |
|||
defineConstraints: [] |
|||
isPreloaded: 0 |
|||
isOverridable: 0 |
|||
isExplicitlyReferenced: 0 |
|||
validateReferences: 1 |
|||
platformData: |
|||
- first: |
|||
Any: |
|||
second: |
|||
enabled: 1 |
|||
settings: {} |
|||
- first: |
|||
Editor: Editor |
|||
second: |
|||
enabled: 0 |
|||
settings: |
|||
CPU: x86_64 |
|||
DefaultValueInitialized: true |
|||
- first: |
|||
Standalone: Linux64 |
|||
second: |
|||
enabled: 1 |
|||
settings: |
|||
CPU: x86_64 |
|||
- first: |
|||
Standalone: OSXUniversal |
|||
second: |
|||
enabled: 0 |
|||
settings: |
|||
CPU: x86_64 |
|||
- first: |
|||
Standalone: Win |
|||
second: |
|||
enabled: 0 |
|||
settings: |
|||
CPU: None |
|||
- first: |
|||
Standalone: Win64 |
|||
second: |
|||
enabled: 1 |
|||
settings: |
|||
CPU: AnyCPU |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
1001
com.unity.uiwidgets/Runtime/cupertino/action_Sheet.cs
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
|
|||
fileFormatVersion: 2 |
|||
guid: e4c32db980b96b84b81d7bee1bb997ba |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using Unity.UIWidgets.animation; |
|||
using Unity.UIWidgets.foundation; |
|||
using Unity.UIWidgets.ui; |
|||
using Unity.UIWidgets.widgets; |
|||
using UnityEngine; |
|||
using Canvas = Unity.UIWidgets.ui.Canvas; |
|||
using Color = Unity.UIWidgets.ui.Color; |
|||
|
|||
namespace Unity.UIWidgets.cupertino { |
|||
static class CupertinoActivityIndicatorUtils { |
|||
public const float _kDefaultIndicatorRadius = 10.0f; |
|||
public const float _kTwoPI = Mathf.PI * 2.0f; |
|||
public const int _kTickCount = 12; |
|||
public const int _kHalfTickCount = _kTickCount / 2; |
|||
public static readonly Color _kTickColor = CupertinoColors.lightBackgroundGray; |
|||
public static readonly Color _kActiveTickColor = new Color(0xFF9D9D9D); |
|||
} |
|||
|
|||
public class CupertinoActivityIndicator : StatefulWidget { |
|||
public CupertinoActivityIndicator( |
|||
Key key = null, |
|||
bool animating = true, |
|||
float radius = CupertinoActivityIndicatorUtils._kDefaultIndicatorRadius |
|||
) : base(key: key) { |
|||
D.assert(radius > 0); |
|||
this.animating = animating; |
|||
this.radius = radius; |
|||
} |
|||
|
|||
public readonly bool animating; |
|||
public readonly float radius; |
|||
|
|||
public override State createState() { |
|||
return new _CupertinoActivityIndicatorState(); |
|||
} |
|||
} |
|||
|
|||
class _CupertinoActivityIndicatorState : TickerProviderStateMixin<CupertinoActivityIndicator> { |
|||
AnimationController _controller; |
|||
|
|||
public override void initState() { |
|||
base.initState(); |
|||
_controller = new AnimationController( |
|||
duration: TimeSpan.FromSeconds(1), |
|||
vsync: this |
|||
); |
|||
|
|||
if (widget.animating) { |
|||
_controller.repeat(); |
|||
} |
|||
} |
|||
|
|||
public override void didUpdateWidget(StatefulWidget oldWidget) { |
|||
base.didUpdateWidget(oldWidget: oldWidget); |
|||
if (oldWidget is CupertinoActivityIndicator _oldWidget) { |
|||
if (widget.animating != _oldWidget.animating) { |
|||
if (widget.animating) { |
|||
_controller.repeat(); |
|||
} |
|||
else { |
|||
_controller.stop(); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
public override void dispose() { |
|||
_controller.dispose(); |
|||
base.dispose(); |
|||
} |
|||
|
|||
public override Widget build(BuildContext context) { |
|||
return new SizedBox( |
|||
height: widget.radius * 2, |
|||
width: widget.radius * 2, |
|||
child: new CustomPaint( |
|||
painter: new _CupertinoActivityIndicatorPainter( |
|||
position: _controller, |
|||
radius: widget.radius |
|||
) |
|||
) |
|||
); |
|||
} |
|||
} |
|||
|
|||
class _CupertinoActivityIndicatorPainter : AbstractCustomPainter { |
|||
public _CupertinoActivityIndicatorPainter( |
|||
Animation<float> position, |
|||
float radius |
|||
) : base(repaint: position) { |
|||
tickFundamentalRRect = RRect.fromLTRBXY( |
|||
left: -radius, |
|||
top: 1.0f * radius / CupertinoActivityIndicatorUtils._kDefaultIndicatorRadius, |
|||
right: -radius / 2.0f, |
|||
bottom: -1.0f * radius / CupertinoActivityIndicatorUtils._kDefaultIndicatorRadius, |
|||
radiusX: 1.0f, |
|||
radiusY: 1.0f |
|||
); |
|||
this.position = position; |
|||
} |
|||
|
|||
readonly Animation<float> position; |
|||
readonly RRect tickFundamentalRRect; |
|||
|
|||
public override void paint(Canvas canvas, Size size) { |
|||
Paint paint = new Paint(); |
|||
|
|||
canvas.save(); |
|||
canvas.translate(size.width / 2.0f, size.height / 2.0f); |
|||
|
|||
int activeTick = (CupertinoActivityIndicatorUtils._kTickCount * position.value).floor(); |
|||
|
|||
for (int i = 0; i < CupertinoActivityIndicatorUtils._kTickCount; ++i) { |
|||
float t = (((i + activeTick) % CupertinoActivityIndicatorUtils._kTickCount) / |
|||
CupertinoActivityIndicatorUtils._kHalfTickCount).clamp(0, 1); |
|||
paint.color = Color.lerp(a: CupertinoActivityIndicatorUtils._kActiveTickColor, |
|||
b: CupertinoActivityIndicatorUtils._kTickColor, t: t); |
|||
canvas.drawRRect(tickFundamentalRRect,paint); |
|||
canvas.rotate(-CupertinoActivityIndicatorUtils._kTwoPI / CupertinoActivityIndicatorUtils._kTickCount); |
|||
} |
|||
|
|||
canvas.restore(); |
|||
} |
|||
|
|||
public override bool shouldRepaint(CustomPainter oldPainter) { |
|||
return (oldPainter as _CupertinoActivityIndicatorPainter).position != position; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: ed3ef7a3308cfad4e968eb19fe99ba4b |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections.Generic; |
|||
using Unity.UIWidgets.foundation; |
|||
using Unity.UIWidgets.material; |
|||
using Unity.UIWidgets.painting; |
|||
using Unity.UIWidgets.ui; |
|||
using Unity.UIWidgets.widgets; |
|||
|
|||
namespace Unity.UIWidgets.cupertino { |
|||
public class CupertinoApp : StatefulWidget { |
|||
public CupertinoApp( |
|||
Key key = null, |
|||
GlobalKey<NavigatorState> navigatorKey = null, |
|||
Widget home = null, |
|||
CupertinoThemeData theme = null, |
|||
Dictionary<string, WidgetBuilder> routes = null, |
|||
string initialRoute = null, |
|||
RouteFactory onGenerateRoute = null, |
|||
RouteFactory onUnknownRoute = null, |
|||
List<NavigatorObserver> navigatorObservers = null, |
|||
TransitionBuilder builder = null, |
|||
string title = "", |
|||
GenerateAppTitle onGenerateTitle = null, |
|||
Color color = null, |
|||
Locale locale = null, |
|||
List<LocalizationsDelegate<CupertinoLocalizations>> localizationsDelegates = null, |
|||
LocaleListResolutionCallback localeListResolutionCallback = null, |
|||
LocaleResolutionCallback localeResolutionCallback = null, |
|||
List<Locale> supportedLocales = null, |
|||
bool showPerformanceOverlay = false |
|||
) : base(key: key) { |
|||
D.assert(title != null); |
|||
|
|||
supportedLocales = supportedLocales ?? new List<Locale> {new Locale("en", "US")}; |
|||
this.navigatorKey = navigatorKey; |
|||
this.home = home; |
|||
this.theme = theme; |
|||
this.routes = routes ?? new Dictionary<string, WidgetBuilder>(); |
|||
this.initialRoute = initialRoute; |
|||
this.onGenerateRoute = onGenerateRoute; |
|||
this.onUnknownRoute = onUnknownRoute; |
|||
this.navigatorObservers = navigatorObservers ?? new List<NavigatorObserver>(); |
|||
this.builder = builder; |
|||
this.title = title; |
|||
this.onGenerateTitle = onGenerateTitle; |
|||
this.color = color; |
|||
this.locale = locale; |
|||
this.localizationsDelegates = localizationsDelegates; |
|||
this.localeListResolutionCallback = localeListResolutionCallback; |
|||
this.localeResolutionCallback = localeResolutionCallback; |
|||
this.supportedLocales = supportedLocales; |
|||
this.showPerformanceOverlay = showPerformanceOverlay; |
|||
} |
|||
|
|||
public readonly GlobalKey<NavigatorState> navigatorKey; |
|||
public readonly Widget home; |
|||
public readonly CupertinoThemeData theme; |
|||
public readonly Dictionary<string, WidgetBuilder> routes; |
|||
public readonly string initialRoute; |
|||
public readonly RouteFactory onGenerateRoute; |
|||
public readonly RouteFactory onUnknownRoute; |
|||
public readonly List<NavigatorObserver> navigatorObservers; |
|||
public readonly TransitionBuilder builder; |
|||
public readonly string title; |
|||
public readonly GenerateAppTitle onGenerateTitle; |
|||
public readonly Color color; |
|||
public readonly Locale locale; |
|||
public readonly List<LocalizationsDelegate<CupertinoLocalizations>> localizationsDelegates; |
|||
public readonly LocaleListResolutionCallback localeListResolutionCallback; |
|||
public readonly LocaleResolutionCallback localeResolutionCallback; |
|||
public readonly List<Locale> supportedLocales; |
|||
public readonly bool showPerformanceOverlay; |
|||
|
|||
public override State createState() { |
|||
return new _CupertinoAppState(); |
|||
} |
|||
|
|||
public static HeroController createCupertinoHeroController() { |
|||
return new HeroController(); |
|||
} |
|||
} |
|||
|
|||
|
|||
public class _AlwaysCupertinoScrollBehavior : ScrollBehavior { |
|||
public override Widget buildViewportChrome(BuildContext context, Widget child, AxisDirection axisDirection) { |
|||
return child; |
|||
} |
|||
|
|||
public override ScrollPhysics getScrollPhysics(BuildContext context) { |
|||
return new BouncingScrollPhysics(); |
|||
} |
|||
} |
|||
|
|||
class _CupertinoAppState : State<CupertinoApp> { |
|||
HeroController _heroController; |
|||
|
|||
public override void initState() { |
|||
base.initState(); |
|||
_heroController = CupertinoApp.createCupertinoHeroController(); |
|||
_updateNavigator(); |
|||
} |
|||
|
|||
public override void didUpdateWidget(StatefulWidget oldWidget) { |
|||
base.didUpdateWidget(oldWidget); |
|||
if (widget.navigatorKey != ((CupertinoApp) oldWidget).navigatorKey) { |
|||
_heroController = CupertinoApp.createCupertinoHeroController(); |
|||
} |
|||
|
|||
_updateNavigator(); |
|||
} |
|||
|
|||
List<NavigatorObserver> _navigatorObservers; |
|||
|
|||
void _updateNavigator() { |
|||
if (widget.home != null || widget.routes.isNotEmpty() || widget.onGenerateRoute != null || |
|||
widget.onUnknownRoute != null) { |
|||
_navigatorObservers = new List<NavigatorObserver>(); |
|||
foreach (var item in widget.navigatorObservers) { |
|||
_navigatorObservers.Add(item); |
|||
} |
|||
} |
|||
else { |
|||
_navigatorObservers = new List<NavigatorObserver>(); |
|||
} |
|||
} |
|||
|
|||
List<LocalizationsDelegate> _localizationsDelegates { |
|||
get { |
|||
var _delegates = new List<LocalizationsDelegate>(); |
|||
if (widget.localizationsDelegates != null) { |
|||
_delegates.AddRange(widget.localizationsDelegates); |
|||
} |
|||
|
|||
_delegates.Add(DefaultCupertinoLocalizations.del); |
|||
//_delegates.Add(DefaultMaterialLocalizations.del);
|
|||
return new List<LocalizationsDelegate>(_delegates); |
|||
} |
|||
} |
|||
|
|||
public override Widget build(BuildContext context) { |
|||
CupertinoThemeData effectiveThemeData = widget.theme ?? new CupertinoThemeData(); |
|||
|
|||
return new ScrollConfiguration( |
|||
behavior: new _AlwaysCupertinoScrollBehavior(), |
|||
child: new CupertinoTheme( |
|||
data: effectiveThemeData, |
|||
child: new WidgetsApp( |
|||
pageRouteBuilder: (RouteSettings settings, WidgetBuilder builder) => |
|||
new CupertinoPageRoute(settings: settings, builder: builder), |
|||
home: widget.home, |
|||
routes: widget.routes, |
|||
initialRoute: widget.initialRoute, |
|||
onGenerateRoute: widget.onGenerateRoute, |
|||
onUnknownRoute: widget.onUnknownRoute, |
|||
builder: widget.builder, |
|||
title: widget.title, |
|||
onGenerateTitle: widget.onGenerateTitle, |
|||
textStyle: effectiveThemeData.textTheme.textStyle, |
|||
color: widget.color ?? CupertinoColors.activeBlue, |
|||
locale: widget.locale, |
|||
localizationsDelegates: _localizationsDelegates, |
|||
localeResolutionCallback: widget.localeResolutionCallback, |
|||
localeListResolutionCallback: widget.localeListResolutionCallback, |
|||
supportedLocales: widget.supportedLocales, |
|||
showPerformanceOverlay: widget.showPerformanceOverlay, |
|||
inspectorSelectButtonBuilder: (BuildContext _context, VoidCallback onPressed) => { |
|||
return CupertinoButton.filled( |
|||
child: new Icon( |
|||
CupertinoIcons.search, |
|||
size: 28.0f, |
|||
color: CupertinoColors.white |
|||
), |
|||
padding: EdgeInsets.zero, |
|||
onPressed: onPressed |
|||
); |
|||
} |
|||
) |
|||
) |
|||
); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: eaa69370ca020aa4ca9cfeff075ab39c |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections.Generic; |
|||
using Unity.UIWidgets.foundation; |
|||
using Unity.UIWidgets.gestures; |
|||
using Unity.UIWidgets.painting; |
|||
using Unity.UIWidgets.rendering; |
|||
using Unity.UIWidgets.ui; |
|||
using Unity.UIWidgets.widgets; |
|||
using TextStyle = Unity.UIWidgets.painting.TextStyle; |
|||
|
|||
namespace Unity.UIWidgets.cupertino { |
|||
class BottomAppBarUtils { |
|||
public const float _kTabBarHeight = 50.0f; |
|||
public static readonly Color _kDefaultTabBarBorderColor = new Color(0x4C000000); |
|||
} |
|||
|
|||
|
|||
public class CupertinoTabBar : StatelessWidget { |
|||
public CupertinoTabBar( |
|||
Key key = null, |
|||
List<BottomNavigationBarItem> items = null, |
|||
ValueChanged<int> onTap = null, |
|||
int currentIndex = 0, |
|||
Color backgroundColor = null, |
|||
Color activeColor = null, |
|||
Color inactiveColor = null, |
|||
float iconSize = 30.0f, |
|||
Border border = null |
|||
) : base(key: key) { |
|||
D.assert(items != null); |
|||
D.assert(items.Count >= 2, |
|||
() => "Tabs need at least 2 items to conform to Apple's HIG" |
|||
); |
|||
D.assert(0 <= currentIndex && currentIndex < items.Count); |
|||
|
|||
|
|||
this.items = items; |
|||
this.onTap = onTap; |
|||
this.currentIndex = currentIndex; |
|||
|
|||
this.backgroundColor = backgroundColor; |
|||
this.activeColor = activeColor; |
|||
this.inactiveColor = inactiveColor ?? CupertinoColors.inactiveGray; |
|||
this.iconSize = iconSize; |
|||
this.border = border ?? new Border( |
|||
top: new BorderSide( |
|||
color: BottomAppBarUtils._kDefaultTabBarBorderColor, |
|||
width: 0.0f, // One physical pixel.
|
|||
style: BorderStyle.solid |
|||
) |
|||
); |
|||
} |
|||
|
|||
public readonly List<BottomNavigationBarItem> items; |
|||
|
|||
public readonly ValueChanged<int> onTap; |
|||
|
|||
public readonly int currentIndex; |
|||
|
|||
public readonly Color backgroundColor; |
|||
|
|||
public readonly Color activeColor; |
|||
|
|||
public readonly Color inactiveColor; |
|||
|
|||
public readonly float iconSize; |
|||
|
|||
public readonly Border border; |
|||
|
|||
public Size preferredSize { |
|||
get { return Size.fromHeight(BottomAppBarUtils._kTabBarHeight); } |
|||
} |
|||
|
|||
public bool opaque(BuildContext context) { |
|||
Color backgroundColor = |
|||
this.backgroundColor ?? CupertinoTheme.of(context).barBackgroundColor; |
|||
return backgroundColor.alpha == 0xFF; |
|||
} |
|||
|
|||
public override Widget build(BuildContext context) { |
|||
float bottomPadding = MediaQuery.of(context).padding.bottom; |
|||
|
|||
Widget result = new DecoratedBox( |
|||
decoration: new BoxDecoration( |
|||
border: border, |
|||
color: backgroundColor ?? CupertinoTheme.of(context).barBackgroundColor |
|||
), |
|||
child: new SizedBox( |
|||
height: BottomAppBarUtils._kTabBarHeight + bottomPadding, |
|||
child: IconTheme.merge( // Default with the inactive state.
|
|||
data: new IconThemeData( |
|||
color: inactiveColor, |
|||
size: iconSize |
|||
), |
|||
child: new DefaultTextStyle( // Default with the inactive state.
|
|||
style: CupertinoTheme.of(context).textTheme.tabLabelTextStyle |
|||
.copyWith(color: inactiveColor), |
|||
child: new Padding( |
|||
padding: EdgeInsets.only(bottom: bottomPadding), |
|||
child: new Row( |
|||
crossAxisAlignment: CrossAxisAlignment.end, |
|||
children: _buildTabItems(context) |
|||
) |
|||
) |
|||
) |
|||
) |
|||
) |
|||
); |
|||
|
|||
if (!opaque(context)) { |
|||
result = new ClipRect( |
|||
child: new BackdropFilter( |
|||
filter: ImageFilter.blur(sigmaX: 10.0f, sigmaY: 10.0f), |
|||
child: result |
|||
) |
|||
); |
|||
} |
|||
|
|||
return result; |
|||
} |
|||
|
|||
List<Widget> _buildTabItems(BuildContext context) { |
|||
List<Widget> result = new List<Widget> { }; |
|||
|
|||
for (int index = 0; index < items.Count; index += 1) { |
|||
bool active = index == currentIndex; |
|||
var tabIndex = index; |
|||
result.Add( |
|||
_wrapActiveItem( |
|||
context, |
|||
new Expanded( |
|||
child: new GestureDetector( |
|||
behavior: HitTestBehavior.opaque, |
|||
onTap: onTap == null ? null : (GestureTapCallback) (() => { onTap(tabIndex); }), |
|||
child: new Padding( |
|||
padding: EdgeInsets.only(bottom: 4.0f), |
|||
child: new Column( |
|||
mainAxisAlignment: MainAxisAlignment.end, |
|||
children: _buildSingleTabItem(items[index], active) |
|||
) |
|||
) |
|||
) |
|||
), |
|||
active: active |
|||
) |
|||
); |
|||
} |
|||
|
|||
return result; |
|||
} |
|||
|
|||
List<Widget> _buildSingleTabItem(BottomNavigationBarItem item, bool active) { |
|||
List<Widget> components = new List<Widget> { |
|||
new Expanded( |
|||
child: new Center(child: active ? item.activeIcon : item.icon) |
|||
) |
|||
}; |
|||
|
|||
if (item.title != null) { |
|||
components.Add(item.title); |
|||
} |
|||
|
|||
return components; |
|||
} |
|||
|
|||
Widget _wrapActiveItem(BuildContext context, Widget item, bool active) { |
|||
if (!active) { |
|||
return item; |
|||
} |
|||
|
|||
Color activeColor = this.activeColor ?? CupertinoTheme.of(context).primaryColor; |
|||
return IconTheme.merge( |
|||
data: new IconThemeData(color: activeColor), |
|||
child: DefaultTextStyle.merge( |
|||
style: new TextStyle(color: activeColor), |
|||
child: item |
|||
) |
|||
); |
|||
} |
|||
|
|||
public CupertinoTabBar copyWith( |
|||
Key key = null, |
|||
List<BottomNavigationBarItem> items = null, |
|||
Color backgroundColor = null, |
|||
Color activeColor = null, |
|||
Color inactiveColor = null, |
|||
float? iconSize = null, |
|||
Border border = null, |
|||
int? currentIndex = null, |
|||
ValueChanged<int> onTap = null |
|||
) { |
|||
return new CupertinoTabBar( |
|||
key: key ?? this.key, |
|||
items: items ?? this.items, |
|||
backgroundColor: backgroundColor ?? this.backgroundColor, |
|||
activeColor: activeColor ?? this.activeColor, |
|||
inactiveColor: inactiveColor ?? this.inactiveColor, |
|||
iconSize: iconSize ?? this.iconSize, |
|||
border: border ?? this.border, |
|||
currentIndex: currentIndex ?? this.currentIndex, |
|||
onTap: onTap ?? this.onTap |
|||
); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: aae818985ea0fb942b943da7205b523c |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using Unity.UIWidgets.animation; |
|||
using Unity.UIWidgets.foundation; |
|||
using Unity.UIWidgets.gestures; |
|||
using Unity.UIWidgets.painting; |
|||
using Unity.UIWidgets.rendering; |
|||
using Unity.UIWidgets.scheduler2; |
|||
using Unity.UIWidgets.ui; |
|||
using Unity.UIWidgets.widgets; |
|||
using TextStyle = Unity.UIWidgets.painting.TextStyle; |
|||
using TickerFuture = Unity.UIWidgets.scheduler2.TickerFuture; |
|||
|
|||
namespace Unity.UIWidgets.cupertino { |
|||
public class CupertinoButtonUtils { |
|||
public static readonly Color _kDisabledBackground = new Color(0xFFA9A9A9); |
|||
public static readonly Color _kDisabledForeground = new Color(0xFFD1D1D1); |
|||
public static readonly EdgeInsets _kButtonPadding = EdgeInsets.all(16.0f); |
|||
public static readonly EdgeInsets _kBackgroundButtonPadding = EdgeInsets.symmetric(vertical: 14.0f, horizontal: 64.0f); |
|||
} |
|||
|
|||
public class CupertinoButton : StatefulWidget { |
|||
public CupertinoButton( |
|||
Widget child, |
|||
VoidCallback onPressed, |
|||
Key key = null, |
|||
EdgeInsets padding = null, |
|||
Color color = null, |
|||
Color disabledColor = null, |
|||
float minSize = 44.0f, |
|||
float pressedOpacity = 0.1f, |
|||
BorderRadius borderRadius = null, |
|||
bool filled = false |
|||
) : base(key: key) { |
|||
D.assert(pressedOpacity >= 0.0 && pressedOpacity <= 1.0); |
|||
_filled = filled; |
|||
this.child = child; |
|||
this.onPressed = onPressed; |
|||
this.padding = padding; |
|||
this.color = color; |
|||
this.disabledColor = disabledColor; |
|||
this.minSize = minSize; |
|||
this.pressedOpacity = pressedOpacity; |
|||
this.borderRadius = borderRadius ?? BorderRadius.all(Radius.circular(8.0f)); |
|||
} |
|||
|
|||
public static CupertinoButton filled( |
|||
Widget child, |
|||
VoidCallback onPressed, |
|||
Key key = null, |
|||
EdgeInsets padding = null, |
|||
Color disabledColor = null, |
|||
float minSize = 44.0f, |
|||
float pressedOpacity = 0.1f, |
|||
BorderRadius borderRadius = null |
|||
) { |
|||
D.assert(pressedOpacity >= 0.0 && pressedOpacity <= 1.0); |
|||
return new CupertinoButton( |
|||
key: key, |
|||
color: null, |
|||
child: child, |
|||
onPressed: onPressed, |
|||
padding: padding, |
|||
disabledColor: disabledColor, |
|||
minSize: minSize, |
|||
pressedOpacity: pressedOpacity, |
|||
borderRadius: borderRadius, |
|||
filled: true |
|||
); |
|||
} |
|||
|
|||
public readonly Widget child; |
|||
|
|||
public readonly EdgeInsets padding; |
|||
|
|||
public readonly Color color; |
|||
|
|||
public readonly Color disabledColor; |
|||
|
|||
public readonly VoidCallback onPressed; |
|||
|
|||
public readonly float minSize; |
|||
|
|||
public readonly float? pressedOpacity; |
|||
|
|||
public readonly BorderRadius borderRadius; |
|||
public readonly bool _filled; |
|||
|
|||
public bool enabled { |
|||
get { return onPressed != null; } |
|||
} |
|||
|
|||
public override State createState() { |
|||
return new _CupertinoButtonState(); |
|||
} |
|||
|
|||
public override void debugFillProperties(DiagnosticPropertiesBuilder properties) { |
|||
base.debugFillProperties(properties); |
|||
properties.add(new FlagProperty("enabled", value: enabled, ifFalse: "disabled")); |
|||
} |
|||
} |
|||
|
|||
class _CupertinoButtonState : SingleTickerProviderStateMixin<CupertinoButton> { |
|||
static readonly TimeSpan kFadeOutDuration = new TimeSpan(0, 0, 0, 0, 10); |
|||
static readonly TimeSpan kFadeInDuration = new TimeSpan(0, 0, 0, 0, 100); |
|||
public readonly FloatTween _opacityTween = new FloatTween(begin: 1.0f, end: 0.0f); |
|||
AnimationController _animationController; |
|||
Animation<float> _opacityAnimation; |
|||
|
|||
public override void initState() { |
|||
base.initState(); |
|||
_animationController = new AnimationController( |
|||
duration: new TimeSpan(0, 0, 0, 0, 200), |
|||
value: 0.0f, |
|||
vsync: this); |
|||
_opacityAnimation = _animationController |
|||
.drive(new CurveTween(curve: Curves.decelerate)) |
|||
.drive(_opacityTween); |
|||
_setTween(); |
|||
} |
|||
|
|||
public override void didUpdateWidget(StatefulWidget old) { |
|||
base.didUpdateWidget(old); |
|||
_setTween(); |
|||
} |
|||
|
|||
void _setTween() { |
|||
if (widget != null) { |
|||
_opacityTween.end = widget.pressedOpacity ?? 1.0f; |
|||
} |
|||
} |
|||
|
|||
public override void dispose() { |
|||
_animationController.dispose(); |
|||
_animationController = null; |
|||
base.dispose(); |
|||
} |
|||
|
|||
bool _buttonHeldDown = false; |
|||
|
|||
void _handleTapDown(TapDownDetails evt) { |
|||
if (!_buttonHeldDown) { |
|||
_buttonHeldDown = true; |
|||
_animate(); |
|||
} |
|||
} |
|||
|
|||
void _handleTapUp(TapUpDetails evt) { |
|||
if (_buttonHeldDown) { |
|||
_buttonHeldDown = false; |
|||
_animate(); |
|||
} |
|||
} |
|||
|
|||
void _handleTapCancel() { |
|||
if (_buttonHeldDown) { |
|||
_buttonHeldDown = false; |
|||
_animate(); |
|||
} |
|||
} |
|||
|
|||
void _animate() { |
|||
if (_animationController.isAnimating) { |
|||
return; |
|||
} |
|||
|
|||
bool wasHeldDown = _buttonHeldDown; |
|||
|
|||
TickerFuture ticker = _buttonHeldDown |
|||
? _animationController.animateTo(1.0f, duration: kFadeOutDuration) |
|||
: _animationController.animateTo(0.0f, duration: kFadeInDuration); |
|||
|
|||
ticker.then(_ => { |
|||
if (mounted && wasHeldDown != _buttonHeldDown) { |
|||
_animate(); |
|||
} |
|||
}); |
|||
/*ticker.then(() => { |
|||
if (mounted && wasHeldDown != _buttonHeldDown) { |
|||
_animate(); |
|||
} |
|||
});*/ |
|||
} |
|||
|
|||
public override Widget build(BuildContext context) { |
|||
bool enabled = widget.enabled; |
|||
Color primaryColor = CupertinoTheme.of(context).primaryColor; |
|||
Color backgroundColor = widget.color ?? (widget._filled ? primaryColor : null); |
|||
|
|||
Color foregroundColor = backgroundColor != null |
|||
? CupertinoTheme.of(context).primaryContrastingColor |
|||
: enabled |
|||
? primaryColor |
|||
: CupertinoButtonUtils._kDisabledForeground; |
|||
|
|||
TextStyle textStyle = |
|||
CupertinoTheme.of(context).textTheme.textStyle.copyWith(color: foregroundColor); |
|||
return new GestureDetector( |
|||
behavior: HitTestBehavior.opaque, |
|||
onTapDown: enabled ? _handleTapDown : (GestureTapDownCallback) null, |
|||
onTapUp: enabled ? _handleTapUp : (GestureTapUpCallback) null, |
|||
onTapCancel: enabled ? _handleTapCancel : (GestureTapCancelCallback) null, |
|||
onTap: widget.onPressed == null |
|||
? (GestureTapCallback) null |
|||
: () => { |
|||
if (widget.onPressed != null) { |
|||
widget.onPressed(); |
|||
} |
|||
}, |
|||
child: new ConstrainedBox( |
|||
constraints: new BoxConstraints( |
|||
minWidth: widget.minSize, |
|||
minHeight: widget.minSize |
|||
), |
|||
child: new FadeTransition( |
|||
opacity: _opacityAnimation, |
|||
child: new DecoratedBox( |
|||
decoration: new BoxDecoration( |
|||
borderRadius: widget.borderRadius, |
|||
color: backgroundColor != null && !enabled |
|||
? widget.disabledColor ?? CupertinoButtonUtils._kDisabledBackground |
|||
: backgroundColor |
|||
), |
|||
child: new Padding( |
|||
padding: widget.padding ?? (backgroundColor != null |
|||
? CupertinoButtonUtils._kBackgroundButtonPadding |
|||
: CupertinoButtonUtils._kButtonPadding), |
|||
child: new Center( |
|||
widthFactor: 1.0f, |
|||
heightFactor: 1.0f, |
|||
child: new DefaultTextStyle( |
|||
style: textStyle, |
|||
child: new IconTheme( |
|||
data: new IconThemeData(color: foregroundColor), |
|||
child: widget.child |
|||
) |
|||
) |
|||
) |
|||
) |
|||
) |
|||
) |
|||
) |
|||
); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 629437eb94ae5aa4bbe7bcf510b6a7cc |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using Unity.UIWidgets.ui; |
|||
|
|||
namespace Unity.UIWidgets.cupertino { |
|||
public class CupertinoColors { |
|||
public static readonly Color activeBlue = new Color(0xFF007AFF); |
|||
|
|||
public static readonly Color activeGreen = new Color(0xFF4CD964); |
|||
|
|||
public static readonly Color activeOrange = new Color(0xFFFF9500); |
|||
|
|||
public static readonly Color white = new Color(0xFFFFFFFF); |
|||
|
|||
public static readonly Color black = new Color(0xFF000000); |
|||
|
|||
public static readonly Color lightBackgroundGray = new Color(0xFFE5E5EA); |
|||
|
|||
public static readonly Color extraLightBackgroundGray = new Color(0xFFEFEFF4); |
|||
|
|||
public static readonly Color darkBackgroundGray = new Color(0xFF171717); |
|||
|
|||
public static readonly Color inactiveGray = new Color(0xFF8E8E93); |
|||
|
|||
public static readonly Color destructiveRed = new Color(0xFFFF3B30); |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: cf635163f4e847c4d8189105ba042987 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
1001
com.unity.uiwidgets/Runtime/cupertino/date_picker.cs
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
|
|||
fileFormatVersion: 2 |
|||
guid: 0afde46bc85349a49bb887e7ef46e8d9 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
1001
com.unity.uiwidgets/Runtime/cupertino/dialog.cs
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
|
|||
fileFormatVersion: 2 |
|||
guid: ce028dee29b7b90409ab91e330e762e2 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using Unity.UIWidgets.widgets; |
|||
|
|||
namespace Unity.UIWidgets.cupertino { |
|||
public static class CupertinoIcons { |
|||
public const string iconFont = "CupertinoIcons"; |
|||
|
|||
public static readonly IconData left_chevron = new IconData(0xf3d2, fontFamily: iconFont); |
|||
public static readonly IconData right_chevron = new IconData(0xf3d3, fontFamily: iconFont); |
|||
public static readonly IconData share = new IconData(0xf4ca, fontFamily: iconFont); |
|||
public static readonly IconData share_solid = new IconData(0xf4cb, fontFamily: iconFont); |
|||
public static readonly IconData book = new IconData(0xf3e7, fontFamily: iconFont); |
|||
public static readonly IconData book_solid = new IconData(0xf3e8, fontFamily: iconFont); |
|||
public static readonly IconData bookmark = new IconData(0xf3e9, fontFamily: iconFont); |
|||
public static readonly IconData bookmark_solid = new IconData(0xf3ea, fontFamily: iconFont); |
|||
public static readonly IconData info = new IconData(0xf44c, fontFamily: iconFont); |
|||
public static readonly IconData reply = new IconData(0xf4c6, fontFamily: iconFont); |
|||
public static readonly IconData conversation_bubble = new IconData(0xf3fb, fontFamily: iconFont); |
|||
public static readonly IconData profile_circled = new IconData(0xf419, fontFamily: iconFont); |
|||
public static readonly IconData plus_circled = new IconData(0xf48a, fontFamily: iconFont); |
|||
public static readonly IconData minus_circled = new IconData(0xf463, fontFamily: iconFont); |
|||
public static readonly IconData flag = new IconData(0xf42c, fontFamily: iconFont); |
|||
public static readonly IconData search = new IconData(0xf4a5, fontFamily: iconFont); |
|||
public static readonly IconData check_mark = new IconData(0xf3fd, fontFamily: iconFont); |
|||
public static readonly IconData check_mark_circled = new IconData(0xf3fe, fontFamily: iconFont); |
|||
public static readonly IconData check_mark_circled_solid = new IconData(0xf3ff, fontFamily: iconFont); |
|||
public static readonly IconData circle = new IconData(0xf401, fontFamily: iconFont); |
|||
public static readonly IconData circle_filled = new IconData(0xf400, fontFamily: iconFont); |
|||
public static readonly IconData back = new IconData(0xf3cf, fontFamily: iconFont); |
|||
public static readonly IconData forward = new IconData(0xf3d1, fontFamily: iconFont); |
|||
public static readonly IconData home = new IconData(0xf447, fontFamily: iconFont); |
|||
public static readonly IconData shopping_cart = new IconData(0xf3f7, fontFamily: iconFont); |
|||
public static readonly IconData ellipsis = new IconData(0xf46a, fontFamily: iconFont); |
|||
public static readonly IconData phone = new IconData(0xf4b8, fontFamily: iconFont); |
|||
public static readonly IconData phone_solid = new IconData(0xf4b9, fontFamily: iconFont); |
|||
public static readonly IconData down_arrow = new IconData(0xf35d, fontFamily: iconFont); |
|||
public static readonly IconData up_arrow = new IconData(0xf366, fontFamily: iconFont); |
|||
public static readonly IconData battery_charging = new IconData(0xf111, fontFamily: iconFont); |
|||
public static readonly IconData battery_empty = new IconData(0xf112, fontFamily: iconFont); |
|||
public static readonly IconData battery_full = new IconData(0xf113, fontFamily: iconFont); |
|||
public static readonly IconData battery_75_percent = new IconData(0xf114, fontFamily: iconFont); |
|||
public static readonly IconData battery_25_percent = new IconData(0xf115, fontFamily: iconFont); |
|||
public static readonly IconData bluetooth = new IconData(0xf116, fontFamily: iconFont); |
|||
public static readonly IconData restart = new IconData(0xf21c, fontFamily: iconFont); |
|||
public static readonly IconData reply_all = new IconData(0xf21d, fontFamily: iconFont); |
|||
public static readonly IconData reply_thick_solid = new IconData(0xf21e, fontFamily: iconFont); |
|||
public static readonly IconData share_up = new IconData(0xf220, fontFamily: iconFont); |
|||
public static readonly IconData shuffle_thick = new IconData(0xf221, fontFamily: iconFont); |
|||
public static readonly IconData photo_camera = new IconData(0xf3f5, fontFamily: iconFont); |
|||
public static readonly IconData photo_camera_solid = new IconData(0xf3f6, fontFamily: iconFont); |
|||
public static readonly IconData video_camera = new IconData(0xf4cc, fontFamily: iconFont); |
|||
public static readonly IconData video_camera_solid = new IconData(0xf4cd, fontFamily: iconFont); |
|||
public static readonly IconData switch_camera = new IconData(0xf49e, fontFamily: iconFont); |
|||
public static readonly IconData switch_camera_solid = new IconData(0xf49f, fontFamily: iconFont); |
|||
public static readonly IconData collections = new IconData(0xf3c9, fontFamily: iconFont); |
|||
public static readonly IconData collections_solid = new IconData(0xf3ca, fontFamily: iconFont); |
|||
public static readonly IconData folder = new IconData(0xf434, fontFamily: iconFont); |
|||
public static readonly IconData folder_solid = new IconData(0xf435, fontFamily: iconFont); |
|||
public static readonly IconData folder_open = new IconData(0xf38a, fontFamily: iconFont); |
|||
public static readonly IconData delete = new IconData(0xf4c4, fontFamily: iconFont); |
|||
public static readonly IconData delete_solid = new IconData(0xf4c5, fontFamily: iconFont); |
|||
public static readonly IconData delete_simple = new IconData(0xf37f, fontFamily: iconFont); |
|||
public static readonly IconData pen = new IconData(0xf2bf, fontFamily: iconFont); |
|||
public static readonly IconData pencil = new IconData(0xf37e, fontFamily: iconFont); |
|||
public static readonly IconData create = new IconData(0xf417, fontFamily: iconFont); |
|||
public static readonly IconData create_solid = new IconData(0xf417, fontFamily: iconFont); |
|||
public static readonly IconData refresh = new IconData(0xf49a, fontFamily: iconFont); |
|||
public static readonly IconData refresh_circled = new IconData(0xf49b, fontFamily: iconFont); |
|||
public static readonly IconData refresh_circled_solid = new IconData(0xf49c, fontFamily: iconFont); |
|||
public static readonly IconData refresh_thin = new IconData(0xf49d, fontFamily: iconFont); |
|||
public static readonly IconData refresh_thick = new IconData(0xf3a8, fontFamily: iconFont); |
|||
public static readonly IconData refresh_bold = new IconData(0xf21c, fontFamily: iconFont); |
|||
public static readonly IconData clear_thick = new IconData(0xf2d7, fontFamily: iconFont); |
|||
public static readonly IconData clear_thick_circled = new IconData(0xf36e, fontFamily: iconFont); |
|||
public static readonly IconData clear = new IconData(0xf404, fontFamily: iconFont); |
|||
public static readonly IconData clear_circled = new IconData(0xf405, fontFamily: iconFont); |
|||
public static readonly IconData clear_circled_solid = new IconData(0xf406, fontFamily: iconFont); |
|||
public static readonly IconData add = new IconData(0xf489, fontFamily: iconFont); |
|||
public static readonly IconData add_circled = new IconData(0xf48a, fontFamily: iconFont); |
|||
public static readonly IconData add_circled_solid = new IconData(0xf48b, fontFamily: iconFont); |
|||
public static readonly IconData gear = new IconData(0xf43c, fontFamily: iconFont); |
|||
public static readonly IconData gear_solid = new IconData(0xf43d, fontFamily: iconFont); |
|||
public static readonly IconData gear_big = new IconData(0xf2f7, fontFamily: iconFont); |
|||
public static readonly IconData settings = new IconData(0xf411, fontFamily: iconFont); |
|||
public static readonly IconData settings_solid = new IconData(0xf412, fontFamily: iconFont); |
|||
public static readonly IconData music_note = new IconData(0xf46b, fontFamily: iconFont); |
|||
public static readonly IconData double_music_note = new IconData(0xf46c, fontFamily: iconFont); |
|||
public static readonly IconData play_arrow = new IconData(0xf487, fontFamily: iconFont); |
|||
public static readonly IconData play_arrow_solid = new IconData(0xf488, fontFamily: iconFont); |
|||
public static readonly IconData pause = new IconData(0xf477, fontFamily: iconFont); |
|||
public static readonly IconData pause_solid = new IconData(0xf478, fontFamily: iconFont); |
|||
public static readonly IconData loop = new IconData(0xf449, fontFamily: iconFont); |
|||
public static readonly IconData loop_thick = new IconData(0xf44a, fontFamily: iconFont); |
|||
public static readonly IconData volume_down = new IconData(0xf3b7, fontFamily: iconFont); |
|||
public static readonly IconData volume_mute = new IconData(0xf3b8, fontFamily: iconFont); |
|||
public static readonly IconData volume_off = new IconData(0xf3b9, fontFamily: iconFont); |
|||
public static readonly IconData volume_up = new IconData(0xf3ba, fontFamily: iconFont); |
|||
public static readonly IconData fullscreen = new IconData(0xf386, fontFamily: iconFont); |
|||
public static readonly IconData fullscreen_exit = new IconData(0xf37d, fontFamily: iconFont); |
|||
public static readonly IconData mic_off = new IconData(0xf45f, fontFamily: iconFont); |
|||
public static readonly IconData mic = new IconData(0xf460, fontFamily: iconFont); |
|||
public static readonly IconData mic_solid = new IconData(0xf461, fontFamily: iconFont); |
|||
public static readonly IconData clock = new IconData(0xf4be, fontFamily: iconFont); |
|||
public static readonly IconData clock_solid = new IconData(0xf4bf, fontFamily: iconFont); |
|||
public static readonly IconData time = new IconData(0xf402, fontFamily: iconFont); |
|||
public static readonly IconData time_solid = new IconData(0xf403, fontFamily: iconFont); |
|||
public static readonly IconData padlock = new IconData(0xf4c8, fontFamily: iconFont); |
|||
public static readonly IconData padlock_solid = new IconData(0xf4c9, fontFamily: iconFont); |
|||
public static readonly IconData eye = new IconData(0xf424, fontFamily: iconFont); |
|||
public static readonly IconData eye_solid = new IconData(0xf425, fontFamily: iconFont); |
|||
public static readonly IconData person = new IconData(0xf47d, fontFamily: iconFont); |
|||
public static readonly IconData person_solid = new IconData(0xf47e, fontFamily: iconFont); |
|||
public static readonly IconData person_add = new IconData(0xf47f, fontFamily: iconFont); |
|||
public static readonly IconData person_add_solid = new IconData(0xf480, fontFamily: iconFont); |
|||
public static readonly IconData group = new IconData(0xf47b, fontFamily: iconFont); |
|||
public static readonly IconData group_solid = new IconData(0xf47c, fontFamily: iconFont); |
|||
public static readonly IconData mail = new IconData(0xf422, fontFamily: iconFont); |
|||
public static readonly IconData mail_solid = new IconData(0xf423, fontFamily: iconFont); |
|||
public static readonly IconData location = new IconData(0xf455, fontFamily: iconFont); |
|||
public static readonly IconData location_solid = new IconData(0xf456, fontFamily: iconFont); |
|||
public static readonly IconData tag = new IconData(0xf48c, fontFamily: iconFont); |
|||
public static readonly IconData tag_solid = new IconData(0xf48d, fontFamily: iconFont); |
|||
public static readonly IconData tags = new IconData(0xf48e, fontFamily: iconFont); |
|||
public static readonly IconData tags_solid = new IconData(0xf48f, fontFamily: iconFont); |
|||
public static readonly IconData bus = new IconData(0xf36d, fontFamily: iconFont); |
|||
public static readonly IconData car = new IconData(0xf36f, fontFamily: iconFont); |
|||
public static readonly IconData car_detailed = new IconData(0xf2c1, fontFamily: iconFont); |
|||
public static readonly IconData train_style_one = new IconData(0xf3af, fontFamily: iconFont); |
|||
public static readonly IconData train_style_two = new IconData(0xf3b4, fontFamily: iconFont); |
|||
public static readonly IconData paw = new IconData(0xf479, fontFamily: iconFont); |
|||
public static readonly IconData paw_solid = new IconData(0xf47a, fontFamily: iconFont); |
|||
public static readonly IconData game_controller = new IconData(0xf43a, fontFamily: iconFont); |
|||
public static readonly IconData game_controller_solid = new IconData(0xf43b, fontFamily: iconFont); |
|||
public static readonly IconData lab_flask = new IconData(0xf430, fontFamily: iconFont); |
|||
public static readonly IconData lab_flask_solid = new IconData(0xf431, fontFamily: iconFont); |
|||
public static readonly IconData heart = new IconData(0xf442, fontFamily: iconFont); |
|||
public static readonly IconData heart_solid = new IconData(0xf443, fontFamily: iconFont); |
|||
public static readonly IconData bell = new IconData(0xf3e1, fontFamily: iconFont); |
|||
public static readonly IconData bell_solid = new IconData(0xf3e2, fontFamily: iconFont); |
|||
public static readonly IconData news = new IconData(0xf471, fontFamily: iconFont); |
|||
public static readonly IconData news_solid = new IconData(0xf472, fontFamily: iconFont); |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: ed8c228d2f54415419ded075a9b16c89 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using Unity.UIWidgets.async2; |
|||
using Unity.UIWidgets.foundation; |
|||
using Unity.UIWidgets.ui; |
|||
using Unity.UIWidgets.widgets; |
|||
|
|||
namespace Unity.UIWidgets.cupertino { |
|||
public enum DatePickerDateTimeOrder { |
|||
date_time_dayPeriod, |
|||
date_dayPeriod_time, |
|||
time_dayPeriod_date, |
|||
dayPeriod_time_date |
|||
} |
|||
|
|||
public enum DatePickerDateOrder { |
|||
dmy, |
|||
mdy, |
|||
ymd, |
|||
ydm |
|||
} |
|||
|
|||
public abstract class CupertinoLocalizations { |
|||
public abstract string datePickerYear(int yearIndex); |
|||
|
|||
public abstract string datePickerMonth(int monthIndex); |
|||
|
|||
public abstract string datePickerDayOfMonth(int dayIndex); |
|||
|
|||
public abstract string datePickerMediumDate(DateTime date); |
|||
|
|||
public abstract string datePickerHour(int hour); |
|||
|
|||
public abstract string datePickerHourSemanticsLabel(int hour); |
|||
|
|||
public abstract string datePickerMinute(int minute); |
|||
|
|||
public abstract string datePickerMinuteSemanticsLabel(int minute); |
|||
|
|||
public abstract DatePickerDateOrder datePickerDateOrder { get; } |
|||
|
|||
public abstract DatePickerDateTimeOrder datePickerDateTimeOrder { get; } |
|||
|
|||
public abstract string anteMeridiemAbbreviation { get; } |
|||
|
|||
public abstract string postMeridiemAbbreviation { get; } |
|||
|
|||
public abstract string alertDialogLabel { get; } |
|||
|
|||
public abstract string timerPickerHour(int hour); |
|||
|
|||
public abstract string timerPickerMinute(int minute); |
|||
|
|||
public abstract string timerPickerSecond(int second); |
|||
|
|||
public abstract string timerPickerHourLabel(int hour); |
|||
|
|||
public abstract string timerPickerMinuteLabel(int minute); |
|||
|
|||
public abstract string timerPickerSecondLabel(int second); |
|||
|
|||
public abstract string cutButtonLabel { get; } |
|||
|
|||
public abstract string copyButtonLabel { get; } |
|||
|
|||
public abstract string pasteButtonLabel { get; } |
|||
|
|||
public abstract string selectAllButtonLabel { get; } |
|||
|
|||
public static CupertinoLocalizations of(BuildContext context) { |
|||
return Localizations.of<CupertinoLocalizations>(context, typeof(CupertinoLocalizations)); |
|||
} |
|||
} |
|||
|
|||
class _CupertinoLocalizationsDelegate : LocalizationsDelegate<CupertinoLocalizations> { |
|||
public _CupertinoLocalizationsDelegate() { } |
|||
|
|||
public override bool isSupported(Locale locale) { |
|||
return locale.languageCode == "en"; |
|||
} |
|||
|
|||
/* public override Future<CupertinoLocalizations> loadT(Locale locale) { |
|||
return DefaultCupertinoLocalizations.load(locale); |
|||
}*/ |
|||
//public override Future<> load(Locale locale) {
|
|||
public override Future<WidgetsLocalizations> load(Locale locale) { |
|||
return DefaultCupertinoLocalizations.load(locale).to<WidgetsLocalizations>(); |
|||
} |
|||
|
|||
public override bool shouldReload(LocalizationsDelegate old) { |
|||
return false; |
|||
} |
|||
|
|||
public override string ToString() { |
|||
return "DefaultCupertinoLocalizations.delegate(en_US)"; |
|||
} |
|||
} |
|||
|
|||
public class DefaultCupertinoLocalizations : CupertinoLocalizations { |
|||
public DefaultCupertinoLocalizations() { } |
|||
|
|||
static readonly List<string> _shortWeekdays = new List<string> { |
|||
"Mon", |
|||
"Tue", |
|||
"Wed", |
|||
"Thu", |
|||
"Fri", |
|||
"Sat", |
|||
"Sun" |
|||
}; |
|||
|
|||
static readonly List<string> _shortMonths = new List<string> { |
|||
"Jan", |
|||
"Feb", |
|||
"Mar", |
|||
"Apr", |
|||
"May", |
|||
"Jun", |
|||
"Jul", |
|||
"Aug", |
|||
"Sep", |
|||
"Oct", |
|||
"Nov", |
|||
"Dec" |
|||
}; |
|||
|
|||
static readonly List<string> _months = new List<string> { |
|||
"January", |
|||
"February", |
|||
"March", |
|||
"April", |
|||
"May", |
|||
"June", |
|||
"July", |
|||
"August", |
|||
"September", |
|||
"October", |
|||
"November", |
|||
"December" |
|||
}; |
|||
|
|||
public override string datePickerYear(int yearIndex) { |
|||
return yearIndex.ToString(); |
|||
} |
|||
|
|||
public override string datePickerMonth(int monthIndex) { |
|||
return _months[monthIndex - 1]; |
|||
} |
|||
|
|||
public override string datePickerDayOfMonth(int dayIndex) { |
|||
return dayIndex.ToString(); |
|||
} |
|||
|
|||
public override string datePickerHour(int hour) { |
|||
return hour.ToString(); |
|||
} |
|||
|
|||
public override string datePickerHourSemanticsLabel(int hour) { |
|||
return hour.ToString() + " o'clock"; |
|||
} |
|||
|
|||
public override string datePickerMinute(int minute) { |
|||
return minute.ToString().PadLeft(2, '0'); |
|||
} |
|||
|
|||
public override string datePickerMinuteSemanticsLabel(int minute) { |
|||
if (minute == 1) { |
|||
return "1 minute"; |
|||
} |
|||
|
|||
return minute.ToString() + " minutes"; |
|||
} |
|||
|
|||
public override string datePickerMediumDate(DateTime date) { |
|||
var day = _shortWeekdays[((int) date.DayOfWeek + 6) % 7]; |
|||
var month = _shortMonths[date.Month - 1]; |
|||
return $"{day} {month} {date.Day.ToString().PadRight(2)} "; |
|||
} |
|||
|
|||
public override DatePickerDateOrder datePickerDateOrder { |
|||
get { return DatePickerDateOrder.mdy; } |
|||
} |
|||
|
|||
public override DatePickerDateTimeOrder datePickerDateTimeOrder { |
|||
get { return DatePickerDateTimeOrder.date_time_dayPeriod; } |
|||
} |
|||
|
|||
public override string anteMeridiemAbbreviation { |
|||
get { return "AM"; } |
|||
} |
|||
|
|||
public override string postMeridiemAbbreviation { |
|||
get { return "PM"; } |
|||
} |
|||
|
|||
public override string alertDialogLabel { |
|||
get { return "Alert"; } |
|||
} |
|||
|
|||
public override string timerPickerHour(int hour) { |
|||
return hour.ToString(); |
|||
} |
|||
|
|||
public override string timerPickerMinute(int minute) { |
|||
return minute.ToString(); |
|||
} |
|||
|
|||
public override string timerPickerSecond(int second) { |
|||
return second.ToString(); |
|||
} |
|||
|
|||
public override string timerPickerHourLabel(int hour) { |
|||
return hour == 1 ? "hour" : "hours"; |
|||
} |
|||
|
|||
public override string timerPickerMinuteLabel(int minute) { |
|||
return "min"; |
|||
} |
|||
|
|||
public override string timerPickerSecondLabel(int second) { |
|||
return "sec"; |
|||
} |
|||
|
|||
public override string cutButtonLabel { |
|||
get { return "Cut"; } |
|||
} |
|||
|
|||
public override string copyButtonLabel { |
|||
get { return "Copy"; } |
|||
} |
|||
|
|||
public override string pasteButtonLabel { |
|||
get { return "Paste"; } |
|||
} |
|||
|
|||
public override string selectAllButtonLabel { |
|||
get { return "Select All"; } |
|||
} |
|||
|
|||
public static Future<CupertinoLocalizations> load(Locale locale) { |
|||
return new SynchronousFuture<CupertinoLocalizations>(new DefaultCupertinoLocalizations()); |
|||
} |
|||
|
|||
public static readonly LocalizationsDelegate<CupertinoLocalizations> |
|||
del = new _CupertinoLocalizationsDelegate(); |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 30e111327cb1ec2428eed691dcaee742 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 4fb1c214b61524a48b988f4e193ad97b |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 0e428c069ad6abb4e80e0a3483f6fe57 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
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 { |
|||
static 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> { |
|||
FixedExtentScrollController _controller; |
|||
|
|||
public override void initState() { |
|||
base.initState(); |
|||
if (widget.scrollController == null) { |
|||
_controller = new FixedExtentScrollController(); |
|||
} |
|||
} |
|||
|
|||
public override void didUpdateWidget(StatefulWidget oldWidget) { |
|||
if (widget.scrollController != null && ((CupertinoPicker) oldWidget).scrollController == null) { |
|||
_controller = null; |
|||
} |
|||
else if (widget.scrollController == null && ((CupertinoPicker) oldWidget).scrollController != null) { |
|||
D.assert(_controller == null); |
|||
_controller = new FixedExtentScrollController(); |
|||
} |
|||
|
|||
base.didUpdateWidget(oldWidget); |
|||
} |
|||
|
|||
public override void dispose() { |
|||
_controller?.dispose(); |
|||
base.dispose(); |
|||
} |
|||
|
|||
void _handleSelectedItemChanged(int index) { |
|||
if (widget.onSelectedItemChanged != null) { |
|||
widget.onSelectedItemChanged(index); |
|||
} |
|||
} |
|||
|
|||
Widget _buildGradientScreen() { |
|||
if (widget.backgroundColor != null && widget.backgroundColor.alpha < 255) { |
|||
return new Container(); |
|||
} |
|||
|
|||
Color widgetBackgroundColor = 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 = widget.backgroundColor?.withAlpha( |
|||
(int) (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: widget.itemExtent * widget.magnification |
|||
) |
|||
), |
|||
new Expanded( |
|||
child: new Container( |
|||
color: foreground |
|||
) |
|||
), |
|||
} |
|||
) |
|||
); |
|||
} |
|||
|
|||
Widget _buildUnderMagnifierScreen() { |
|||
Color foreground = widget.backgroundColor?.withAlpha( |
|||
(int) (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: widget.itemExtent * widget.magnification |
|||
) |
|||
), |
|||
new Expanded(child: new Container()) |
|||
} |
|||
); |
|||
} |
|||
|
|||
Widget _addBackgroundToChild(Widget child) { |
|||
return new DecoratedBox( |
|||
decoration: new BoxDecoration( |
|||
color: widget.backgroundColor |
|||
), |
|||
child: child |
|||
); |
|||
} |
|||
|
|||
public override Widget build(BuildContext context) { |
|||
Widget result = new Stack( |
|||
children: new List<Widget> { |
|||
Positioned.fill( |
|||
child: ListWheelScrollView.useDelegate( |
|||
controller: widget.scrollController ?? _controller, |
|||
physics: new FixedExtentScrollPhysics(), |
|||
diameterRatio: widget.diameterRatio, |
|||
perspective: CupertinoPickerUtils._kDefaultPerspective, |
|||
offAxisFraction: widget.offAxisFraction, |
|||
useMagnifier: widget.useMagnifier, |
|||
magnification: widget.magnification, |
|||
itemExtent: widget.itemExtent, |
|||
onSelectedItemChanged: _handleSelectedItemChanged, |
|||
childDelegate: widget.childDelegate |
|||
) |
|||
), |
|||
_buildGradientScreen(), |
|||
_buildMagnifierScreen() |
|||
} |
|||
); |
|||
if (widget.backgroundColor != null && widget.backgroundColor.alpha < 255) { |
|||
result = new Stack( |
|||
children: new List<Widget> { |
|||
_buildUnderMagnifierScreen(), _addBackgroundToChild(result), |
|||
} |
|||
); |
|||
} |
|||
else { |
|||
result = _addBackgroundToChild(result); |
|||
} |
|||
|
|||
return result; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: bf0858feee06e8c46bf820fe90a17071 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 699b3c09353fafc40b33fd5c0470048f |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using Unity.UIWidgets.animation; |
|||
using Unity.UIWidgets.async2; |
|||
using Unity.UIWidgets.foundation; |
|||
using Unity.UIWidgets.ui; |
|||
using Unity.UIWidgets.widgets; |
|||
|
|||
namespace Unity.UIWidgets.cupertino { |
|||
class CupertinoScrollbarUtils { |
|||
public static readonly Color _kScrollbarColor = new Color(0x99777777); |
|||
public const float _kScrollbarThickness = 2.5f; |
|||
public const float _kScrollbarMainAxisMargin = 4.0f; |
|||
public const float _kScrollbarCrossAxisMargin = 2.5f; |
|||
public const float _kScrollbarMinLength = 36.0f; |
|||
public const float _kScrollbarMinOverscrollLength = 8.0f; |
|||
public static readonly Radius _kScrollbarRadius = Radius.circular(1.25f); |
|||
public static readonly TimeSpan _kScrollbarTimeToFade = new TimeSpan(0, 0, 0, 0, 50); |
|||
public static readonly TimeSpan _kScrollbarFadeDuration = new TimeSpan(0, 0, 0, 0, 250); |
|||
} |
|||
|
|||
public class CupertinoScrollbar : StatefulWidget { |
|||
public CupertinoScrollbar( |
|||
Widget child, |
|||
Key key = null |
|||
) : base(key: key) { |
|||
this.child = child; |
|||
} |
|||
|
|||
public readonly Widget child; |
|||
public readonly ScrollController controller; |
|||
public readonly bool isAlwaysShown; |
|||
|
|||
public override State createState() { |
|||
return new _CupertinoScrollbarState(); |
|||
} |
|||
} |
|||
|
|||
class _CupertinoScrollbarState : TickerProviderStateMixin<CupertinoScrollbar> { |
|||
ScrollbarPainter _painter; |
|||
|
|||
TextDirection _textDirection; |
|||
|
|||
AnimationController _fadeoutAnimationController; |
|||
Animation<float> _fadeoutOpacityAnimation; |
|||
double _dragScrollbarPositionY; |
|||
Timer _fadeoutTimer; |
|||
|
|||
|
|||
public override void initState() { |
|||
base.initState(); |
|||
_fadeoutAnimationController = new AnimationController( |
|||
vsync: this, |
|||
duration: CupertinoScrollbarUtils._kScrollbarFadeDuration |
|||
); |
|||
_fadeoutOpacityAnimation = new CurvedAnimation( |
|||
parent: _fadeoutAnimationController, |
|||
curve: Curves.fastOutSlowIn |
|||
); |
|||
} |
|||
|
|||
|
|||
public override void didChangeDependencies() { |
|||
base.didChangeDependencies(); |
|||
_textDirection = Directionality.of(context); |
|||
_painter = _buildCupertinoScrollbarPainter(); |
|||
} |
|||
|
|||
ScrollbarPainter _buildCupertinoScrollbarPainter() { |
|||
return new ScrollbarPainter( |
|||
color: CupertinoScrollbarUtils._kScrollbarColor, |
|||
textDirection: _textDirection, |
|||
thickness: CupertinoScrollbarUtils._kScrollbarThickness, |
|||
fadeoutOpacityAnimation: _fadeoutOpacityAnimation, |
|||
mainAxisMargin: CupertinoScrollbarUtils._kScrollbarMainAxisMargin, |
|||
crossAxisMargin: CupertinoScrollbarUtils._kScrollbarCrossAxisMargin, |
|||
radius: CupertinoScrollbarUtils._kScrollbarRadius, |
|||
minLength: CupertinoScrollbarUtils._kScrollbarMinLength, |
|||
minOverscrollLength: CupertinoScrollbarUtils._kScrollbarMinOverscrollLength |
|||
); |
|||
} |
|||
|
|||
bool _handleScrollNotification(ScrollNotification notification) { |
|||
if (notification is ScrollUpdateNotification || |
|||
notification is OverscrollNotification) { |
|||
if (_fadeoutAnimationController.status != AnimationStatus.forward) { |
|||
_fadeoutAnimationController.forward(); |
|||
} |
|||
|
|||
_fadeoutTimer?.cancel(); |
|||
_painter.update(notification.metrics, notification.metrics.axisDirection); |
|||
} |
|||
else if (notification is ScrollEndNotification) { |
|||
if (_dragScrollbarPositionY == null) { |
|||
_startFadeoutTimer(); |
|||
} |
|||
|
|||
/*_fadeoutTimer?.cancel(); |
|||
_fadeoutTimer = Window.instance.run(CupertinoScrollbarUtils._kScrollbarTimeToFade, () => { |
|||
_fadeoutAnimationController.reverse(); |
|||
_fadeoutTimer = null; |
|||
});*/ |
|||
} |
|||
|
|||
return false; |
|||
} |
|||
|
|||
|
|||
public override void dispose() { |
|||
_fadeoutAnimationController.dispose(); |
|||
_fadeoutTimer?.cancel(); |
|||
_painter.dispose(); |
|||
base.dispose(); |
|||
} |
|||
|
|||
void _startFadeoutTimer() { |
|||
if (!widget.isAlwaysShown) { |
|||
_fadeoutTimer?.cancel(); |
|||
_fadeoutTimer = Timer.create(CupertinoScrollbarUtils._kScrollbarTimeToFade, () => { |
|||
_fadeoutAnimationController.reverse(); |
|||
_fadeoutTimer = null; |
|||
}); |
|||
} |
|||
} |
|||
|
|||
|
|||
public override Widget build(BuildContext context) { |
|||
return new NotificationListener<ScrollNotification>( |
|||
onNotification: _handleScrollNotification, |
|||
child: new RepaintBoundary( |
|||
child: new CustomPaint( |
|||
foregroundPainter: _painter, |
|||
child: new RepaintBoundary( |
|||
child: widget.child |
|||
) |
|||
) |
|||
) |
|||
); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 55b1201340c47f94b91591a011603a8a |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using Unity.UIWidgets.animation; |
|||
using Unity.UIWidgets.foundation; |
|||
using Unity.UIWidgets.gestures; |
|||
using Unity.UIWidgets.rendering; |
|||
using Unity.UIWidgets.scheduler2; |
|||
using Unity.UIWidgets.ui; |
|||
using Unity.UIWidgets.widgets; |
|||
using UnityEngine; |
|||
using Canvas = Unity.UIWidgets.ui.Canvas; |
|||
using Color = Unity.UIWidgets.ui.Color; |
|||
using Rect = Unity.UIWidgets.ui.Rect; |
|||
|
|||
namespace Unity.UIWidgets.cupertino { |
|||
class SliderUtils { |
|||
public const float _kPadding = 8.0f; |
|||
public static readonly Color _kTrackColor = new Color(0xFFB5B5B5); |
|||
public const float _kSliderHeight = 2.0f * (CupertinoThumbPainter.radius + _kPadding); |
|||
public const float _kSliderWidth = 176.0f; // Matches Material Design slider.
|
|||
public static readonly TimeSpan _kDiscreteTransitionDuration = new TimeSpan(0, 0, 0, 0, 500); |
|||
public const float _kAdjustmentUnit = 0.1f; // Matches iOS implementation of material slider.
|
|||
} |
|||
|
|||
public class CupertinoSlider : StatefulWidget { |
|||
public CupertinoSlider( |
|||
Key key = null, |
|||
float? value = null, |
|||
ValueChanged<float> onChanged = null, |
|||
ValueChanged<float> onChangeStart = null, |
|||
ValueChanged<float> onChangeEnd = null, |
|||
float min = 0.0f, |
|||
float max = 1.0f, |
|||
int? divisions = null, |
|||
Color activeColor = null |
|||
) : base(key: key) { |
|||
D.assert(value != null); |
|||
D.assert(onChanged != null); |
|||
D.assert(value >= min && value <= max); |
|||
D.assert(divisions == null || divisions > 0); |
|||
this.value = value.Value; |
|||
this.onChanged = onChanged; |
|||
this.onChangeStart = onChangeStart; |
|||
this.onChangeEnd = onChangeEnd; |
|||
this.min = min; |
|||
this.max = max; |
|||
this.divisions = divisions; |
|||
this.activeColor = activeColor; |
|||
} |
|||
|
|||
public readonly float value; |
|||
|
|||
public readonly ValueChanged<float> onChanged; |
|||
|
|||
public readonly ValueChanged<float> onChangeStart; |
|||
|
|||
public readonly ValueChanged<float> onChangeEnd; |
|||
|
|||
public readonly float min; |
|||
|
|||
public readonly float max; |
|||
|
|||
public readonly int? divisions; |
|||
|
|||
public readonly Color activeColor; |
|||
|
|||
public override State createState() { |
|||
return new _CupertinoSliderState(); |
|||
} |
|||
|
|||
public override void debugFillProperties(DiagnosticPropertiesBuilder properties) { |
|||
base.debugFillProperties(properties); |
|||
properties.add(new FloatProperty("value", value)); |
|||
properties.add(new FloatProperty("min", min)); |
|||
properties.add(new FloatProperty("max", max)); |
|||
} |
|||
} |
|||
|
|||
class _CupertinoSliderState : TickerProviderStateMixin<CupertinoSlider> { |
|||
void _handleChanged(float value) { |
|||
D.assert(widget.onChanged != null); |
|||
float lerpValue = MathUtils.lerpFloat(widget.min, widget.max, value); |
|||
if (lerpValue != widget.value) { |
|||
widget.onChanged(lerpValue); |
|||
} |
|||
} |
|||
|
|||
void _handleDragStart(float value) { |
|||
D.assert(widget.onChangeStart != null); |
|||
widget.onChangeStart(MathUtils.lerpFloat(widget.min, widget.max, value)); |
|||
} |
|||
|
|||
void _handleDragEnd(float value) { |
|||
D.assert(widget.onChangeEnd != null); |
|||
widget.onChangeEnd(MathUtils.lerpFloat(widget.min, widget.max, value)); |
|||
} |
|||
|
|||
public override Widget build(BuildContext context) { |
|||
return new _CupertinoSliderRenderObjectWidget( |
|||
value: (widget.value - widget.min) / (widget.max - widget.min), |
|||
divisions: widget.divisions, |
|||
activeColor: widget.activeColor ?? CupertinoTheme.of(context).primaryColor, |
|||
onChanged: widget.onChanged != null ? (ValueChanged<float>) _handleChanged : null, |
|||
onChangeStart: widget.onChangeStart != null ? (ValueChanged<float>) _handleDragStart : null, |
|||
onChangeEnd: widget.onChangeEnd != null ? (ValueChanged<float>) _handleDragEnd : null, |
|||
vsync: this |
|||
); |
|||
} |
|||
} |
|||
|
|||
class _CupertinoSliderRenderObjectWidget : LeafRenderObjectWidget { |
|||
public _CupertinoSliderRenderObjectWidget( |
|||
Key key = null, |
|||
float? value = null, |
|||
int? divisions = null, |
|||
Color activeColor = null, |
|||
ValueChanged<float> onChanged = null, |
|||
ValueChanged<float> onChangeStart = null, |
|||
ValueChanged<float> onChangeEnd = null, |
|||
TickerProvider vsync = null |
|||
) : base(key: key) { |
|||
this.value = value; |
|||
this.divisions = divisions; |
|||
this.activeColor = activeColor; |
|||
this.onChanged = onChanged; |
|||
this.onChangeStart = onChangeStart; |
|||
this.onChangeEnd = onChangeEnd; |
|||
this.vsync = vsync; |
|||
} |
|||
|
|||
public readonly float? value; |
|||
public readonly int? divisions; |
|||
public readonly Color activeColor; |
|||
public readonly ValueChanged<float> onChanged; |
|||
public readonly ValueChanged<float> onChangeStart; |
|||
public readonly ValueChanged<float> onChangeEnd; |
|||
public readonly TickerProvider vsync; |
|||
|
|||
public override RenderObject createRenderObject(BuildContext context) { |
|||
return new _RenderCupertinoSlider( |
|||
value: value ?? 0.0f, |
|||
divisions: divisions, |
|||
activeColor: activeColor, |
|||
onChanged: onChanged, |
|||
onChangeStart: onChangeStart, |
|||
onChangeEnd: onChangeEnd, |
|||
vsync: vsync |
|||
); |
|||
} |
|||
|
|||
public override void updateRenderObject(BuildContext context, RenderObject _renderObject) { |
|||
_RenderCupertinoSlider renderObject = _renderObject as _RenderCupertinoSlider; |
|||
renderObject.value = value ?? 0.0f; |
|||
renderObject.divisions = divisions; |
|||
renderObject.activeColor = activeColor; |
|||
renderObject.onChanged = onChanged; |
|||
renderObject.onChangeStart = onChangeStart; |
|||
renderObject.onChangeEnd = onChangeEnd; |
|||
} |
|||
} |
|||
|
|||
class _RenderCupertinoSlider : RenderConstrainedBox { |
|||
public _RenderCupertinoSlider( |
|||
float value, |
|||
int? divisions = null, |
|||
Color activeColor = null, |
|||
ValueChanged<float> onChanged = null, |
|||
ValueChanged<float> onChangeStart = null, |
|||
ValueChanged<float> onChangeEnd = null, |
|||
TickerProvider vsync = null |
|||
) : base(additionalConstraints: BoxConstraints.tightFor(width: SliderUtils._kSliderWidth, |
|||
height: SliderUtils._kSliderHeight)) { |
|||
D.assert(value >= 0.0f && value <= 1.0f); |
|||
_value = value; |
|||
_divisions = divisions; |
|||
_activeColor = activeColor; |
|||
_onChanged = onChanged; |
|||
this.onChangeStart = onChangeStart; |
|||
this.onChangeEnd = onChangeEnd; |
|||
_drag = new HorizontalDragGestureRecognizer(); |
|||
_drag.onStart = _handleDragStart; |
|||
_drag.onUpdate = _handleDragUpdate; |
|||
_drag.onEnd = _handleDragEnd; |
|||
_position = new AnimationController( |
|||
value: value, |
|||
duration: SliderUtils._kDiscreteTransitionDuration, |
|||
vsync: vsync |
|||
); |
|||
_position.addListener(markNeedsPaint); |
|||
} |
|||
|
|||
public float value { |
|||
get { return _value; } |
|||
set { |
|||
D.assert(value >= 0.0f && value <= 1.0f); |
|||
if (value == _value) { |
|||
return; |
|||
} |
|||
|
|||
_value = value; |
|||
if (divisions != null) { |
|||
_position.animateTo(value, curve: Curves.fastOutSlowIn); |
|||
} |
|||
else { |
|||
_position.setValue(value); |
|||
} |
|||
} |
|||
} |
|||
|
|||
float _value; |
|||
|
|||
public int? divisions { |
|||
get { return _divisions; } |
|||
set { |
|||
if (value == _divisions) { |
|||
return; |
|||
} |
|||
|
|||
_divisions = value; |
|||
markNeedsPaint(); |
|||
} |
|||
} |
|||
|
|||
int? _divisions; |
|||
|
|||
public Color activeColor { |
|||
get { return _activeColor; } |
|||
set { |
|||
if (value == _activeColor) { |
|||
return; |
|||
} |
|||
|
|||
_activeColor = value; |
|||
markNeedsPaint(); |
|||
} |
|||
} |
|||
|
|||
Color _activeColor; |
|||
|
|||
public ValueChanged<float> onChanged { |
|||
get { return _onChanged; } |
|||
set { |
|||
if (value == _onChanged) { |
|||
return; |
|||
} |
|||
|
|||
_onChanged = value; |
|||
} |
|||
} |
|||
|
|||
ValueChanged<float> _onChanged; |
|||
|
|||
public ValueChanged<float> onChangeStart; |
|||
public ValueChanged<float> onChangeEnd; |
|||
|
|||
|
|||
AnimationController _position; |
|||
|
|||
HorizontalDragGestureRecognizer _drag; |
|||
float _currentDragValue = 0.0f; |
|||
|
|||
float _discretizedCurrentDragValue { |
|||
get { |
|||
float dragValue = _currentDragValue.clamp(0.0f, 1.0f); |
|||
if (divisions != null) { |
|||
dragValue = Mathf.Round(dragValue * divisions.Value) / divisions.Value; |
|||
} |
|||
|
|||
return dragValue; |
|||
} |
|||
} |
|||
|
|||
public float _trackLeft { |
|||
get { return SliderUtils._kPadding; } |
|||
} |
|||
|
|||
public float _trackRight { |
|||
get { return size.width - SliderUtils._kPadding; } |
|||
} |
|||
|
|||
float _thumbCenter { |
|||
get { |
|||
float visualPosition = _value; |
|||
|
|||
return MathUtils.lerpFloat(_trackLeft + CupertinoThumbPainter.radius, |
|||
_trackRight - CupertinoThumbPainter.radius, |
|||
visualPosition); |
|||
} |
|||
} |
|||
|
|||
public bool isInteractive { |
|||
get { return onChanged != null; } |
|||
} |
|||
|
|||
void _handleDragStart(DragStartDetails details) { |
|||
_startInteraction(details.globalPosition); |
|||
} |
|||
|
|||
void _handleDragUpdate(DragUpdateDetails details) { |
|||
if (isInteractive) { |
|||
float extent = Mathf.Max(SliderUtils._kPadding, |
|||
size.width - 2.0f * (SliderUtils._kPadding + CupertinoThumbPainter.radius)); |
|||
float? valueDelta = details.primaryDelta / extent; |
|||
_currentDragValue += valueDelta ?? 0.0f; |
|||
|
|||
onChanged(_discretizedCurrentDragValue); |
|||
} |
|||
} |
|||
|
|||
void _handleDragEnd(DragEndDetails details) { |
|||
_endInteraction(); |
|||
} |
|||
|
|||
void _startInteraction(Offset globalPosition) { |
|||
if (isInteractive) { |
|||
if (onChangeStart != null) { |
|||
onChangeStart(_discretizedCurrentDragValue); |
|||
} |
|||
|
|||
_currentDragValue = _value; |
|||
onChanged(_discretizedCurrentDragValue); |
|||
} |
|||
} |
|||
|
|||
void _endInteraction() { |
|||
if (onChangeEnd != null) { |
|||
onChangeEnd(_discretizedCurrentDragValue); |
|||
} |
|||
|
|||
_currentDragValue = 0.0f; |
|||
} |
|||
|
|||
protected override bool hitTestSelf(Offset position) { |
|||
return (position.dx - _thumbCenter).abs() < CupertinoThumbPainter.radius + SliderUtils._kPadding; |
|||
} |
|||
|
|||
public override void handleEvent(PointerEvent e, HitTestEntry entry) { |
|||
D.assert(debugHandleEvent(e, entry)); |
|||
if (e is PointerDownEvent pointerDownEvent && isInteractive) { |
|||
_drag.addPointer(pointerDownEvent); |
|||
} |
|||
} |
|||
|
|||
CupertinoThumbPainter _thumbPainter = new CupertinoThumbPainter(); |
|||
|
|||
public override |
|||
void paint(PaintingContext context, Offset offset) { |
|||
float visualPosition; |
|||
Color leftColor; |
|||
Color rightColor; |
|||
visualPosition = _position.value; |
|||
leftColor = SliderUtils._kTrackColor; |
|||
rightColor = _activeColor; |
|||
|
|||
float trackCenter = offset.dy + size.height / 2.0f; |
|||
float trackLeft = offset.dx + _trackLeft; |
|||
float trackTop = trackCenter - 1.0f; |
|||
float trackBottom = trackCenter + 1.0f; |
|||
float trackRight = offset.dx + _trackRight; |
|||
float trackActive = offset.dx + _thumbCenter; |
|||
|
|||
Canvas canvas = context.canvas; |
|||
|
|||
if (visualPosition > 0.0f) { |
|||
Paint paint = new Paint(); |
|||
paint.color = rightColor; |
|||
canvas.drawRRect(RRect.fromLTRBXY(trackLeft, trackTop, trackActive, trackBottom, 1.0f, 1.0f), paint); |
|||
} |
|||
|
|||
if (visualPosition < 1.0f) { |
|||
Paint paint = new Paint(); |
|||
paint.color = leftColor; |
|||
canvas.drawRRect(RRect.fromLTRBXY(trackActive, trackTop, trackRight, trackBottom, 1.0f, 1.0f), paint); |
|||
} |
|||
|
|||
Offset thumbCenter = new Offset(trackActive, trackCenter); |
|||
_thumbPainter.paint(canvas, |
|||
Rect.fromCircle(center: thumbCenter, radius: CupertinoThumbPainter.radius)); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: c692b7c8464330e48a01d99464265341 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using Unity.UIWidgets.animation; |
|||
using Unity.UIWidgets.foundation; |
|||
using Unity.UIWidgets.gestures; |
|||
using Unity.UIWidgets.rendering; |
|||
using Unity.UIWidgets.scheduler2; |
|||
using Unity.UIWidgets.ui; |
|||
using Unity.UIWidgets.widgets; |
|||
using UnityEngine; |
|||
using Canvas = Unity.UIWidgets.ui.Canvas; |
|||
using Color = Unity.UIWidgets.ui.Color; |
|||
using Rect = Unity.UIWidgets.ui.Rect; |
|||
|
|||
namespace Unity.UIWidgets.cupertino { |
|||
class CupertinoSwitchUtils { |
|||
public const float _kTrackWidth = 51.0f; |
|||
public const float _kTrackHeight = 31.0f; |
|||
public const float _kTrackRadius = _kTrackHeight / 2.0f; |
|||
public const float _kTrackInnerStart = _kTrackHeight / 2.0f; |
|||
public const float _kTrackInnerEnd = _kTrackWidth - _kTrackInnerStart; |
|||
public const float _kTrackInnerLength = _kTrackInnerEnd - _kTrackInnerStart; |
|||
public const float _kSwitchWidth = 59.0f; |
|||
public const float _kSwitchHeight = 39.0f; |
|||
public const float _kCupertinoSwitchDisabledOpacity = 0.5f; |
|||
public static readonly Color _kTrackColor = CupertinoColors.lightBackgroundGray; |
|||
public static readonly TimeSpan _kReactionDuration = new TimeSpan(0, 0, 0, 0, 300); |
|||
public static readonly TimeSpan _kToggleDuration = new TimeSpan(0, 0, 0, 0, 200); |
|||
} |
|||
|
|||
public class CupertinoSwitch : StatefulWidget { |
|||
public CupertinoSwitch( |
|||
bool value, |
|||
ValueChanged<bool> onChanged, |
|||
Key key = null, |
|||
Color activeColor = null, |
|||
DragStartBehavior dragStartBehavior = DragStartBehavior.start |
|||
) : base(key: key) { |
|||
this.value = value; |
|||
this.onChanged = onChanged; |
|||
this.activeColor = activeColor; |
|||
this.dragStartBehavior = dragStartBehavior; |
|||
} |
|||
|
|||
public readonly bool value; |
|||
|
|||
public readonly ValueChanged<bool> onChanged; |
|||
|
|||
public readonly Color activeColor; |
|||
|
|||
public readonly DragStartBehavior dragStartBehavior; |
|||
|
|||
public override State createState() { |
|||
return new _CupertinoSwitchState(); |
|||
} |
|||
|
|||
public override void debugFillProperties(DiagnosticPropertiesBuilder properties) { |
|||
base.debugFillProperties(properties); |
|||
properties.add(new FlagProperty("value", value: value, ifTrue: "on", ifFalse: "off", showName: true)); |
|||
properties.add(new ObjectFlagProperty<ValueChanged<bool>>("onChanged", onChanged, ifNull: "disabled")); |
|||
} |
|||
} |
|||
|
|||
class _CupertinoSwitchState : TickerProviderStateMixin<CupertinoSwitch> { |
|||
public override Widget build(BuildContext context) { |
|||
return new Opacity( |
|||
opacity: widget.onChanged == null ? CupertinoSwitchUtils._kCupertinoSwitchDisabledOpacity : 1.0f, |
|||
child: new _CupertinoSwitchRenderObjectWidget( |
|||
value: widget.value, |
|||
activeColor: widget.activeColor ?? CupertinoColors.activeGreen, |
|||
onChanged: widget.onChanged, |
|||
vsync: this, |
|||
dragStartBehavior: widget.dragStartBehavior |
|||
) |
|||
); |
|||
} |
|||
} |
|||
|
|||
class _CupertinoSwitchRenderObjectWidget : LeafRenderObjectWidget { |
|||
public _CupertinoSwitchRenderObjectWidget( |
|||
Key key = null, |
|||
bool value = false, |
|||
Color activeColor = null, |
|||
ValueChanged<bool> onChanged = null, |
|||
TickerProvider vsync = null, |
|||
DragStartBehavior dragStartBehavior = DragStartBehavior.start |
|||
) : base(key: key) { |
|||
this.value = value; |
|||
this.activeColor = activeColor; |
|||
this.onChanged = onChanged; |
|||
this.vsync = vsync; |
|||
this.dragStartBehavior = dragStartBehavior; |
|||
} |
|||
|
|||
public readonly bool value; |
|||
public readonly Color activeColor; |
|||
public readonly ValueChanged<bool> onChanged; |
|||
public readonly TickerProvider vsync; |
|||
public readonly DragStartBehavior dragStartBehavior; |
|||
|
|||
public override RenderObject createRenderObject(BuildContext context) { |
|||
return new _RenderCupertinoSwitch( |
|||
value: value, |
|||
activeColor: activeColor, |
|||
onChanged: onChanged, |
|||
textDirection: Directionality.of(context), |
|||
vsync: vsync, |
|||
dragStartBehavior: dragStartBehavior |
|||
); |
|||
} |
|||
|
|||
public override void updateRenderObject(BuildContext context, RenderObject renderObject) { |
|||
var _renderObject = renderObject as _RenderCupertinoSwitch; |
|||
_renderObject.value = value; |
|||
_renderObject.activeColor = activeColor; |
|||
_renderObject.onChanged = onChanged; |
|||
_renderObject.textDirection = Directionality.of(context); |
|||
_renderObject.vsync = vsync; |
|||
_renderObject.dragStartBehavior = dragStartBehavior; |
|||
} |
|||
} |
|||
|
|||
|
|||
class _RenderCupertinoSwitch : RenderConstrainedBox { |
|||
public _RenderCupertinoSwitch( |
|||
bool value, |
|||
Color activeColor, |
|||
TextDirection textDirection, |
|||
TickerProvider vsync, |
|||
ValueChanged<bool> onChanged = null, |
|||
DragStartBehavior dragStartBehavior = DragStartBehavior.start |
|||
) : base(additionalConstraints: BoxConstraints.tightFor( |
|||
width: CupertinoSwitchUtils._kSwitchWidth, |
|||
height: CupertinoSwitchUtils._kSwitchHeight) |
|||
) { |
|||
D.assert(activeColor != null); |
|||
D.assert(vsync != null); |
|||
_value = value; |
|||
_activeColor = activeColor; |
|||
_onChanged = onChanged; |
|||
_textDirection = textDirection; |
|||
_vsync = vsync; |
|||
|
|||
_tap = new TapGestureRecognizer() { |
|||
onTapDown = _handleTapDown, |
|||
onTap = _handleTap, |
|||
onTapUp = _handleTapUp, |
|||
onTapCancel = _handleTapCancel, |
|||
}; |
|||
|
|||
_drag = new HorizontalDragGestureRecognizer() { |
|||
onStart = _handleDragStart, |
|||
onUpdate = _handleDragUpdate, |
|||
onEnd = _handleDragEnd, |
|||
dragStartBehavior = dragStartBehavior |
|||
}; |
|||
|
|||
_positionController = new AnimationController( |
|||
duration: CupertinoSwitchUtils._kToggleDuration, |
|||
value: value ? 1.0f : 0.0f, |
|||
vsync: vsync |
|||
); |
|||
_position = new CurvedAnimation( |
|||
parent: _positionController, |
|||
curve: Curves.linear |
|||
); |
|||
_position.addListener(markNeedsPaint); |
|||
_position.addStatusListener(_handlePositionStateChanged); |
|||
|
|||
_reactionController = new AnimationController( |
|||
duration: CupertinoSwitchUtils._kReactionDuration, |
|||
vsync: vsync |
|||
); |
|||
_reaction = new CurvedAnimation( |
|||
parent: _reactionController, |
|||
curve: Curves.ease |
|||
); |
|||
_reaction.addListener(markNeedsPaint); |
|||
} |
|||
|
|||
AnimationController _positionController; |
|||
CurvedAnimation _position; |
|||
AnimationController _reactionController; |
|||
Animation<float> _reaction; |
|||
|
|||
public bool value { |
|||
get { return _value; } |
|||
set { |
|||
if (value == _value) { |
|||
return; |
|||
} |
|||
|
|||
_value = value; |
|||
// this.markNeedsSemanticsUpdate();
|
|||
_position.curve = Curves.ease; |
|||
_position.reverseCurve = Curves.ease.flipped; |
|||
if (value) { |
|||
_positionController.forward(); |
|||
} |
|||
else { |
|||
_positionController.reverse(); |
|||
} |
|||
} |
|||
} |
|||
|
|||
bool _value; |
|||
|
|||
public TickerProvider vsync { |
|||
get { return _vsync; } |
|||
set { |
|||
D.assert(value != null); |
|||
if (value == _vsync) { |
|||
return; |
|||
} |
|||
|
|||
_vsync = value; |
|||
_positionController.resync(vsync); |
|||
_reactionController.resync(vsync); |
|||
} |
|||
} |
|||
|
|||
TickerProvider _vsync; |
|||
|
|||
public Color activeColor { |
|||
get { return _activeColor; } |
|||
set { |
|||
D.assert(value != null); |
|||
if (value == _activeColor) { |
|||
return; |
|||
} |
|||
|
|||
_activeColor = value; |
|||
markNeedsPaint(); |
|||
} |
|||
} |
|||
|
|||
Color _activeColor; |
|||
|
|||
public ValueChanged<bool> onChanged { |
|||
get { return _onChanged; } |
|||
set { |
|||
if (value == _onChanged) { |
|||
return; |
|||
} |
|||
|
|||
bool wasInteractive = isInteractive; |
|||
_onChanged = value; |
|||
if (wasInteractive != isInteractive) { |
|||
markNeedsPaint(); |
|||
} |
|||
} |
|||
} |
|||
|
|||
ValueChanged<bool> _onChanged; |
|||
|
|||
public TextDirection textDirection { |
|||
get { return _textDirection; } |
|||
set { |
|||
if (_textDirection == value) { |
|||
return; |
|||
} |
|||
|
|||
_textDirection = value; |
|||
markNeedsPaint(); |
|||
} |
|||
} |
|||
|
|||
TextDirection _textDirection; |
|||
|
|||
|
|||
public DragStartBehavior dragStartBehavior { |
|||
get { return _drag.dragStartBehavior; } |
|||
set { |
|||
if (_drag.dragStartBehavior == value) { |
|||
return; |
|||
} |
|||
|
|||
_drag.dragStartBehavior = value; |
|||
} |
|||
} |
|||
|
|||
public bool isInteractive { |
|||
get { return onChanged != null; } |
|||
} |
|||
|
|||
TapGestureRecognizer _tap; |
|||
HorizontalDragGestureRecognizer _drag; |
|||
|
|||
public override void attach(object _owner) { |
|||
base.attach(_owner); |
|||
if (value) { |
|||
_positionController.forward(); |
|||
} |
|||
else { |
|||
_positionController.reverse(); |
|||
} |
|||
|
|||
if (isInteractive) { |
|||
switch (_reactionController.status) { |
|||
case AnimationStatus.forward: |
|||
_reactionController.forward(); |
|||
break; |
|||
case AnimationStatus.reverse: |
|||
_reactionController.reverse(); |
|||
break; |
|||
case AnimationStatus.dismissed: |
|||
case AnimationStatus.completed: |
|||
break; |
|||
} |
|||
} |
|||
} |
|||
|
|||
public override void detach() { |
|||
_positionController.stop(); |
|||
_reactionController.stop(); |
|||
base.detach(); |
|||
} |
|||
|
|||
void _handlePositionStateChanged(AnimationStatus status) { |
|||
if (isInteractive) { |
|||
if (status == AnimationStatus.completed && !_value) { |
|||
onChanged(true); |
|||
} |
|||
else if (status == AnimationStatus.dismissed && _value) { |
|||
onChanged(false); |
|||
} |
|||
} |
|||
} |
|||
|
|||
void _handleTapDown(TapDownDetails details) { |
|||
if (isInteractive) { |
|||
_reactionController.forward(); |
|||
} |
|||
} |
|||
|
|||
void _handleTap() { |
|||
if (isInteractive) { |
|||
onChanged(!_value); |
|||
_emitVibration(); |
|||
} |
|||
} |
|||
|
|||
void _handleTapUp(TapUpDetails details) { |
|||
if (isInteractive) { |
|||
_reactionController.reverse(); |
|||
} |
|||
} |
|||
|
|||
void _handleTapCancel() { |
|||
if (isInteractive) { |
|||
_reactionController.reverse(); |
|||
} |
|||
} |
|||
|
|||
void _handleDragStart(DragStartDetails details) { |
|||
if (isInteractive) { |
|||
_reactionController.forward(); |
|||
_emitVibration(); |
|||
} |
|||
} |
|||
|
|||
void _handleDragUpdate(DragUpdateDetails details) { |
|||
if (isInteractive) { |
|||
_position.curve = null; |
|||
_position.reverseCurve = null; |
|||
float delta = details.primaryDelta / CupertinoSwitchUtils._kTrackInnerLength ?? 0f; |
|||
|
|||
_positionController.setValue(_positionController.value + delta); |
|||
|
|||
// switch (this.textDirection) {
|
|||
// case TextDirection.rtl:
|
|||
// this._positionController.setValue(this._positionController.value - delta);
|
|||
// break;
|
|||
// case TextDirection.ltr:
|
|||
// this._positionController.setValue(this._positionController.value + delta);
|
|||
// break;
|
|||
// }
|
|||
} |
|||
} |
|||
|
|||
void _handleDragEnd(DragEndDetails details) { |
|||
if (_position.value >= 0.5) { |
|||
_positionController.forward(); |
|||
} |
|||
else { |
|||
_positionController.reverse(); |
|||
} |
|||
|
|||
_reactionController.reverse(); |
|||
} |
|||
|
|||
void _emitVibration() { |
|||
// switch (Platform defaultTargetPlatform) {
|
|||
// case TargetPlatform.iOS:
|
|||
// HapticFeedback.lightImpact();
|
|||
// break;
|
|||
// case TargetPlatform.fuchsia:
|
|||
// case TargetPlatform.android:
|
|||
// break;
|
|||
// }
|
|||
return; |
|||
} |
|||
|
|||
protected override bool hitTestSelf(Offset position) { |
|||
return true; |
|||
} |
|||
|
|||
public override void handleEvent(PointerEvent evt, HitTestEntry entry) { |
|||
D.assert(debugHandleEvent(evt, entry)); |
|||
if (evt is PointerDownEvent && isInteractive) { |
|||
_drag.addPointer(evt as PointerDownEvent); |
|||
_tap.addPointer(evt as PointerDownEvent); |
|||
} |
|||
} |
|||
|
|||
// public override void describeSemanticsConfiguration(SemanticsConfiguration config) {
|
|||
// base.describeSemanticsConfiguration(config);
|
|||
//
|
|||
// if (isInteractive)
|
|||
// config.onTap = _handleTap;
|
|||
//
|
|||
// config.isEnabled = isInteractive;
|
|||
// config.isToggled = _value;
|
|||
// }
|
|||
|
|||
public readonly CupertinoThumbPainter _thumbPainter = new CupertinoThumbPainter(); |
|||
|
|||
public override void paint(PaintingContext context, Offset offset) { |
|||
Canvas canvas = context.canvas; |
|||
|
|||
float currentValue = _position.value; |
|||
float currentReactionValue = _reaction.value; |
|||
|
|||
float visualPosition = 0f; |
|||
switch (textDirection) { |
|||
case TextDirection.rtl: |
|||
visualPosition = 1.0f - currentValue; |
|||
break; |
|||
case TextDirection.ltr: |
|||
visualPosition = currentValue; |
|||
break; |
|||
} |
|||
|
|||
Color trackColor = _value ? activeColor : CupertinoSwitchUtils._kTrackColor; |
|||
float borderThickness = |
|||
1.5f + (CupertinoSwitchUtils._kTrackRadius - 1.5f) * Mathf.Max(currentReactionValue, currentValue); |
|||
|
|||
Paint paint = new Paint(); |
|||
paint.color = trackColor; |
|||
|
|||
Rect trackRect = Rect.fromLTWH( |
|||
offset.dx + (size.width - CupertinoSwitchUtils._kTrackWidth) / 2.0f, |
|||
offset.dy + (size.height - CupertinoSwitchUtils._kTrackHeight) / 2.0f, |
|||
CupertinoSwitchUtils._kTrackWidth, |
|||
CupertinoSwitchUtils._kTrackHeight |
|||
); |
|||
RRect outerRRect = RRect.fromRectAndRadius(trackRect, Radius.circular(CupertinoSwitchUtils |
|||
._kTrackRadius)); |
|||
RRect innerRRect = RRect.fromRectAndRadius(trackRect.deflate(borderThickness), Radius.circular |
|||
(CupertinoSwitchUtils._kTrackRadius)); |
|||
canvas.drawDRRect(outerRRect, innerRRect, paint); |
|||
|
|||
float currentThumbExtension = CupertinoThumbPainter.extension * currentReactionValue; |
|||
float thumbLeft = MathUtils.lerpFloat( |
|||
trackRect.left + CupertinoSwitchUtils._kTrackInnerStart - CupertinoThumbPainter.radius, |
|||
trackRect.left + CupertinoSwitchUtils._kTrackInnerEnd - CupertinoThumbPainter.radius - |
|||
currentThumbExtension, |
|||
visualPosition |
|||
); |
|||
float thumbRight = MathUtils.lerpFloat( |
|||
trackRect.left + CupertinoSwitchUtils._kTrackInnerStart + CupertinoThumbPainter.radius + |
|||
currentThumbExtension, |
|||
trackRect.left + CupertinoSwitchUtils._kTrackInnerEnd + CupertinoThumbPainter.radius, |
|||
visualPosition |
|||
); |
|||
float thumbCenterY = offset.dy + size.height / 2.0f; |
|||
|
|||
_thumbPainter.paint(canvas, Rect.fromLTRB( |
|||
thumbLeft, |
|||
thumbCenterY - CupertinoThumbPainter.radius, |
|||
thumbRight, |
|||
thumbCenterY + CupertinoThumbPainter.radius |
|||
)); |
|||
} |
|||
|
|||
|
|||
public override void debugFillProperties(DiagnosticPropertiesBuilder description) { |
|||
base.debugFillProperties(description); |
|||
description.add( |
|||
new FlagProperty("value", value: value, ifTrue: "checked", ifFalse: "unchecked", showName: true)); |
|||
description.add(new FlagProperty("isInteractive", value: isInteractive, ifTrue: "enabled", |
|||
ifFalse: "disabled", |
|||
showName: true, defaultValue: true)); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 6216d964b6d93c34cb861fd15181b25b |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using Unity.UIWidgets.foundation; |
|||
using Unity.UIWidgets.painting; |
|||
using Unity.UIWidgets.rendering; |
|||
using Unity.UIWidgets.ui; |
|||
using Unity.UIWidgets.widgets; |
|||
|
|||
namespace Unity.UIWidgets.cupertino { |
|||
public class CupertinoTabScaffold : StatefulWidget { |
|||
public CupertinoTabScaffold( |
|||
Key key = null, |
|||
CupertinoTabBar tabBar = null, |
|||
IndexedWidgetBuilder tabBuilder = null, |
|||
Color backgroundColor = null, |
|||
bool resizeToAvoidBottomInset = true |
|||
) : base(key: key) { |
|||
D.assert(tabBar != null); |
|||
D.assert(tabBuilder != null); |
|||
this.tabBar = tabBar; |
|||
this.tabBuilder = tabBuilder; |
|||
this.backgroundColor = backgroundColor; |
|||
this.resizeToAvoidBottomInset = resizeToAvoidBottomInset; |
|||
} |
|||
|
|||
|
|||
public readonly CupertinoTabBar tabBar; |
|||
|
|||
public readonly IndexedWidgetBuilder tabBuilder; |
|||
|
|||
public readonly Color backgroundColor; |
|||
|
|||
public readonly bool resizeToAvoidBottomInset; |
|||
|
|||
public override State createState() { |
|||
return new _CupertinoTabScaffoldState(); |
|||
} |
|||
} |
|||
|
|||
class _CupertinoTabScaffoldState : State<CupertinoTabScaffold> { |
|||
int _currentPage; |
|||
|
|||
public override void initState() { |
|||
base.initState(); |
|||
_currentPage = widget.tabBar.currentIndex; |
|||
|
|||
} |
|||
|
|||
public override void didUpdateWidget(StatefulWidget _oldWidget) { |
|||
CupertinoTabScaffold oldWidget = _oldWidget as CupertinoTabScaffold; |
|||
base.didUpdateWidget(oldWidget); |
|||
if (_currentPage >= widget.tabBar.items.Count) { |
|||
_currentPage = widget.tabBar.items.Count - 1; |
|||
D.assert(_currentPage >= 0, |
|||
() => "CupertinoTabBar is expected to keep at least 2 tabs after updating" |
|||
); |
|||
} |
|||
|
|||
if (widget.tabBar.currentIndex != oldWidget.tabBar.currentIndex) { |
|||
_currentPage = widget.tabBar.currentIndex; |
|||
} |
|||
} |
|||
|
|||
public override Widget build(BuildContext context) { |
|||
List<Widget> stacked = new List<Widget> { }; |
|||
|
|||
MediaQueryData existingMediaQuery = MediaQuery.of(context); |
|||
MediaQueryData newMediaQuery = MediaQuery.of(context); |
|||
|
|||
Widget content = new _TabSwitchingView( |
|||
currentTabIndex: _currentPage, |
|||
tabNumber: widget.tabBar.items.Count, |
|||
tabBuilder: widget.tabBuilder |
|||
); |
|||
EdgeInsets contentPadding = EdgeInsets.zero; |
|||
|
|||
if (widget.resizeToAvoidBottomInset) { |
|||
newMediaQuery = newMediaQuery.removeViewInsets(removeBottom: true); |
|||
contentPadding = EdgeInsets.only(bottom: existingMediaQuery.viewInsets.bottom); |
|||
} |
|||
|
|||
if (widget.tabBar != null && |
|||
(!widget.resizeToAvoidBottomInset || |
|||
widget.tabBar.preferredSize.height > existingMediaQuery.viewInsets.bottom)) { |
|||
float bottomPadding = widget.tabBar.preferredSize.height + existingMediaQuery.padding.bottom; |
|||
|
|||
if (widget.tabBar.opaque(context)) { |
|||
contentPadding = EdgeInsets.only(bottom: bottomPadding); |
|||
} |
|||
else { |
|||
newMediaQuery = newMediaQuery.copyWith( |
|||
padding: newMediaQuery.padding.copyWith( |
|||
bottom: bottomPadding |
|||
) |
|||
); |
|||
} |
|||
} |
|||
|
|||
content = new MediaQuery( |
|||
data: newMediaQuery, |
|||
child: new Padding( |
|||
padding: contentPadding, |
|||
child: content |
|||
) |
|||
); |
|||
|
|||
stacked.Add(content); |
|||
|
|||
if (widget.tabBar != null) { |
|||
stacked.Add(new Align( |
|||
alignment: Alignment.bottomCenter, |
|||
child: widget.tabBar.copyWith( |
|||
currentIndex: _currentPage, |
|||
onTap: (int newIndex) => { |
|||
setState(() => { _currentPage = newIndex; }); |
|||
if (widget.tabBar.onTap != null) { |
|||
widget.tabBar.onTap(newIndex); |
|||
} |
|||
} |
|||
) |
|||
)); |
|||
} |
|||
|
|||
return new DecoratedBox( |
|||
decoration: new BoxDecoration( |
|||
color: widget.backgroundColor ?? CupertinoTheme.of(context).scaffoldBackgroundColor |
|||
), |
|||
child: new Stack( |
|||
children: stacked |
|||
) |
|||
); |
|||
} |
|||
} |
|||
|
|||
class _TabSwitchingView : StatefulWidget { |
|||
public _TabSwitchingView( |
|||
int currentTabIndex, |
|||
int tabNumber, |
|||
IndexedWidgetBuilder tabBuilder |
|||
) { |
|||
D.assert(tabNumber > 0); |
|||
D.assert(tabBuilder != null); |
|||
this.currentTabIndex = currentTabIndex; |
|||
this.tabNumber = tabNumber; |
|||
this.tabBuilder = tabBuilder; |
|||
} |
|||
|
|||
public readonly int currentTabIndex; |
|||
public readonly int tabNumber; |
|||
public readonly IndexedWidgetBuilder tabBuilder; |
|||
|
|||
public override State createState() { |
|||
return new _TabSwitchingViewState(); |
|||
} |
|||
} |
|||
|
|||
class _TabSwitchingViewState : State<_TabSwitchingView> { |
|||
List<Widget> tabs; |
|||
List<FocusScopeNode> tabFocusNodes; |
|||
|
|||
public override void initState() { |
|||
base.initState(); |
|||
tabs = new List<Widget>(widget.tabNumber); |
|||
for (int i = 0; i < widget.tabNumber; i++) { |
|||
tabs.Add(null); |
|||
} |
|||
tabFocusNodes = Enumerable.Repeat(new FocusScopeNode(), widget.tabNumber).ToList(); |
|||
} |
|||
|
|||
public override void didChangeDependencies() { |
|||
base.didChangeDependencies(); |
|||
_focusActiveTab(); |
|||
} |
|||
|
|||
public override void didUpdateWidget(StatefulWidget _oldWidget) { |
|||
_TabSwitchingView oldWidget = _oldWidget as _TabSwitchingView; |
|||
base.didUpdateWidget(oldWidget); |
|||
_focusActiveTab(); |
|||
} |
|||
|
|||
void _focusActiveTab() { |
|||
FocusScope.of(context).setFirstFocus(tabFocusNodes[widget.currentTabIndex]); |
|||
} |
|||
|
|||
public override void dispose() { |
|||
foreach (FocusScopeNode focusScopeNode in tabFocusNodes) { |
|||
focusScopeNode.detach(); |
|||
} |
|||
|
|||
base.dispose(); |
|||
} |
|||
|
|||
public override Widget build(BuildContext context) { |
|||
List<Widget> children = new List<Widget>(); |
|||
for (int index = 0; index < widget.tabNumber; index++) { |
|||
bool active = index == widget.currentTabIndex; |
|||
|
|||
var tabIndex = index; |
|||
if (active || tabs[index] != null) { |
|||
tabs[index] = widget.tabBuilder(context, tabIndex); |
|||
} |
|||
|
|||
children.Add(new Offstage( |
|||
offstage: !active, |
|||
child: new TickerMode( |
|||
enabled: active, |
|||
child: new FocusScope( |
|||
node: tabFocusNodes[index], |
|||
child: tabs[index] ?? new Container() |
|||
) |
|||
) |
|||
)); |
|||
} |
|||
|
|||
return new Stack( |
|||
fit: StackFit.expand, |
|||
children: children |
|||
); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 2cd55505780bfb04d86fe98f2c80b359 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections.Generic; |
|||
using Unity.UIWidgets.foundation; |
|||
using Unity.UIWidgets.widgets; |
|||
|
|||
namespace Unity.UIWidgets.cupertino { |
|||
public class CupertinoTabView : StatefulWidget { |
|||
public CupertinoTabView( |
|||
Key key = null, |
|||
WidgetBuilder builder = null, |
|||
GlobalKey<NavigatorState> navigatorKey = null, |
|||
string defaultTitle = null, |
|||
Dictionary<string, WidgetBuilder> routes = null, |
|||
RouteFactory onGenerateRoute = null, |
|||
RouteFactory onUnknownRoute = null, |
|||
List<NavigatorObserver> navigatorObservers = null |
|||
) : base(key: key) { |
|||
this.builder = builder; |
|||
this.navigatorKey = navigatorKey; |
|||
this.defaultTitle = defaultTitle; |
|||
this.routes = routes; |
|||
this.onGenerateRoute = onGenerateRoute; |
|||
this.onUnknownRoute = onUnknownRoute; |
|||
this.navigatorObservers = navigatorObservers ?? new List<NavigatorObserver>(); |
|||
} |
|||
|
|||
public readonly WidgetBuilder builder; |
|||
|
|||
public readonly GlobalKey<NavigatorState> navigatorKey; |
|||
|
|||
public readonly string defaultTitle; |
|||
|
|||
public readonly Dictionary<string, WidgetBuilder> routes; |
|||
|
|||
public readonly RouteFactory onGenerateRoute; |
|||
|
|||
public readonly RouteFactory onUnknownRoute; |
|||
|
|||
public readonly List<NavigatorObserver> navigatorObservers; |
|||
|
|||
public override State createState() { |
|||
return new _CupertinoTabViewState(); |
|||
} |
|||
} |
|||
|
|||
class _CupertinoTabViewState : State<CupertinoTabView> { |
|||
HeroController _heroController; |
|||
List<NavigatorObserver> _navigatorObservers; |
|||
|
|||
public override void initState() { |
|||
base.initState(); |
|||
_heroController = CupertinoApp.createCupertinoHeroController(); |
|||
_updateObservers(); |
|||
} |
|||
|
|||
public override void didUpdateWidget(StatefulWidget oldWidget) { |
|||
base.didUpdateWidget(oldWidget); |
|||
CupertinoTabView _oldWidget = (CupertinoTabView) oldWidget; |
|||
if (widget.navigatorKey != _oldWidget.navigatorKey |
|||
|| widget.navigatorObservers != _oldWidget.navigatorObservers) { |
|||
_updateObservers(); |
|||
} |
|||
} |
|||
|
|||
void _updateObservers() { |
|||
_navigatorObservers = |
|||
new List<NavigatorObserver>(widget.navigatorObservers); |
|||
_navigatorObservers.Add(_heroController); |
|||
} |
|||
|
|||
public override Widget build(BuildContext context) { |
|||
return new Navigator( |
|||
key: widget.navigatorKey, |
|||
onGenerateRoute: _onGenerateRoute, |
|||
onUnknownRoute: _onUnknownRoute, |
|||
observers: _navigatorObservers |
|||
); |
|||
} |
|||
|
|||
Route _onGenerateRoute(RouteSettings settings) { |
|||
string name = settings.name; |
|||
WidgetBuilder routeBuilder = null; |
|||
string title = null; |
|||
if (name == Navigator.defaultRouteName && widget.builder != null) { |
|||
routeBuilder = widget.builder; |
|||
title = widget.defaultTitle; |
|||
} |
|||
else if (widget.routes != null) { |
|||
routeBuilder = widget.routes[name]; |
|||
} |
|||
|
|||
if (routeBuilder != null) { |
|||
return new CupertinoPageRoute( |
|||
builder: routeBuilder, |
|||
title: title, |
|||
settings: settings |
|||
); |
|||
} |
|||
|
|||
if (widget.onGenerateRoute != null) { |
|||
return widget.onGenerateRoute(settings); |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
|
|||
Route _onUnknownRoute(RouteSettings settings) { |
|||
D.assert(() => { |
|||
if (widget.onUnknownRoute == null) { |
|||
throw new UIWidgetsError( |
|||
$"Could not find a generator for route {settings} in the {GetType()}.\n" + |
|||
"Generators for routes are searched for in the following order:\n" + |
|||
" 1. For the \"/\" route, the \"builder\" property, if non-null, is used.\n" + |
|||
" 2. Otherwise, the \"routes\" table is used, if it has an entry for " + |
|||
"the route.\n" + |
|||
" 3. Otherwise, onGenerateRoute is called. It should return a " + |
|||
"non-null value for any valid route not handled by \"builder\" and \"routes\".\n" + |
|||
" 4. Finally if all else fails onUnknownRoute is called.\n" + |
|||
"Unfortunately, onUnknownRoute was not set." |
|||
); |
|||
} |
|||
|
|||
return true; |
|||
}); |
|||
|
|||
Route result = widget.onUnknownRoute(settings); |
|||
D.assert(() => { |
|||
if (result == null) { |
|||
throw new UIWidgetsError( |
|||
"The onUnknownRoute callback returned null.\n" + |
|||
$"When the {GetType()} requested the route {settings} from its " + |
|||
"onUnknownRoute callback, the callback returned null. Such callbacks " + |
|||
"must never return null." |
|||
); |
|||
} |
|||
|
|||
return true; |
|||
}); |
|||
return result; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: b95af00e8d4e2be499f76f5448914453 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections.Generic; |
|||
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 StrutStyle = Unity.UIWidgets.painting.StrutStyle; |
|||
using TextStyle = Unity.UIWidgets.painting.TextStyle; |
|||
|
|||
namespace Unity.UIWidgets.cupertino { |
|||
class CupertinoTextFieldUtils { |
|||
public static readonly BorderSide _kDefaultRoundedBorderSide = new BorderSide( |
|||
color: CupertinoColors.lightBackgroundGray, |
|||
style: BorderStyle.solid, |
|||
width: 0.0f |
|||
); |
|||
|
|||
public static readonly Border _kDefaultRoundedBorder = new Border( |
|||
top: _kDefaultRoundedBorderSide, |
|||
bottom: _kDefaultRoundedBorderSide, |
|||
left: _kDefaultRoundedBorderSide, |
|||
right: _kDefaultRoundedBorderSide |
|||
); |
|||
|
|||
public static readonly BoxDecoration _kDefaultRoundedBorderDecoration = new BoxDecoration( |
|||
border: _kDefaultRoundedBorder, |
|||
borderRadius: BorderRadius.all(Radius.circular(4.0f)) |
|||
); |
|||
|
|||
public static readonly Color _kSelectionHighlightColor = new Color(0x667FAACF); |
|||
|
|||
public static readonly Color _kInactiveTextColor = new Color(0xFFC2C2C2); |
|||
|
|||
public static readonly Color _kDisabledBackground = new Color(0xFFFAFAFA); |
|||
|
|||
public const int _iOSHorizontalCursorOffsetPixels = -2; |
|||
} |
|||
|
|||
public enum OverlayVisibilityMode { |
|||
never, |
|||
editing, |
|||
notEditing, |
|||
always |
|||
} |
|||
|
|||
public class CupertinoTextField : StatefulWidget { |
|||
public CupertinoTextField( |
|||
Key key = null, |
|||
TextEditingController controller = null, |
|||
FocusNode focusNode = null, |
|||
BoxDecoration decoration = null, |
|||
EdgeInsets padding = null, |
|||
string placeholder = null, |
|||
TextStyle placeholderStyle = null, |
|||
Widget prefix = null, |
|||
OverlayVisibilityMode prefixMode = OverlayVisibilityMode.always, |
|||
Widget suffix = null, |
|||
OverlayVisibilityMode suffixMode = OverlayVisibilityMode.always, |
|||
OverlayVisibilityMode clearButtonMode = OverlayVisibilityMode.never, |
|||
TextInputType keyboardType = null, |
|||
TextInputAction? textInputAction = null, |
|||
TextCapitalization textCapitalization = TextCapitalization.none, |
|||
TextStyle style = null, |
|||
StrutStyle strutStyle = null, |
|||
TextAlign textAlign = TextAlign.left, |
|||
bool autofocus = false, |
|||
bool obscureText = false, |
|||
bool autocorrect = true, |
|||
int? maxLines = 1, |
|||
int? minLines = null, |
|||
bool expands = false, |
|||
int? maxLength = null, |
|||
bool maxLengthEnforced = true, |
|||
ValueChanged<string> onChanged = null, |
|||
VoidCallback onEditingComplete = null, |
|||
ValueChanged<string> onSubmitted = null, |
|||
List<TextInputFormatter> inputFormatters = null, |
|||
bool? enabled = null, |
|||
float cursorWidth = 2.0f, |
|||
Radius cursorRadius = null, |
|||
Color cursorColor = null, |
|||
ui.Brightness? keyboardAppearance = null, |
|||
EdgeInsets scrollPadding = null, |
|||
DragStartBehavior dragStartBehavior = DragStartBehavior.start, |
|||
ScrollPhysics scrollPhysics = 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"); |
|||
D.assert(!expands || (maxLines == null && minLines == null), |
|||
() => "minLines and maxLines must be null when expands is true."); |
|||
D.assert(maxLength == null || maxLength > 0); |
|||
|
|||
this.controller = controller; |
|||
this.focusNode = focusNode; |
|||
this.decoration = decoration ?? CupertinoTextFieldUtils._kDefaultRoundedBorderDecoration; |
|||
this.padding = padding ?? EdgeInsets.all(6.0f); |
|||
this.placeholder = placeholder; |
|||
this.placeholderStyle = placeholderStyle ?? new TextStyle( |
|||
fontWeight: FontWeight.w300, |
|||
color: CupertinoTextFieldUtils._kInactiveTextColor |
|||
); |
|||
this.prefix = prefix; |
|||
this.prefixMode = prefixMode; |
|||
this.suffix = suffix; |
|||
this.suffixMode = suffixMode; |
|||
this.clearButtonMode = clearButtonMode; |
|||
this.textInputAction = textInputAction; |
|||
this.textCapitalization = textCapitalization; |
|||
this.style = style; |
|||
this.strutStyle = strutStyle; |
|||
this.textAlign = textAlign; |
|||
this.autofocus = autofocus; |
|||
this.obscureText = obscureText; |
|||
this.autocorrect = autocorrect; |
|||
this.maxLines = maxLines; |
|||
this.minLines = minLines; |
|||
this.expands = expands; |
|||
this.maxLength = maxLength; |
|||
this.maxLengthEnforced = maxLengthEnforced; |
|||
this.onChanged = onChanged; |
|||
this.onEditingComplete = onEditingComplete; |
|||
this.onSubmitted = onSubmitted; |
|||
this.inputFormatters = inputFormatters; |
|||
this.enabled = enabled; |
|||
this.cursorWidth = cursorWidth; |
|||
this.cursorRadius = cursorRadius ?? Radius.circular(2.0f); |
|||
this.cursorColor = cursorColor; |
|||
this.keyboardAppearance = keyboardAppearance; |
|||
this.scrollPadding = scrollPadding ?? EdgeInsets.all(20.0f); |
|||
this.dragStartBehavior = dragStartBehavior; |
|||
this.scrollPhysics = scrollPhysics; |
|||
this.keyboardType = keyboardType ?? (maxLines == 1 ? TextInputType.text : TextInputType.multiline); |
|||
} |
|||
|
|||
public readonly TextEditingController controller; |
|||
|
|||
public readonly FocusNode focusNode; |
|||
|
|||
public readonly BoxDecoration decoration; |
|||
|
|||
public readonly EdgeInsets padding; |
|||
|
|||
public readonly string placeholder; |
|||
|
|||
public readonly TextStyle placeholderStyle; |
|||
|
|||
public readonly Widget prefix; |
|||
|
|||
public readonly OverlayVisibilityMode prefixMode; |
|||
|
|||
public readonly Widget suffix; |
|||
|
|||
public readonly OverlayVisibilityMode suffixMode; |
|||
|
|||
public readonly OverlayVisibilityMode clearButtonMode; |
|||
|
|||
public readonly TextInputType keyboardType; |
|||
|
|||
public readonly TextInputAction? textInputAction; |
|||
|
|||
public readonly TextCapitalization textCapitalization; |
|||
|
|||
public readonly TextStyle style; |
|||
|
|||
public readonly StrutStyle strutStyle; |
|||
|
|||
public readonly TextAlign textAlign; |
|||
|
|||
public readonly bool autofocus; |
|||
|
|||
public readonly bool obscureText; |
|||
|
|||
public readonly bool autocorrect; |
|||
|
|||
public readonly int? maxLines; |
|||
|
|||
public readonly int? minLines; |
|||
|
|||
public readonly bool expands; |
|||
|
|||
public readonly int? maxLength; |
|||
|
|||
public readonly bool maxLengthEnforced; |
|||
|
|||
public readonly ValueChanged<string> onChanged; |
|||
|
|||
public readonly VoidCallback onEditingComplete; |
|||
|
|||
public readonly ValueChanged<string> onSubmitted; |
|||
|
|||
public readonly List<TextInputFormatter> inputFormatters; |
|||
|
|||
public readonly bool? enabled; |
|||
|
|||
public readonly float cursorWidth; |
|||
|
|||
public readonly Radius cursorRadius; |
|||
|
|||
public readonly Color cursorColor; |
|||
|
|||
public readonly ui.Brightness? keyboardAppearance; |
|||
|
|||
public readonly EdgeInsets scrollPadding; |
|||
|
|||
public readonly DragStartBehavior dragStartBehavior; |
|||
|
|||
public readonly ScrollPhysics scrollPhysics; |
|||
|
|||
public override State createState() { |
|||
return new _CupertinoTextFieldState(); |
|||
} |
|||
|
|||
public override void debugFillProperties(DiagnosticPropertiesBuilder properties) { |
|||
base.debugFillProperties(properties); |
|||
|
|||
properties.add( |
|||
new DiagnosticsProperty<TextEditingController>("controller", controller, defaultValue: null)); |
|||
properties.add(new DiagnosticsProperty<FocusNode>("focusNode", focusNode, defaultValue: null)); |
|||
properties.add(new DiagnosticsProperty<BoxDecoration>("decoration", decoration)); |
|||
properties.add(new DiagnosticsProperty<EdgeInsets>("padding", padding)); |
|||
properties.add(new StringProperty("placeholder", placeholder)); |
|||
properties.add(new DiagnosticsProperty<TextStyle>("placeholderStyle", placeholderStyle)); |
|||
properties.add(new DiagnosticsProperty<OverlayVisibilityMode>("prefix", |
|||
prefix == null ? OverlayVisibilityMode.never : prefixMode)); |
|||
properties.add(new DiagnosticsProperty<OverlayVisibilityMode>("suffix", |
|||
suffix == null ? OverlayVisibilityMode.never : suffixMode)); |
|||
properties.add(new DiagnosticsProperty<OverlayVisibilityMode>("clearButtonMode", clearButtonMode)); |
|||
properties.add(new DiagnosticsProperty<TextInputType>("keyboardType", keyboardType, |
|||
defaultValue: TextInputType.text)); |
|||
properties.add(new DiagnosticsProperty<TextStyle>("style", style, defaultValue: null)); |
|||
properties.add(new DiagnosticsProperty<bool>("autofocus", autofocus, defaultValue: false)); |
|||
properties.add(new DiagnosticsProperty<bool>("obscureText", obscureText, defaultValue: false)); |
|||
properties.add(new DiagnosticsProperty<bool>("autocorrect", autocorrect, defaultValue: false)); |
|||
properties.add(new IntProperty("maxLines", maxLines, defaultValue: 1)); |
|||
properties.add(new IntProperty("minLines", minLines, defaultValue: null)); |
|||
properties.add(new DiagnosticsProperty<bool>("expands", expands, defaultValue: false)); |
|||
properties.add(new IntProperty("maxLength", maxLength, defaultValue: null)); |
|||
properties.add(new FlagProperty("maxLengthEnforced", value: maxLengthEnforced, |
|||
ifTrue: "max length enforced")); |
|||
properties.add(new DiagnosticsProperty<Color>("cursorColor", cursorColor, defaultValue: null)); |
|||
properties.add( |
|||
new DiagnosticsProperty<ScrollPhysics>("scrollPhysics", scrollPhysics, defaultValue: null)); |
|||
} |
|||
} |
|||
|
|||
class _CupertinoTextFieldState : AutomaticKeepAliveClientMixin<CupertinoTextField> { |
|||
GlobalKey<EditableTextState> _editableTextKey = GlobalKey<EditableTextState>.key(); |
|||
|
|||
TextEditingController _controller; |
|||
|
|||
TextEditingController _effectiveController { |
|||
get { return widget.controller ?? _controller; } |
|||
} |
|||
|
|||
FocusNode _focusNode; |
|||
|
|||
FocusNode _effectiveFocusNode { |
|||
get { return widget.focusNode ?? _focusNode ?? (_focusNode = new FocusNode()); } |
|||
} |
|||
|
|||
public override void initState() { |
|||
base.initState(); |
|||
if (widget.controller == null) { |
|||
_controller = new TextEditingController(); |
|||
_controller.addListener(updateKeepAlive); |
|||
} |
|||
} |
|||
|
|||
public override void didUpdateWidget(StatefulWidget oldWidget) { |
|||
base.didUpdateWidget(oldWidget); |
|||
CupertinoTextField _oldWidget = (CupertinoTextField) oldWidget; |
|||
|
|||
if (widget.controller == null && _oldWidget.controller != null) { |
|||
_controller = TextEditingController.fromValue(_oldWidget.controller.value); |
|||
_controller.addListener(updateKeepAlive); |
|||
} |
|||
else if (widget.controller != null && _oldWidget.controller == null) { |
|||
_controller = null; |
|||
} |
|||
|
|||
bool isEnabled = widget.enabled ?? true; |
|||
bool wasEnabled = _oldWidget.enabled ?? true; |
|||
|
|||
if (wasEnabled && !isEnabled) { |
|||
_effectiveFocusNode.unfocus(); |
|||
} |
|||
} |
|||
|
|||
public override void dispose() { |
|||
_focusNode?.dispose(); |
|||
_controller?.removeListener(updateKeepAlive); |
|||
base.dispose(); |
|||
} |
|||
|
|||
void _requestKeyboard() { |
|||
_editableTextKey.currentState?.requestKeyboard(); |
|||
} |
|||
|
|||
RenderEditable _renderEditable { |
|||
get { return _editableTextKey.currentState.renderEditable; } |
|||
} |
|||
|
|||
void _handleTapDown(TapDownDetails details) { |
|||
_renderEditable.handleTapDown(details); |
|||
} |
|||
|
|||
|
|||
void _handleSingleTapUp(TapUpDetails details) { |
|||
_renderEditable.selectWordEdge(cause: SelectionChangedCause.tap); |
|||
_requestKeyboard(); |
|||
} |
|||
|
|||
void _handleSingleLongTapStart(LongPressStartDetails details) { |
|||
_renderEditable.selectPositionAt( |
|||
from: details.globalPosition, |
|||
cause: SelectionChangedCause.longPress |
|||
); |
|||
} |
|||
|
|||
void _handleSingleLongTapMoveUpdate(LongPressMoveUpdateDetails details) { |
|||
_renderEditable.selectPositionAt( |
|||
from: details.globalPosition, |
|||
cause: SelectionChangedCause.longPress |
|||
); |
|||
} |
|||
|
|||
void _handleSingleLongTapEnd(LongPressEndDetails details) { |
|||
_editableTextKey.currentState.showToolbar(); |
|||
} |
|||
|
|||
void _handleDoubleTapDown(TapDownDetails details) { |
|||
_renderEditable.selectWord(cause: SelectionChangedCause.tap); |
|||
_editableTextKey.currentState.showToolbar(); |
|||
} |
|||
|
|||
void _handleMouseDragSelectionStart(DragStartDetails details) { |
|||
_renderEditable.selectPositionAt( |
|||
from: details.globalPosition, |
|||
cause: SelectionChangedCause.drag |
|||
); |
|||
} |
|||
|
|||
void _handleMouseDragSelectionUpdate( |
|||
DragStartDetails startDetails, |
|||
DragUpdateDetails updateDetails |
|||
) { |
|||
_renderEditable.selectPositionAt( |
|||
from: startDetails.globalPosition, |
|||
to: updateDetails.globalPosition, |
|||
cause: SelectionChangedCause.drag |
|||
); |
|||
} |
|||
|
|||
void _handleMouseDragSelectionEnd(DragEndDetails details) { |
|||
_requestKeyboard(); |
|||
} |
|||
|
|||
void _handleSelectionChanged(TextSelection selection, SelectionChangedCause cause) { |
|||
if (cause == SelectionChangedCause.longPress) { |
|||
_editableTextKey.currentState?.bringIntoView(selection.basePos); |
|||
} |
|||
} |
|||
|
|||
protected override bool wantKeepAlive { |
|||
get { return _controller?.text?.isNotEmpty() == true; } |
|||
} |
|||
|
|||
bool _shouldShowAttachment( |
|||
OverlayVisibilityMode attachment, |
|||
bool hasText |
|||
) { |
|||
switch (attachment) { |
|||
case OverlayVisibilityMode.never: |
|||
return false; |
|||
case OverlayVisibilityMode.always: |
|||
return true; |
|||
case OverlayVisibilityMode.editing: |
|||
return hasText; |
|||
case OverlayVisibilityMode.notEditing: |
|||
return !hasText; |
|||
} |
|||
|
|||
D.assert(false); |
|||
return false; |
|||
} |
|||
|
|||
bool _showPrefixWidget(TextEditingValue text) { |
|||
return widget.prefix != null && _shouldShowAttachment( |
|||
attachment: widget.prefixMode, |
|||
hasText: text.text.isNotEmpty() |
|||
); |
|||
} |
|||
|
|||
bool _showSuffixWidget(TextEditingValue text) { |
|||
return widget.suffix != null && _shouldShowAttachment( |
|||
attachment: widget.suffixMode, |
|||
hasText: text.text.isNotEmpty() |
|||
); |
|||
} |
|||
|
|||
bool _showClearButton(TextEditingValue text) { |
|||
return _shouldShowAttachment( |
|||
attachment: widget.clearButtonMode, |
|||
hasText: text.text.isNotEmpty() |
|||
); |
|||
} |
|||
|
|||
Widget _addTextDependentAttachments(Widget editableText, TextStyle textStyle, TextStyle placeholderStyle) { |
|||
D.assert(editableText != null); |
|||
D.assert(textStyle != null); |
|||
D.assert(placeholderStyle != null); |
|||
|
|||
if (widget.placeholder == null && |
|||
widget.clearButtonMode == OverlayVisibilityMode.never && |
|||
widget.prefix == null && |
|||
widget.suffix == null) { |
|||
return editableText; |
|||
} |
|||
|
|||
return new ValueListenableBuilder<TextEditingValue>( |
|||
valueListenable: _effectiveController, |
|||
child: editableText, |
|||
builder: (BuildContext context, TextEditingValue text, Widget child) => { |
|||
List<Widget> rowChildren = new List<Widget>(); |
|||
|
|||
if (_showPrefixWidget(text)) { |
|||
rowChildren.Add(widget.prefix); |
|||
} |
|||
|
|||
List<Widget> stackChildren = new List<Widget>(); |
|||
if (widget.placeholder != null && text.text.isEmpty()) { |
|||
stackChildren.Add( |
|||
new Padding( |
|||
padding: widget.padding, |
|||
child: new Text( |
|||
widget.placeholder, |
|||
maxLines: 1, |
|||
overflow: TextOverflow.ellipsis, |
|||
style: placeholderStyle |
|||
) |
|||
) |
|||
); |
|||
} |
|||
|
|||
stackChildren.Add(child); |
|||
rowChildren.Add( |
|||
new Expanded |
|||
(child: new Stack |
|||
(children: stackChildren))); |
|||
|
|||
if (_showSuffixWidget(text)) { |
|||
rowChildren.Add(widget.suffix); |
|||
} |
|||
else if (_showClearButton(text)) { |
|||
rowChildren.Add( |
|||
new GestureDetector( |
|||
onTap: widget.enabled ?? true |
|||
? () => { |
|||
bool textChanged = _effectiveController.text.isNotEmpty(); |
|||
_effectiveController.clear(); |
|||
if (widget.onChanged != null && textChanged) { |
|||
widget.onChanged(_effectiveController.text); |
|||
} |
|||
} |
|||
: (GestureTapCallback) null, |
|||
child: new Padding( |
|||
padding: EdgeInsets.symmetric(horizontal: 6.0f), |
|||
child: new Icon( |
|||
CupertinoIcons.clear_thick_circled, |
|||
size: 18.0f, |
|||
color: CupertinoTextFieldUtils._kInactiveTextColor |
|||
) |
|||
) |
|||
) |
|||
); |
|||
} |
|||
|
|||
return new Row(children: rowChildren); |
|||
} |
|||
); |
|||
} |
|||
|
|||
public override Widget build(BuildContext context) { |
|||
base.build(context); |
|||
TextEditingController controller = _effectiveController; |
|||
List<TextInputFormatter> formatters = widget.inputFormatters ?? new List<TextInputFormatter>(); |
|||
bool enabled = widget.enabled ?? true; |
|||
Offset cursorOffset = |
|||
new Offset( |
|||
CupertinoTextFieldUtils._iOSHorizontalCursorOffsetPixels / MediaQuery.of(context).devicePixelRatio, |
|||
0); |
|||
if (widget.maxLength != null && widget.maxLengthEnforced) { |
|||
formatters.Add(new LengthLimitingTextInputFormatter(widget.maxLength)); |
|||
} |
|||
|
|||
CupertinoThemeData themeData = CupertinoTheme.of(context); |
|||
TextStyle textStyle = themeData.textTheme.textStyle.merge(widget.style); |
|||
TextStyle placeholderStyle = textStyle.merge(widget.placeholderStyle); |
|||
ui.Brightness keyboardAppearance = widget.keyboardAppearance ?? themeData.brightness; |
|||
Color cursorColor = widget.cursorColor ?? themeData.primaryColor; |
|||
|
|||
Widget paddedEditable = new Padding( |
|||
padding: widget.padding, |
|||
child: new RepaintBoundary( |
|||
child: new EditableText( |
|||
key: _editableTextKey, |
|||
controller: controller, |
|||
focusNode: _effectiveFocusNode, |
|||
keyboardType: widget.keyboardType, |
|||
textInputAction: widget.textInputAction, |
|||
textCapitalization: widget.textCapitalization, |
|||
style: textStyle, |
|||
strutStyle: widget.strutStyle, |
|||
textAlign: widget.textAlign, |
|||
autofocus: widget.autofocus, |
|||
obscureText: widget.obscureText, |
|||
autocorrect: widget.autocorrect, |
|||
maxLines: widget.maxLines, |
|||
minLines: widget.minLines, |
|||
expands: widget.expands, |
|||
selectionColor: CupertinoTextFieldUtils._kSelectionHighlightColor, |
|||
selectionControls: CupertinoTextSelectionUtils.cupertinoTextSelectionControls, |
|||
onChanged: widget.onChanged, |
|||
onSelectionChanged: _handleSelectionChanged, |
|||
onEditingComplete: widget.onEditingComplete, |
|||
onSubmitted: widget.onSubmitted, |
|||
inputFormatters: formatters, |
|||
rendererIgnoresPointer: true, |
|||
cursorWidth: widget.cursorWidth, |
|||
cursorRadius: widget.cursorRadius, |
|||
cursorColor: cursorColor, |
|||
cursorOpacityAnimates: true, |
|||
cursorOffset: cursorOffset, |
|||
paintCursorAboveText: true, |
|||
backgroundCursorColor: CupertinoColors.inactiveGray, |
|||
scrollPadding: widget.scrollPadding, |
|||
keyboardAppearance: keyboardAppearance, |
|||
dragStartBehavior: widget.dragStartBehavior, |
|||
scrollPhysics: widget.scrollPhysics |
|||
) |
|||
) |
|||
); |
|||
|
|||
return new IgnorePointer( |
|||
ignoring: !enabled, |
|||
child: new Container( |
|||
decoration: widget.decoration, |
|||
child: new Container( |
|||
color: enabled |
|||
? null |
|||
: CupertinoTheme.of(context).brightness == ui.Brightness.light |
|||
? CupertinoTextFieldUtils._kDisabledBackground |
|||
: CupertinoColors.darkBackgroundGray, |
|||
child: new TextSelectionGestureDetector( |
|||
onTapDown: _handleTapDown, |
|||
onSingleTapUp: _handleSingleTapUp, |
|||
onSingleLongTapStart: _handleSingleLongTapStart, |
|||
onSingleLongTapMoveUpdate: _handleSingleLongTapMoveUpdate, |
|||
onSingleLongTapEnd: _handleSingleLongTapEnd, |
|||
onDoubleTapDown: _handleDoubleTapDown, |
|||
onDragSelectionStart: _handleMouseDragSelectionStart, |
|||
onDragSelectionUpdate: _handleMouseDragSelectionUpdate, |
|||
onDragSelectionEnd: _handleMouseDragSelectionEnd, |
|||
behavior: HitTestBehavior.translucent, |
|||
child: _addTextDependentAttachments(paddedEditable, textStyle, placeholderStyle) |
|||
) |
|||
) |
|||
) |
|||
); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 7d2dd8bd369e9e044a2480212136f639 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections.Generic; |
|||
using Unity.UIWidgets.foundation; |
|||
using Unity.UIWidgets.painting; |
|||
using Unity.UIWidgets.rendering; |
|||
using Unity.UIWidgets.service; |
|||
using Unity.UIWidgets.ui; |
|||
using Unity.UIWidgets.widgets; |
|||
using UnityEngine; |
|||
using Canvas = Unity.UIWidgets.ui.Canvas; |
|||
using Color = Unity.UIWidgets.ui.Color; |
|||
using Rect = Unity.UIWidgets.ui.Rect; |
|||
using TextStyle = Unity.UIWidgets.painting.TextStyle; |
|||
using Transform = Unity.UIWidgets.widgets.Transform; |
|||
|
|||
namespace Unity.UIWidgets.cupertino { |
|||
public static class CupertinoTextSelectionUtils { |
|||
public static readonly TextSelectionControls cupertinoTextSelectionControls = new _CupertinoTextSelectionControls(); |
|||
|
|||
public const float _kHandlesPadding = 18.0f; |
|||
|
|||
public const float _kToolbarScreenPadding = 8.0f; |
|||
|
|||
public const float _kToolbarHeight = 36.0f; |
|||
|
|||
public static readonly Color _kToolbarBackgroundColor = new Color(0xFF2E2E2E); |
|||
|
|||
public static readonly Color _kToolbarDividerColor = new Color(0xFFB9B9B9); |
|||
|
|||
public static readonly Color _kHandlesColor = new Color(0xFF136FE0); |
|||
|
|||
public static readonly Size _kSelectionOffset = new Size(20.0f, 30.0f); |
|||
|
|||
public static readonly Size _kToolbarTriangleSize = new Size(18.0f, 9.0f); |
|||
|
|||
public static readonly EdgeInsets _kToolbarButtonPadding = |
|||
EdgeInsets.symmetric(vertical: 10.0f, horizontal: 18.0f); |
|||
|
|||
public static readonly BorderRadius _kToolbarBorderRadius = BorderRadius.all(Radius.circular(7.5f)); |
|||
|
|||
public static readonly TextStyle _kToolbarButtonFontStyle = new TextStyle( |
|||
fontSize: 14.0f, |
|||
letterSpacing: -0.11f, |
|||
fontWeight: FontWeight.w300, |
|||
color: CupertinoColors.white |
|||
); |
|||
} |
|||
|
|||
class _TextSelectionToolbarNotchPainter : AbstractCustomPainter { |
|||
public override void paint(Canvas canvas, Size size) { |
|||
Paint paint = new Paint(); |
|||
paint.color = CupertinoTextSelectionUtils._kToolbarBackgroundColor; |
|||
paint.style = PaintingStyle.fill; |
|||
|
|||
Path triangle = new Path(); |
|||
triangle.lineTo(CupertinoTextSelectionUtils._kToolbarTriangleSize.width / 2, 0.0f); |
|||
triangle.lineTo(0.0f, CupertinoTextSelectionUtils._kToolbarTriangleSize.height); |
|||
triangle.lineTo(-(CupertinoTextSelectionUtils._kToolbarTriangleSize.width / 2), 0.0f); |
|||
triangle.close(); |
|||
canvas.drawPath(triangle, paint); |
|||
} |
|||
|
|||
public override bool shouldRepaint(CustomPainter oldPainter) { |
|||
return false; |
|||
} |
|||
} |
|||
|
|||
class _TextSelectionToolbar : StatelessWidget { |
|||
public _TextSelectionToolbar( |
|||
Key key = null, |
|||
VoidCallback handleCut = null, |
|||
VoidCallback handleCopy = null, |
|||
VoidCallback handlePaste = null, |
|||
VoidCallback handleSelectAll = null |
|||
) : base(key: key) { |
|||
this.handleCut = handleCut; |
|||
this.handleCopy = handleCopy; |
|||
this.handlePaste = handlePaste; |
|||
this.handleSelectAll = handleSelectAll; |
|||
} |
|||
|
|||
readonly VoidCallback handleCut; |
|||
|
|||
readonly VoidCallback handleCopy; |
|||
|
|||
readonly VoidCallback handlePaste; |
|||
|
|||
readonly VoidCallback handleSelectAll; |
|||
|
|||
|
|||
public override Widget build(BuildContext context) { |
|||
List<Widget> items = new List<Widget>(); |
|||
Widget onePhysicalPixelVerticalDivider = |
|||
new SizedBox(width: 1.0f / MediaQuery.of(context).devicePixelRatio); |
|||
CupertinoLocalizations localizations = CupertinoLocalizations.of(context); |
|||
|
|||
if (handleCut != null) { |
|||
items.Add(_buildToolbarButton(localizations.cutButtonLabel, handleCut)); |
|||
} |
|||
|
|||
if (handleCopy != null) { |
|||
if (items.isNotEmpty()) { |
|||
items.Add(onePhysicalPixelVerticalDivider); |
|||
} |
|||
|
|||
items.Add(_buildToolbarButton(localizations.copyButtonLabel, handleCopy)); |
|||
} |
|||
|
|||
if (handlePaste != null) { |
|||
if (items.isNotEmpty()) { |
|||
items.Add(onePhysicalPixelVerticalDivider); |
|||
} |
|||
|
|||
items.Add(_buildToolbarButton(localizations.pasteButtonLabel, handlePaste)); |
|||
} |
|||
|
|||
if (handleSelectAll != null) { |
|||
if (items.isNotEmpty()) { |
|||
items.Add(onePhysicalPixelVerticalDivider); |
|||
} |
|||
|
|||
items.Add(_buildToolbarButton(localizations.selectAllButtonLabel, handleSelectAll)); |
|||
} |
|||
|
|||
Widget triangle = SizedBox.fromSize( |
|||
size: CupertinoTextSelectionUtils._kToolbarTriangleSize, |
|||
child: new CustomPaint( |
|||
painter: new _TextSelectionToolbarNotchPainter() |
|||
) |
|||
); |
|||
|
|||
return new Column( |
|||
mainAxisSize: MainAxisSize.min, |
|||
children: new List<Widget> { |
|||
new ClipRRect( |
|||
borderRadius: CupertinoTextSelectionUtils._kToolbarBorderRadius, |
|||
child: new DecoratedBox( |
|||
decoration: new BoxDecoration( |
|||
color: CupertinoTextSelectionUtils._kToolbarDividerColor, |
|||
borderRadius: CupertinoTextSelectionUtils._kToolbarBorderRadius, |
|||
border: Border.all(color: CupertinoTextSelectionUtils._kToolbarBackgroundColor, |
|||
width: 0) |
|||
), |
|||
child: new Row(mainAxisSize: MainAxisSize.min, children: items) |
|||
) |
|||
), |
|||
triangle, |
|||
new Padding(padding: EdgeInsets.only(bottom: 10.0f)) |
|||
} |
|||
); |
|||
} |
|||
|
|||
CupertinoButton _buildToolbarButton(string text, VoidCallback onPressed) { |
|||
return new CupertinoButton( |
|||
child: new Text(text, style: CupertinoTextSelectionUtils._kToolbarButtonFontStyle), |
|||
color: CupertinoTextSelectionUtils._kToolbarBackgroundColor, |
|||
minSize: CupertinoTextSelectionUtils._kToolbarHeight, |
|||
padding: CupertinoTextSelectionUtils._kToolbarButtonPadding, |
|||
borderRadius: null, |
|||
pressedOpacity: 0.7f, |
|||
onPressed: onPressed |
|||
); |
|||
} |
|||
} |
|||
|
|||
class _TextSelectionToolbarLayout : SingleChildLayoutDelegate { |
|||
public _TextSelectionToolbarLayout( |
|||
Size screenSize, |
|||
Rect globalEditableRegion, |
|||
Offset position) { |
|||
this.screenSize = screenSize; |
|||
this.globalEditableRegion = globalEditableRegion; |
|||
this.position = position; |
|||
} |
|||
|
|||
readonly Size screenSize; |
|||
|
|||
readonly Rect globalEditableRegion; |
|||
|
|||
readonly Offset position; |
|||
|
|||
public override BoxConstraints getConstraintsForChild(BoxConstraints constraints) { |
|||
return constraints.loosen(); |
|||
} |
|||
|
|||
public override Offset getPositionForChild(Size size, Size childSize) { |
|||
Offset globalPosition = globalEditableRegion.topLeft + position; |
|||
|
|||
float x = globalPosition.dx - childSize.width / 2.0f; |
|||
float y = globalPosition.dy - childSize.height; |
|||
|
|||
if (x < CupertinoTextSelectionUtils._kToolbarScreenPadding) { |
|||
x = CupertinoTextSelectionUtils._kToolbarScreenPadding; |
|||
} |
|||
else if (x + childSize.width > screenSize.width - CupertinoTextSelectionUtils._kToolbarScreenPadding) { |
|||
x = screenSize.width - childSize.width - CupertinoTextSelectionUtils._kToolbarScreenPadding; |
|||
} |
|||
|
|||
if (y < CupertinoTextSelectionUtils._kToolbarScreenPadding) { |
|||
y = CupertinoTextSelectionUtils._kToolbarScreenPadding; |
|||
} |
|||
else if (y + childSize.height > |
|||
screenSize.height - CupertinoTextSelectionUtils._kToolbarScreenPadding) { |
|||
y = screenSize.height - childSize.height - CupertinoTextSelectionUtils._kToolbarScreenPadding; |
|||
} |
|||
|
|||
return new Offset(x, y); |
|||
} |
|||
|
|||
public override bool shouldRelayout(SingleChildLayoutDelegate oldDelegate) { |
|||
_TextSelectionToolbarLayout _oldDelegate = (_TextSelectionToolbarLayout) oldDelegate; |
|||
return screenSize != _oldDelegate.screenSize |
|||
|| globalEditableRegion != _oldDelegate.globalEditableRegion |
|||
|| position != _oldDelegate.position; |
|||
} |
|||
} |
|||
|
|||
class _TextSelectionHandlePainter : AbstractCustomPainter { |
|||
public _TextSelectionHandlePainter(Offset origin) { |
|||
this.origin = origin; |
|||
} |
|||
|
|||
readonly Offset origin; |
|||
|
|||
|
|||
public override void paint(Canvas canvas, Size size) { |
|||
Paint paint = new Paint(); |
|||
paint.color = CupertinoTextSelectionUtils._kHandlesColor; |
|||
paint.strokeWidth = 2.0f; |
|||
|
|||
canvas.drawCircle(origin.translate(0.0f, 4.0f), 5.5f, paint); |
|||
canvas.drawLine( |
|||
origin, |
|||
origin.translate( |
|||
0.0f, |
|||
-(size.height - 2.0f * CupertinoTextSelectionUtils._kHandlesPadding) |
|||
), |
|||
paint |
|||
); |
|||
} |
|||
|
|||
public override bool shouldRepaint(CustomPainter oldPainter) { |
|||
_TextSelectionHandlePainter _oldPainter = (_TextSelectionHandlePainter) oldPainter; |
|||
return origin != _oldPainter.origin; |
|||
} |
|||
} |
|||
|
|||
class _CupertinoTextSelectionControls : TextSelectionControls { |
|||
public override Size handleSize { |
|||
get { return CupertinoTextSelectionUtils._kSelectionOffset; } |
|||
} |
|||
|
|||
public override Widget buildToolbar(BuildContext context, Rect globalEditableRegion, Offset position, |
|||
TextSelectionDelegate del) { |
|||
D.assert(WidgetsD.debugCheckHasMediaQuery(context)); |
|||
return new ConstrainedBox( |
|||
constraints: BoxConstraints.tight(globalEditableRegion.size), |
|||
child: new CustomSingleChildLayout( |
|||
layoutDelegate: new _TextSelectionToolbarLayout( |
|||
MediaQuery.of(context).size, |
|||
globalEditableRegion, |
|||
position |
|||
), |
|||
child: new _TextSelectionToolbar( |
|||
handleCut: canCut(del) ? () => handleCut(del) : (VoidCallback) null, |
|||
handleCopy: canCopy(del) ? () => handleCopy(del) : (VoidCallback) null, |
|||
handlePaste: canPaste(del) ? () => handlePaste(del) : (VoidCallback) null, |
|||
handleSelectAll: canSelectAll(del) ? () => handleSelectAll(del) : (VoidCallback) null |
|||
) |
|||
) |
|||
); |
|||
} |
|||
|
|||
|
|||
public override Widget buildHandle(BuildContext context, TextSelectionHandleType type, float textLineHeight) { |
|||
Size desiredSize = new Size( |
|||
2.0f * CupertinoTextSelectionUtils._kHandlesPadding, |
|||
textLineHeight + 2.0f * CupertinoTextSelectionUtils._kHandlesPadding |
|||
); |
|||
|
|||
Widget handle = SizedBox.fromSize( |
|||
size: desiredSize, |
|||
child: new CustomPaint( |
|||
painter: new _TextSelectionHandlePainter( |
|||
origin: new Offset(CupertinoTextSelectionUtils._kHandlesPadding, |
|||
textLineHeight + CupertinoTextSelectionUtils._kHandlesPadding) |
|||
) |
|||
) |
|||
); |
|||
|
|||
switch (type) { |
|||
case TextSelectionHandleType.left: |
|||
Matrix4 matrix = new Matrix4().rotationZ(Mathf.PI); |
|||
matrix.translate(-CupertinoTextSelectionUtils._kHandlesPadding, |
|||
-CupertinoTextSelectionUtils._kHandlesPadding); |
|||
|
|||
return new Transform( |
|||
transform: matrix, |
|||
child: handle |
|||
); |
|||
case TextSelectionHandleType.right: |
|||
return new Transform( |
|||
transform:new Matrix4().translationValues( |
|||
-CupertinoTextSelectionUtils._kHandlesPadding, |
|||
-(textLineHeight + CupertinoTextSelectionUtils._kHandlesPadding), |
|||
0 |
|||
), |
|||
child: handle |
|||
); |
|||
case TextSelectionHandleType.collapsed: |
|||
return new Container(); |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 8f420271876af9a49b7c8e1faa3dff17 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using Unity.UIWidgets.foundation; |
|||
using Unity.UIWidgets.service; |
|||
using Unity.UIWidgets.ui; |
|||
using Brightness = Unity.UIWidgets.ui.Brightness; |
|||
using TextStyle = Unity.UIWidgets.painting.TextStyle; |
|||
|
|||
namespace Unity.UIWidgets.cupertino { |
|||
static class CupertinoTextThemeDataUtils { |
|||
public static readonly TextStyle _kDefaultLightTextStyle = new TextStyle( |
|||
inherit: false, |
|||
fontFamily: ".SF Pro Text", |
|||
fontSize: 17.0f, |
|||
letterSpacing: -0.41f, |
|||
color: CupertinoColors.black, |
|||
decoration: TextDecoration.none |
|||
); |
|||
|
|||
public static readonly TextStyle _kDefaultDarkTextStyle = new TextStyle( |
|||
inherit: false, |
|||
fontFamily: ".SF Pro Text", |
|||
fontSize: 17.0f, |
|||
letterSpacing: -0.41f, |
|||
color: CupertinoColors.white, |
|||
decoration: TextDecoration.none |
|||
); |
|||
|
|||
public static readonly TextStyle _kDefaultActionTextStyle = new TextStyle( |
|||
inherit: false, |
|||
fontFamily: ".SF Pro Text", |
|||
fontSize: 17.0f, |
|||
letterSpacing: -0.41f, |
|||
color: CupertinoColors.activeBlue, |
|||
decoration: TextDecoration.none |
|||
); |
|||
|
|||
public static readonly TextStyle _kDefaultTabLabelTextStyle = new TextStyle( |
|||
inherit: false, |
|||
fontFamily: ".SF Pro Text", |
|||
fontSize: 10.0f, |
|||
letterSpacing: -0.24f, |
|||
color: CupertinoColors.inactiveGray |
|||
); |
|||
|
|||
public static readonly TextStyle _kDefaultMiddleTitleLightTextStyle = new TextStyle( |
|||
inherit: false, |
|||
fontFamily: ".SF Pro Text", |
|||
fontSize: 17.0f, |
|||
fontWeight: FontWeight.w600, |
|||
letterSpacing: -0.41f, |
|||
color: CupertinoColors.black |
|||
); |
|||
|
|||
public static readonly TextStyle _kDefaultMiddleTitleDarkTextStyle = new TextStyle( |
|||
inherit: false, |
|||
fontFamily: ".SF Pro Text", |
|||
fontSize: 17.0f, |
|||
fontWeight: FontWeight.w600, |
|||
letterSpacing: -0.41f, |
|||
color: CupertinoColors.white |
|||
); |
|||
|
|||
public static readonly TextStyle _kDefaultLargeTitleLightTextStyle = new TextStyle( |
|||
inherit: false, |
|||
fontFamily: ".SF Pro Display", |
|||
fontSize: 34.0f, |
|||
fontWeight: FontWeight.w700, |
|||
letterSpacing: 0.41f, |
|||
color: CupertinoColors.black |
|||
); |
|||
|
|||
public static readonly TextStyle _kDefaultLargeTitleDarkTextStyle = new TextStyle( |
|||
inherit: false, |
|||
fontFamily: ".SF Pro Display", |
|||
fontSize: 34.0f, |
|||
fontWeight: FontWeight.w700, |
|||
letterSpacing: 0.41f, |
|||
color: CupertinoColors.white |
|||
); |
|||
} |
|||
|
|||
|
|||
public class CupertinoTextThemeData : Diagnosticable { |
|||
public CupertinoTextThemeData( |
|||
Color primaryColor = null, |
|||
Brightness? brightness = null, |
|||
TextStyle textStyle = null, |
|||
TextStyle actionTextStyle = null, |
|||
TextStyle tabLabelTextStyle = null, |
|||
TextStyle navTitleTextStyle = null, |
|||
TextStyle navLargeTitleTextStyle = null, |
|||
TextStyle navActionTextStyle = null |
|||
) { |
|||
_primaryColor = primaryColor ?? CupertinoColors.activeBlue; |
|||
_brightness = brightness; |
|||
_textStyle = textStyle; |
|||
_actionTextStyle = actionTextStyle; |
|||
_tabLabelTextStyle = tabLabelTextStyle; |
|||
_navTitleTextStyle = navTitleTextStyle; |
|||
_navLargeTitleTextStyle = navLargeTitleTextStyle; |
|||
_navActionTextStyle = navActionTextStyle; |
|||
} |
|||
|
|||
readonly Color _primaryColor; |
|||
readonly Brightness? _brightness; |
|||
|
|||
bool _isLight { |
|||
get { return _brightness != Brightness.dark; } |
|||
} |
|||
|
|||
readonly TextStyle _textStyle; |
|||
|
|||
public TextStyle textStyle { |
|||
get { |
|||
return _textStyle ?? (_isLight |
|||
? CupertinoTextThemeDataUtils._kDefaultLightTextStyle |
|||
: CupertinoTextThemeDataUtils._kDefaultDarkTextStyle); |
|||
} |
|||
} |
|||
|
|||
readonly TextStyle _actionTextStyle; |
|||
|
|||
public TextStyle actionTextStyle { |
|||
get { |
|||
return _actionTextStyle ?? CupertinoTextThemeDataUtils._kDefaultActionTextStyle.copyWith( |
|||
color: _primaryColor |
|||
); |
|||
} |
|||
} |
|||
|
|||
readonly TextStyle _tabLabelTextStyle; |
|||
|
|||
public TextStyle tabLabelTextStyle { |
|||
get { return _tabLabelTextStyle ?? CupertinoTextThemeDataUtils._kDefaultTabLabelTextStyle; } |
|||
} |
|||
|
|||
readonly TextStyle _navTitleTextStyle; |
|||
|
|||
public TextStyle navTitleTextStyle { |
|||
get { |
|||
return _navTitleTextStyle ?? |
|||
(_isLight |
|||
? CupertinoTextThemeDataUtils._kDefaultMiddleTitleLightTextStyle |
|||
: CupertinoTextThemeDataUtils._kDefaultMiddleTitleDarkTextStyle); |
|||
} |
|||
} |
|||
|
|||
readonly TextStyle _navLargeTitleTextStyle; |
|||
|
|||
/// Typography of large titles in sliver navigation bars.
|
|||
public TextStyle navLargeTitleTextStyle { |
|||
get { |
|||
return _navLargeTitleTextStyle ?? |
|||
(_isLight |
|||
? CupertinoTextThemeDataUtils._kDefaultLargeTitleLightTextStyle |
|||
: CupertinoTextThemeDataUtils._kDefaultLargeTitleDarkTextStyle); |
|||
} |
|||
} |
|||
|
|||
readonly TextStyle _navActionTextStyle; |
|||
|
|||
public TextStyle navActionTextStyle { |
|||
get { |
|||
return _navActionTextStyle ?? CupertinoTextThemeDataUtils._kDefaultActionTextStyle.copyWith( |
|||
color: _primaryColor |
|||
); |
|||
} |
|||
} |
|||
|
|||
public CupertinoTextThemeData copyWith( |
|||
Color primaryColor, |
|||
Brightness? brightness, |
|||
TextStyle textStyle, |
|||
TextStyle actionTextStyle, |
|||
TextStyle tabLabelTextStyle, |
|||
TextStyle navTitleTextStyle, |
|||
TextStyle navLargeTitleTextStyle, |
|||
TextStyle navActionTextStyle |
|||
) { |
|||
return new CupertinoTextThemeData( |
|||
primaryColor: primaryColor ?? _primaryColor, |
|||
brightness: brightness ?? _brightness, |
|||
textStyle: textStyle ?? _textStyle, |
|||
actionTextStyle: actionTextStyle ?? _actionTextStyle, |
|||
tabLabelTextStyle: tabLabelTextStyle ?? _tabLabelTextStyle, |
|||
navTitleTextStyle: navTitleTextStyle ?? _navTitleTextStyle, |
|||
navLargeTitleTextStyle: navLargeTitleTextStyle ?? _navLargeTitleTextStyle, |
|||
navActionTextStyle: navActionTextStyle ?? _navActionTextStyle |
|||
); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: c7d45005fd9f6034c8dabd6d98cab122 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using Unity.UIWidgets.foundation; |
|||
using Unity.UIWidgets.service; |
|||
using Unity.UIWidgets.ui; |
|||
using Unity.UIWidgets.widgets; |
|||
using Brightness = Unity.UIWidgets.ui.Brightness; |
|||
|
|||
namespace Unity.UIWidgets.cupertino { |
|||
static class CupertinoThemeDataUtils { |
|||
public static readonly Color _kDefaultBarLightBackgroundColor = new Color(0xCCF8F8F8); |
|||
public static readonly Color _kDefaultBarDarkBackgroundColor = new Color(0xB7212121); |
|||
} |
|||
|
|||
public class CupertinoTheme : StatelessWidget { |
|||
public CupertinoTheme( |
|||
CupertinoThemeData data, |
|||
Widget child, |
|||
Key key = null |
|||
) : base(key: key) { |
|||
D.assert(child != null); |
|||
D.assert(data != null); |
|||
this.data = data; |
|||
this.child = child; |
|||
} |
|||
|
|||
public readonly CupertinoThemeData data; |
|||
|
|||
public readonly Widget child; |
|||
|
|||
public static CupertinoThemeData of(BuildContext context) { |
|||
_InheritedCupertinoTheme inheritedTheme = |
|||
(_InheritedCupertinoTheme) context.inheritFromWidgetOfExactType(typeof(_InheritedCupertinoTheme)); |
|||
return inheritedTheme?.theme?.data ?? new CupertinoThemeData(); |
|||
} |
|||
|
|||
|
|||
public override Widget build(BuildContext context) { |
|||
return new _InheritedCupertinoTheme( |
|||
theme: this, |
|||
child: new IconTheme( |
|||
data: new IconThemeData(color: data.primaryColor), |
|||
child: child |
|||
) |
|||
); |
|||
} |
|||
} |
|||
|
|||
class _InheritedCupertinoTheme : InheritedWidget { |
|||
public _InheritedCupertinoTheme( |
|||
CupertinoTheme theme, |
|||
Widget child, |
|||
Key key = null |
|||
) |
|||
: base(key: key, child: child) { |
|||
D.assert(theme != null); |
|||
this.theme = theme; |
|||
} |
|||
|
|||
public readonly CupertinoTheme theme; |
|||
|
|||
public override bool updateShouldNotify(InheritedWidget old) { |
|||
return theme.data != ((_InheritedCupertinoTheme) old).theme.data; |
|||
} |
|||
} |
|||
|
|||
public class CupertinoThemeData : Diagnosticable { |
|||
public CupertinoThemeData( |
|||
Brightness? brightness = null, |
|||
Color primaryColor = null, |
|||
Color primaryContrastingColor = null, |
|||
CupertinoTextThemeData textTheme = null, |
|||
Color barBackgroundColor = null, |
|||
Color scaffoldBackgroundColor = null |
|||
) { |
|||
_brightness = brightness; |
|||
_primaryColor = primaryColor; |
|||
_primaryContrastingColor = primaryContrastingColor; |
|||
_textTheme = textTheme; |
|||
_barBackgroundColor = barBackgroundColor; |
|||
_scaffoldBackgroundColor = scaffoldBackgroundColor; |
|||
} |
|||
|
|||
public static CupertinoThemeData raw( |
|||
Brightness? brightness = null, |
|||
Color primaryColor = null, |
|||
Color primaryContrastingColor = null, |
|||
CupertinoTextThemeData textTheme = null, |
|||
Color barBackgroundColor = null, |
|||
Color scaffoldBackgroundColor = null |
|||
) { |
|||
D.assert(brightness != null); |
|||
D.assert(primaryColor != null); |
|||
D.assert(primaryContrastingColor != null); |
|||
D.assert(textTheme != null); |
|||
D.assert(barBackgroundColor != null); |
|||
D.assert(scaffoldBackgroundColor != null); |
|||
return new CupertinoThemeData( |
|||
brightness: brightness, |
|||
primaryColor: primaryColor, |
|||
primaryContrastingColor: primaryContrastingColor, |
|||
textTheme: textTheme, |
|||
barBackgroundColor: barBackgroundColor, |
|||
scaffoldBackgroundColor: scaffoldBackgroundColor |
|||
); |
|||
} |
|||
|
|||
bool _isLight { |
|||
get { return brightness == Brightness.light; } |
|||
} |
|||
|
|||
public Brightness brightness { |
|||
get { return _brightness ?? Brightness.light; } |
|||
} |
|||
|
|||
readonly Brightness? _brightness; |
|||
|
|||
public Color primaryColor { |
|||
get { |
|||
return _primaryColor ?? |
|||
(_isLight ? CupertinoColors.activeBlue : CupertinoColors.activeOrange); |
|||
} |
|||
} |
|||
|
|||
readonly Color _primaryColor; |
|||
|
|||
public Color primaryContrastingColor { |
|||
get { |
|||
return _primaryContrastingColor ?? |
|||
(_isLight ? CupertinoColors.white : CupertinoColors.black); |
|||
} |
|||
} |
|||
|
|||
readonly Color _primaryContrastingColor; |
|||
|
|||
public CupertinoTextThemeData textTheme { |
|||
get { |
|||
return _textTheme ?? new CupertinoTextThemeData( |
|||
brightness: brightness, |
|||
primaryColor: primaryColor |
|||
); |
|||
} |
|||
} |
|||
|
|||
readonly CupertinoTextThemeData _textTheme; |
|||
|
|||
public Color barBackgroundColor { |
|||
get { |
|||
return _barBackgroundColor ?? |
|||
(_isLight |
|||
? CupertinoThemeDataUtils._kDefaultBarLightBackgroundColor |
|||
: CupertinoThemeDataUtils._kDefaultBarDarkBackgroundColor); |
|||
} |
|||
} |
|||
|
|||
readonly Color _barBackgroundColor; |
|||
|
|||
public Color scaffoldBackgroundColor { |
|||
get { |
|||
return _scaffoldBackgroundColor ?? |
|||
(_isLight ? CupertinoColors.white : CupertinoColors.black); |
|||
} |
|||
} |
|||
|
|||
readonly Color _scaffoldBackgroundColor; |
|||
|
|||
public CupertinoThemeData noDefault() { |
|||
return new _NoDefaultCupertinoThemeData( |
|||
_brightness, |
|||
_primaryColor, |
|||
_primaryContrastingColor, |
|||
_textTheme, |
|||
_barBackgroundColor, |
|||
_scaffoldBackgroundColor |
|||
); |
|||
} |
|||
|
|||
public CupertinoThemeData copyWith( |
|||
Brightness? brightness = null, |
|||
Color primaryColor = null, |
|||
Color primaryContrastingColor = null, |
|||
CupertinoTextThemeData textTheme = null, |
|||
Color barBackgroundColor = null, |
|||
Color scaffoldBackgroundColor = null |
|||
) { |
|||
return new CupertinoThemeData( |
|||
brightness: brightness ?? _brightness, |
|||
primaryColor: primaryColor ?? _primaryColor, |
|||
primaryContrastingColor: primaryContrastingColor ?? _primaryContrastingColor, |
|||
textTheme: textTheme ?? _textTheme, |
|||
barBackgroundColor: barBackgroundColor ?? _barBackgroundColor, |
|||
scaffoldBackgroundColor: scaffoldBackgroundColor ?? _scaffoldBackgroundColor |
|||
); |
|||
} |
|||
|
|||
public override void debugFillProperties(DiagnosticPropertiesBuilder properties) { |
|||
base.debugFillProperties(properties); |
|||
CupertinoThemeData defaultData = new CupertinoThemeData(); |
|||
properties.add( |
|||
new EnumProperty<Brightness>("brightness", brightness, defaultValue: defaultData.brightness)); |
|||
properties.add(new DiagnosticsProperty<Color>("primaryColor", primaryColor, |
|||
defaultValue: defaultData.primaryColor)); |
|||
properties.add(new DiagnosticsProperty<Color>("primaryContrastingColor", primaryContrastingColor, |
|||
defaultValue: defaultData.primaryContrastingColor)); |
|||
properties.add( |
|||
new DiagnosticsProperty<CupertinoTextThemeData>("textTheme", textTheme, |
|||
defaultValue: defaultData.textTheme)); |
|||
properties.add(new DiagnosticsProperty<Color>("barBackgroundColor", barBackgroundColor, |
|||
defaultValue: defaultData.barBackgroundColor)); |
|||
properties.add(new DiagnosticsProperty<Color>("scaffoldBackgroundColor", scaffoldBackgroundColor, |
|||
defaultValue: defaultData.scaffoldBackgroundColor)); |
|||
} |
|||
} |
|||
|
|||
class _NoDefaultCupertinoThemeData : CupertinoThemeData { |
|||
public _NoDefaultCupertinoThemeData( |
|||
Brightness? brightness, |
|||
Color primaryColor, |
|||
Color primaryContrastingColor, |
|||
CupertinoTextThemeData textTheme, |
|||
Color barBackgroundColor, |
|||
Color scaffoldBackgroundColor |
|||
) { |
|||
this.brightness = brightness; |
|||
this.primaryColor = primaryColor; |
|||
this.primaryContrastingColor = primaryContrastingColor; |
|||
this.textTheme = textTheme; |
|||
this.barBackgroundColor = barBackgroundColor; |
|||
this.scaffoldBackgroundColor = scaffoldBackgroundColor; |
|||
} |
|||
|
|||
public new readonly Brightness? brightness; |
|||
|
|||
public new readonly Color primaryColor; |
|||
|
|||
public new readonly Color primaryContrastingColor; |
|||
|
|||
public new readonly CupertinoTextThemeData textTheme; |
|||
|
|||
public new readonly Color barBackgroundColor; |
|||
|
|||
public new readonly Color scaffoldBackgroundColor; |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 0b560c283dac79b49a529c6917cf840c |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using Unity.UIWidgets.painting; |
|||
using Unity.UIWidgets.ui; |
|||
|
|||
namespace Unity.UIWidgets.cupertino { |
|||
public class CupertinoThumbPainter { |
|||
public CupertinoThumbPainter( |
|||
Color color = null, |
|||
Color shadowColor = null |
|||
) { |
|||
_shadowPaint = new BoxShadow( |
|||
color: shadowColor, |
|||
blurRadius: 1.0f |
|||
).toPaint(); |
|||
|
|||
this.color = color ?? CupertinoColors.white; |
|||
this.shadowColor = shadowColor ?? new Color(0x2C000000); |
|||
} |
|||
|
|||
public readonly Color color; |
|||
|
|||
public readonly Color shadowColor; |
|||
|
|||
public readonly Paint _shadowPaint; |
|||
|
|||
public const float radius = 14.0f; |
|||
|
|||
public const float extension = 7.0f; |
|||
|
|||
public void paint(Canvas canvas, Rect rect) { |
|||
RRect rrect = RRect.fromRectAndRadius( |
|||
rect, |
|||
Radius.circular(rect.shortestSide / 2.0f) |
|||
); |
|||
|
|||
canvas.drawRRect(rrect, _shadowPaint); |
|||
canvas.drawRRect(rrect.shift(new Offset(0.0f, 3.0f)), _shadowPaint); |
|||
var _paint = new Paint(); |
|||
_paint.color = color; |
|||
canvas.drawRRect(rrect, _paint); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: a3bf47fd342929d4aabe1bd72fc22eb0 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 5c3d34af75804254da0566129e0d4ac0 |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 628dbae83defc65479f1ad3d8c9acbfb |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue