Skip to content
This repository was archived by the owner on Apr 29, 2021. It is now read-only.

Commit ba81f4d

Browse files
author
Yuncong Zhang
authored
Merge pull request #279 from IIzzaya/cupertino
Cupertino
2 parents 2d12f28 + 9395191 commit ba81f4d

File tree

6 files changed

+228
-5
lines changed

6 files changed

+228
-5
lines changed

Runtime/cupertino/app.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ public CupertinoApp(
2727
List<Locale> supportedLocales = null,
2828
bool showPerformanceOverlay = false
2929
) : base(key: key) {
30-
D.assert(routes != null);
31-
D.assert(navigatorObservers != null);
32-
D.assert(title != null);
33-
D.assert(showPerformanceOverlay != null);
30+
// D.assert(routes != null);
31+
// D.assert(navigatorObservers != null);
32+
// D.assert(title != null);
33+
// D.assert(showPerformanceOverlay != null);
3434

3535
supportedLocales = supportedLocales ?? new List<Locale> {new Locale("en", "US")};
3636
this.navigatorKey = navigatorKey;

Runtime/cupertino/page_scaffold.cs

+143
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using Unity.UIWidgets.animation;
4+
using Unity.UIWidgets.foundation;
5+
using Unity.UIWidgets.painting;
6+
using Unity.UIWidgets.ui;
7+
using Unity.UIWidgets.widgets;
8+
9+
namespace Unity.UIWidgets.cupertino {
10+
public class CupertinoPageScaffold : StatefulWidget {
11+
/// Creates a layout for pages with a navigation bar at the top.
12+
public CupertinoPageScaffold(
13+
Widget child,
14+
Key key = null,
15+
ObstructingPreferredSizeWidget navigationBar = null,
16+
Color backgroundColor = null,
17+
bool resizeToAvoidBottomInset = true
18+
) : base(key: key) {
19+
D.assert(child != null);
20+
D.assert(resizeToAvoidBottomInset != null);
21+
22+
this.child = child;
23+
this.navigationBar = navigationBar;
24+
this.backgroundColor = backgroundColor;
25+
this.resizeToAvoidBottomInset = resizeToAvoidBottomInset;
26+
}
27+
28+
public readonly ObstructingPreferredSizeWidget navigationBar;
29+
public readonly Widget child;
30+
public readonly Color backgroundColor;
31+
public readonly bool resizeToAvoidBottomInset;
32+
33+
34+
public override State createState() {
35+
return new _CupertinoPageScaffoldState();
36+
}
37+
}
38+
39+
class _CupertinoPageScaffoldState : State<CupertinoPageScaffold> {
40+
public readonly ScrollController _primaryScrollController = new ScrollController();
41+
42+
void _handleStatusBarTap() {
43+
// Only act on the scroll controller if it has any attached scroll positions.
44+
if (this._primaryScrollController.hasClients) {
45+
this._primaryScrollController.animateTo(
46+
0.0f,
47+
duration: new TimeSpan(0, 0, 0, 0, 500),
48+
curve: Curves.linearToEaseOut
49+
);
50+
}
51+
}
52+
53+
public override Widget build(BuildContext context) {
54+
List<Widget> stacked = new List<Widget>();
55+
56+
Widget paddedContent = this.widget.child;
57+
58+
MediaQueryData existingMediaQuery = MediaQuery.of(context);
59+
if (this.widget.navigationBar != null) {
60+
float topPadding = this.widget.navigationBar.preferredSize.height + existingMediaQuery.padding.top;
61+
62+
float bottomPadding = this.widget.resizeToAvoidBottomInset
63+
? existingMediaQuery.viewInsets.bottom
64+
: 0.0f;
65+
66+
EdgeInsets newViewInsets = this.widget.resizeToAvoidBottomInset
67+
? existingMediaQuery.viewInsets.copyWith(bottom: 0.0f)
68+
: existingMediaQuery.viewInsets;
69+
70+
bool fullObstruction =
71+
this.widget.navigationBar.fullObstruction == false
72+
? CupertinoTheme.of(context).barBackgroundColor.alpha == 0xFF
73+
: this.widget.navigationBar.fullObstruction;
74+
75+
if (fullObstruction) {
76+
paddedContent = new MediaQuery(
77+
data: existingMediaQuery
78+
.removePadding(removeTop: true)
79+
.copyWith(
80+
viewInsets: newViewInsets
81+
),
82+
child: new Padding(
83+
padding: EdgeInsets.only(top: topPadding, bottom: bottomPadding),
84+
child: paddedContent
85+
)
86+
);
87+
}
88+
else {
89+
paddedContent = new MediaQuery(
90+
data: existingMediaQuery.copyWith(
91+
padding: existingMediaQuery.padding.copyWith(
92+
top: topPadding
93+
),
94+
viewInsets: newViewInsets
95+
),
96+
child: new Padding(
97+
padding: EdgeInsets.only(bottom: bottomPadding),
98+
child: paddedContent
99+
)
100+
);
101+
}
102+
}
103+
104+
stacked.Add(new PrimaryScrollController(
105+
controller: this._primaryScrollController,
106+
child: paddedContent
107+
));
108+
109+
if (this.widget.navigationBar != null) {
110+
stacked.Add(new Positioned(
111+
top: 0.0f,
112+
left: 0.0f,
113+
right: 0.0f,
114+
child: this.widget.navigationBar
115+
));
116+
}
117+
118+
stacked.Add(new Positioned(
119+
top: 0.0f,
120+
left: 0.0f,
121+
right: 0.0f,
122+
height: existingMediaQuery.padding.top,
123+
child: new GestureDetector(
124+
onTap: this._handleStatusBarTap
125+
)
126+
)
127+
);
128+
129+
return new DecoratedBox(
130+
decoration: new BoxDecoration(
131+
color: this.widget.backgroundColor ?? CupertinoTheme.of(context).scaffoldBackgroundColor
132+
),
133+
child: new Stack(
134+
children: stacked
135+
)
136+
);
137+
}
138+
}
139+
140+
public abstract class ObstructingPreferredSizeWidget : PreferredSizeWidget {
141+
public bool fullObstruction { get; }
142+
}
143+
}

Runtime/cupertino/page_scaffold.cs.meta

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Runtime/cupertino/theme.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ static class CupertinoThemeDataUtils {
99
public static readonly Color _kDefaultBarDarkBackgroundColor = new Color(0xB7212121);
1010
}
1111

12-
class CupertinoTheme : StatelessWidget {
12+
public class CupertinoTheme : StatelessWidget {
1313
public CupertinoTheme(
1414
CupertinoThemeData data,
1515
Widget child,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
using Unity.UIWidgets.animation;
2+
using Unity.UIWidgets.cupertino;
3+
using Unity.UIWidgets.editor;
4+
using Unity.UIWidgets.foundation;
5+
using Unity.UIWidgets.painting;
6+
using Unity.UIWidgets.ui;
7+
using Unity.UIWidgets.widgets;
8+
using UnityEditor;
9+
using UnityEngine;
10+
using Rect = UnityEngine.Rect;
11+
12+
namespace UIWidgetsSample {
13+
public class CupertinoSample : UIWidgetsEditorWindow {
14+
[MenuItem("UIWidgetsTests/CupertinoSample")]
15+
public static void gallery() {
16+
GetWindow<CupertinoSample>();
17+
}
18+
19+
protected override void OnEnable() {
20+
FontManager.instance.addFont(Resources.Load<Font>("CupertinoIcons"), "CupertinoIcons");
21+
base.OnEnable();
22+
}
23+
24+
protected override Widget createWidget() {
25+
Debug.Log("[Cupertino Sample] Created");
26+
return new CupertinoSampleApp();
27+
}
28+
}
29+
30+
31+
public class CupertinoSampleApp : StatelessWidget {
32+
public override Widget build(BuildContext context) {
33+
return new CupertinoApp(
34+
theme: new CupertinoThemeData(
35+
textTheme: new CupertinoTextThemeData(
36+
navLargeTitleTextStyle: new TextStyle(
37+
fontWeight: FontWeight.bold,
38+
fontSize: 70f,
39+
color: CupertinoColors.activeBlue
40+
)
41+
)),
42+
home: new CupertinoSampleWidget()
43+
);
44+
}
45+
}
46+
47+
public class CupertinoSampleWidget : StatefulWidget {
48+
public CupertinoSampleWidget(Key key = null) : base(key) { }
49+
50+
public override State createState() {
51+
return new CupertinoSampleWidgetState();
52+
}
53+
}
54+
55+
public class CupertinoSampleWidgetState : State<CupertinoSampleWidget> {
56+
public override Widget build(BuildContext context) {
57+
return new CupertinoPageScaffold(
58+
child: new Center(
59+
child: new Text("Hello Cupertino",
60+
style: CupertinoTheme.of(context).textTheme.navLargeTitleTextStyle
61+
)
62+
)
63+
);
64+
}
65+
}
66+
}

Samples/UIWidgetSample/Editor/CupertinoSampleWidget.cs.meta

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)