Skip to content
This repository was archived by the owner on Dec 28, 2023. It is now read-only.

Commit d2d2bd5

Browse files
committed
Add ContentPopup
1 parent 8b15584 commit d2d2bd5

6 files changed

Lines changed: 423 additions & 0 deletions

File tree

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
/*
2+
* Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
3+
*
4+
* Licensed under the Flora License, Version 1.1 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://floralicense.org/license/
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
using System;
18+
using Xamarin.Forms;
19+
using Xamarin.Forms.Platform.Tizen;
20+
using XForms = Xamarin.Forms.Forms;
21+
22+
[assembly: Dependency(typeof(Tizen.Wearable.CircularUI.Forms.Renderer.ContentPopupImplementation))]
23+
24+
namespace Tizen.Wearable.CircularUI.Forms.Renderer
25+
{
26+
public class ContentPopupImplementation : IContentPopup, IDisposable
27+
{
28+
View _content;
29+
StackLayout _contentView;
30+
ElmSharp.Popup _popUp;
31+
ElmSharp.EvasObject _nativeContent;
32+
bool _isDisposed;
33+
34+
public event EventHandler BackButtonPressed;
35+
36+
public ContentPopupImplementation()
37+
{
38+
_popUp = new ElmSharp.Popup(XForms.NativeParent);
39+
_popUp.Style = "circle";
40+
41+
_popUp.BackButtonPressed += BackButtonPressedHandler;
42+
_popUp.Dismissed += OnDismissed;
43+
44+
_contentView = new StackLayout();
45+
}
46+
47+
~ContentPopupImplementation()
48+
{
49+
Dispose(false);
50+
}
51+
52+
public void Dispose()
53+
{
54+
Dispose(true);
55+
GC.SuppressFinalize(this);
56+
}
57+
58+
protected virtual void Dispose(bool disposing)
59+
{
60+
if (_isDisposed)
61+
return;
62+
63+
if (disposing)
64+
{
65+
if (_nativeContent != null)
66+
{
67+
_nativeContent.Unrealize();
68+
_nativeContent = null;
69+
}
70+
71+
if (_popUp != null)
72+
{
73+
_popUp.BackButtonPressed -= BackButtonPressedHandler;
74+
_popUp.Dismissed -= OnDismissed;
75+
_popUp.Unrealize();
76+
_popUp = null;
77+
}
78+
}
79+
80+
_isDisposed = true;
81+
}
82+
83+
public View Content
84+
{
85+
get
86+
{
87+
return _content;
88+
}
89+
set
90+
{
91+
_content = value;
92+
UpdateContent();
93+
}
94+
}
95+
96+
void BackButtonPressedHandler(object sender, EventArgs e)
97+
{
98+
BackButtonPressed?.Invoke(this, EventArgs.Empty);
99+
}
100+
101+
void UpdateContent()
102+
{
103+
if (!XForms.IsInitialized)
104+
{
105+
Log.Debug(FormsCircularUI.Tag, "Tizen Forms is not initialized");
106+
return;
107+
}
108+
109+
_contentView.Children.Clear();
110+
if (Content != null)
111+
{
112+
_contentView.Children.Add(Content);
113+
114+
var renderer = Platform.GetOrCreateRenderer(_contentView);
115+
(renderer as LayoutRenderer)?.RegisterOnLayoutUpdated();
116+
117+
var sizeRequest = _contentView.Measure(XForms.NativeParent.Geometry.Width, XForms.NativeParent.Geometry.Height).Request.ToPixel();
118+
_nativeContent = renderer.NativeView;
119+
_nativeContent.MinimumHeight = sizeRequest.Height;
120+
121+
_popUp.SetContent(_nativeContent, true);
122+
}
123+
else
124+
{
125+
if (_nativeContent != null)
126+
{
127+
_nativeContent.Unrealize();
128+
_nativeContent = null;
129+
}
130+
_popUp.SetContent(null, true);
131+
}
132+
}
133+
134+
public void Show()
135+
{
136+
if (!XForms.IsInitialized)
137+
{
138+
throw new InvalidOperationException("When the Application's Platform is not initialized, it can not show the Dialog.");
139+
}
140+
141+
if (_popUp != null)
142+
{
143+
_popUp.Show();
144+
}
145+
}
146+
147+
public void Dismiss()
148+
{
149+
_popUp.Hide();
150+
_popUp.Dismiss();
151+
}
152+
153+
void OnDismissed(object sender, EventArgs e)
154+
{
155+
Dispose();
156+
}
157+
}
158+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/*
2+
* Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
3+
*
4+
* Licensed under the Flora License, Version 1.1 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://floralicense.org/license/
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
using System;
18+
using Xamarin.Forms;
19+
20+
namespace Tizen.Wearable.CircularUI.Forms
21+
{
22+
/// <summary>
23+
/// The ContentPopup is a Popup, which allows you to customize the View to be displayed.
24+
/// </summary>
25+
/// <since_tizen> 4 </since_tizen>
26+
public class ContentPopup : BindableObject
27+
{
28+
/// <summary>
29+
/// BindableProperty. Identifies the content bindable property.
30+
/// </summary>
31+
/// <since_tizen> 4 </since_tizen>
32+
public static readonly BindableProperty ContentProperty = BindableProperty.Create(nameof(Content), typeof(View), typeof(ContentPopup), null);
33+
34+
IContentPopup _popUp;
35+
36+
/// <summary>
37+
/// Occurs when the device's back button is pressed.
38+
/// </summary>
39+
/// <since_tizen> 4 </since_tizen>
40+
public event EventHandler BackButtonPressed;
41+
42+
/// <summary>
43+
/// Creates and initializes a new instance of the ContentPopup class.
44+
/// </summary>
45+
/// <since_tizen> 4 </since_tizen>
46+
public ContentPopup()
47+
{
48+
_popUp = DependencyService.Get<IContentPopup>(DependencyFetchTarget.NewInstance);
49+
if (_popUp == null)
50+
throw new InvalidOperationException("Object reference not set to an instance of a Popup.");
51+
52+
_popUp.BackButtonPressed += (s, e) =>
53+
{
54+
BackButtonPressed?.Invoke(this, EventArgs.Empty);
55+
};
56+
57+
SetBinding(ContentProperty, new Binding(nameof(Content), mode: BindingMode.OneWayToSource, source: _popUp));
58+
}
59+
60+
/// <summary>
61+
/// Gets or sets content view of the Popup.
62+
/// </summary>
63+
/// <since_tizen> 4 </since_tizen>
64+
public View Content
65+
{
66+
get { return (View)GetValue(ContentProperty); }
67+
set { SetValue(ContentProperty, value); }
68+
}
69+
70+
/// <summary>
71+
/// Shows the ContentPopup.
72+
/// </summary>
73+
/// <since_tizen> 4 </since_tizen>
74+
public void Show()
75+
{
76+
_popUp.Show();
77+
}
78+
79+
/// <summary>
80+
/// Dismisses the ContentPopup.
81+
/// </summary>
82+
/// <since_tizen> 4 </since_tizen>
83+
public void Dismiss(object result = null)
84+
{
85+
_popUp.Dismiss();
86+
}
87+
}
88+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
3+
*
4+
* Licensed under the Flora License, Version 1.1 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://floralicense.org/license/
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
using System;
18+
using Xamarin.Forms;
19+
20+
namespace Tizen.Wearable.CircularUI.Forms
21+
{
22+
/// <summary>
23+
/// The IContentPopup is an interface to describe confirmation pop-up which has content area
24+
/// </summary>
25+
/// <since_tizen> 4 </since_tizen>
26+
internal interface IContentPopup
27+
{
28+
/// <summary>
29+
/// Occurs when the Back button is pressed.
30+
/// </summary>
31+
/// <since_tizen> 4 </since_tizen>
32+
event EventHandler BackButtonPressed;
33+
34+
/// <summary>
35+
/// Gets or sets content view of the Popup.
36+
/// </summary>
37+
/// <since_tizen> 4 </since_tizen>
38+
View Content { get; set; }
39+
40+
/// <summary>
41+
/// Shows the Popup
42+
/// </summary>
43+
/// <since_tizen> 4 </since_tizen>
44+
void Show();
45+
46+
/// <summary>
47+
/// Dismisses the Popup
48+
/// </summary>
49+
/// <since_tizen> 4 </since_tizen>
50+
void Dismiss();
51+
}
52+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<ContentPage
3+
x:Class="WearableUIGallery.TC.TCContentPopupTest"
4+
xmlns="http://xamarin.com/schemas/2014/forms"
5+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
6+
xmlns:local="clr-namespace:WearableUIGallery"
7+
xmlns:w="clr-namespace:Tizen.Wearable.CircularUI.Forms;assembly=Tizen.Wearable.CircularUI.Forms"
8+
w:CircleSurfaceEffectBehavior.RotaryFocusObject="{x:Reference myscroller}">
9+
<ContentPage.Behaviors>
10+
<w:CircleSurfaceEffectBehavior/>
11+
</ContentPage.Behaviors>
12+
<ContentPage.Content>
13+
<w:CircleScrollView x:Name="myscroller" Orientation="Vertical">
14+
<StackLayout Padding="0,50,0,50">
15+
<Label
16+
x:Name="label1"
17+
HorizontalOptions="CenterAndExpand"
18+
Text="ContentPopup test"
19+
VerticalOptions="Start" />
20+
<Button
21+
AutomationId="dismisstest1"
22+
x:Name="button1"
23+
Clicked="OnContentPopupDismissBackKeyClicked"
24+
FontSize="Small"
25+
HeightRequest="50"
26+
HorizontalOptions="Center"
27+
Text="Dismiss test 1"
28+
VerticalOptions="CenterAndExpand"
29+
WidthRequest="300" />
30+
<Button
31+
AutomationId="dismisstest2"
32+
x:Name="button2"
33+
Clicked="OnContentPopupDismissButtonClicked"
34+
FontSize="Small"
35+
HeightRequest="50"
36+
HorizontalOptions="Center"
37+
Text="Dismiss test 2"
38+
VerticalOptions="CenterAndExpand"
39+
WidthRequest="300" />
40+
</StackLayout>
41+
</w:CircleScrollView>
42+
</ContentPage.Content>
43+
</ContentPage>

0 commit comments

Comments
 (0)