浏览代码

Merge branch 'cupertino' of github.com:UnityTech/UIWidgets into yczhang1.5.4

/main
Yuncong Zhang 5 年前
当前提交
61bdc1b5
共有 6 个文件被更改,包括 228 次插入5 次删除
  1. 8
      Runtime/cupertino/app.cs
  2. 2
      Runtime/cupertino/theme.cs
  3. 143
      Runtime/cupertino/page_scaffold.cs
  4. 11
      Runtime/cupertino/page_scaffold.cs.meta
  5. 66
      Samples/UIWidgetSample/Editor/CupertinoSampleWidget.cs
  6. 3
      Samples/UIWidgetSample/Editor/CupertinoSampleWidget.cs.meta

8
Runtime/cupertino/app.cs


List<Locale> supportedLocales = null,
bool showPerformanceOverlay = false
) : base(key: key) {
D.assert(routes != null);
D.assert(navigatorObservers != null);
D.assert(title != null);
D.assert(showPerformanceOverlay != null);
// D.assert(routes != null);
// D.assert(navigatorObservers != null);
// D.assert(title != null);
// D.assert(showPerformanceOverlay != null);
supportedLocales = supportedLocales ?? new List<Locale> {new Locale("en", "US")};
this.navigatorKey = navigatorKey;

2
Runtime/cupertino/theme.cs


public static readonly Color _kDefaultBarDarkBackgroundColor = new Color(0xB7212121);
}
class CupertinoTheme : StatelessWidget {
public class CupertinoTheme : StatelessWidget {
public CupertinoTheme(
CupertinoThemeData data,
Widget child,

143
Runtime/cupertino/page_scaffold.cs


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; }
}
}

11
Runtime/cupertino/page_scaffold.cs.meta


fileFormatVersion: 2
guid: c8f7baea91a434b17b549b70613e6976
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

66
Samples/UIWidgetSample/Editor/CupertinoSampleWidget.cs


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
)
)
);
}
}
}

3
Samples/UIWidgetSample/Editor/CupertinoSampleWidget.cs.meta


fileFormatVersion: 2
guid: 92aa3442134248a38d03c2a24a8a9962
timeCreated: 1566545424
正在加载...
取消
保存