5
5
using Unity . UIWidgets . rendering ;
6
6
using Unity . UIWidgets . ui ;
7
7
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 ;
12
8
using TextStyle = Unity . UIWidgets . painting . TextStyle ;
13
9
14
10
namespace Unity . UIWidgets . cupertino {
15
11
class CupertinoActionSheetUtils {
16
- public static TextStyle _kActionSheetActionStyle = new TextStyle (
12
+ public static readonly TextStyle _kActionSheetActionStyle = new TextStyle (
17
13
// fontFamily: ".SF UI Text",
18
14
fontFamily : ".SF Pro Text" ,
19
15
inherit : false ,
@@ -23,7 +19,7 @@ class CupertinoActionSheetUtils {
23
19
textBaseline : TextBaseline . alphabetic
24
20
) ;
25
21
26
- public static TextStyle _kActionSheetContentStyle = new TextStyle (
22
+ public static readonly TextStyle _kActionSheetContentStyle = new TextStyle (
27
23
// fontFamily: ".SF UI Text",
28
24
fontFamily : ".SF Pro Text" ,
29
25
inherit : false ,
@@ -33,16 +29,16 @@ class CupertinoActionSheetUtils {
33
29
textBaseline : TextBaseline . alphabetic
34
30
) ;
35
31
36
- public static BoxDecoration _kAlertBlurOverlayDecoration = new BoxDecoration (
32
+ public static readonly BoxDecoration _kAlertBlurOverlayDecoration = new BoxDecoration (
37
33
color : CupertinoColors . white ,
38
34
backgroundBlendMode : BlendMode . overlay
39
35
) ;
40
36
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 ) ;
46
42
47
43
public const float _kBlurAmount = 20.0f ;
48
44
public const float _kEdgeHorizontalPadding = 8.0f ;
@@ -109,8 +105,6 @@ Widget _buildActions() {
109
105
return new Container ( height : 0.0f ) ;
110
106
}
111
107
112
- Debug . Log ( "_buildActions" ) ;
113
-
114
108
return new Container (
115
109
child : new _CupertinoAlertActionSection (
116
110
children : this . actions ,
@@ -193,7 +187,6 @@ public CupertinoActionSheetAction(
193
187
bool isDefaultAction = false ,
194
188
bool isDestructiveAction = false
195
189
) {
196
- Debug . Log ( "constructor" ) ;
197
190
D . assert ( child != null ) ;
198
191
D . assert ( onPressed != null ) ;
199
192
this . child = child ;
@@ -208,7 +201,6 @@ public CupertinoActionSheetAction(
208
201
public readonly Widget child ;
209
202
210
203
public override Widget build ( BuildContext context ) {
211
- Debug . Log ( "build" ) ;
212
204
TextStyle style = CupertinoActionSheetUtils . _kActionSheetActionStyle ;
213
205
214
206
if ( this . isDefaultAction ) {
@@ -219,7 +211,6 @@ public override Widget build(BuildContext context) {
219
211
style = style . copyWith ( color : CupertinoColors . destructiveRed ) ;
220
212
}
221
213
222
-
223
214
return new GestureDetector (
224
215
onTap : ( ) => this . onPressed ( ) ,
225
216
behavior : HitTestBehavior . opaque ,
@@ -353,11 +344,11 @@ public override void mount(Element parent, object newSlot) {
353
344
}
354
345
355
346
protected override void insertChildRenderObject ( RenderObject child , object slot ) {
356
- this . _placeChildInSlot ( child , ( _AlertSections ) slot ) ;
347
+ this . _placeChildInSlot ( child , slot ) ;
357
348
}
358
349
359
350
protected override void moveChildRenderObject ( RenderObject child , object slot ) {
360
- this . _placeChildInSlot ( child , ( _AlertSections ) slot ) ;
351
+ this . _placeChildInSlot ( child , slot ) ;
361
352
}
362
353
363
354
public override void update ( Widget newWidget ) {
@@ -388,8 +379,8 @@ protected override void removeChildRenderObject(RenderObject child) {
388
379
}
389
380
}
390
381
391
- void _placeChildInSlot ( RenderObject child , _AlertSections slot ) {
392
- switch ( slot ) {
382
+ void _placeChildInSlot ( RenderObject child , object slot ) {
383
+ switch ( ( _AlertSections ) slot ) {
393
384
case _AlertSections . contentSection :
394
385
this . renderObject . contentSection = child as RenderBox ;
395
386
break ;
@@ -751,12 +742,11 @@ public override State createState() {
751
742
752
743
class _CupertinoAlertActionSectionState : State < _CupertinoAlertActionSection > {
753
744
public override Widget build ( BuildContext context ) {
754
- Debug . Log ( "AlertAction build" ) ;
755
745
float devicePixelRatio = MediaQuery . of ( context ) . devicePixelRatio ;
756
746
757
747
List < Widget > interactiveButtons = new List < Widget > ( ) ;
758
748
for ( int i = 0 ; i < this . widget . children . Count ; i += 1 ) {
759
- interactiveButtons . Add ( new _PressableActionButton (
749
+ interactiveButtons . Add ( new _PressableActionSheetActionButton (
760
750
child : this . widget . children [ i ]
761
751
)
762
752
) ;
@@ -775,14 +765,79 @@ public override Widget build(BuildContext context) {
775
765
}
776
766
}
777
767
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
+
778
834
class _CupertinoAlertActionsRenderWidget : MultiChildRenderObjectWidget {
779
835
public _CupertinoAlertActionsRenderWidget (
780
836
List < Widget > actionButtons ,
781
837
Key key = null ,
782
838
float dividerThickness = 0.0f ,
783
839
bool hasCancelButton = false
784
840
) : base ( key : key , children : actionButtons ) {
785
- Debug . Log ( "AlertActionRenderWidget build" ) ;
786
841
this . _dividerThickness = dividerThickness ;
787
842
this . _hasCancelButton = hasCancelButton ;
788
843
}
@@ -812,8 +867,7 @@ public _RenderCupertinoAlertActions(
812
867
) {
813
868
this . _dividerThickness = dividerThickness ;
814
869
this . _hasCancelButton = hasCancelButton ;
815
- this . addAll ( children ) ;
816
- Debug . Log ( "_RenderCupertinoAlertActions" ) ;
870
+ this . addAll ( children ?? new List < RenderBox > ( ) ) ;
817
871
}
818
872
819
873
public float dividerThickness {
@@ -861,8 +915,8 @@ public bool hasCancelButton {
861
915
} ;
862
916
863
917
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 ( ) ;
866
920
}
867
921
}
868
922
@@ -984,13 +1038,15 @@ void _drawButtonBackgroundsAndDividersStacked(Canvas canvas, Offset offset) {
984
1038
RenderBox child = this . firstChild ;
985
1039
RenderBox prevChild = null ;
986
1040
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 ;
989
1044
bool isButtonPressed = currentButtonParentData . isPressed ;
990
1045
bool isPrevButtonPressed = false ;
991
1046
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 ;
994
1050
isPrevButtonPressed = previousButtonParentData . isPressed ;
995
1051
}
996
1052
0 commit comments