Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SPEC] New IDialogService for Prism.Forms #1814

Closed
dansiegel opened this issue May 29, 2019 · 4 comments · Fixed by #1825
Closed

[SPEC] New IDialogService for Prism.Forms #1814

dansiegel opened this issue May 29, 2019 · 4 comments · Fixed by #1825
Assignees
Milestone

Comments

@dansiegel
Copy link
Member

dansiegel commented May 29, 2019

Description

Native Dialogs are UGLY! Prism.Forms should follow the example of Prism.WPF and introduce a similar user experience in which we can register X.F. Views as a Dialog which can then be overlaid on top of the current page. This would allow developers to develop dialogs that have a precise look and feel that matches their existing app and provide the exact functionality that they require.

Proposed SPEC

So as to not confuse people we will be introducing some new API's and we'll be very selective about the existing API's we support.

Existing Supported API's

  • IAutoInitialize - This will automatically set properties based on the IDialogParameters. This will look for the DialogParameterAttribute instead of the NavigationParameterAttribute

New API's

public interface IDialogService
{
    void ShowDialog(string name, IDialogParameters parameters, Action<IDialogResult> callback);
}

public interface IDialogResult : INavigationResult
{
    IDialogParameters Parameters { get; }
}

public interface IDialogParameters : INavigationParameters
{
}

public interface IDialogAware
{
    bool CanCloseDialog();

    void OnDialogClosed();

    void OnDialogOpened(IDialogParameters parameters);

    event Action<IDialogParameters> RequestClose;
}

Using the Dialog

To start using dialogs you will need to register any Xamarin.Forms View using a new IContainerRegistry extension like so:

// ViewModel automatically resolved by the VML
containerRegistry.RegisterDialog<SomeDialog>();

// ViewModel explicitly set
containerRegistry.RegisterDialog<AnotherDialog, AnotherDialogViewModel>();

// Overriding the Type.Name for the Dialog
containerRegistry.RegisterDialog<FooDialog>("fooDialog");

To use the Dialog you can inject the IDialogService into any ViewModel and call ShowDialog like so:

public class ViewAViewModel : BindableBase
{
    public ViewAViewModel(IDialogService dialogService)
    {
        ShowDialog = new DelegateCommand(() => dialogService.ShowDialog("SomeDialog"));
    }

    public ICommand ShowDialog { get; }
}

Additionally a new XAML Extension would be added to allow you to Show a Dialog.

<Button Text="Show Some Alert"
        Command="{prism:ShowDialog AlertDialog}" />

In classic Prism.Forms style ShowDialog should accept querystrings so that you can display a dialog like:

dialogService.ShowDialog("AlertDialog?title=Error&message=Hello%20World");

Page Mask

The Dialog Service will put a mask between your existing content and the Dialog. The Dialog Service will look in the Application Resources for a Style that targets a BoxView with the Key PrismDialogMaskStyle. If it finds one it will use that style, otherwise it will use a default style.

To close the dialog when the user taps outside of the dialog on the mask layer, you must add the key closeOnBackgroundTapped when calling ShowDialog. This could be done either with the querystring or DialogParameters.

In the Dialog ViewModel

The Dialog must have a ViewModel and the ViewModel must implement IDialogAware. This would look something like:

public class AlertDialogViewModel : BindableBase, IAutoInitialize, IDialogAware
{
    public AlertDialogViewModel()
    {
        CloseCommand = new DelegateCommand(() => RequestClose(null));
    }

    private string _title;
    public string Title
    {
        get => _title;
        set => SetProperty(ref _title, value);
    }

    private string _message;
    public string Message
    {
        get => _message;
        set => SetProperty(ref _message, value);
    }

    public DelegateCommand CloseCommand { get; }

    public event Action<IDialogParameters> RequestClose;

    public bool CanCloseDialog() =>
        true;

    public void OnDialogClosed()
    {

    }

    public void OnDialogOpened(IDialogParameters parameters)
    {

    }
}
@dansiegel dansiegel added this to the Prism 7.2 milestone May 29, 2019
@dansiegel dansiegel self-assigned this May 29, 2019
@SkyeHoefling
Copy link
Contributor

@dansiegel would it be helpful if xamarin/Xamarin.Forms#1778 (Xamarin.Forms Popups) was completed for this feature? I need to implement this for a project I am working on and I am planning to submit a PR back to Xamarin.Forms for it.

If I am reading this Spec correctly it appears this implementation would be easier if it could leverage the IPopup spec documented in the Xamarin.Forms issue

@dansiegel
Copy link
Member Author

@ahoefling I actually already have it working... in the process though we discovered a bug in Xamarin.Forms that they were looking into

@brianlagunas
Copy link
Member

Not to mention that popups API is awful

@lock
Copy link

lock bot commented Jan 28, 2020

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Jan 28, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants