diff --git a/.gitignore b/.gitignore index 10f16da..b0eb4b4 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ ## files generated by popular Visual Studio add-ons. .vs/ +mono_crash.* # User-specific files *.suo diff --git a/AiForms.Dialogs.Android/DialogImplementation.cs b/AiForms.Dialogs.Android/DialogImplementation.cs index 1e2e71a..ef4a187 100644 --- a/AiForms.Dialogs.Android/DialogImplementation.cs +++ b/AiForms.Dialogs.Android/DialogImplementation.cs @@ -7,13 +7,8 @@ namespace AiForms.Dialogs [Android.Runtime.Preserve(AllMembers = true)] public class DialogImplementation : IDialog { - public static readonly string ExtraDialogTag = "ExtraDialog"; - internal ExtraPlatformDialog ExtraDialog; - FragmentManager FragmentManager => Dialogs.FragmentManager; - public DialogImplementation() { - ExtraDialog = new ExtraPlatformDialog(); } public IReusableDialog Create(object viewModel = null) where TView : DialogView @@ -30,8 +25,6 @@ public IReusableDialog Create(DialogView view, object viewModel = null) public async Task ShowAsync(object viewModel = null) where TView : DialogView { - if (IsRunning()) return false; - using (var dlg = Create(viewModel)) { return await dlg.ShowAsync(); @@ -40,19 +33,10 @@ public async Task ShowAsync(object viewModel = null) where TView : public async Task ShowAsync(DialogView view, object viewModel = null) { - if (IsRunning()) return false; - using (var dlg = Create(view, viewModel)) { return await dlg.ShowAsync(); } } - - bool IsRunning() - { - var dialog = Dialogs.FragmentManager.FindFragmentByTag(DialogImplementation.ExtraDialogTag); - return dialog != null; - } - } } diff --git a/AiForms.Dialogs.Android/ExtraPlatformDialog.cs b/AiForms.Dialogs.Android/ExtraPlatformDialog.cs index 0d3278f..29ffc5e 100644 --- a/AiForms.Dialogs.Android/ExtraPlatformDialog.cs +++ b/AiForms.Dialogs.Android/ExtraPlatformDialog.cs @@ -17,6 +17,11 @@ public class ExtraPlatformDialog : Android.App.DialogFragment DialogView _dialogView; ViewGroup _contentView; + public ExtraPlatformDialog() { } + + // System Required! + public ExtraPlatformDialog(IntPtr handle, JniHandleOwnership transfer) :base(handle,transfer) { } + public override Android.App.Dialog OnCreateDialog(Bundle savedInstanceState) { base.OnCreateDialog(savedInstanceState); diff --git a/AiForms.Dialogs.Android/ReusableDialog.cs b/AiForms.Dialogs.Android/ReusableDialog.cs index 5eb38a6..069a243 100644 --- a/AiForms.Dialogs.Android/ReusableDialog.cs +++ b/AiForms.Dialogs.Android/ReusableDialog.cs @@ -1,4 +1,5 @@ using System; +using System.Threading; using System.Threading.Tasks; using AiForms.Dialogs.Abstractions; using Android.App; @@ -16,18 +17,18 @@ namespace AiForms.Dialogs [Android.Runtime.Preserve(AllMembers = true)] public class ReusableDialog:Java.Lang.Object, IReusableDialog, View.IOnKeyListener { - DialogImplementation _extraDialog; - ExtraPlatformDialog _platformDialog => _extraDialog.ExtraDialog; + ExtraPlatformDialog _platformDialog; FragmentManager FragmentManager => Dialogs.FragmentManager; DialogView _dlgView; IVisualElementRenderer _renderer; ViewGroup _contentView; Action OnceInitializeAction; + Guid _guid; public ReusableDialog(DialogView view) { - _dlgView = view; - _extraDialog = Dialog.Instance as DialogImplementation; + _dlgView = view; + _guid = Guid.NewGuid(); // Because the process can't be executed until application completely loads, // set the action here to execute later on. @@ -125,7 +126,7 @@ void Initialize() public async Task ShowAsync() { - var dialog = FragmentManager.FindFragmentByTag(DialogImplementation.ExtraDialogTag); + var dialog = FragmentManager.FindFragmentByTag(_guid.ToString()); if (dialog != null) { return false; @@ -148,7 +149,7 @@ async void complete(object sender, EventArgs e) _dlgView.RunDismissalAnimation(); await Dismiss(); tcs.SetResult(true); - }; + } _dlgView.DialogNotifierInternal.Canceled += cancel; _dlgView.DialogNotifierInternal.Completed += complete; @@ -157,8 +158,9 @@ async void complete(object sender, EventArgs e) var payload = new ExtraDialogPayload(_dlgView,_contentView); var bundle = new Bundle(); bundle.PutSerializable("extraDialogPayload", payload); + _platformDialog = new ExtraPlatformDialog(); _platformDialog.Arguments = bundle; - _platformDialog.Show(FragmentManager, DialogImplementation.ExtraDialogTag); + _platformDialog.Show(FragmentManager, _guid.ToString()); try { @@ -171,6 +173,7 @@ async void complete(object sender, EventArgs e) _dlgView.TearDown(); payload.Dispose(); bundle.Dispose(); + } } @@ -190,7 +193,7 @@ protected override void Dispose(bool disposing) if (!_renderer.View.IsDisposed()) { _renderer.View.Dispose(); - } + } _contentView.Dispose(); _contentView = null; @@ -198,8 +201,6 @@ protected override void Dispose(bool disposing) _renderer.Dispose(); _renderer = null; - _extraDialog = null; - OnceInitializeAction = null; } base.Dispose(disposing); @@ -256,9 +257,11 @@ void handler(object sender, Animation.AnimationEndEventArgs e) await tcs.Task; anim.AnimationEnd -= handler; - var dialog = FragmentManager.FindFragmentByTag(DialogImplementation.ExtraDialogTag); + var dialog = FragmentManager.FindFragmentByTag(_guid.ToString()); dialog.Dismiss(); _contentView.RemoveFromParent(); + _platformDialog.Dispose(); + _platformDialog = null; await Task.Delay(250); // wait for a bit time until the dialog is completely released. } diff --git a/Sample/Sample/ViewModels/DialogTestViewModel.cs b/Sample/Sample/ViewModels/DialogTestViewModel.cs index 1759a2d..0ba259a 100644 --- a/Sample/Sample/ViewModels/DialogTestViewModel.cs +++ b/Sample/Sample/ViewModels/DialogTestViewModel.cs @@ -76,7 +76,7 @@ string GetHAlignString() string GetVAlignString() { - switch (HorizontalLayoutAlignment) + switch (VerticalLayoutAlignment) { case LayoutAlignment.Start: return "Top"; diff --git a/Sample/Sample/ViewModels/SurveyPageViewModel.cs b/Sample/Sample/ViewModels/SurveyPageViewModel.cs new file mode 100644 index 0000000..bef1f56 --- /dev/null +++ b/Sample/Sample/ViewModels/SurveyPageViewModel.cs @@ -0,0 +1,26 @@ +using System; +using AiForms.Dialogs.Abstractions; +using Prism.Mvvm; +using Reactive.Bindings; +using Sample.Views; +using Sample.Views.Dialogs; + +namespace Sample.ViewModels +{ + public class SurveyPageViewModel:BindableBase + { + public ReactiveCommand ShowDialogCommand { get; } = new ReactiveCommand(); + public SurveyPageViewModel() + { + var dialog = AiForms.Dialogs.Dialog.Instance; + ShowDialogCommand.Subscribe(async _ => + { + var ret = await dialog.ShowAsync(); + if (ret) + { + //await dialog.ShowAsync(); + } + }); + } + } +} diff --git a/Sample/Sample/Views/Dialogs/TestDialog.xaml b/Sample/Sample/Views/Dialogs/TestDialog.xaml new file mode 100644 index 0000000..b79fe1d --- /dev/null +++ b/Sample/Sample/Views/Dialogs/TestDialog.xaml @@ -0,0 +1,10 @@ + + + +