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

Commit

Permalink
Add ContentPopup
Browse files Browse the repository at this point in the history
  • Loading branch information
sung-su committed Apr 21, 2020
1 parent 8b15584 commit ed56cee
Show file tree
Hide file tree
Showing 6 changed files with 423 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
/*
* Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Flora License, Version 1.1 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://floralicense.org/license/
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

using System;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Tizen;
using XForms = Xamarin.Forms.Forms;

[assembly: Dependency(typeof(Tizen.Wearable.CircularUI.Forms.Renderer.ContentPopupImplementation))]

namespace Tizen.Wearable.CircularUI.Forms.Renderer
{
public class ContentPopupImplementation : IContentPopup, IDisposable
{
View _content;
StackLayout _contentView;
ElmSharp.Popup _popUp;
ElmSharp.EvasObject _nativeContent;
bool _isDisposed;

public event EventHandler BackButtonPressed;

public ContentPopupImplementation()
{
_popUp = new ElmSharp.Popup(XForms.NativeParent);
_popUp.Style = "circle";

_popUp.BackButtonPressed += BackButtonPressedHandler;
_popUp.Dismissed += OnDismissed;

_contentView = new StackLayout();
}

~ContentPopupImplementation()
{
Dispose(false);
}

public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

protected virtual void Dispose(bool disposing)
{
if (_isDisposed)
return;

if (disposing)
{
if (_nativeContent != null)
{
_nativeContent.Unrealize();
_nativeContent = null;
}

if (_popUp != null)
{
_popUp.BackButtonPressed -= BackButtonPressedHandler;
_popUp.Dismissed -= OnDismissed;
_popUp.Unrealize();
_popUp = null;
}
}

_isDisposed = true;
}

public View Content
{
get
{
return _content;
}
set
{
_content = value;
UpdateContent();
}
}

void BackButtonPressedHandler(object sender, EventArgs e)
{
BackButtonPressed?.Invoke(this, EventArgs.Empty);
}

void UpdateContent()
{
if (!XForms.IsInitialized)
{
Log.Debug(FormsCircularUI.Tag, "Tizen Forms is not initialized");
return;
}

_contentView.Children.Clear();
if (Content != null)
{
_contentView.Children.Add(Content);

var renderer = Platform.GetOrCreateRenderer(_contentView);
(renderer as LayoutRenderer)?.RegisterOnLayoutUpdated();

var sizeRequest = _contentView.Measure(XForms.NativeParent.Geometry.Width, XForms.NativeParent.Geometry.Height).Request.ToPixel();
_nativeContent = renderer.NativeView;
_nativeContent.MinimumHeight = sizeRequest.Height;

_popUp.SetContent(_nativeContent, true);
}
else
{
if (_nativeContent != null)
{
_nativeContent.Unrealize();
_nativeContent = null;
}
_popUp.SetContent(null, true);
}
}

public void Show()
{
if (!XForms.IsInitialized)
{
throw new InvalidOperationException("When the Application's Platform is not initialized, it can not show the Dialog.");
}

if (_popUp != null)
{
_popUp.Show();
}
}

public void Dismiss()
{
_popUp.Hide();
_popUp.Dismiss();
}

void OnDismissed(object sender, EventArgs e)
{
Dispose();
}
}
}
88 changes: 88 additions & 0 deletions src/Tizen.Wearable.CircularUI.Forms/ContentPopup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Flora License, Version 1.1 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://floralicense.org/license/
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

using System;
using Xamarin.Forms;

namespace Tizen.Wearable.CircularUI.Forms
{
/// <summary>
/// The ContentPopup is a Popup, which allows you to customize the View to be displayed.
/// </summary>
/// <since_tizen> 4 </since_tizen>
public class ContentPopup : BindableObject
{
/// <summary>
/// BindableProperty. Identifies the content bindable property.
/// </summary>
/// <since_tizen> 4 </since_tizen>
public static readonly BindableProperty ContentProperty = BindableProperty.Create(nameof(Content), typeof(View), typeof(TwoButtonPopup), null);

IContentPopup _popUp;

/// <summary>
/// Occurs when the device's back button is pressed.
/// </summary>
/// <since_tizen> 4 </since_tizen>
public event EventHandler BackButtonPressed;

/// <summary>
/// Creates and initializes a new instance of the ContentPopup class.
/// </summary>
/// <since_tizen> 4 </since_tizen>
public ContentPopup()
{
_popUp = DependencyService.Get<IContentPopup>(DependencyFetchTarget.NewInstance);
if (_popUp == null)
throw new InvalidOperationException("Object reference not set to an instance of a Popup.");

_popUp.BackButtonPressed += (s, e) =>
{
BackButtonPressed?.Invoke(this, EventArgs.Empty);
};

SetBinding(ContentProperty, new Binding(nameof(Content), mode: BindingMode.OneWayToSource, source: _popUp));
}

/// <summary>
/// Gets or sets content view of the Popup.
/// </summary>
/// <since_tizen> 4 </since_tizen>
public View Content
{
get { return (View)GetValue(ContentProperty); }
set { SetValue(ContentProperty, value); }
}

/// <summary>
/// Shows the ContentPopup.
/// </summary>
/// <since_tizen> 4 </since_tizen>
public void Show()
{
_popUp.Show();
}

/// <summary>
/// Dismisses the ContentPopup.
/// </summary>
/// <since_tizen> 4 </since_tizen>
public void Dismiss(object result = null)
{
_popUp.Dismiss();
}
}
}
52 changes: 52 additions & 0 deletions src/Tizen.Wearable.CircularUI.Forms/IContentPopup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Flora License, Version 1.1 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://floralicense.org/license/
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

using System;
using Xamarin.Forms;

namespace Tizen.Wearable.CircularUI.Forms
{
/// <summary>
/// The IContentPopup is an interface to describe confirmation pop-up which has content area
/// </summary>
/// <since_tizen> 4 </since_tizen>
internal interface IContentPopup
{
/// <summary>
/// Occurs when the Back button is pressed.
/// </summary>
/// <since_tizen> 4 </since_tizen>
event EventHandler BackButtonPressed;

/// <summary>
/// Gets or sets content view of the Popup.
/// </summary>
/// <since_tizen> 4 </since_tizen>
View Content { get; set; }

/// <summary>
/// Shows the Popup
/// </summary>
/// <since_tizen> 4 </since_tizen>
void Show();

/// <summary>
/// Dismisses the Popup
/// </summary>
/// <since_tizen> 4 </since_tizen>
void Dismiss();
}
}
43 changes: 43 additions & 0 deletions test/WearableUIGallery/WearableUIGallery/TC/TCContentPopup.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage
x:Class="WearableUIGallery.TC.TCContentPopupTest"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:WearableUIGallery"
xmlns:w="clr-namespace:Tizen.Wearable.CircularUI.Forms;assembly=Tizen.Wearable.CircularUI.Forms"
w:CircleSurfaceEffectBehavior.RotaryFocusObject="{x:Reference myscroller}">
<ContentPage.Behaviors>
<w:CircleSurfaceEffectBehavior/>
</ContentPage.Behaviors>
<ContentPage.Content>
<w:CircleScrollView x:Name="myscroller" Orientation="Vertical">
<StackLayout Padding="0,50,0,50">
<Label
x:Name="label1"
HorizontalOptions="CenterAndExpand"
Text="ContentPopup test"
VerticalOptions="Start" />
<Button
AutomationId="dismisstest1"
x:Name="button1"
Clicked="OnContentPopupDismissBackKeyClicked"
FontSize="Small"
HeightRequest="50"
HorizontalOptions="Center"
Text="Dismiss test 1"
VerticalOptions="CenterAndExpand"
WidthRequest="300" />
<Button
AutomationId="dismisstest2"
x:Name="button2"
Clicked="OnContentPopupDismissButtonClicked"
FontSize="Small"
HeightRequest="50"
HorizontalOptions="Center"
Text="Dismiss test 2"
VerticalOptions="CenterAndExpand"
WidthRequest="300" />
</StackLayout>
</w:CircleScrollView>
</ContentPage.Content>
</ContentPage>
Loading

0 comments on commit ed56cee

Please sign in to comment.