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

Commit 2ac24eb

Browse files
authored
Merge pull request #284 from IIzzaya/cupertino
[Cupertino] Update Cupertino gallery
2 parents 5dc07a0 + 95dc2c1 commit 2ac24eb

28 files changed

+1311
-404
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: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@
1313

1414
namespace Unity.UIWidgets.cupertino {
1515
class CupertinoSwitchUtils {
16-
public static float _kTrackWidth = 51.0f;
17-
public static float _kTrackHeight = 31.0f;
18-
public static float _kTrackRadius = _kTrackHeight / 2.0f;
19-
public static float _kTrackInnerStart = _kTrackHeight / 2.0f;
20-
public static float _kTrackInnerEnd = _kTrackWidth - _kTrackInnerStart;
21-
public static float _kTrackInnerLength = _kTrackInnerEnd - _kTrackInnerStart;
22-
public static float _kSwitchWidth = 59.0f;
23-
public static float _kSwitchHeight = 39.0f;
24-
public static float _kCupertinoSwitchDisabledOpacity = 0.5f;
16+
public const float _kTrackWidth = 51.0f;
17+
public const float _kTrackHeight = 31.0f;
18+
public const float _kTrackRadius = _kTrackHeight / 2.0f;
19+
public const float _kTrackInnerStart = _kTrackHeight / 2.0f;
20+
public const float _kTrackInnerEnd = _kTrackWidth - _kTrackInnerStart;
21+
public const float _kTrackInnerLength = _kTrackInnerEnd - _kTrackInnerStart;
22+
public const float _kSwitchWidth = 59.0f;
23+
public const float _kSwitchHeight = 39.0f;
24+
public const float _kCupertinoSwitchDisabledOpacity = 0.5f;
2525
public static Color _kTrackColor = CupertinoColors.lightBackgroundGray;
2626
public static TimeSpan _kReactionDuration = new TimeSpan(0, 0, 0, 0, 300);
2727
public static TimeSpan _kToggleDuration = new TimeSpan(0, 0, 0, 0, 200);
@@ -100,10 +100,9 @@ public _CupertinoSwitchRenderObjectWidget(
100100
public readonly ValueChanged<bool> onChanged;
101101
public readonly TickerProvider vsync;
102102
public readonly DragStartBehavior dragStartBehavior;
103-
104-
103+
105104
public override RenderObject createRenderObject(BuildContext context) {
106-
return (RenderObject) new _RenderCupertinoSwitch(
105+
return new _RenderCupertinoSwitch(
107106
value: this.value,
108107
activeColor: this.activeColor,
109108
onChanged: this.onChanged,
@@ -131,7 +130,7 @@ public _RenderCupertinoSwitch(
131130
Color activeColor,
132131
TextDirection textDirection,
133132
TickerProvider vsync,
134-
ValueChanged<bool> onChanged,
133+
ValueChanged<bool> onChanged = null,
135134
DragStartBehavior dragStartBehavior = DragStartBehavior.start
136135
) : base(additionalConstraints: BoxConstraints.tightFor(
137136
width: CupertinoSwitchUtils._kSwitchWidth,
@@ -197,6 +196,7 @@ public bool value {
197196
}
198197

199198
this._value = value;
199+
// this.markNeedsSemanticsUpdate();
200200
this._position.curve = Curves.ease;
201201
this._position.reverseCurve = Curves.ease.flipped;
202202
if (value) {
@@ -210,7 +210,6 @@ public bool value {
210210

211211
bool _value;
212212

213-
214213
public TickerProvider vsync {
215214
get { return this._vsync; }
216215
set {
@@ -294,8 +293,8 @@ public bool isInteractive {
294293
TapGestureRecognizer _tap;
295294
HorizontalDragGestureRecognizer _drag;
296295

297-
public override void attach(object owne) {
298-
base.attach(this.owner);
296+
public override void attach(object _owner) {
297+
base.attach(_owner);
299298
if (this.value) {
300299
this._positionController.forward();
301300
}
@@ -372,14 +371,17 @@ void _handleDragUpdate(DragUpdateDetails details) {
372371
this._position.curve = null;
373372
this._position.reverseCurve = null;
374373
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-
}
374+
375+
this._positionController.setValue(this._positionController.value + delta);
376+
377+
// switch (this.textDirection) {
378+
// case TextDirection.rtl:
379+
// this._positionController.setValue(this._positionController.value - delta);
380+
// break;
381+
// case TextDirection.ltr:
382+
// this._positionController.setValue(this._positionController.value + delta);
383+
// break;
384+
// }
383385
}
384386
}
385387

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: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using Unity.UIWidgets.cupertino;
2+
using Unity.UIWidgets.widgets;
3+
4+
namespace UIWidgetsGallery.gallery {
5+
/*
6+
class CupertinoProgressIndicatorDemo : StatelessWidget {
7+
public static string routeName = "/cupertino/progress_indicator";
8+
9+
public override
10+
Widget build(BuildContext context) {
11+
return new CupertinoPageScaffold(
12+
navigationBar: new CupertinoNavigationBar(
13+
previousPageTitle: "Cupertino",
14+
middle: new Text("Activity Indicator"),
15+
trailing: new CupertinoDemoDocumentationButton(routeName)
16+
),
17+
child: new Center(
18+
child: new CupertinoActivityIndicator()
19+
)
20+
);
21+
}
22+
}
23+
*/
24+
}

Samples/UIWidgetsGallery/demo/cupertino/cupertino_activity_indicator_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.

0 commit comments

Comments
 (0)