-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Issue10530.cs
159 lines (123 loc) · 3.38 KB
/
Issue10530.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
using System.Collections.Generic;
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;
#if UITEST
using Xamarin.Forms.Core.UITests;
using Xamarin.UITest;
using NUnit.Framework;
#endif
namespace Xamarin.Forms.Controls.Issues
{
#if UITEST
[Category(UITestCategories.SwipeView)]
#endif
[Preserve(AllMembers = true)]
[Issue(IssueTracker.Github, 10530, "[Bug] Swipe View Null Reference Exception while trying to change visibility of swipe item", PlatformAffected.Android)]
public class Issue10530 : TestContentPage
{
public Issue10530()
{
Title = "Issue 10530";
var vm = new Issue10530ViewModel();
BindingContext = vm;
var layout = new StackLayout();
var swipeView = new SwipeView();
var swipeViewContent = new Grid
{
BackgroundColor = Color.LightGray,
HeightRequest = 60
};
var infoLabel = new Label
{
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.Center
};
infoLabel.SetBinding(Label.TextProperty, "Item.Text");
swipeViewContent.Children.Add(infoLabel);
swipeView.Content = swipeViewContent;
var swipeItemView = new SwipeItemView();
swipeItemView.SetBinding(IsVisibleProperty, "Item.RetryAvailable");
var swipeItemContent = new Grid
{
BackgroundColor = Color.Orange,
WidthRequest = 100
};
var swipeItemLabel = new Label
{
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.Center,
Text = "Retry",
TextColor = Color.White
};
swipeItemContent.Children.Add(swipeItemLabel);
swipeItemView.Content = swipeItemContent;
swipeView.LeftItems = new SwipeItems { swipeItemView };
layout.Children.Add(swipeView);
var changeButton = new Button
{
Text = "Update Item RetryAvailable"
};
layout.Children.Add(changeButton);
Content = layout;
swipeItemView.Invoked += (sender, args) =>
{
vm.MakeRetryInvisibleCommand.Execute(vm.Item);
};
changeButton.Clicked += (sender, args) =>
{
var item = vm.Item;
if (item.RetryAvailable)
vm.MakeRetryInvisibleCommand.Execute(vm.Item);
else
vm.MakeRetryVisibleCommand.Execute(vm.Item);
};
vm.MakeRetryVisibleCommand.Execute(vm.Item);
}
protected override void Init()
{
#if APP
Device.SetFlags(new List<string>(Device.Flags ?? new List<string>()) { "SwipeView_Experimental" });
#endif
}
}
[Preserve(AllMembers = true)]
public class Issue10530Item : BindableObject
{
bool _retryAvailable;
public string Text { get; set; }
public bool RetryAvailable
{
get => _retryAvailable;
set
{
_retryAvailable = value;
OnPropertyChanged();
}
}
}
[Preserve(AllMembers = true)]
public class Issue10530ViewModel : BindableObject
{
public Issue10530ViewModel()
{
LoadItem();
MakeRetryInvisibleCommand = new Command<Issue10530Item>((item) => MakeRetryInvisible(item));
MakeRetryVisibleCommand = new Command<Issue10530Item>((item) => MakeRetryVisible(item));
}
public Issue10530Item Item { get; set; }
public Command<Issue10530Item> MakeRetryInvisibleCommand { get; set; }
public Command<Issue10530Item> MakeRetryVisibleCommand { get; set; }
void LoadItem()
{
Item = new Issue10530Item { Text = "Item 1" };
}
void MakeRetryVisible(Issue10530Item item)
{
item.RetryAvailable = true;
}
void MakeRetryInvisible(Issue10530Item item)
{
item.RetryAvailable = false;
}
}
}