Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UWP Win 10 Tinder swipe card inside Pivot?

Firstly here's the link to my minimal version project.
I am trying to create a tinder swipe card kind of effect inside my Pivot Page. After referring Lightstone Carousel Was able to create one in C# and XAML which works inside a Grid.
Now my problem is that custom control should come inside a Pivot element. As pivot's default manipulation overrides my control's swipe Manipulation on TOUCH devices. How can I bubble down to my custom control.
Wasn't able to find Touchin Win 10 app as per @Romasz answer.
Any other control suggestion with similar effect would also be appreciated. XAML

<Pivot>    
        <PivotItem>
            <Grid Background="White">
                <Grid.RowDefinitions>
                    <RowDefinition Height="*"/>
                    <RowDefinition Height="3*"/>
                    <RowDefinition Height="*"/>
                </Grid.RowDefinitions>
                <Grid Grid.Row="0" Background="LightBlue"/>
                <Grid Grid.Row="1" >
                    <ctrl:Carrousel  Grid.Row="0" Background="Green"   ItemsSource="{Binding Datas}" 
                        SelectedIndex="0"
                        TransitionDuration="2500" 
                        Depth="700" 
                        MaxVisibleItems="15"
                        x:Name="CarrouselElement"
                        Rotation="50" 
                        TranslateY="0"
                        TranslateX ="1200">
                        <ctrl:Carrousel.EasingFunction>
                            <CubicEase EasingMode="EaseOut" />
                        </ctrl:Carrousel.EasingFunction>
                        <ctrl:Carrousel.ItemTemplate>
                            <DataTemplate>
                                <Grid Background="Red">
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="Auto"/>
                                        <RowDefinition Height="Auto"/>
                                    </Grid.RowDefinitions>
                                    <Border BorderBrush="#bfbfbf" BorderThickness="1">
                                        <Grid HorizontalAlignment="Stretch">
                                            <Grid.RowDefinitions>
                                                <RowDefinition Height="Auto"/>
                                                <RowDefinition Height="Auto"/>
                                            </Grid.RowDefinitions>
                                            <Image Source="{Binding BitmapImage}" Stretch="Fill"></Image>
                                            <Border Grid.Row="1" Background="White">
                                                <TextBlock  Text="{Binding Title}"  FontSize="16" Margin="4"/>
                                            </Border>                                              
                                        </Grid>
                                    </Border>
                                    <Rectangle Grid.Row="1" Height="12" Margin="0,0,0,0" VerticalAlignment="Bottom" >
                                        <Rectangle.Fill>
                                            <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                                <GradientStop Color="#bfbfbf"/>
                                                <GradientStop Color="Transparent" Offset="1"/>
                                            </LinearGradientBrush>
                                        </Rectangle.Fill>
                                    </Rectangle>
                                </Grid>    
                            </DataTemplate>
                        </ctrl:Carrousel.ItemTemplate>
                    </ctrl:Carrousel>
                </Grid>  
            </Grid>
        </PivotItem>
        <PivotItem>
        </PivotItem>    
    </Pivot>

As per @Chris W. query following two show the Tinder swipe effect
1) Web Version
2) Objective C Code

To see similar effect in app remove the encasing pivot control and pivot items and it would work fine.

EDIT As per @Romasz comment have uploaded a new sample. There are two upper one being my custom control where left and right swipe now works but vertical swipe doesn't. Below is default ListView where scroll swipe everything works but there is no Tinder kind effect. The only reason of creating the control is to add effect.

like image 222
Jerin Avatar asked May 25 '16 08:05

Jerin


1 Answers

According to your second sample, add ManipulationMode="System,TranslateX" to your carrousel. This should allow to move scrollviewer vertically and swipe through images horizontally:

<ctrl:Carrousel  Grid.Row="0" Background="LightGreen" ItemsSource="{Binding Datas}" ManipulationMode="System,TranslateX"
                 SelectedIndex="0" TransitionDuration="2500" Depth="700" MaxVisibleItems="15" x:Name="CarrouselElement"
                 Rotation="50" TranslateY="0" TranslateX ="1200">

There will be only just one problem - while the vertical scrollviewer is working and you swipe left/right, even on carrousel, the pivot will react with the change of item. There are two ways in this situation, I think:

  • first, disable inertia of your scrollviewer - IsScrollInertiaEnabled="False". But, as this solution doesn't look nice, I thought about different way,
  • second, disable pivot while the scrollviewer is working. For this case you will have to subscribe to ViewChanged event of your scrollviewer and control pivot's IsLocked property:

    <ScrollViewer ViewChanged="ScrollViewer_ViewChanged" VerticalScrollBarVisibility="Hidden" HorizontalScrollBarVisibility="Disabled">
    

    in the code behind (I've also named your pivot):

    private void ScrollViewer_ViewChanged(object sender, ScrollViewerViewChangedEventArgs e) => myPivot.IsLocked = e.IsIntermediate;
    

As for changing pivot upon first/last element, I think you should be able to handle this by modifying a little the carrousel - provide events informing about the first/last item. Upon this you can invoke the pivot change.

like image 155
Romasz Avatar answered Sep 27 '22 16:09

Romasz