Yuncong Zhang
5 年前
当前提交
61bdc1b5
共有 6 个文件被更改,包括 228 次插入 和 5 次删除
-
8Runtime/cupertino/app.cs
-
2Runtime/cupertino/theme.cs
-
143Runtime/cupertino/page_scaffold.cs
-
11Runtime/cupertino/page_scaffold.cs.meta
-
66Samples/UIWidgetSample/Editor/CupertinoSampleWidget.cs
-
3Samples/UIWidgetSample/Editor/CupertinoSampleWidget.cs.meta
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using Unity.UIWidgets.animation; |
|||
using Unity.UIWidgets.foundation; |
|||
using Unity.UIWidgets.painting; |
|||
using Unity.UIWidgets.ui; |
|||
using Unity.UIWidgets.widgets; |
|||
|
|||
namespace Unity.UIWidgets.cupertino { |
|||
public class CupertinoPageScaffold : StatefulWidget { |
|||
/// Creates a layout for pages with a navigation bar at the top.
|
|||
public CupertinoPageScaffold( |
|||
Widget child, |
|||
Key key = null, |
|||
ObstructingPreferredSizeWidget navigationBar = null, |
|||
Color backgroundColor = null, |
|||
bool resizeToAvoidBottomInset = true |
|||
) : base(key: key) { |
|||
D.assert(child != null); |
|||
D.assert(resizeToAvoidBottomInset != null); |
|||
|
|||
this.child = child; |
|||
this.navigationBar = navigationBar; |
|||
this.backgroundColor = backgroundColor; |
|||
this.resizeToAvoidBottomInset = resizeToAvoidBottomInset; |
|||
} |
|||
|
|||
public readonly ObstructingPreferredSizeWidget navigationBar; |
|||
public readonly Widget child; |
|||
public readonly Color backgroundColor; |
|||
public readonly bool resizeToAvoidBottomInset; |
|||
|
|||
|
|||
public override State createState() { |
|||
return new _CupertinoPageScaffoldState(); |
|||
} |
|||
} |
|||
|
|||
class _CupertinoPageScaffoldState : State<CupertinoPageScaffold> { |
|||
public readonly ScrollController _primaryScrollController = new ScrollController(); |
|||
|
|||
void _handleStatusBarTap() { |
|||
// Only act on the scroll controller if it has any attached scroll positions.
|
|||
if (this._primaryScrollController.hasClients) { |
|||
this._primaryScrollController.animateTo( |
|||
0.0f, |
|||
duration: new TimeSpan(0, 0, 0, 0, 500), |
|||
curve: Curves.linearToEaseOut |
|||
); |
|||
} |
|||
} |
|||
|
|||
public override Widget build(BuildContext context) { |
|||
List<Widget> stacked = new List<Widget>(); |
|||
|
|||
Widget paddedContent = this.widget.child; |
|||
|
|||
MediaQueryData existingMediaQuery = MediaQuery.of(context); |
|||
if (this.widget.navigationBar != null) { |
|||
float topPadding = this.widget.navigationBar.preferredSize.height + existingMediaQuery.padding.top; |
|||
|
|||
float bottomPadding = this.widget.resizeToAvoidBottomInset |
|||
? existingMediaQuery.viewInsets.bottom |
|||
: 0.0f; |
|||
|
|||
EdgeInsets newViewInsets = this.widget.resizeToAvoidBottomInset |
|||
? existingMediaQuery.viewInsets.copyWith(bottom: 0.0f) |
|||
: existingMediaQuery.viewInsets; |
|||
|
|||
bool fullObstruction = |
|||
this.widget.navigationBar.fullObstruction == false |
|||
? CupertinoTheme.of(context).barBackgroundColor.alpha == 0xFF |
|||
: this.widget.navigationBar.fullObstruction; |
|||
|
|||
if (fullObstruction) { |
|||
paddedContent = new MediaQuery( |
|||
data: existingMediaQuery |
|||
.removePadding(removeTop: true) |
|||
.copyWith( |
|||
viewInsets: newViewInsets |
|||
), |
|||
child: new Padding( |
|||
padding: EdgeInsets.only(top: topPadding, bottom: bottomPadding), |
|||
child: paddedContent |
|||
) |
|||
); |
|||
} |
|||
else { |
|||
paddedContent = new MediaQuery( |
|||
data: existingMediaQuery.copyWith( |
|||
padding: existingMediaQuery.padding.copyWith( |
|||
top: topPadding |
|||
), |
|||
viewInsets: newViewInsets |
|||
), |
|||
child: new Padding( |
|||
padding: EdgeInsets.only(bottom: bottomPadding), |
|||
child: paddedContent |
|||
) |
|||
); |
|||
} |
|||
} |
|||
|
|||
stacked.Add(new PrimaryScrollController( |
|||
controller: this._primaryScrollController, |
|||
child: paddedContent |
|||
)); |
|||
|
|||
if (this.widget.navigationBar != null) { |
|||
stacked.Add(new Positioned( |
|||
top: 0.0f, |
|||
left: 0.0f, |
|||
right: 0.0f, |
|||
child: this.widget.navigationBar |
|||
)); |
|||
} |
|||
|
|||
stacked.Add(new Positioned( |
|||
top: 0.0f, |
|||
left: 0.0f, |
|||
right: 0.0f, |
|||
height: existingMediaQuery.padding.top, |
|||
child: new GestureDetector( |
|||
onTap: this._handleStatusBarTap |
|||
) |
|||
) |
|||
); |
|||
|
|||
return new DecoratedBox( |
|||
decoration: new BoxDecoration( |
|||
color: this.widget.backgroundColor ?? CupertinoTheme.of(context).scaffoldBackgroundColor |
|||
), |
|||
child: new Stack( |
|||
children: stacked |
|||
) |
|||
); |
|||
} |
|||
} |
|||
|
|||
public abstract class ObstructingPreferredSizeWidget : PreferredSizeWidget { |
|||
public bool fullObstruction { get; } |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: c8f7baea91a434b17b549b70613e6976 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using Unity.UIWidgets.animation; |
|||
using Unity.UIWidgets.cupertino; |
|||
using Unity.UIWidgets.editor; |
|||
using Unity.UIWidgets.foundation; |
|||
using Unity.UIWidgets.painting; |
|||
using Unity.UIWidgets.ui; |
|||
using Unity.UIWidgets.widgets; |
|||
using UnityEditor; |
|||
using UnityEngine; |
|||
using Rect = UnityEngine.Rect; |
|||
|
|||
namespace UIWidgetsSample { |
|||
public class CupertinoSample : UIWidgetsEditorWindow { |
|||
[MenuItem("UIWidgetsTests/CupertinoSample")] |
|||
public static void gallery() { |
|||
GetWindow<CupertinoSample>(); |
|||
} |
|||
|
|||
protected override void OnEnable() { |
|||
FontManager.instance.addFont(Resources.Load<Font>("CupertinoIcons"), "CupertinoIcons"); |
|||
base.OnEnable(); |
|||
} |
|||
|
|||
protected override Widget createWidget() { |
|||
Debug.Log("[Cupertino Sample] Created"); |
|||
return new CupertinoSampleApp(); |
|||
} |
|||
} |
|||
|
|||
|
|||
public class CupertinoSampleApp : StatelessWidget { |
|||
public override Widget build(BuildContext context) { |
|||
return new CupertinoApp( |
|||
theme: new CupertinoThemeData( |
|||
textTheme: new CupertinoTextThemeData( |
|||
navLargeTitleTextStyle: new TextStyle( |
|||
fontWeight: FontWeight.bold, |
|||
fontSize: 70f, |
|||
color: CupertinoColors.activeBlue |
|||
) |
|||
)), |
|||
home: new CupertinoSampleWidget() |
|||
); |
|||
} |
|||
} |
|||
|
|||
public class CupertinoSampleWidget : StatefulWidget { |
|||
public CupertinoSampleWidget(Key key = null) : base(key) { } |
|||
|
|||
public override State createState() { |
|||
return new CupertinoSampleWidgetState(); |
|||
} |
|||
} |
|||
|
|||
public class CupertinoSampleWidgetState : State<CupertinoSampleWidget> { |
|||
public override Widget build(BuildContext context) { |
|||
return new CupertinoPageScaffold( |
|||
child: new Center( |
|||
child: new Text("Hello Cupertino", |
|||
style: CupertinoTheme.of(context).textTheme.navLargeTitleTextStyle |
|||
) |
|||
) |
|||
); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 92aa3442134248a38d03c2a24a8a9962 |
|||
timeCreated: 1566545424 |
撰写
预览
正在加载...
取消
保存
Reference in new issue