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

Commit 823e088

Browse files
committed
[Cupertino] Fix bugs & Update Gallery.
1 parent 5dc07a0 commit 823e088

17 files changed

+604
-391
lines changed

Runtime/cupertino/nav_bar.cs

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
using Color = Unity.UIWidgets.ui.Color;
1212
using Rect = Unity.UIWidgets.ui.Rect;
1313
using TextStyle = Unity.UIWidgets.painting.TextStyle;
14-
using Transform = Unity.UIWidgets.widgets.Transform;
1514

1615
namespace Unity.UIWidgets.cupertino {
1716
class NavBarUtils {
@@ -40,9 +39,9 @@ class NavBarUtils {
4039
public static readonly _HeroTag _defaultHeroTag = new _HeroTag(null);
4140

4241
public static Widget _wrapWithBackground(
43-
Border border,
44-
Color backgroundColor,
45-
Widget child,
42+
Border border = null,
43+
Color backgroundColor = null,
44+
Widget child = null,
4645
bool updateSystemUiOverlay = true
4746
) {
4847
Widget result = child;
@@ -240,16 +239,6 @@ public CupertinoNavigationBar(
240239
bool transitionBetweenRoutes = true,
241240
object heroTag = null
242241
) : base(key: key) {
243-
D.assert(
244-
heroTag != null,
245-
() => "heroTag cannot be null. Use transitionBetweenRoutes = false to " +
246-
"disable Hero transition on this navigation bar."
247-
);
248-
D.assert(
249-
!transitionBetweenRoutes || ReferenceEquals(heroTag, NavBarUtils._defaultHeroTag),
250-
() => "Cannot specify a heroTag override if this navigation bar does not " +
251-
"transition due to transitionBetweenRoutes = false."
252-
);
253242
this.leading = leading;
254243
this.automaticallyImplyLeading = automaticallyImplyLeading;
255244
this.automaticallyImplyMiddle = automaticallyImplyMiddle;
@@ -262,6 +251,18 @@ public CupertinoNavigationBar(
262251
this.actionsForegroundColor = actionsForegroundColor;
263252
this.transitionBetweenRoutes = transitionBetweenRoutes;
264253
this.heroTag = heroTag ?? NavBarUtils._defaultHeroTag;
254+
255+
D.assert(
256+
this.heroTag != null,
257+
() => "heroTag cannot be null. Use transitionBetweenRoutes = false to " +
258+
"disable Hero transition on this navigation bar."
259+
);
260+
261+
D.assert(
262+
!transitionBetweenRoutes || ReferenceEquals(this.heroTag, NavBarUtils._defaultHeroTag),
263+
() => "Cannot specify a heroTag override if this navigation bar does not " +
264+
"transition due to transitionBetweenRoutes = false."
265+
);
265266
}
266267

267268
public readonly Widget leading;
@@ -663,6 +664,9 @@ public _PersistentNavigationBar(
663664
EdgeInsets padding = null,
664665
bool? middleVisible = null
665666
) : base(key: key) {
667+
this.components = components;
668+
this.padding = padding;
669+
this.middleVisible = middleVisible ?? true;
666670
}
667671

668672
public readonly _NavigationBarStaticComponents components;
@@ -1084,8 +1088,7 @@ public override Widget build(BuildContext context) {
10841088

10851089

10861090
class _BackChevron : StatelessWidget {
1087-
public _BackChevron(Key key = null) : base(key: key) {
1088-
}
1091+
public _BackChevron(Key key = null) : base(key: key) { }
10891092

10901093
public override Widget build(BuildContext context) {
10911094
TextStyle textStyle = DefaultTextStyle.of(context).style;
@@ -1172,6 +1175,7 @@ public _TransitionableNavigationBar(
11721175
) : base(key: componentsKeys.navBarBoxKey) {
11731176
D.assert(largeExpanded != null);
11741177
D.assert(!largeExpanded.Value || this.largeTitleTextStyle != null);
1178+
11751179
this.componentsKeys = componentsKeys;
11761180
this.backgroundColor = backgroundColor;
11771181
this.backButtonTextStyle = backButtonTextStyle;

Runtime/cupertino/scrollbar.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
using Unity.UIWidgets.widgets;
77

88
namespace Unity.UIWidgets.cupertino {
9-
public class CupertinoScrollbarUtils {
9+
class CupertinoScrollbarUtils {
1010
public static Color _kScrollbarColor = new Color(0x99777777);
11-
public static float _kScrollbarThickness = 2.5f;
12-
public static float _kScrollbarMainAxisMargin = 4.0f;
13-
public static float _kScrollbarCrossAxisMargin = 2.5f;
14-
public static float _kScrollbarMinLength = 36.0f;
15-
public static float _kScrollbarMinOverscrollLength = 8.0f;
11+
public const float _kScrollbarThickness = 2.5f;
12+
public const float _kScrollbarMainAxisMargin = 4.0f;
13+
public const float _kScrollbarCrossAxisMargin = 2.5f;
14+
public const float _kScrollbarMinLength = 36.0f;
15+
public const float _kScrollbarMinOverscrollLength = 8.0f;
1616
public static Radius _kScrollbarRadius = Radius.circular(1.25f);
1717
public static TimeSpan _kScrollbarTimeToFade = new TimeSpan(0, 0, 0, 0, 50);
1818
public static TimeSpan _kScrollbarFadeDuration = new TimeSpan(0, 0, 0, 0, 250);
@@ -28,7 +28,9 @@ public CupertinoScrollbar(
2828

2929
public readonly Widget child;
3030

31-
public override State createState() => new _CupertinoScrollbarState();
31+
public override State createState() {
32+
return new _CupertinoScrollbarState();
33+
}
3234
}
3335

3436
class _CupertinoScrollbarState : TickerProviderStateMixin<CupertinoScrollbar> {

Runtime/cupertino/switch.cs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public _CupertinoSwitchRenderObjectWidget(
103103

104104

105105
public override RenderObject createRenderObject(BuildContext context) {
106-
return (RenderObject) new _RenderCupertinoSwitch(
106+
return new _RenderCupertinoSwitch(
107107
value: this.value,
108108
activeColor: this.activeColor,
109109
onChanged: this.onChanged,
@@ -131,7 +131,7 @@ public _RenderCupertinoSwitch(
131131
Color activeColor,
132132
TextDirection textDirection,
133133
TickerProvider vsync,
134-
ValueChanged<bool> onChanged,
134+
ValueChanged<bool> onChanged = null,
135135
DragStartBehavior dragStartBehavior = DragStartBehavior.start
136136
) : base(additionalConstraints: BoxConstraints.tightFor(
137137
width: CupertinoSwitchUtils._kSwitchWidth,
@@ -197,6 +197,7 @@ public bool value {
197197
}
198198

199199
this._value = value;
200+
// this.markNeedsSemanticsUpdate();
200201
this._position.curve = Curves.ease;
201202
this._position.reverseCurve = Curves.ease.flipped;
202203
if (value) {
@@ -210,7 +211,6 @@ public bool value {
210211

211212
bool _value;
212213

213-
214214
public TickerProvider vsync {
215215
get { return this._vsync; }
216216
set {
@@ -372,14 +372,17 @@ void _handleDragUpdate(DragUpdateDetails details) {
372372
this._position.curve = null;
373373
this._position.reverseCurve = null;
374374
float delta = details.primaryDelta / CupertinoSwitchUtils._kTrackInnerLength ?? 0f;
375-
switch (this.textDirection) {
376-
case TextDirection.rtl:
377-
this._positionController.setValue(this._positionController.value - delta);
378-
break;
379-
case TextDirection.ltr:
380-
this._positionController.setValue(this._positionController.value + delta);
381-
break;
382-
}
375+
376+
this._positionController.setValue(this._positionController.value + delta);
377+
378+
// switch (this.textDirection) {
379+
// case TextDirection.rtl:
380+
// this._positionController.setValue(this._positionController.value - delta);
381+
// break;
382+
// case TextDirection.ltr:
383+
// this._positionController.setValue(this._positionController.value + delta);
384+
// break;
385+
// }
383386
}
384387
}
385388

Runtime/ui/text.cs

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -425,23 +425,18 @@ public class FontWeight : IEquatable<FontWeight> {
425425

426426
public readonly int index;
427427

428-
public static readonly FontWeight w100 = new FontWeight(0);
429-
public static readonly FontWeight w200 = new FontWeight(1);
430-
public static readonly FontWeight w300 = new FontWeight(2);
431-
public static readonly FontWeight w400 = new FontWeight(3);
432-
public static readonly FontWeight w500 = new FontWeight(4);
433-
public static readonly FontWeight w600 = new FontWeight(5);
434-
435-
public static readonly FontWeight w700 = new FontWeight(6);
436-
437-
public static readonly FontWeight w800 = new FontWeight(7);
438-
439-
public static readonly FontWeight w900 = new FontWeight(8);
440-
441-
428+
public static readonly FontWeight w100 = new FontWeight(0); // Ultralight
429+
public static readonly FontWeight w200 = new FontWeight(1); // Thin
430+
public static readonly FontWeight w300 = new FontWeight(2); // Light
431+
public static readonly FontWeight w400 = new FontWeight(3); // Regular
432+
public static readonly FontWeight w500 = new FontWeight(4); // Medium
433+
public static readonly FontWeight w600 = new FontWeight(5); // Semibold
434+
public static readonly FontWeight w700 = new FontWeight(6); // Bold
435+
public static readonly FontWeight w800 = new FontWeight(7); // Heavy
436+
public static readonly FontWeight w900 = new FontWeight(8); // Black
437+
442438
public static readonly FontWeight normal = w400;
443439

444-
445440
public static readonly FontWeight bold = w700;
446441

447442
public static readonly List<FontWeight> values = new List<FontWeight> {

Samples/UIWidgetsGallery/Editor/GalleryMainEditor.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ protected override Widget createWidget() {
2020
protected override void OnEnable() {
2121
FontManager.instance.addFont(Resources.Load<Font>("MaterialIcons-Regular"), "Material Icons");
2222
FontManager.instance.addFont(Resources.Load<Font>("GalleryIcons"), "GalleryIcons");
23+
24+
FontManager.instance.addFont(Resources.Load<Font>("CupertinoIcons"), "CupertinoIcons");
25+
FontManager.instance.addFont(Resources.Load<Font>(path: "SF-Pro-Text-Regular"), ".SF Pro Text", FontWeight.w400);
26+
FontManager.instance.addFont(Resources.Load<Font>(path: "SF-Pro-Text-Semibold"), ".SF Pro Text", FontWeight.w600);
27+
FontManager.instance.addFont(Resources.Load<Font>(path: "SF-Pro-Text-Bold"), ".SF Pro Text", FontWeight.w700);
2328
base.OnEnable();
2429
}
2530
}

Samples/UIWidgetsGallery/GalleryMain.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ protected override void OnEnable() {
1515
FontManager.instance.addFont(Resources.Load<Font>("MaterialIcons-Regular"), "Material Icons");
1616
FontManager.instance.addFont(Resources.Load<Font>("GalleryIcons"), "GalleryIcons");
1717

18+
FontManager.instance.addFont(Resources.Load<Font>("CupertinoIcons"), "CupertinoIcons");
19+
FontManager.instance.addFont(Resources.Load<Font>(path: "SF-Pro-Text-Regular"), ".SF Pro Text", FontWeight.w400);
20+
FontManager.instance.addFont(Resources.Load<Font>(path: "SF-Pro-Text-Semibold"), ".SF Pro Text", FontWeight.w600);
21+
FontManager.instance.addFont(Resources.Load<Font>(path: "SF-Pro-Text-Bold"), ".SF Pro Text", FontWeight.w700);
22+
1823
base.OnEnable();
1924
}
2025
}

Samples/UIWidgetsGallery/demo/cupertino.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
using System.Collections.Generic;
2+
using Unity.UIWidgets.cupertino;
3+
using Unity.UIWidgets.material;
4+
using Unity.UIWidgets.painting;
5+
using Unity.UIWidgets.rendering;
6+
using Unity.UIWidgets.widgets;
7+
8+
namespace UIWidgetsGallery.gallery {
9+
class CupertinoButtonsDemo : StatefulWidget {
10+
public static string routeName = "/cupertino/buttons";
11+
public override State createState() => new _CupertinoButtonDemoState();
12+
}
13+
14+
class _CupertinoButtonDemoState : State<CupertinoButtonsDemo> {
15+
int _pressedCount = 0;
16+
17+
18+
public override Widget build(BuildContext context) {
19+
return new CupertinoPageScaffold(
20+
navigationBar: new CupertinoNavigationBar(
21+
middle: new Text("Buttons"),
22+
previousPageTitle: "Cupertino",
23+
trailing: new CupertinoDemoDocumentationButton(CupertinoButtonsDemo.routeName)
24+
),
25+
child: new DefaultTextStyle(
26+
style: CupertinoTheme.of(context).textTheme.textStyle,
27+
child: new SafeArea(
28+
child: new Column(
29+
children: new List<Widget> {
30+
new Padding(
31+
padding: EdgeInsets.all(16.0f),
32+
child: new Text(
33+
"iOS themed buttons are flat. They can have borders or backgrounds but only when necessary."
34+
)
35+
),
36+
new Expanded(
37+
child: new Column(
38+
mainAxisAlignment: MainAxisAlignment.center,
39+
children: new List<Widget> {
40+
new Text(this._pressedCount > 0
41+
? $"Button pressed {this._pressedCount} time" +
42+
(this._pressedCount == 1 ? "" : "s")
43+
: " "),
44+
new Padding(padding: EdgeInsets.all(12.0f)),
45+
new Align(
46+
alignment: new Alignment(0.0f, -0.2f),
47+
child:
48+
new Row(
49+
mainAxisSize: MainAxisSize.min,
50+
children: new List<Widget> {
51+
new CupertinoButton(
52+
child: new Text("Cupertino Button"),
53+
onPressed:
54+
() => { this.setState(() => { this._pressedCount += 1; }); }
55+
),
56+
new CupertinoButton(
57+
child: new Text("Disabled"),
58+
onPressed: null
59+
)
60+
}
61+
)
62+
),
63+
new Padding(padding: EdgeInsets.all(12.0f)),
64+
CupertinoButton.filled(
65+
child: new Text("With Background"),
66+
onPressed:
67+
() => { this.setState(() => { this._pressedCount += 1; }); }
68+
),
69+
new Padding(padding: EdgeInsets.all(12.0f)),
70+
CupertinoButton.filled(
71+
child: new Text("Disabled"),
72+
onPressed: null
73+
),
74+
}
75+
)
76+
)
77+
}
78+
)
79+
)
80+
)
81+
);
82+
}
83+
}
84+
}

Samples/UIWidgetsGallery/demo/cupertino/cupertino_buttons_demo.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Samples/UIWidgetsGallery/gallery/demo.cs

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Collections.Generic;
22
using System.Linq;
3+
using Unity.UIWidgets.cupertino;
34
using Unity.UIWidgets.foundation;
45
using Unity.UIWidgets.material;
56
using Unity.UIWidgets.painting;
@@ -42,7 +43,7 @@ public bool Equals(ComponentDemoTabData other) {
4243
&& other.description == this.description
4344
&& other.documentationUrl == this.documentationUrl;
4445
}
45-
46+
4647
public override bool Equals(object obj) {
4748
if (ReferenceEquals(null, obj)) {
4849
return false;
@@ -175,8 +176,7 @@ public override State createState() {
175176
}
176177

177178
public class FullScreenCodeDialogState : State<FullScreenCodeDialog> {
178-
public FullScreenCodeDialogState() {
179-
}
179+
public FullScreenCodeDialogState() { }
180180

181181
string _exampleCode;
182182

@@ -250,4 +250,28 @@ public override Widget build(BuildContext context) {
250250
);
251251
}
252252
}
253+
254+
class CupertinoDemoDocumentationButton : StatelessWidget {
255+
public CupertinoDemoDocumentationButton(
256+
string routeName,
257+
Key key = null
258+
) : base(key: key) {
259+
this.documentationUrl = DemoUtils.kDemoDocumentationUrl[routeName];
260+
261+
D.assert(
262+
DemoUtils.kDemoDocumentationUrl[routeName] != null,
263+
() => $"A documentation URL was not specified for demo route {routeName} in kAllGalleryDemos"
264+
);
265+
}
266+
267+
public readonly string documentationUrl;
268+
269+
public override Widget build(BuildContext context) {
270+
return new CupertinoButton(
271+
padding: EdgeInsets.zero,
272+
child: new Icon(CupertinoIcons.book),
273+
onPressed: () => Application.OpenURL(this.documentationUrl)
274+
);
275+
}
276+
}
253277
}

0 commit comments

Comments
 (0)