This repository was archived by the owner on May 1, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 8 files changed +49
-66
lines changed Expand file tree Collapse file tree 8 files changed +49
-66
lines changed Original file line number Diff line number Diff line change 15
15
16
16
namespace Xamarin . CommunityToolkit . UI . Views
17
17
{
18
- class SnackBar
18
+ partial class SnackBar
19
19
{
20
- internal async ValueTask Show ( VisualElement sender , SnackBarOptions arguments )
20
+ internal partial async ValueTask Show ( VisualElement sender , SnackBarOptions arguments )
21
21
{
22
22
var renderer = await GetRendererWithRetries ( sender ) ?? throw new ArgumentException ( "Provided VisualElement cannot be parent to SnackBar" , nameof ( sender ) ) ;
23
23
var snackBar = AndroidSnackBar . Make ( renderer . View , arguments . MessageOptions . Message , ( int ) arguments . Duration . TotalMilliseconds ) ;
@@ -87,20 +87,7 @@ internal async ValueTask Show(VisualElement sender, SnackBarOptions arguments)
87
87
88
88
foreach ( var action in arguments . Actions )
89
89
{
90
- snackBar . SetAction ( action . Text , async _ =>
91
- {
92
- try
93
- {
94
- if ( action . Action != null )
95
- await action . Action ( ) ;
96
-
97
- arguments . SetResult ( true ) ;
98
- }
99
- catch ( Exception ex )
100
- {
101
- arguments . SetException ( ex ) ;
102
- }
103
- } ) ;
90
+ snackBar . SetAction ( action . Text , async _ => await OnActionClick ( action , arguments ) . ConfigureAwait ( false ) ) ;
104
91
if ( action . ForegroundColor != Forms . Color . Default )
105
92
{
106
93
snackBar . SetActionTextColor ( action . ForegroundColor . ToAndroid ( ) ) ;
Original file line number Diff line number Diff line change 11
11
12
12
namespace Xamarin . CommunityToolkit . UI . Views
13
13
{
14
- class SnackBar
14
+ partial class SnackBar
15
15
{
16
16
Timer ? snackBarTimer ;
17
17
18
- public ValueTask Show ( VisualElement visualElement , SnackBarOptions arguments )
18
+ internal partial ValueTask Show ( VisualElement visualElement , SnackBarOptions arguments )
19
19
{
20
20
var mainWindow = ( Platform . GetRenderer ( visualElement ) . Container . Child as Forms . Platform . GTK . Controls . Page ) ? . Children [ 0 ] as VBox ;
21
21
var snackBarLayout = GetSnackBarLayout ( mainWindow , arguments ) ;
@@ -56,20 +56,10 @@ HBox GetSnackBarLayout(Container? container, SnackBarOptions arguments)
56
56
button . ModifyBg ( StateType . Normal , action . BackgroundColor . ToGtkColor ( ) ) ;
57
57
button . ModifyFg ( StateType . Normal , action . ForegroundColor . ToGtkColor ( ) ) ;
58
58
59
- button . Clicked += async ( sender , e ) =>
59
+ button . Clicked += async ( _ , _ ) =>
60
60
{
61
61
snackBarTimer ? . Stop ( ) ;
62
- try
63
- {
64
- if ( action . Action != null )
65
- await action . Action ( ) ;
66
-
67
- arguments . SetResult ( true ) ;
68
- }
69
- catch ( Exception ex )
70
- {
71
- arguments . SetException ( ex ) ;
72
- }
62
+ await OnActionClick ( action , arguments ) . ConfigureAwait ( false ) ;
73
63
container ? . Remove ( snackBarLayout ) ;
74
64
} ;
75
65
Original file line number Diff line number Diff line change 15
15
16
16
namespace Xamarin . CommunityToolkit . UI . Views
17
17
{
18
- class SnackBar
18
+ partial class SnackBar
19
19
{
20
- internal ValueTask Show ( VisualElement sender , SnackBarOptions arguments )
20
+ internal partial ValueTask Show ( VisualElement sender , SnackBarOptions arguments )
21
21
{
22
22
var snackBar = NativeSnackBar . MakeSnackBar ( arguments . MessageOptions . Message )
23
23
. SetDuration ( arguments . Duration )
@@ -123,17 +123,7 @@ internal ValueTask Show(VisualElement sender, SnackBarOptions arguments)
123
123
actionButton . SetAction ( async ( ) =>
124
124
{
125
125
snackBar . Dismiss ( ) ;
126
- try
127
- {
128
- if ( action . Action != null )
129
- await action . Action ( ) ;
130
-
131
- arguments . SetResult ( true ) ;
132
- }
133
- catch ( Exception ex )
134
- {
135
- arguments . SetException ( ex ) ;
136
- }
126
+ await OnActionClick ( action , arguments ) . ConfigureAwait ( false ) ;
137
127
} ) ;
138
128
139
129
snackBar . Actions . Add ( actionButton ) ;
Original file line number Diff line number Diff line change 5
5
6
6
namespace Xamarin . CommunityToolkit . UI . Views
7
7
{
8
- class SnackBar
8
+ partial class SnackBar
9
9
{
10
- internal ValueTask Show ( VisualElement sender , SnackBarOptions arguments ) => throw new PlatformNotSupportedException ( ) ;
10
+ internal partial ValueTask Show ( VisualElement sender , SnackBarOptions arguments ) => throw new PlatformNotSupportedException ( ) ;
11
11
}
12
12
}
Original file line number Diff line number Diff line change
1
+ using System ;
2
+ using System . Threading . Tasks ;
3
+ using Xamarin . CommunityToolkit . UI . Views . Options ;
4
+ using Xamarin . Forms ;
5
+
6
+ namespace Xamarin . CommunityToolkit . UI . Views
7
+ {
8
+ partial class SnackBar
9
+ {
10
+ internal partial ValueTask Show ( VisualElement sender , SnackBarOptions arguments ) ;
11
+
12
+ async Task OnActionClick ( SnackBarActionOptions action , SnackBarOptions arguments )
13
+ {
14
+ try
15
+ {
16
+ if ( action . Action != null )
17
+ await action . Action ( ) ;
18
+
19
+ arguments . SetResult ( true ) ;
20
+ }
21
+ catch ( Exception ex )
22
+ {
23
+ arguments . SetException ( ex ) ;
24
+ }
25
+ }
26
+ }
27
+ }
Original file line number Diff line number Diff line change 6
6
7
7
namespace Xamarin . CommunityToolkit . UI . Views
8
8
{
9
- class SnackBar
9
+ partial class SnackBar
10
10
{
11
- internal ValueTask Show ( Forms . VisualElement sender , SnackBarOptions arguments )
11
+ internal partial ValueTask Show ( Forms . VisualElement sender , SnackBarOptions arguments )
12
12
{
13
13
var snackBarDialog =
14
14
Forms . Platform . Tizen . Native . Dialog . CreateDialog ( Forms . Forms . NativeParent ,
@@ -25,25 +25,14 @@ internal ValueTask Show(Forms.VisualElement sender, SnackBarOptions arguments)
25
25
{
26
26
var ok = new EButton ( snackBarDialog ) { Text = action . Text } ;
27
27
snackBarDialog . NeutralButton = ok ;
28
- ok . Clicked += async ( s , evt ) =>
28
+ ok . Clicked += async ( _ , _ ) =>
29
29
{
30
30
snackBarDialog . Dismiss ( ) ;
31
- try
32
- {
33
- if ( action . Action != null )
34
- await action . Action ( ) ;
35
-
36
- arguments . SetResult ( true ) ;
37
- }
38
- catch ( Exception ex )
39
- {
40
- arguments . SetException ( ex ) ;
41
- }
42
- } ;
31
+ await OnActionClick ( action , arguments ) . ConfigureAwait ( false ) ; } ;
43
32
}
44
33
45
- snackBarDialog . TimedOut += ( s , evt ) => DismissSnackBar ( ) ;
46
- snackBarDialog . BackButtonPressed += ( s , evt ) => DismissSnackBar ( ) ;
34
+ snackBarDialog . TimedOut += ( _ , _ ) => DismissSnackBar ( ) ;
35
+ snackBarDialog . BackButtonPressed += ( _ , _ ) => DismissSnackBar ( ) ;
47
36
snackBarDialog . Show ( ) ;
48
37
49
38
return default ;
Original file line number Diff line number Diff line change 9
9
10
10
namespace Xamarin . CommunityToolkit . UI . Views
11
11
{
12
- class SnackBar
12
+ partial class SnackBar
13
13
{
14
14
DispatcherTimer ? snackBarTimer ;
15
15
@@ -35,7 +35,7 @@ class SnackBar
35
35
return null ;
36
36
}
37
37
38
- internal ValueTask Show ( Forms . VisualElement visualElement , SnackBarOptions arguments )
38
+ internal partial ValueTask Show ( Forms . VisualElement visualElement , SnackBarOptions arguments )
39
39
{
40
40
var snackBarLayout = new SnackBarLayout ( arguments ) ;
41
41
var pageControl = Platform . GetRenderer ( visualElement ) . ContainerElement . Parent ;
Original file line number Diff line number Diff line change 11
11
12
12
namespace Xamarin . CommunityToolkit . UI . Views
13
13
{
14
- class SnackBar
14
+ partial class SnackBar
15
15
{
16
16
Timer ? snackBarTimer ;
17
17
18
- internal ValueTask Show ( Forms . VisualElement visualElement , SnackBarOptions arguments )
18
+ internal partial ValueTask Show ( Forms . VisualElement visualElement , SnackBarOptions arguments )
19
19
{
20
20
var formsAppBar = System . Windows . Application . Current . MainWindow . FindChild < FormsAppBar > ( "PART_BottomAppBar" ) ;
21
21
var currentContent = formsAppBar . Content ;
You can’t perform that action at this time.
0 commit comments