3 using Xamarin.Forms.Platform.Tizen;
4 using TForms = Xamarin.Forms.Platform.Tizen.Forms;
5 using EPopup = ElmSharp.Popup;
6 using Tizen.Xamarin.Forms.Extension.Renderer;
8 [assembly: Dependency(typeof(DialogImplementation))]
10 namespace Tizen.Xamarin.Forms.Extension.Renderer
12 class DialogImplementation : IDialog, IDisposable
21 StackLayout _contentView;
22 LayoutOptions _horizontalOption = LayoutOptions.Center;
23 LayoutOptions _verticalOption = LayoutOptions.End;
25 LayoutOptions _previousHorizontalOption = LayoutOptions.Center;
27 bool _isDisposed = false;
29 ElmSharp.Button _nativePositive;
31 ElmSharp.Button _nativeNeutral;
32 ElmSharp.Button _nativeNegative;
33 ElmSharp.EvasObject _nativeContent;
35 public event EventHandler Hidden;
37 public event EventHandler OutsideClicked;
39 public event EventHandler Shown;
41 public event EventHandler BackButtonPressed;
43 public DialogImplementation()
45 _control = new EPopup((TForms.Context as FormsApplication).MainWindow);
47 _control.ShowAnimationFinished += ShowAnimationFinishedHandler;
48 _control.Dismissed += DismissedHandler;
49 _control.OutsideClicked += OutsideClickedHandler;
50 _control.BackButtonPressed += BackButtonPressedHandler;
52 _contentView = new StackLayout();
55 ~DialogImplementation()
73 public Button Positive
99 public Button Negative
125 public string Subtitle
138 public LayoutOptions HorizontalOption
142 return _horizontalOption;
146 _horizontalOption = value;
147 UpdateHorizontalOption();
151 public LayoutOptions VerticalOption
155 return _verticalOption;
159 _verticalOption = value;
160 UpdateVerticalOption();
166 if (Application.Current.Platform == null)
168 throw new Exception("When the Application's Platform is null, can not show the Dialog.");
170 if (_contentView.Platform == null)
182 public void Dispose()
185 GC.SuppressFinalize(this);
188 protected virtual void Dispose(bool disposing)
195 if (_nativePositive != null)
197 _nativePositive.Unrealize();
198 _nativePositive = null;
200 if (_nativeNeutral != null)
202 _nativeNeutral.Unrealize();
203 _nativeNeutral = null;
205 if (_nativeNegative != null)
207 _nativeNegative.Unrealize();
208 _nativeNegative = null;
210 if (_nativeContent != null)
212 _nativeContent.Unrealize();
213 _nativeContent = null;
216 if (_control != null)
218 _control.ShowAnimationFinished -= ShowAnimationFinishedHandler;
219 _control.Dismissed -= DismissedHandler;
220 _control.OutsideClicked -= OutsideClickedHandler;
221 _control.BackButtonPressed -= BackButtonPressedHandler;
223 _control.Unrealize();
231 void ShowAnimationFinishedHandler(object sender, EventArgs e)
233 _nativeContent?.MarkChanged();
234 Shown?.Invoke(this, EventArgs.Empty);
237 void DismissedHandler(object sender, EventArgs e)
239 Hidden?.Invoke(this, EventArgs.Empty);
242 void OutsideClickedHandler(object sender, EventArgs e)
244 OutsideClicked?.Invoke(this, EventArgs.Empty);
247 void BackButtonPressedHandler(object sender, EventArgs e)
249 BackButtonPressed?.Invoke(this, EventArgs.Empty);
254 if (Application.Current.Platform == null)
257 _contentView.Children.Clear();
261 _contentView.Children.Add(Content);
263 _contentView.Platform = Application.Current.Platform;
265 var renderer = Platform.GetOrCreateRenderer(_contentView);
266 (renderer as LayoutRenderer)?.RegisterOnLayoutUpdated();
268 var sizeRequest = _contentView.Measure((TForms.Context as FormsApplication).MainWindow.ScreenSize.Width, (TForms.Context as FormsApplication).MainWindow.ScreenSize.Height).Request.ToPixel();
270 _nativeContent = renderer.NativeView;
271 _nativeContent.MinimumHeight = sizeRequest.Height;
273 _control.SetPartContent("default", _nativeContent, true);
277 _control.SetPartContent("default", null, true);
281 void UpdatePositive()
283 _nativePositive?.Hide();
285 if (Positive != null)
287 _nativePositive = (ElmSharp.Button)Platform.GetOrCreateRenderer(Positive).NativeView;
288 _nativePositive.Style = "popup";
292 _nativePositive = null;
295 _control.SetPartContent("button1", _nativePositive, true);
300 _nativeNeutral?.Hide();
304 _nativeNeutral = (ElmSharp.Button)Platform.GetOrCreateRenderer(Neutral).NativeView;
305 _nativeNeutral.Style = "popup";
309 _nativeNeutral = null;
312 _control.SetPartContent("button2", _nativeNeutral, true);
315 void UpdateNegative()
317 _nativeNegative?.Hide();
319 if (Negative != null)
321 _nativeNegative = (ElmSharp.Button)Platform.GetOrCreateRenderer(Negative).NativeView;
322 _nativeNegative.Style = "popup";
326 _nativeNegative = null;
329 _control.SetPartContent("button3", _nativeNegative, true);
334 _control.SetPartText("title,text", Title);
337 void UpdateSubtitle()
339 _control.SetPartText("subtitle,text", Subtitle);
342 void UpdateHorizontalOption()
344 switch (HorizontalOption.Alignment)
346 case LayoutAlignment.Start:
347 _control.AlignmentX = 0.0;
350 case LayoutAlignment.Center:
351 _control.AlignmentX = 0.5;
354 case LayoutAlignment.End:
355 _control.AlignmentX = 1.0;
358 case LayoutAlignment.Fill:
359 _control.AlignmentX = -1;
362 if (HorizontalOption.Alignment == LayoutAlignment.Fill || _previousHorizontalOption.Alignment == LayoutAlignment.Fill)
365 _previousHorizontalOption = HorizontalOption;
369 void UpdateVerticalOption()
371 switch (VerticalOption.Alignment)
373 case LayoutAlignment.Start:
374 _control.AlignmentY = 0.0;
377 case LayoutAlignment.Center:
378 _control.AlignmentY = 0.5;
381 case LayoutAlignment.End:
382 _control.AlignmentY = 1.0;
385 case LayoutAlignment.Fill:
386 _control.AlignmentY = -1;