-
Notifications
You must be signed in to change notification settings - Fork 32
Add ContentPopup #276
base: master
Are you sure you want to change the base?
Add ContentPopup #276
Conversation
/// 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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public static readonly BindableProperty ContentProperty = BindableProperty.Create(nameof(Content), typeof(View), typeof(TwoButtonPopup), null); | |
public static readonly BindableProperty ContentProperty = BindableProperty.Create(nameof(Content), typeof(View), typeof(ContentPopup), null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed.
Currently, I am considering changing to a renderer structure. |
} | ||
} | ||
|
||
public void Dispose() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use Dispose pattern
public void Dispose()
{
Dispose(true);
}
protected virtual void Dispose(bool disposing)
{
if (disposing && _renderer != null)
{
_renderer.Dispose();
_renderer = null;
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed.
/// <summary> | ||
/// Shows the popup. | ||
/// </summary> | ||
void Show(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No more need
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed.
public void Dismiss() | ||
{ | ||
_popup?.Hide(); | ||
_popup?.Dismiss(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should not use Dismiss
, because it destroy popup
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed.
/// 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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to update parent
void UpdateContent()
{
OnChildAdded(Content);
}
// it is method of Element
protected virtual void OnChildAdded(Element child)
{
child.Parent = this;
child.ApplyBindings(skipBindingContext: false, fromBindingContextChanged: true);
ChildAdded?.Invoke(this, new ElementEventArgs(child));
OnDescendantAdded(child);
foreach (Element element in child.Descendants())
OnDescendantAdded(element);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed.
|
||
public void SetElement(Element element) | ||
{ | ||
element.Parent = Application.Current.Parent; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Set only if no parent
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed.
var renderer = Platform.GetOrCreateRenderer(_element.Content); | ||
(renderer as LayoutRenderer)?.RegisterOnLayoutUpdated(); | ||
var native = renderer.NativeView; | ||
var sizeRequest = _element.Content.Measure(XForms.NativeParent.Geometry.Width, XForms.NativeParent.Geometry.Height).Request.ToPixel(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed.
(renderer as LayoutRenderer)?.RegisterOnLayoutUpdated(); | ||
var native = renderer.NativeView; | ||
var sizeRequest = _element.Content.Measure(XForms.NativeParent.Geometry.Width, XForms.NativeParent.Geometry.Height).Request.ToPixel(); | ||
native.MinimumHeight = sizeRequest.Height; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Content should be always fullscreen size
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed.
Please test BindingContext chaining is working on ContentPopup. ContentPopup should use parent's BindingContext, if not set a BindingContext |
@@ -48,6 +48,7 @@ public static void Init() | |||
{ | |||
if (IsInitialized) return; | |||
IsInitialized = true; | |||
ContentPopup.RendererFunc = () => new ContentPopupRenderer(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where this technique come from?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
come from me 😉
ElmSharp.Popup _popup; | ||
ContentPopup _element; | ||
|
||
public void SetElement(Element element) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public void SetElement(Element element) | |
public void SetElement(ContentPopup element) |
Because it is ContentPopupRenderer
void OnDismissed(object sender, EventArgs e) | ||
{ | ||
_element.SendDismissed(); | ||
Dispose(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you dispose it?
var renderer = Platform.GetOrCreateRenderer(_element.Content); | ||
(renderer as LayoutRenderer)?.RegisterOnLayoutUpdated(); | ||
var native = renderer.NativeView; | ||
native.MinimumHeight = 360; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not use static value 360
How about use align and weight?
native.AlignmentX= -1;
native.AlignmentY= -1;
native.WeightX = 1;
native.WeightY = 1;
@@ -48,6 +48,7 @@ public static void Init() | |||
{ | |||
if (IsInitialized) return; | |||
IsInitialized = true; | |||
ContentPopup.RendererFunc = () => new ContentPopupRenderer(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ContentPopup.RendererFunc = () => new ContentPopupRenderer(); | |
ContentPopup.CreateRenderer = () => new ContentPopupRenderer(); |
|
||
private void OnContentPopupDismissButtonClicked(object sender, EventArgs e) | ||
{ | ||
ContentPopup _popup = new ContentPopup(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
using (ContentPopup _popup = new ContentPopup())
{
var dismiss = new Button
{
Text = "Dismiss",
};
dismiss.Clicked += (s, ee) =>
{
_popup?.Dismiss();
label1.Text = "Test2 Dismissed";
};
var label = new Label
{
Text = "This ContentPopup is dismissed as a below dismiss button.",
HorizontalTextAlignment = TextAlignment.Center,
};
var grid = new Grid();
grid.HeightRequest = 360;
grid.WidthRequest = 360;
grid.RowDefinitions.Add(new RowDefinition());
grid.RowDefinitions.Add(new RowDefinition());
grid.RowDefinitions.Add(new RowDefinition());
grid.RowDefinitions.Add(new RowDefinition());
grid.RowDefinitions.Add(new RowDefinition());
grid.Children.Add(label, 0, 1, 1, 3);
grid.Children.Add(dismiss, 0, 1, 3, 4);
_popup.Content = grid;
_popup.Show();
TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>();
_popup.Dismissed += (s, evt) => tcs.SetResult(true);
_ = await tcs.Task;
}
|
||
private void OnContentPopupDismissBackKeyClicked(object sender, EventArgs e) | ||
{ | ||
ContentPopup _popup = new ContentPopup(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
using (ContentPopup _popup = new ContentPopup())
{
_popup.BackButtonPressed += (s, ee) =>
{
_popup?.Dismiss();
label1.Text = "Test1 Dismissed";
};
string _longText = "This ContentPopup is dismissed as a back key.";
var content = new Label { Text = _longText, HorizontalTextAlignment = TextAlignment.Center };
_popup.Content = content;
_popup.Show();
TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>();
_popup.Dismissed += (s, evt) => tcs.SetResult(true);
_ = await tcs.Task;
}
/// Shows the popup. | ||
/// </summary> | ||
/// <since_tizen> 4 </since_tizen> | ||
public void Show() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about rename to Open
?
and How about return Task that indicate closing timing
TaskCompletionSource<bool> _tcsForDismiss;
public Task Open()
{
IsShow = true;
_tcsForDismiss = new TaskCompletionSource<bool>();
return _tcsForDismiss.Task;
}
public void SendDismissed()
{
Dismissed?.Invoke(this, EventArgs.Empty);
_tcsForDismiss?.TrySetResult(true);
}
If you provide Task
we can easily use
using (var popup = new ContentPopup()) {
poup.Content = new StackLayout { ... };
_ = await popup.Open();
}
Fixed with reference to the above comments. |
var renderer = Platform.GetOrCreateRenderer(_element.Content); | ||
(renderer as LayoutRenderer)?.RegisterOnLayoutUpdated(); | ||
var native = renderer.NativeView; | ||
native.MinimumHeight = XForms.NativeParent.Geometry.Height; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about use AligementX/Y and WeightX/Y?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will set MinimunHeight
and MinimumWidth
instead of Alignment
and Weight
.
/// 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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TwoWay binding is more proper
defaultBindingMode : BindingMode.TwoWay
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
public static async Task ShowPopup(ContentPopup popup) | ||
{ | ||
if (popup == null) | ||
await Task.FromResult(false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
await Task.FromResult(false); | |
return Task.FromResult(false); | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change to return
using (var renderer = DependencyService.Get<IContentPopupRenderer>(DependencyFetchTarget.NewInstance)) | ||
{ | ||
if (renderer == null) | ||
await Task.FromResult(false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
await Task.FromResult(false); | |
return Task.FromResult(false); | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change to return
|
||
popup.Content = label; | ||
|
||
await ContentPopupManager.ShowPopup(popup); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
await ContentPopupManager.ShowPopup(popup); | |
await Navigation.ShowPopup(popup); | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
public Task Open() | ||
{ | ||
_popup.Show(); | ||
_element.IsOpen = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_element.IsOpen = true; | |
_element.SetValueFromRenderer(ContentPopup.IsOpenProperty, true); | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We decided to think again about providing ContentPopup
on Galaxy Watch, which has a smaller screen size than mobile or TV.
The two main parts we are concerned with are:
- Since the screen is small, the popup always occupies the entire screen, so there is no difference from using the page.
- The complexity of managing the bezel interaction between the content of pop-ups created in a new window and the content of the existing page can be increased.
Description of Change
Add ContentPopup.
It is a popup with only one view, and has less interface restrictions than other popups. (
TwoButtonPopup
,InformationPopup
)API Changes
Added:
Usage:
Screenshot:
