This repository was archived by the owner on Dec 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 32
Add ContentPopup #276
Open
sung-su
wants to merge
5
commits into
Samsung:master
Choose a base branch
from
sung-su:contentpopup
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add ContentPopup #276
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
134 changes: 134 additions & 0 deletions
134
src/Tizen.Wearable.CircularUI.Forms.Renderer/ContentPopupRenderer.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,134 @@ | ||
| /* | ||
| * 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 System.ComponentModel; | ||
| using System.Threading.Tasks; | ||
| using Xamarin.Forms; | ||
| using Xamarin.Forms.Platform.Tizen; | ||
| using XForms = Xamarin.Forms.Forms; | ||
|
|
||
| [assembly: Dependency(typeof(Tizen.Wearable.CircularUI.Forms.Renderer.ContentPopupRenderer))] | ||
|
|
||
| namespace Tizen.Wearable.CircularUI.Forms.Renderer | ||
| { | ||
| public class ContentPopupRenderer : IContentPopupRenderer | ||
| { | ||
| ElmSharp.Popup _popup; | ||
| ContentPopup _element; | ||
| TaskCompletionSource<bool> _tcs; | ||
|
|
||
| public ContentPopupRenderer() | ||
| { | ||
| _popup = new ElmSharp.Popup(XForms.NativeParent); | ||
| _popup.Style = "circle"; | ||
| _popup.BackButtonPressed += OnBackButtonPressed; | ||
| _popup.Dismissed += OnDismissed; | ||
| } | ||
|
|
||
| ~ContentPopupRenderer() | ||
| { | ||
| Dispose(false); | ||
| } | ||
|
|
||
| public void SetElement(ContentPopup element) | ||
| { | ||
| if (element.Parent == null) | ||
| element.Parent = Application.Current; | ||
| element.PropertyChanged += OnElementPropertyChanged; | ||
| _element = element; | ||
|
|
||
| UpdateContent(); | ||
| } | ||
|
|
||
| public void Dispose() | ||
| { | ||
| Dispose(true); | ||
| GC.SuppressFinalize(this); | ||
| } | ||
|
|
||
| public Task Open() | ||
| { | ||
| _popup.Show(); | ||
| _element.SetValueFromRenderer(ContentPopup.IsOpenProperty, true); | ||
| _tcs = new TaskCompletionSource<bool>(); | ||
| return _tcs.Task; | ||
| } | ||
|
|
||
| protected void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e) | ||
| { | ||
| if (e.PropertyName == ContentPopup.ContentProperty.PropertyName) | ||
| UpdateContent(); | ||
|
|
||
| if (e.PropertyName == ContentPopup.IsOpenProperty.PropertyName) | ||
| UpdateIsOpen(); | ||
| } | ||
|
|
||
| protected virtual void Dispose(bool disposing) | ||
| { | ||
| if (disposing) | ||
| { | ||
| if (_popup != null) | ||
| { | ||
| _popup.BackButtonPressed -= OnBackButtonPressed; | ||
| _popup.Dismissed -= OnDismissed; | ||
| _popup.Unrealize(); | ||
| _popup = null; | ||
| } | ||
| if (_element != null) | ||
| { | ||
| _element.PropertyChanged -= OnElementPropertyChanged; | ||
| _element = null; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| void OnBackButtonPressed(object sender, EventArgs e) | ||
myroot marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| if (!_element.SendBackButtonPressed()) | ||
| _popup?.Hide(); | ||
| } | ||
|
|
||
| void OnDismissed(object sender, EventArgs e) | ||
| { | ||
| _element.SendDismissed(); | ||
| _tcs?.SetResult(true); | ||
| } | ||
|
|
||
| void UpdateContent() | ||
| { | ||
| if (_element.Content != null) | ||
| { | ||
| var renderer = Platform.GetOrCreateRenderer(_element.Content); | ||
| (renderer as LayoutRenderer)?.RegisterOnLayoutUpdated(); | ||
| var native = renderer.NativeView; | ||
| native.MinimumHeight = XForms.NativeParent.Geometry.Height; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about use AligementX/Y and WeightX/Y?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will set |
||
| native.MinimumWidth = XForms.NativeParent.Geometry.Width; | ||
| _popup.SetContent(native, false); | ||
| } | ||
| else | ||
| { | ||
| _popup.SetContent(null, false); | ||
| } | ||
| } | ||
|
|
||
| void UpdateIsOpen() | ||
| { | ||
| if (!_element.IsOpen) | ||
| _popup?.Hide(); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| /* | ||
| * 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 System.ComponentModel; | ||
| 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 : Element | ||
| { | ||
| /// <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(ContentPopup), null, propertyChanged: (b, o, n) => ((ContentPopup)b).UpdateContent()); | ||
|
|
||
| /// <summary> | ||
| /// BindableProperty. Identifies the IsShow bindable property. | ||
| /// </summary> | ||
| /// <since_tizen> 4 </since_tizen> | ||
| public static readonly BindableProperty IsOpenProperty = BindableProperty.Create(nameof(IsOpen), typeof(bool), typeof(ContentPopup), false, defaultBindingMode: BindingMode.TwoWay); | ||
|
|
||
| /// <summary> | ||
| /// Occurs when the popup is dismissed. | ||
| /// </summary> | ||
| /// <since_tizen> 4 </since_tizen> | ||
| public event EventHandler Dismissed; | ||
|
|
||
| /// <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> | ||
| /// Gets or sets the popup is opened. | ||
| /// </summary> | ||
| /// <since_tizen> 4 </since_tizen> | ||
| public bool IsOpen | ||
| { | ||
| get { return (bool)GetValue(IsOpenProperty); } | ||
| set { SetValue(IsOpenProperty, value); } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Dismisses the popup. | ||
| /// </summary> | ||
| /// <since_tizen> 4 </since_tizen> | ||
| public void Dismiss() | ||
| { | ||
| IsOpen = false; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// For internal use. | ||
| /// </summary> | ||
| [EditorBrowsable(EditorBrowsableState.Never)] | ||
| public void SendDismissed() | ||
| { | ||
| Dismissed?.Invoke(this, EventArgs.Empty); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// For internal use. | ||
| /// </summary> | ||
| [EditorBrowsable(EditorBrowsableState.Never)] | ||
| public bool SendBackButtonPressed() | ||
| { | ||
| return OnBackButtonPressed(); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// To change the default behavior of the BackButton. Default behavior is dismiss. | ||
| /// </summary> | ||
| /// <returns>Default is false</returns> | ||
| protected virtual bool OnBackButtonPressed() | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| protected override void OnBindingContextChanged() | ||
| { | ||
| base.OnBindingContextChanged(); | ||
| if (Content != null) | ||
| SetInheritedBindingContext(Content, BindingContext); | ||
| } | ||
|
|
||
| void UpdateContent() | ||
| { | ||
| if (Content != null) | ||
| OnChildAdded(Content); | ||
| } | ||
| } | ||
| } |
45 changes: 45 additions & 0 deletions
45
src/Tizen.Wearable.CircularUI.Forms/ContentPopupManager.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| /* | ||
| * 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.Threading.Tasks; | ||
| using Xamarin.Forms; | ||
|
|
||
| namespace Tizen.Wearable.CircularUI.Forms | ||
| { | ||
| public static class ContentPopupManager | ||
| { | ||
| public static async Task ShowPopup(this INavigation navigation, ContentPopup popup) | ||
| { | ||
| await ShowPopup(popup); | ||
| } | ||
|
|
||
| public static async Task ShowPopup(ContentPopup popup) | ||
| { | ||
| if (popup == null) | ||
| return; | ||
|
|
||
| using (var renderer = DependencyService.Get<IContentPopupRenderer>(DependencyFetchTarget.NewInstance)) | ||
| { | ||
| if (renderer == null) | ||
| return; | ||
|
|
||
| renderer.SetElement(popup); | ||
|
|
||
| await renderer.Open(); | ||
| } | ||
| } | ||
| } | ||
| } |
40 changes: 40 additions & 0 deletions
40
src/Tizen.Wearable.CircularUI.Forms/IContentPopupRenderer.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| /* | ||
| * 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 System.Threading.Tasks; | ||
|
|
||
| namespace Tizen.Wearable.CircularUI.Forms | ||
| { | ||
| /// <summary> | ||
| /// Base interface for ContentPopup renderer. | ||
| /// </summary> | ||
| /// <since_tizen> 4 </since_tizen> | ||
| public interface IContentPopupRenderer : IDisposable | ||
| { | ||
| /// <summary> | ||
| /// Sets the Element associated with this renderer. | ||
| /// </summary> | ||
| /// <param name="element">New element.</param> | ||
| void SetElement(ContentPopup element); | ||
|
|
||
| /// <summary> | ||
| /// Open a popup. | ||
| /// </summary> | ||
| /// <returns>Returns a Task with the dismiss result of the popup.</returns> | ||
| Task Open(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -72,4 +72,4 @@ internal interface ITwoButtonPopup | |
| /// <since_tizen> 4 </since_tizen> | ||
| void Dismiss(); | ||
| } | ||
| } | ||
| } | ||
43 changes: 43 additions & 0 deletions
43
test/WearableUIGallery/WearableUIGallery/TC/TCContentPopup.xaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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="OnContentPopupTest1Clicked" | ||
| FontSize="Small" | ||
| HeightRequest="50" | ||
| HorizontalOptions="Center" | ||
| Text="Dismiss test 1" | ||
| VerticalOptions="CenterAndExpand" | ||
| WidthRequest="300" /> | ||
| <Button | ||
| AutomationId="dismisstest2" | ||
| x:Name="button2" | ||
| Clicked="OnContentPopupTest2Clicked" | ||
| FontSize="Small" | ||
| HeightRequest="50" | ||
| HorizontalOptions="Center" | ||
| Text="Dismiss test 2" | ||
| VerticalOptions="CenterAndExpand" | ||
| WidthRequest="300" /> | ||
| </StackLayout> | ||
| </w:CircleScrollView> | ||
| </ContentPage.Content> | ||
| </ContentPage> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.