Skip to content
This repository was archived by the owner on May 1, 2024. It is now read-only.

Commit 02e0397

Browse files
committed
Added Popover controls for Android, UWP and partially for iOS. Rebased branch on v4.6.0
1 parent 3b8f14b commit 02e0397

File tree

15 files changed

+732
-81
lines changed

15 files changed

+732
-81
lines changed

Xamarin.Forms.Controls/GalleryPages/PopoverGallery.cs renamed to Xamarin.Forms.Controls/GalleryPages/PopupGalleries/PopoverGallery.cs

Lines changed: 69 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public PopoverGallery ()
1818
layout.RowDefinitions.Add(new RowDefinition { Height = GridLength.Star });
1919
layout.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });
2020

21-
var top = new StackLayout { Children = { PopoverWithLabel(), PopoverWithLayout(), TermsOfServicePopup() } };
21+
var top = new StackLayout { Children = { PopoverWithLabel(), PopoverWithLayout(), PopoverWithCloseButtonLayout(), PopoverWithCloseButtonLayoutNoSize(), TermsOfServicePopup() } };
2222
Grid.SetRow(top, 0);
2323

2424
// Putting one of the buttons on the bottom so if we're on the iPad we can see the little popover arrows working
@@ -31,33 +31,31 @@ public PopoverGallery ()
3131
Content = layout;
3232
}
3333

34-
Button CreateButton(string text, string automationId, View content)
34+
Button CreateButton(string text, string automationId, View content, Color color, bool isAnchored = false, Size size = default(Size), Color border = default(Color))
3535
{
3636
var button = new Button { Text = text, AutomationId = automationId };
3737
button.Clicked += async (sender, e) =>
3838
{
39-
var popover = new Popup(content, text, anchor: button);
39+
var popover = isAnchored ?
40+
new Popup(content) { Anchor = button, Size = size, Color = color, BorderColor = border } :
41+
new Popup(content) { Size = size, Color = color, BorderColor = border };
4042

4143
var result = await Navigation.ShowPopup(popover);
4244

43-
await DisplayAlert(ResultTitle, result.ToString(), DismissText);
45+
await DisplayAlert(ResultTitle, "Popup Dismissed", DismissText);
4446
};
4547

4648
return button;
4749
}
4850

4951
Button PopoverWithLabel()
5052
{
51-
return CreateButton("Popup with Label", "testPopupWithLabel",
52-
new Label
53-
{
54-
Text = "This is just a Label inside of a Popup. This is a basic popup which takes a View, and is only light-dismissable.",
55-
LineBreakMode = LineBreakMode.WordWrap,
56-
HorizontalTextAlignment = TextAlignment.Center,
57-
VerticalTextAlignment = TextAlignment.Center,
58-
HorizontalOptions = LayoutOptions.Fill,
59-
VerticalOptions = LayoutOptions.Fill
60-
});
53+
var button = new Button
54+
{
55+
Text = "Label Popovers"
56+
};
57+
button.Clicked += async (s, e) => await Navigation.PushAsync(new PopupLabelGallery());
58+
return button;
6159
}
6260

6361
Button PopoverWithLayout()
@@ -73,7 +71,51 @@ Button PopoverWithLayout()
7371
}
7472
};
7573

76-
return CreateButton("Popup with Layout", "testPopupWithLayout", content);
74+
return CreateButton("Popup with Layout", "testPopupWithLayout", content, Color.White, size: new Size(800,800));
75+
}
76+
77+
Button PopoverWithCloseButtonLayout()
78+
{
79+
var content = new Grid
80+
{
81+
Margin = new Thickness(20),
82+
Padding = new Thickness(20),
83+
Children =
84+
{
85+
new Label { LineBreakMode = LineBreakMode.WordWrap, Text = Placeholder, BackgroundColor = Color.White },
86+
new Frame
87+
{
88+
HorizontalOptions = new LayoutOptions(LayoutAlignment.Center, true),
89+
VerticalOptions = new LayoutOptions(LayoutAlignment.Start, true),
90+
Margin = new Thickness(0, -30, 0, 0),
91+
BackgroundColor = Color.Orange
92+
}
93+
}
94+
};
95+
96+
return CreateButton("Popup with Close Button Layout", "testPopupWithCloseButtonLayout", content, Color.Transparent, size: new Size(500,500), border: Color.Transparent);
97+
}
98+
99+
Button PopoverWithCloseButtonLayoutNoSize()
100+
{
101+
var content = new Grid
102+
{
103+
Margin = new Thickness(20),
104+
Padding = new Thickness(20),
105+
Children =
106+
{
107+
new Label { LineBreakMode = LineBreakMode.WordWrap, Text = Placeholder, BackgroundColor = Color.White },
108+
new Frame
109+
{
110+
HorizontalOptions = new LayoutOptions(LayoutAlignment.Center, true),
111+
VerticalOptions = new LayoutOptions(LayoutAlignment.Start, true),
112+
Margin = new Thickness(0, -30, 0, 0),
113+
BackgroundColor = Color.Orange
114+
}
115+
}
116+
};
117+
118+
return CreateButton("Popup with Close Button Layout No Size", "testPopupWithCloseButtonLayout", content, Color.Transparent, border: Color.Transparent);
77119
}
78120

79121

@@ -84,7 +126,7 @@ Button PopoverWithDatePicker()
84126
button.Clicked += async (sender, e) =>
85127
{
86128
// Create a DateChooserPopup which uses DateChooserPopupControl as its content and is anchored to this button
87-
var popup = new DateChooserPopup(new DateChooserPopupControl(), "Select Date", button);
129+
var popup = new DateChooserPopup(new DateChooserPopupControl(), button);
88130

89131
// Show the popup and await the DateTime? result
90132
DateTime? result = await Navigation.ShowPopup(popup);
@@ -98,10 +140,11 @@ Button PopoverWithDatePicker()
98140

99141
class DateChooserPopup : Popup<DateTime?>
100142
{
101-
public DateChooserPopup(IPopupView<DateTime?> popupView, string title = null, View anchor = null)
102-
: base(popupView, title, false, anchor)
143+
public DateChooserPopup(View popupView, View anchor = null, Size size = default(Size))
103144
{
104-
// Note that this popup is not light-dismissable
145+
View = popupView;
146+
Anchor = anchor;
147+
Size = size;
105148
}
106149

107150
protected override DateTime? OnLightDismissed()
@@ -148,6 +191,7 @@ public DateChooserPopupControl()
148191
}
149192
}
150193

194+
// TODO - This does not work in UWP for some reason, it needs more investigation
151195
Button TermsOfServicePopup()
152196
{
153197
var button = new Button { Text = "Terms of Service Popup" };
@@ -160,13 +204,16 @@ Button TermsOfServicePopup()
160204
+ string.Concat(Enumerable.Repeat(Placeholder + "\n", 10))
161205
};
162206

163-
var scrollView = new ScrollView { Content = tos, Margin = new Thickness(20) };
207+
var scrollView = new ScrollView { Content = tos, Margin = new Thickness(20), HorizontalOptions = new LayoutOptions(LayoutAlignment.Center, true) };
208+
209+
164210

165-
// Create the popup, specifying the text for the buttons
166-
var tosPopup = new BinaryResultPopup(scrollView, "Terms of Service", anchor: button, affirmativeText: "Accept", negativeText: "Reject", size: new Size(400, 500));
167211

168212
button.Clicked += async (sender, args) =>
169213
{
214+
// Create the popup, specifying the text for the buttons
215+
var tosPopup = new BooleanPopup(scrollView, anchor: button, affirmativeText: "Accept", negativeText: "Reject", size: new Size(800, 400));
216+
170217
// Reset the popup in case we've already gotten a result from it
171218
tosPopup.Reset();
172219

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
namespace Xamarin.Forms.Controls
2+
{
3+
public class PopupLabelColorGallery : ContentPage
4+
{
5+
public PopupLabelColorGallery()
6+
{
7+
Content = new StackLayout
8+
{
9+
Children =
10+
{
11+
CreatePopupWithBackground(),
12+
CreatePopupWithBackgroundAndSize()
13+
}
14+
};
15+
}
16+
17+
private View CreatePopupWithBackgroundAndSize()
18+
{
19+
var button = new Button
20+
{
21+
Text = "Popup with Background and Size"
22+
};
23+
button.Clicked += async (s, e) =>
24+
{
25+
View label = new Label
26+
{
27+
Text = "This is just a Label inside of a Popup. This is a basic popup which takes a View, and is only light-dismissable.",
28+
LineBreakMode = LineBreakMode.WordWrap,
29+
HorizontalTextAlignment = TextAlignment.Center,
30+
VerticalTextAlignment = TextAlignment.Center,
31+
HorizontalOptions = LayoutOptions.CenterAndExpand,
32+
VerticalOptions = LayoutOptions.CenterAndExpand
33+
};
34+
35+
var popup = new Popup(label)
36+
{
37+
Size = new Size(600, 600),
38+
Color = Color.Green
39+
};
40+
41+
var result = await Navigation.ShowPopup(popup);
42+
};
43+
44+
return button;
45+
}
46+
47+
private Button CreatePopupWithBackground()
48+
{
49+
var button = new Button
50+
{
51+
Text = "Popup with Green Background"
52+
};
53+
button.Clicked += async (s, e) =>
54+
{
55+
View label = new Label
56+
{
57+
Text = "This is just a Label inside of a Popup. This is a basic popup which takes a View, and is only light-dismissable.",
58+
LineBreakMode = LineBreakMode.WordWrap,
59+
HorizontalTextAlignment = TextAlignment.Center,
60+
VerticalTextAlignment = TextAlignment.Center
61+
};
62+
63+
var popup = new Popup(label)
64+
{
65+
Color = Color.Green
66+
};
67+
var result = await Navigation.ShowPopup(popup);
68+
};
69+
70+
return button;
71+
}
72+
}
73+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using System;
2+
3+
namespace Xamarin.Forms.Controls
4+
{
5+
public class PopupLabelGallery : ContentPage
6+
{
7+
public PopupLabelGallery()
8+
{
9+
Content = new StackLayout
10+
{
11+
Children =
12+
{
13+
LayoutOptionsButton(),
14+
PopupLabelColorGallery()
15+
}
16+
};
17+
}
18+
19+
private View PopupLabelColorGallery()
20+
{
21+
var button = new Button
22+
{
23+
Text = "Label - Color"
24+
};
25+
button.Clicked += async (s, e) =>
26+
{
27+
await Navigation.PushAsync(new PopupLabelColorGallery());
28+
};
29+
return button;
30+
}
31+
32+
private Button LayoutOptionsButton()
33+
{
34+
var button = new Button
35+
{
36+
Text = "Label - Layout Options"
37+
};
38+
button.Clicked += async (s, e) =>
39+
{
40+
await Navigation.PushAsync(new PopupLabelLayoutOptionsGallery());
41+
};
42+
43+
return button;
44+
}
45+
}
46+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
namespace Xamarin.Forms.Controls
2+
{
3+
public class PopupLabelLayoutOptionsGallery : ContentPage
4+
{
5+
public PopupLabelLayoutOptionsGallery()
6+
{
7+
Content = new StackLayout
8+
{
9+
Children =
10+
{
11+
CreateLabelButton("Label - Centered", LayoutOptions.CenterAndExpand, LayoutOptions.CenterAndExpand),
12+
CreateLabelButton("Label - Top Centered", LayoutOptions.CenterAndExpand, LayoutOptions.StartAndExpand),
13+
CreateLabelButton("Label - Bottom Centered", LayoutOptions.CenterAndExpand, LayoutOptions.EndAndExpand),
14+
CreateLabelButton("Label - Right Centered", LayoutOptions.EndAndExpand, LayoutOptions.CenterAndExpand),
15+
CreateLabelButton("Label - Left Centered", LayoutOptions.StartAndExpand, LayoutOptions.CenterAndExpand),
16+
CreateLabelButton("Label - Top Left", LayoutOptions.StartAndExpand, LayoutOptions.StartAndExpand),
17+
CreateLabelButton("Label - Top Right", LayoutOptions.EndAndExpand, LayoutOptions.StartAndExpand),
18+
CreateLabelButton("Label - Bottom Left", LayoutOptions.StartAndExpand, LayoutOptions.EndAndExpand),
19+
CreateLabelButton("Label - Bottom Right", LayoutOptions.EndAndExpand, LayoutOptions.EndAndExpand),
20+
}
21+
};
22+
}
23+
24+
private Button CreateLabelButton(string label, LayoutOptions horizontalAlignment, LayoutOptions verticalAlignment)
25+
{
26+
var button = new Button
27+
{
28+
Text = label,
29+
};
30+
button.Clicked += async (s, e) =>
31+
{
32+
var popup = new Popup(BuildLabel(horizontalAlignment, verticalAlignment))
33+
{
34+
Size = new Size(700, 700)
35+
};
36+
var result = await Navigation.ShowPopup(popup);
37+
};
38+
39+
return button;
40+
}
41+
42+
private View BuildLabel(LayoutOptions horizontalAlignment, LayoutOptions verticalAlignment)
43+
{
44+
return new Label
45+
{
46+
Text = "This is just a Label inside of a Popup. This is a basic popup which takes a View, and is only light-dismissable.",
47+
LineBreakMode = LineBreakMode.WordWrap,
48+
WidthRequest = 100,
49+
HorizontalTextAlignment = TextAlignment.Center,
50+
VerticalTextAlignment = TextAlignment.Center,
51+
HorizontalOptions = horizontalAlignment,
52+
VerticalOptions = verticalAlignment
53+
};
54+
}
55+
}
56+
}

0 commit comments

Comments
 (0)