Swipe and load more in nested scrollview.

VikasAgarwalVikasAgarwal INMember ✭✭

I am creating a screen which is able to display category and it's video list in the horizontal scroll. The combo of category and video list scroller are multiple on the same screen.
I want to load more video on scroll right for the particular category.
I am able to find more records based on the category but video horizontal scroll is not getting update.
Below is my code.

XMAL page:

 <ContentPage.Content>
        <StackLayout Spacing="0">
        <StackLayout HeightRequest="1" />
        <ScrollView BackgroundColor="{Binding BackgroundColor}" x:Name="rootCategoryContainer">
            <local:HVScrollGridView x:Name="listVODCategory" ItemsSource="{Binding SVODCatalog}" ListOrientation="Vertical" VerticalOptions="Start">
                <local:HVScrollGridView.ItemTemplate>
                    <DataTemplate>
                        <Grid HorizontalOptions="FillAndExpand">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="50" />
                                <RowDefinition Height="215" />
                            </Grid.RowDefinitions>
                            <StackLayout x:Name="headerRow" Grid.Row="0" HeightRequest="50" BackgroundColor="{Binding BarBackgroundColor}">
                                <Label Text="{Binding name}" TextColor="White" FontSize="18" VerticalOptions="CenterAndExpand" FontAttributes="Bold" Margin="10,0,0,0">
                                <Label.GestureRecognizers>
                                    <TapGestureRecognizer CommandParameter="{Binding id}" Tapped="SVOD_CategoryClicked" NumberOfTapsRequired="1" />
                                </Label.GestureRecognizers> 
                                </Label>
                            </StackLayout>
                            <local:HVScrollGridView x:Name="listVODAssets" SelectedCommand="{Binding id}" ListOrientation="Horizontal" ItemsSource="{Binding SubCategories, Mode=TwoWay }" Grid.Row="1" BackgroundColor="{Binding StackBackgroundColor}" SelectedItemChanged="Handle_SelectedItemChanged">
                                <local:HVScrollGridView.ItemTemplate>
                                    <DataTemplate>
                                        <ContentView>
                                            <ContentView.Content>
                                                <StackLayout WidthRequest="112" HeightRequest="210" Margin="10,10,0,0">
                                                    <Grid RowSpacing="0" ColumnSpacing="5">
                                                        <Grid.RowDefinitions>
                                                            <RowDefinition Height="170">
                                                            </RowDefinition>
                                                            <RowDefinition Height="40">
                                                            </RowDefinition>
                                                        </Grid.RowDefinitions>
                                                        <ffimageloading:CachedImage Source="{Binding poster}" LoadingPlaceholder="default_asset.png" ErrorPlaceholder="default_asset.png" Grid.Row="0" Aspect="AspectFill" HeightRequest="170" DownsampleToViewSize="true">
                                                            <ffimageloading:CachedImage.Transformations>
                                                                <ffTransformations:BlurredTransformation Radius="15" />
                                                            </ffimageloading:CachedImage.Transformations>
                                                        </ffimageloading:CachedImage>
                                                        <ffimageloading:CachedImage x:Name="Image" HeightRequest="170" Grid.Row="0" LoadingPlaceholder="default_asset.png" ErrorPlaceholder="default_asset.png" DownsampleToViewSize="true" Aspect="AspectFit" Source="{Binding poster}">
                                                        </ffimageloading:CachedImage>
                                                        <Label x:Name="label" Text="{Binding title}" Margin="0,5,0,0" Grid.Row="1" TextColor="White" FontSize="14" FontAttributes="Bold" HorizontalTextAlignment="Center" LineBreakMode="TailTruncation" >
                                                        </Label>
                                                        </Grid>
                                                    <!--<StackLayout.GestureRecognizers>
                                                        <SwipeGestureRecognizer Direction="Left" CommandParameter="{Binding rootCategoryId}" Swiped="Handle_Swiped_1" />
                                                    </StackLayout.GestureRecognizers> -->
                                                </StackLayout>
                                            </ContentView.Content>
                                        </ContentView>
                                    </DataTemplate>
                                </local:HVScrollGridView.ItemTemplate>
                                    <local:HVScrollGridView.GestureRecognizers>
                                                        <SwipeGestureRecognizer Direction="Left" CommandParameter="{Binding id}" Swiped="SVODAssetsSwipped" />
                                                    </local:HVScrollGridView.GestureRecognizers> 
                            </local:HVScrollGridView>
                        </Grid>
                    </DataTemplate>
                </local:HVScrollGridView.ItemTemplate>
            </local:HVScrollGridView>
        </ScrollView>
    </StackLayout>
    </ContentPage.Content>

C#:

 public static double categoryViewLastScrolledPosition = 0;
        private SVODAssetViewModel model;
        public string DefaultCategoryImage { get; set; }
        public Color StackColor { get; set; }
        private string categoryId;
        bool initialLoad;

        public SVODPage()
        {
            model = new SVODAssetViewModel();
            categoryId = "";
            InitializeComponent();
            initialLoad = true;
        }
        public SVODPage(string catId, string categoryName)
        {
            model = new SVODAssetViewModel(categoryName);
            categoryId = catId;
            InitializeComponent();
            initialLoad =true;
        }
        protected async override void OnAppearing()
        { 
            if (initialLoad)
            {
                initialLoad = false;
                await model.MapAssets(categoryId);
                listVODCategory.ItemsSource = model.SVODCatalog;
               // BindingContext = model;
            }
            OnPropertyChanged();
            base.OnAppearing();
        }
async void SVODAssetsSwipped(object sender, SwipedEventArgs e)
        {
            var catId = (e.Parameter) as string;
            await model.GetAssetsByCategoryId(catId);
            var subCategory = model.SVODCatalog.Where(x => x.id == catId).FirstOrDefault();
            //listVODCategory.ItemsSource = null;  // When I use this line it is able to load new records but also set scroll position to start.
            listVODCategory.ItemsSource = model.SVODCatalog;
        }

Sign In or Register to comment.