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

Commit bbb259f

Browse files
author
Yuncong Zhang
authored
Merge pull request #297 from UnityTech/cupertinosample
Cupertinosample
2 parents 906a84b + a74cc9b commit bbb259f

File tree

16 files changed

+488
-434
lines changed

16 files changed

+488
-434
lines changed

Runtime/cupertino/action_sheet.cs

Lines changed: 88 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,11 @@
55
using Unity.UIWidgets.rendering;
66
using Unity.UIWidgets.ui;
77
using Unity.UIWidgets.widgets;
8-
using UnityEngine;
9-
using Canvas = Unity.UIWidgets.ui.Canvas;
10-
using Color = Unity.UIWidgets.ui.Color;
11-
using Rect = Unity.UIWidgets.ui.Rect;
128
using TextStyle = Unity.UIWidgets.painting.TextStyle;
139

1410
namespace Unity.UIWidgets.cupertino {
1511
class CupertinoActionSheetUtils {
16-
public static TextStyle _kActionSheetActionStyle = new TextStyle(
12+
public static readonly TextStyle _kActionSheetActionStyle = new TextStyle(
1713
// fontFamily: ".SF UI Text",
1814
fontFamily: ".SF Pro Text",
1915
inherit: false,
@@ -23,7 +19,7 @@ class CupertinoActionSheetUtils {
2319
textBaseline: TextBaseline.alphabetic
2420
);
2521

26-
public static TextStyle _kActionSheetContentStyle = new TextStyle(
22+
public static readonly TextStyle _kActionSheetContentStyle = new TextStyle(
2723
// fontFamily: ".SF UI Text",
2824
fontFamily: ".SF Pro Text",
2925
inherit: false,
@@ -33,16 +29,16 @@ class CupertinoActionSheetUtils {
3329
textBaseline: TextBaseline.alphabetic
3430
);
3531

36-
public static BoxDecoration _kAlertBlurOverlayDecoration = new BoxDecoration(
32+
public static readonly BoxDecoration _kAlertBlurOverlayDecoration = new BoxDecoration(
3733
color: CupertinoColors.white,
3834
backgroundBlendMode: BlendMode.overlay
3935
);
4036

41-
public static Color _kBackgroundColor = new Color(0xD1F8F8F8);
42-
public static Color _kPressedColor = new Color(0xA6E5E5EA);
43-
public static Color _kButtonDividerColor = new Color(0x403F3F3F);
44-
public static Color _kContentTextColor = new Color(0xFF8F8F8F);
45-
public static Color _kCancelButtonPressedColor = new Color(0xFFEAEAEA);
37+
public static readonly Color _kBackgroundColor = new Color(0xD1F8F8F8);
38+
public static readonly Color _kPressedColor = new Color(0xA6E5E5EA);
39+
public static readonly Color _kButtonDividerColor = new Color(0x403F3F3F);
40+
public static readonly Color _kContentTextColor = new Color(0xFF8F8F8F);
41+
public static readonly Color _kCancelButtonPressedColor = new Color(0xFFEAEAEA);
4642

4743
public const float _kBlurAmount = 20.0f;
4844
public const float _kEdgeHorizontalPadding = 8.0f;
@@ -109,8 +105,6 @@ Widget _buildActions() {
109105
return new Container(height: 0.0f);
110106
}
111107

112-
Debug.Log("_buildActions");
113-
114108
return new Container(
115109
child: new _CupertinoAlertActionSection(
116110
children: this.actions,
@@ -193,7 +187,6 @@ public CupertinoActionSheetAction(
193187
bool isDefaultAction = false,
194188
bool isDestructiveAction = false
195189
) {
196-
Debug.Log("constructor");
197190
D.assert(child != null);
198191
D.assert(onPressed != null);
199192
this.child = child;
@@ -208,7 +201,6 @@ public CupertinoActionSheetAction(
208201
public readonly Widget child;
209202

210203
public override Widget build(BuildContext context) {
211-
Debug.Log("build");
212204
TextStyle style = CupertinoActionSheetUtils._kActionSheetActionStyle;
213205

214206
if (this.isDefaultAction) {
@@ -219,7 +211,6 @@ public override Widget build(BuildContext context) {
219211
style = style.copyWith(color: CupertinoColors.destructiveRed);
220212
}
221213

222-
223214
return new GestureDetector(
224215
onTap: () => this.onPressed(),
225216
behavior: HitTestBehavior.opaque,
@@ -353,11 +344,11 @@ public override void mount(Element parent, object newSlot) {
353344
}
354345

355346
protected override void insertChildRenderObject(RenderObject child, object slot) {
356-
this._placeChildInSlot(child, (_AlertSections) slot);
347+
this._placeChildInSlot(child, slot);
357348
}
358349

359350
protected override void moveChildRenderObject(RenderObject child, object slot) {
360-
this._placeChildInSlot(child, (_AlertSections) slot);
351+
this._placeChildInSlot(child, slot);
361352
}
362353

363354
public override void update(Widget newWidget) {
@@ -388,8 +379,8 @@ protected override void removeChildRenderObject(RenderObject child) {
388379
}
389380
}
390381

391-
void _placeChildInSlot(RenderObject child, _AlertSections slot) {
392-
switch (slot) {
382+
void _placeChildInSlot(RenderObject child, object slot) {
383+
switch ((_AlertSections) slot) {
393384
case _AlertSections.contentSection:
394385
this.renderObject.contentSection = child as RenderBox;
395386
break;
@@ -751,12 +742,11 @@ public override State createState() {
751742

752743
class _CupertinoAlertActionSectionState : State<_CupertinoAlertActionSection> {
753744
public override Widget build(BuildContext context) {
754-
Debug.Log("AlertAction build");
755745
float devicePixelRatio = MediaQuery.of(context).devicePixelRatio;
756746

757747
List<Widget> interactiveButtons = new List<Widget>();
758748
for (int i = 0; i < this.widget.children.Count; i += 1) {
759-
interactiveButtons.Add(new _PressableActionButton(
749+
interactiveButtons.Add(new _PressableActionSheetActionButton(
760750
child: this.widget.children[i]
761751
)
762752
);
@@ -775,14 +765,79 @@ public override Widget build(BuildContext context) {
775765
}
776766
}
777767

768+
class _PressableActionSheetActionButton : StatefulWidget {
769+
public _PressableActionSheetActionButton(
770+
Widget child
771+
) {
772+
this.child = child;
773+
}
774+
775+
public readonly Widget child;
776+
777+
public override State createState() {
778+
return new _PressableActionSheetActionButtonState();
779+
}
780+
}
781+
782+
class _PressableActionSheetActionButtonState : State<_PressableActionSheetActionButton> {
783+
bool _isPressed = false;
784+
785+
public override Widget build(BuildContext context) {
786+
return new _ActionSheetActionButtonParentDataWidget(
787+
isPressed: this._isPressed,
788+
child: new GestureDetector(
789+
behavior: HitTestBehavior.opaque,
790+
onTapDown: (TapDownDetails details) => this.setState(() => { this._isPressed = true; }),
791+
onTapUp: (TapUpDetails details) => this.setState(() => { this._isPressed = false; }),
792+
onTapCancel: () => this.setState(() => this._isPressed = false),
793+
child: this.widget.child
794+
)
795+
);
796+
}
797+
}
798+
799+
class _ActionSheetActionButtonParentDataWidget : ParentDataWidget<_CupertinoAlertActionsRenderWidget> {
800+
public _ActionSheetActionButtonParentDataWidget(
801+
Widget child,
802+
bool isPressed = false,
803+
Key key = null
804+
) : base(key: key, child: child) {
805+
this.isPressed = isPressed;
806+
}
807+
808+
public readonly bool isPressed;
809+
810+
public override void applyParentData(RenderObject renderObject) {
811+
D.assert(renderObject.parentData is _ActionSheetActionButtonParentData);
812+
_ActionSheetActionButtonParentData parentData =
813+
renderObject.parentData as _ActionSheetActionButtonParentData;
814+
if (parentData.isPressed != this.isPressed) {
815+
parentData.isPressed = this.isPressed;
816+
AbstractNodeMixinDiagnosticableTree targetParent = renderObject.parent;
817+
if (targetParent is RenderObject) {
818+
((RenderObject) targetParent).markNeedsPaint();
819+
}
820+
}
821+
}
822+
}
823+
824+
class _ActionSheetActionButtonParentData : MultiChildLayoutParentData {
825+
public _ActionSheetActionButtonParentData(
826+
bool isPressed = false
827+
) {
828+
this.isPressed = isPressed;
829+
}
830+
831+
public bool isPressed;
832+
}
833+
778834
class _CupertinoAlertActionsRenderWidget : MultiChildRenderObjectWidget {
779835
public _CupertinoAlertActionsRenderWidget(
780836
List<Widget> actionButtons,
781837
Key key = null,
782838
float dividerThickness = 0.0f,
783839
bool hasCancelButton = false
784840
) : base(key: key, children: actionButtons) {
785-
Debug.Log("AlertActionRenderWidget build");
786841
this._dividerThickness = dividerThickness;
787842
this._hasCancelButton = hasCancelButton;
788843
}
@@ -812,8 +867,7 @@ public _RenderCupertinoAlertActions(
812867
) {
813868
this._dividerThickness = dividerThickness;
814869
this._hasCancelButton = hasCancelButton;
815-
this.addAll(children);
816-
Debug.Log("_RenderCupertinoAlertActions");
870+
this.addAll(children ?? new List<RenderBox>());
817871
}
818872

819873
public float dividerThickness {
@@ -861,8 +915,8 @@ public bool hasCancelButton {
861915
};
862916

863917
public override void setupParentData(RenderObject child) {
864-
if (!(child.parentData is _ActionButtonParentData)) {
865-
child.parentData = new _ActionButtonParentData();
918+
if (!(child.parentData is _ActionSheetActionButtonParentData)) {
919+
child.parentData = new _ActionSheetActionButtonParentData();
866920
}
867921
}
868922

@@ -984,13 +1038,15 @@ void _drawButtonBackgroundsAndDividersStacked(Canvas canvas, Offset offset) {
9841038
RenderBox child = this.firstChild;
9851039
RenderBox prevChild = null;
9861040
while (child != null) {
987-
D.assert(child.parentData is _ActionButtonParentData);
988-
_ActionButtonParentData currentButtonParentData = child.parentData as _ActionButtonParentData;
1041+
D.assert(child.parentData is _ActionSheetActionButtonParentData);
1042+
_ActionSheetActionButtonParentData currentButtonParentData =
1043+
child.parentData as _ActionSheetActionButtonParentData;
9891044
bool isButtonPressed = currentButtonParentData.isPressed;
9901045
bool isPrevButtonPressed = false;
9911046
if (prevChild != null) {
992-
D.assert(prevChild.parentData is _ActionButtonParentData);
993-
_ActionButtonParentData previousButtonParentData = prevChild.parentData as _ActionButtonParentData;
1047+
D.assert(prevChild.parentData is _ActionSheetActionButtonParentData);
1048+
_ActionSheetActionButtonParentData previousButtonParentData =
1049+
prevChild.parentData as _ActionSheetActionButtonParentData;
9941050
isPrevButtonPressed = previousButtonParentData.isPressed;
9951051
}
9961052

Runtime/cupertino/button.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212

1313
namespace Unity.UIWidgets.cupertino {
1414
public class CupertinoButtonUtils {
15-
public static Color _kDisabledBackground = new Color(0xFFA9A9A9);
16-
public static Color _kDisabledForeground = new Color(0xFFD1D1D1);
17-
public static EdgeInsets _kButtonPadding = EdgeInsets.all(16.0f);
18-
public static EdgeInsets _kBackgroundButtonPadding = EdgeInsets.symmetric(vertical: 14.0f, horizontal: 64.0f);
15+
public static readonly Color _kDisabledBackground = new Color(0xFFA9A9A9);
16+
public static readonly Color _kDisabledForeground = new Color(0xFFD1D1D1);
17+
public static readonly EdgeInsets _kButtonPadding = EdgeInsets.all(16.0f);
18+
public static readonly EdgeInsets _kBackgroundButtonPadding = EdgeInsets.symmetric(vertical: 14.0f, horizontal: 64.0f);
1919
}
2020

2121
public class CupertinoButton : StatefulWidget {

Runtime/cupertino/colors.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,24 @@
22

33
namespace Unity.UIWidgets.cupertino {
44
public class CupertinoColors {
5-
public static Color activeBlue = new Color(0xFF007AFF);
5+
public static readonly Color activeBlue = new Color(0xFF007AFF);
66

7-
public static Color activeGreen = new Color(0xFF4CD964);
7+
public static readonly Color activeGreen = new Color(0xFF4CD964);
88

9-
public static Color activeOrange = new Color(0xFFFF9500);
9+
public static readonly Color activeOrange = new Color(0xFFFF9500);
1010

11-
public static Color white = new Color(0xFFFFFFFF);
11+
public static readonly Color white = new Color(0xFFFFFFFF);
1212

13-
public static Color black = new Color(0xFF000000);
13+
public static readonly Color black = new Color(0xFF000000);
1414

15-
public static Color lightBackgroundGray = new Color(0xFFE5E5EA);
15+
public static readonly Color lightBackgroundGray = new Color(0xFFE5E5EA);
1616

17-
public static Color extraLightBackgroundGray = new Color(0xFFEFEFF4);
17+
public static readonly Color extraLightBackgroundGray = new Color(0xFFEFEFF4);
1818

19-
public static Color darkBackgroundGray = new Color(0xFF171717);
19+
public static readonly Color darkBackgroundGray = new Color(0xFF171717);
2020

21-
public static Color inactiveGray = new Color(0xFF8E8E93);
21+
public static readonly Color inactiveGray = new Color(0xFF8E8E93);
2222

23-
public static Color destructiveRed = new Color(0xFFFF3B30);
23+
public static readonly Color destructiveRed = new Color(0xFFFF3B30);
2424
}
2525
}

0 commit comments

Comments
 (0)