When using Prism to DeepLink to a row inside a ListView, how can I update the ListView scroll and highlight?

182 views Asked by At

I am using Xamarin Forms with Prism, based on this GitHub sample..

Desired Behavior

  1. Deep link is clicked, showing the detail view:

    enter image description here

  2. User presses back button. Scroll and highlight the linked selection (not happening).
    None of the OnNavigation events are firing. Is this a bug? How do I accomplish this?

    enter image description here

App.Xaml

public partial class App : PrismApplication
{
    public App(IPlatformInitializer initializer = null) : base(initializer) { }

    protected override async void OnInitialized()
    {
        InitializeComponent();

        await NavigationService.NavigateAsync("MainTabbedPage/NavigationPage/ShowsListPage/DetailPage?show=279121");
        //await NavigationService.NavigateAsync("MainTabbedPage/NavigationPage/ShowsListPage");
    }

    protected override void RegisterTypes()
    {
        Container.RegisterTypeForNavigation<UpcomingShowsPage>();
        Container.RegisterTypeForNavigation<ShowsListPage>(); // <-- Problematic ListView
        Container.RegisterTypeForNavigation<DetailPage>();
        Container.RegisterTypeForNavigation<MainTabbedPage>();
        Container.RegisterTypeForNavigation<NavigationPage>();
        Container.RegisterType<ITsApiService, TsApiService>();
    }

ShowsListPage.xaml

ContentPage is using the Prism directive: prism:ViewModelLocator.AutowireViewModel="True". (nothing special)

ShowsListPageViewModel.cs

using System.Collections.ObjectModel;
using InfoSeries.Core.Models;
using InfoSeries.Core.Services;
using Prism.Commands;
using Prism.Mvvm;
using Prism.Navigation;
using Xamarin.Forms;

namespace DeepNavigation.ViewModels
{
    public class ShowsListPageViewModel : BindableBase, INavigationAware
    {
        private readonly ITsApiService _tsApiService;
        private readonly INavigationService _navigationService;
        private ObservableCollection<SerieFollowersVM> _highlightSeries;

        public ObservableCollection<SerieFollowersVM> HighlightSeries
        {
            get { return _highlightSeries; }
            set { SetProperty(ref _highlightSeries, value); }
        }


        public ShowsListPageViewModel(ITsApiService tsApiService, INavigationService navigationService)
        {
            _tsApiService = tsApiService;
            _navigationService = navigationService;
        }

        public void OnNavigatedFrom(NavigationParameters parameters)
        {

        }

        public async void OnNavigatedTo(NavigationParameters parameters)
        {
            var series = await _tsApiService.GetStatsTopSeries();
            HighlightSeries = new ObservableCollection<SerieFollowersVM>(series);
        }

        public void OnNavigatingTo(NavigationParameters parameters)
        {

        }

        private DelegateCommand<ItemTappedEventArgs> _goToDetailPage;

        public DelegateCommand<ItemTappedEventArgs> GoToDetailPage
        {
            get
            {
                if (_goToDetailPage == null)
                {
                    _goToDetailPage = new DelegateCommand<ItemTappedEventArgs>(async selected =>
                    {
                        NavigationParameters param = new NavigationParameters();
                        var serie = selected.Item as SerieFollowersVM;
                        param.Add("show", serie.Id);
                        await _navigationService.NavigateAsync("DetailPage", param);
                    });
                }

                return _goToDetailPage;
            }
        }
    }
}

Question

  • How can I get the back button to select the list view?
  • Is there any platform guidance saying that the back button after a deep link must go to the source calling application.. rendering this question useless? (e.g. pop the navigation back to Chrome/Safari)
0

There are 0 answers