This repository was archived by the owner on May 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathSwipeViewCoreGalleryPage.cs
118 lines (96 loc) · 3.35 KB
/
SwipeViewCoreGalleryPage.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
using Xamarin.Forms.CustomAttributes;
namespace Xamarin.Forms.Controls
{
internal class SwipeViewCoreGalleryPage : CoreGalleryPage<SwipeView>
{
protected override bool SupportsFocus
{
get { return false; }
}
protected override bool SupportsScroll
{
get { return false; }
}
protected override void InitializeElement(SwipeView element)
{
element.HeightRequest = 60;
element.BackgroundColor = Color.LightGray;
element.Content = GetSwipeContent(SwipeDirection.Left);
element.LeftItems = GetRevealSwipeItems();
element.RightItems = GetExecuteSwipeItems();
}
protected override void Build(StackLayout stackLayout)
{
base.Build(stackLayout);
var rightItemsContainer = new ValueViewContainer<SwipeView>(Test.SwipeView.RightItems, new SwipeView { RightItems = GetRevealSwipeItems(), Content = GetSwipeContent(SwipeDirection.Right), HeightRequest = 60, BackgroundColor = Color.LightPink }, "RightItems", value => value.ToString());
var topItemsContainer = new ValueViewContainer<SwipeView>(Test.SwipeView.TopItems, new SwipeView { TopItems = GetRevealSwipeItems(), Content = GetSwipeContent(SwipeDirection.Up), HeightRequest = 60, BackgroundColor = Color.LightSkyBlue }, "TopItems", value => value.ToString());
var bottomItemsContainer = new ValueViewContainer<SwipeView>(Test.SwipeView.BottomItems, new SwipeView { BottomItems = GetRevealSwipeItems(), Content = GetSwipeContent(SwipeDirection.Down), HeightRequest = 60, BackgroundColor = Color.LightGray }, "BottomItems", value => value.ToString());
Add(rightItemsContainer);
Add(topItemsContainer);
Add(bottomItemsContainer);
}
internal SwipeItems GetRevealSwipeItems()
{
var addSwipeItem = new SwipeItem { BackgroundColor = Color.Green, Text = "Add", IconImageSource = "coffee.png" };
addSwipeItem.Invoked += (sender, e) =>
{
DisplayAlert("SwipeView", "Add Invoked", "OK");
};
var modifySwipeItem = new SwipeItem { BackgroundColor = Color.Orange, Text = "Modify", IconImageSource = "calculator.png" };
modifySwipeItem.Invoked += (sender, e) =>
{
DisplayAlert("SwipeView", "Modify Invoked", "OK");
};
var swipeItems = new SwipeItems
{
addSwipeItem,
modifySwipeItem
};
swipeItems.Mode = SwipeMode.Reveal;
return swipeItems;
}
internal SwipeItems GetExecuteSwipeItems()
{
var deleteSwipeItem = new SwipeItem { BackgroundColor = Color.Red, Text = "Delete", IconImageSource = "coffee.png" };
deleteSwipeItem.Invoked += (sender, e) =>
{
DisplayAlert("SwipeView", "Delete Invoked", "OK");
};
var swipeItems = new SwipeItems
{
deleteSwipeItem
};
swipeItems.Mode = SwipeMode.Execute;
return swipeItems;
}
internal Grid GetSwipeContent(SwipeDirection swipeDirection)
{
var content = new Grid
{
BackgroundColor = Color.LightGoldenrodYellow
};
var info = new Label
{
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.Center
};
switch (swipeDirection)
{
case SwipeDirection.Down:
info.Text = "Swipe to the Top";
break;
case SwipeDirection.Left:
info.Text = "Swipe to the Right";
break;
case SwipeDirection.Right:
info.Text = "Swipe to the Left";
break;
case SwipeDirection.Up:
info.Text = "Swipe to the Bottom";
break;
}
content.Children.Add(info);
return content;
}
}
}