Giter Site home page Giter Site logo

andreimisiukevich / cardview Goto Github PK

View Code? Open in Web Editor NEW
713.0 22.0 114.0 3.42 MB

CardsView | CarouselView | CoverflowView | CubeView for Xamarin.Forms

License: MIT License

C# 100.00%
cardviews xamarin-forms carouselview tinder-swiper carousel cardsview coverflowview coverflow cubeview hacktoberfest

cardview's Introduction

GIF

CardsView CarouselView CoverFlowView CubeView
ScaleFactor & OpacityFactor ScaleFactory & OpacityFactor [2] TabsControl

Setup

  • Available on NuGet: CardsView NuGet
  • Add nuget package to your Xamarin.Forms .NETSTANDARD/PCL project and to your platform-specific projects
  • Add (AFTER Forms.Init(...)):
    • CardsViewRenderer.Preserve() AppDelegate in FinishedLaunching for iOS
    • CardsViewRenderer.Preserve() MainActivity in OnCreate for Android
Platform Version
Xamarin.iOS iOS 7+
Xamarin.Mac All
Xamarin.Android API 15+
Windows 10 UWP 10+
Tizen 4.0+
Gtk All
WPF .NET 4.5
.NET Standard 2.0+

C#:

-> Create CardsView and setup it

var cardsView = new CardsView
{
    ItemTemplate = new DataTemplate(() => new ContentView()) //your template
};
cardsView.SetBinding(CardsView.ItemsSourceProperty, nameof(PanCardSampleViewModel.Items));
cardsView.SetBinding(CardsView.SelectedIndexProperty, nameof(PanCardSampleViewModel.CurrentIndex));

-> Optionaly you can create ViewModel... or not... as you wish

-> Indicators bar (For CarouselView, perhaps). It's easy to add indicators -> Just add IndicatorsControl into your carouselView as a child view.

carouselView.Children.Add(new IndicatorsControl());

XAML:

<cards:CarouselView 
    ItemsSource="{Binding Items}"
    SelectedIndex="{Binding CurrentIndex}">
    <cards:CarouselView.ItemTemplate>
        <DataTemplate>
            <ContentView>
                <Frame 
                    VerticalOptions="Center"
                    HorizontalOptions="Center"
                    HeightRequest="300"
                    WidthRequest="300"
                    Padding="0" 
                    HasShadow="false"
                    IsClippedToBounds="true"
                    CornerRadius="10"
                    BackgroundColor="{Binding Color}">
                    
                    <Image Source="{Binding Source}"/> 
                    
                </Frame>
            </ContentView>
        </DataTemplate>
    </cards:CarouselView.ItemTemplate>

    <controls:LeftArrowControl/>
    <controls:RightArrowControl/>
    <controls:IndicatorsControl/>
</cards:CarouselView>

Also you are able to manage IndicatorsControl appearing/disappearing. For example if user doesn't select new page during N miliseconds, the indicators will disappear. Just set ToFadeDuration = 2000 (2 seconds delay before disappearing) You manage LeftArrowControl and RightArrowControl as well as IndicatorsControl (ToFadeDuration is presented too).

Indicators styling:

 <ContentPage.Resources>
    <ResourceDictionary>
        <Style x:Key="ActiveIndicator" TargetType="Frame">
            <Setter Property="BackgroundColor" Value="Red" />
        </Style>
        <Style x:Key="InactiveIndicator" TargetType="Frame">
            <Setter Property="BackgroundColor" Value="Transparent" />
            <Setter Property="OutlineColor" Value="Red" />
        </Style>
    </ResourceDictionary>
</ContentPage.Resources>

... 

<controls:IndicatorsControl ToFadeDuration="1500"
          SelectedIndicatorStyle="{StaticResource ActiveIndicator}"
          UnselectedIndicatorStyle="{StaticResource InactiveIndicator}"/>

if you want to add items directly through xaml

...
    <cards:CarouselView.ItemsSource>
            <x:Array Type="{x:Type View}">
                <ContentView>
                    <Image Source="yourImage.png"/>
                </ContentView>
                <RelativeLayout>
                    <Button Text="Click" />
                </RelativeLayout>
                <StackLayout>
                    <Label Text="any text"/>
                </StackLayout>
            </x:Array>
    </cards:CarouselView.ItemsSource>
...

if you want to achieve scale or opacity changing effects for side views (ScaleFactor & OpacityFactor), you should mange corresponding properties in processor and pass them to view constructor via x:Arguments:

<ContentPage 
    ...
    xmlns:cards="clr-namespace:PanCardView;assembly=PanCardView"
    xmlns:proc="clr-namespace:PanCardView.Processors;assembly=PanCardView">

...

<cards:CoverFlowView 
      PositionShiftValue="145"
      ItemsSource="{Binding Items}">

      <x:Arguments>
          <proc:CoverFlowProcessor ScaleFactor="0.75" OpacityFactor="0.25" />
      </x:Arguments>

  <cards:CoverFlowView.ItemTemplate>
      <DataTemplate>
         <Frame
             Margin="80">
               
              ....

          </Frame>
      </DataTemplate>
  </cards:CoverFlowView.ItemTemplate>

</cards:CoverFlowView>

...

-> If you want to customize indicators, you need set SelectedIndicatorStyle and/or UnselectedIndicatorStyle, or you are able to extend this class and override several methods. Also you can customize position of indicators (You need to set Rotation / AbsoluteLayout Flags and Bounds etc.)

This class is describing default indicators styles (each default indicator item is Frame) https://github.com/AndreiMisiukevich/CardView/blob/master/PanCardView/Styles/DefaultIndicatorItemStyles.cs

MORE SAMPLES you can find here https://github.com/AndreiMisiukevich/CardView/tree/master/PanCardViewSample

Custom Animations

You are able to create custom animations, just implement IProcessor or extend existing processors (change animation speed or type etc.) https://github.com/AndreiMisiukevich/CardView/tree/master/PanCardView/Processors

Workarounds

-> If you want to put your cardsView/carouselView INTO a TabbedPage on Android:

  1. Add an event handler for the UserInteraction event
  2. On UserInteractionStatus.Started: Disable TabbedPage Swipe Scrolling
  3. On UserInteractionStatus.Ending/Ended: Enabled TabbedPage Swipe Scrolling

Example:

  1. TabbedPage:
public partial class TabbedHomePage : Xamarin.Forms.TabbedPage
{
    public static TabbedHomePage Current { get; private set; }

    public TabbedHomePage()
    {
        Current = this;
    }

    public static void DisableSwipe()
    {
        Current.On<Android>().DisableSwipePaging();
    }
    
    public static void EnableSwipe()
    {
        Current.On<Android>().EnableSwipePaging();
    }
}
  1. Page with CardsView/CarouselView:
public PageWithCarouselView()
{
    InitializeComponent();

    carouselView.UserInteracted += CarouselView_UserInteracted;
}

private void CarouselView_UserInteracted(PanCardView.CardsView view, PanCardView.EventArgs.UserInteractedEventArgs args)
{
    if (args.Status == PanCardView.Enums.UserInteractionStatus.Started)
    {
        TabbedHomePage.DisableSwipe();
    }
    if (args.Status == PanCardView.Enums.UserInteractionStatus.Ended)
    {
        TabbedHomePage.EnableSwipe();
    }
}

-> If you don't want to handle vertical swipes or they interrupt your scrolling, you can set IsVerticalSwipeEnabled = "false"

-> If all these tricks didn't help you, you may use IsPanInteractionEnabled = false This trick disables pan interaction, but preserve ability to swipe cards.

-> If you get crashes during ItemsSource update, try to add/set items in Main Thread (Device.BeginInvokeOnMainThread)

-> GTK use click / double click for forward/back navigation.

Check source code for more info, or just ask me =)

Full documentation

https://github.com/AndreiMisiukevich/CardView/tree/master/docs

License

The MIT License (MIT) see License file

Contribution

Feel free to create issues and PRs 😃

cardview's People

Contributors

andreimisiukevich avatar b099l3 avatar baranpirincal avatar erdugen avatar ernestoyaquello avatar ieuanwalker avatar inquisitorjax avatar jtone123 avatar karlingen avatar kurianov-pavel avatar logicsandbox avatar maukur avatar phenek avatar pomezny avatar rookiejava avatar rotorgames avatar tdoell avatar troyvnit avatar vecalion avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cardview's Issues

Set up UWP project sample

I'm working on Mac.. So, I can't test this pack on UWP.
Maybe, somebody want to help?
I will be grateful)

is it possible to override swipe ?

i want to distinguish vertical swipe and horizontal swipe.
how can i make cardview worked only when absX is lager than absY ?
and i want my app use vertical swipe event.

i wrote code like this . this code work to swipe on UWP but it doesnt work to swipe on Andriod.

namespace PanCardViewSample.Views
{
public class FlashCardsView : CardsView
{
double x, y;
public FlashCardsView()
{
this.IsPanEnabled = false;
var panGesture = new PanGestureRecognizer();
panGesture.PanUpdated += OnPanUpdated_FlashCardsView;
GestureRecognizers.Add(panGesture);

    }

    public void OnPanUpdated_FlashCardsView(object sender, PanUpdatedEventArgs e)
    {
        int id = (int)e.StatusType;
        switch (e.StatusType)
        {
            case GestureStatus.Started:
                x = 0;
                y = 0;
                break;
            case GestureStatus.Running:
                x += e.TotalX;
                y += e.TotalY;
                break;

            case GestureStatus.Completed:

                var absX = Math.Abs(x);
                var absY = Math.Abs(y);

                if(absX > absY)
                {
                    if (x < -20)
                        ProcessGestureLeft();
                    else if (x > 20)
                        ProcessGestureRight();
                }
                else
                {
                    if (y < -20)
                        ProcessGestureUp();
                    else if (y > 20)
                        ProcessGestureDown();
                }
                break;
        }
    }

    private void ProcessGestureUp()
    {
        System.Diagnostics.Debug.WriteLine("ProcessGestureUp");
    }

    private void ProcessGestureDown()
    {
        System.Diagnostics.Debug.WriteLine("ProcessGestureDown");
    }
    private void ProcessGestureLeft()
    {
        System.Diagnostics.Debug.WriteLine("ProcessGestureLeft");
        this.CurrentIndex -= 1;
    }

    private void ProcessGestureRight()
    {
        System.Diagnostics.Debug.WriteLine("ProcessGestureRight");
        this.CurrentIndex += 1;
    }
}

}

Ways to handle 'micro-scroll'

Hello,
Currently I have a button inside a PanCardView, but it is very hard to register a tap on the button as moving your finger slightly will cause the page to begin to swipe (move with your finger). I see properties like 'SwipeThresholdDistance', but it doesn't seem to be having an effect.

Is there a way to limit the swipe sensitivity to give an opportunity for the button to be clicked? This might just be an issue on Xamarin / Android, but if you can suggest something I can do with the CardView - I am all ears!

Thanks.

Problems with view when updating collection

Hi,
I think there is some bug in View handling or caching. I have this situation:CarouselView with Items bound to ObservableCollection. In ItemTemplate there is simple Grid with Image and Label. I use Label.GestureRecognizer to remove current Item. When I remove item from ObservableCollection CurrentIndex is reset to 0, it can be easily workarounded by "holding" current index and then setting it back. But when CarouselView is on first item(i.e. CurrentIndex=0) and this first item is removed view stays the same. Image(whole Item, to be precise) is not changed until I swipe to next and then back. I tried IsViewCacheEnabled="False" without any effect. I understand Carousel only refresh when CurrentIndex is changed but in this particular situation I need to trigger reload(removing and setting back Binding context makes things only worse, beacause image than stays on top of carousel, and other images slide under). Issue is not limited to Image, I tried replacing image with Label and issue persist

I cannot provide repro solution at the moment , but simply removing first element from ObservableCollection bound to Items after page is loaded via button or something similar should produce described result.

Strange crash on Micromax Q415 Android 5.1.1 (LMY47V)

Hi Andrei,
I cannot reproduce this issue locally.

But maybe you will have ideas

System.Collections.Generic.KeyNotFoundException: The given key 'd0a62975-860b-4230-8625-fc1c54dac304' was not present in the dictionary.
  at System.ThrowHelper.ThrowKeyNotFoundException (System.Object key) <0xa18bc674 + 0x00040> in <2eb4e6dcb9e24a7197a80754c771a4d1>:0
  at System.Collections.Generic.Dictionary`2[TKey,TValue].get_Item (TKey key) [0x0001e] in <2eb4e6dcb9e24a7197a80754c771a4d1>:0
  at PanCardView.CardsView.RemoveRangeViewsInUse (System.Guid gestureId) [0x00011] in <10c7bd54520649c1aeecf968ee222939>:0
  at PanCardView.CardsView+<OnTouchEnded>d__233.MoveNext () [0x002eb] in <10c7bd54520649c1aeecf968ee222939>:0
  at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__6_0 (System.Object state) <0xa1a94218 + 0x00058> in <2eb4e6dcb9e24a7197a80754c771a4d1>:0
  at Android.App.SyncContext+<>c__DisplayClass2_0.<Post>b__0 () <0xa16ae0a0 + 0x00017> in <503d9613285443639dc3b4625e0c2f0d>:0
  at Java.Lang.Thread+RunnableImplementor.Run () <0xa171d76c + 0x0002f> in <503d9613285443639dc3b4625e0c2f0d>:0
  at Java.Lang.IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this) <0xa1722ebc + 0x00057> in <503d9613285443639dc3b4625e0c2f0d>:0
  at (wrapper dynamic-method) System.Object.c790a66d-4d3a-4116-a333-4ed30e921184(intptr,intptr)

Sizing carousel view to full width without weird margins

For example
In Iphone emulator 2436x1125 i need to specify a height of ~250px
In Android device 782x480 i need to specify a height of ~215px

Something weird in iphone emulator for example, with 1125px width, for the image to fully cover horizontally no way the carousel should have less than ~500px height while testing it needs ~250px height.

Default constructor not found for type PanCardView.Droid.CardsViewRenderer

Hi!

I used the CardsView control inside the PullToRefreshLayout from jamesmontemagno control, when the app start throws me the error:
Default constructor not found for type PanCardView.Droid.CardsViewRenderer

How could I avoid this error? first I try not link the assemblies in config properties, then I try creating a custom render with default constructor without luck.

I used xamarin forms 2.4
thanks for your help

ItemSource doesn't update

How can I change the items shown? Neither replacing Items completely or using a bound ObservableCollection and modifying its contents seem to do the trick. I have a hierarchical data set to display and when the user taps on an item, I'd like to replace the whole carousel with the items one level below.

System.NullReferenceException: Object reference not set to an instance of an object.

Getting a null reference exception when trying to initialize the carousel view. I don't have a lot of info, because I can't track down the source of the exception, and no amount of try-catches have been able to narrow it down.

I'm trying to use your carousel, because the only other decent option has stopped support, and is giving me too much grief.

My code for initializing the carousel is:

var carousel = new PanCardView.CarouselView()
            {
                ItemTemplate = new DataTemplate(() =>
                {
                    var img = new CachedImage();
                    img.SetBinding(CachedImage.SourceProperty, "ImageUrl");
                    //img.Clicked += Image_Clicked;
                    return new ViewCell() { View = img };
                })
            };
            carousel.SetBinding(PanCardView.CarouselView.ItemsProperty, nameof(CarouselImages));
            carousel.SetBinding(PanCardView.CarouselView.CurrentIndexProperty, nameof(CarouselPosition));

            CarouselViewContainer.Children.Add(carousel);

From what I can tell, the exception gets thrown sometime after the code runs the return new ViewCell() { View = img }; line.

CarouselView crashing app (sometimes OS) when swiping down in scrollview

The app is crashing (sometimes causing OS reboot) when I'm scrolling from over the carouselView in Android (haven't tested iOS yet).

My hierarchy looks like this...

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:cardView="clr-namespace:PanCardView.Controls;assembly=PanCardView"
             xmlns:carousel="clr-namespace:PanCardView;assembly=PanCardView"
             x:Class="App.Pages.HomePage">
    <ContentPage.Content>
        <cardView:ParentScrollView>
            <StackLayout x:Name="MainLayout" Style="{ DynamicResource BackgroundLightGray }">
                    .....

                <StackLayout x:Name="PromotionStack" VerticalOptions="Start" HorizontalOptions="FillAndExpand" />

                .........
            </StackLayout>
        </cardView:ParentScrollView>
    </ContentPage.Content>
</ContentPage>

And the code behind does this:

PromotionStack.Children.Add(new PanCardView.CarouselView() {
                HorizontalOptions = LayoutOptions.FillAndExpand,
                Items = new List<View>() {
                            new CardView()
                            {
                                Content = new StackLayout()
                                {
                                    HorizontalOptions = LayoutOptions.FillAndExpand,
                                    Children = { new CachedImage() { Source = "https://aldrichsolutions.com/images/app/banner.jpg?x=3", Aspect = Aspect.Fill } }
                                }
                            },
                            new CardView()
                            {
                                Content = new StackLayout()
                                {
                                    HorizontalOptions = LayoutOptions.FillAndExpand,
                                    Children = { new CachedImage() { Source = "https://aldrichsolutions.com/images/app/banner.jpg?x=3", Aspect = Aspect.Fill } }
                                }
                            }
                        }
            });

GIF showing behavior:

6ff8288a-f3c5-4f0d-9c7c-a1ecea70b4ed

On a related note, if I set my images to any other aspect (or no aspect) the carousel is still just as tall, but the image scales properly, just with a bunch of white space underneath. Any suggestions on how to fix that? I'd like the carousel to just automatically height itself to the images being passed in if possible - as I won't know the height of the images beforehand.

View indicator

Is there anyway to add a view indicator to this to see what page you're on?
I can't find any code for it however all other views have them included

Non-public API usage - iOS Issue

When I try to upload the binary to the app store I get the following message from apple:

"We identified one or more issues with a recent delivery for your app, "<<APP_NAME>>". Please correct the following issues, then upload again.

Non-public API usage:

The app references non-public selectors in <<APP_NAME>>.iOS: applicationWillTerminate, setOrientation:animated:, terminateWithSuccess

If method names in your source code match the private Apple APIs listed above, altering your method names will help prevent this app from being flagged in future submissions. In addition, note that one or more of the above APIs may be located in a static library that was included with your app. If so, they must be removed."

carouselView iOS IOrdinateHandler

The custom scroll function for the ParentScrollView (HandleOrdinateValue) is performing incorrectly. It will go past the height of my outer scrollview.

Swiping issues in Android

On android only (so far as I've been able to see). swiping seems to fail sometimes. In testing, I've found that if I do large fast swipes, the image will move over a little, and then stick. If I do large slow swipes, it does a little better, but still doesn't move to the next image. The only consistent way to swipe over is a small quick swipe, maybe half an inch or so (5.5" display).

Andrei suggested here that I set 'IsPanInCourse' to false, but that didn't seem to make any difference.

Current carousel code

public List<SliderImage> CarouselImages { get; set; }
...
var carousel = new PanCardView.CarouselView()
            {
                ItemTemplate = new DataTemplate(() =>
                {
                    var img = new ClickableCachedImage();
                    img.SetBinding(ClickableCachedImage.SourceProperty, "ImageUrl");
                    img.Clicked += Image_Clicked;
                    return new ContentView() { Content = img };
                }),
                //IsPanInCourse = false, // didn't seem to make a difference
            };

SliderImage is a simple class that essentially just holds a string value of ImageUrl, and ClickableCachedImage is a class that essentially inherits from Xamarin.Forms.Image. Switching to using Xamarin.Forms.Image's doesn't change anything.

If I were to guess, it seems like there are hard constraints on either/both swipe distance, and/or swipe time. And instead of going back to default position when one of those constraints is hit, the carousel just freezes where it is.

Let me know if there's any other information I could provide that could be helpful.

Thanks for the plugin BTW, it's pretty awesome.

ItemTemplate visual BindingContext getting copied between the Items property of the CarouselView

I use the CarouselView inside a ContentView. This CarouselView has a binding to a list of Weeks (in order to print out the weeks for a certain year). Then, I use the ItemTemplate to print each week as I want to. Each week then has to print its 7 days via a DayCell custom control (another ContentView) to which I assign the BindingContext from the XAML code. Here's the XAML:

<ContentView xmlns="http://xamarin.com/schemas/2014/forms" 
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="NomadApp.Helpers.Controls.Agenda.Agenda"
             xmlns:Carousel="clr-namespace:PanCardView;assembly=PanCardView"
             xmlns:AgendaHelpers="clr-namespace:NomadApp.Helpers.Controls.Agenda"
             x:Name="this">

    <ContentView.Content>


                <Carousel:CarouselView Grid.Row="1" 
                                       x:Name="carouselView" 
                                       Items="{Binding Source={x:Reference this}, Path=Weeks}"
                                       SwipeThresholdDistance="300" 
                                       VerticalOptions="FillAndExpand" >
                    
                    <Carousel:CarouselView.ItemTemplate>
                        <DataTemplate>

                            <Grid x:Name="daysGrid">

                                <Grid.RowDefinitions>
                                    <RowDefinition Height="*"/>
                                </Grid.RowDefinitions>

                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition/>
                                    <ColumnDefinition/>
                                    <ColumnDefinition/>
                                    <ColumnDefinition/>
                                    <ColumnDefinition/>
                                    <ColumnDefinition/>
                                    <ColumnDefinition/>
                                </Grid.ColumnDefinitions>

                                <AgendaHelpers:DayCell Grid.Column="0" BindingContext="{Binding Days[0]}"/>
                                <AgendaHelpers:DayCell Grid.Column="1" BindingContext="{Binding Days[1]}"/>
                                <AgendaHelpers:DayCell Grid.Column="2" BindingContext="{Binding Days[2]}"/>
                                <AgendaHelpers:DayCell Grid.Column="3" BindingContext="{Binding Days[3]}"/>
                                <AgendaHelpers:DayCell Grid.Column="4" BindingContext="{Binding Days[4]}"/>
                                <AgendaHelpers:DayCell Grid.Column="5" BindingContext="{Binding Days[5]}"/>
                                <AgendaHelpers:DayCell Grid.Column="6" BindingContext="{Binding Days[6]}"/>
                                
                            </Grid>

                        </DataTemplate>

                    </Carousel:CarouselView.ItemTemplate>
                </Carousel:CarouselView>

    </ContentView.Content>
</ContentView>

Each DayCell has a tap gesture recognizer to detect when we tap on the DayCell and when this happens, it draws a circle on this DayCell. Problem is, the drawing is getting made for same DayCell every 4 weeks. So if I select a day, then every 4 weeks, this same day gets selected.

I'm thinking of a problem in the control on how it manages the BindingContext declaration as I do it in the XAML. I know that this is not a problem from my code or the way a manage the 'selection' because with this https://github.com/alexrainman/CarouselView Carousel View, I do not have that problem.

Does anyone have a clue on what I can do?

For more context, this is the code for my Weeks collection and object:

Week collection bound to the CarouselView:

        /// <summary>
        /// The weeks that the agenda holds
        /// </summary>
        public ObservableCollection<Week> Weeks { get => _weeks; set { _weeks = value; OnPropertyChanged(nameof(Weeks)); } }

Week object:

    public class Week
    {
        #region Properties

        /// <summary>
        /// This week's number in the year
        /// </summary>
        public int WeekNumber { get; set; }

        /// <summary>
        /// The 7 days a week must have
        /// </summary>
        /// <remarks>
        /// TODO: Don't assign after having done bindings to this week's days, or bindings will be lost! 
        /// </remarks>
        public List<Day> Days { get; set; }

        public DateTime FirstMondayDate
        {
            get => _firstMondayDate;
            set
            {
                FirstMondayNumber = value.Day;
                _firstMondayDate = value;
            }

        }
        /// <summary>
        /// The number  in the month of the first day in this week
        /// </summary>
        /// <remarks>
        /// TODO: Don't assign after having done bindings to this week's days, or bindings will be lost! 
        /// </remarks>
        public int FirstMondayNumber
        {
            get { return _firstMondayNumber; }
            set
            {
                _firstMondayNumber = value;
                UpdateDays();
            }
        }

        /// <summary>
        /// The number in the month of the last day in this week
        /// </summary>
        public int LastSundayNumber
        {
            get { return _lastSundayNumber; }
            set
            {
                _lastSundayNumber = value;
                UpdateDays();
            }
        }


        #endregion
    }

How to use this ??

I added the Nuget and trying to use on XAML. But i am not getting where is the "cards:CarouselView". What do i have to declair to get this assembly ?

<cards:CarouselView >

Feature Request - Ability to set Front and Back Processors via property/xaml

Would remove the need to setup control in code-behind.

Currently the only way to not need to place code for injecting processors is to sub-class CardsView/CarouselView and pass them into base().

Allowing the setup of processors from Xaml via static resources/bindings would make control much cleaner and MVVM'y.

Looks possible, but I will try it out to see.

Very slow and infinite cycle. Use it in xaml

Hello. I'm using a not very complicated template. However, your component is running slowly with it.
I would like to see the possibility of easy use in xaml (without CardViewItemFactory, use DataTemplate).
Also, when we initialize an empty list, we have an infinite loop (see CardsView.cs line 1066).
if index = 0 and _itemsCount = 0
0 >= 0
0 -= 0
........ infinite

CardsViewRenderer ObjectDisposed crash

The same, I cannot reproduce

Maybe you have ideas...

CardsViewRenderer.OnTouchEvent (Android.Views.MotionEvent e)
System.ObjectDisposedException: Cannot access a disposed object. Object name: 'Android.Views.GestureDetector'.
JniPeerMembers.AssertSelf (Java.Interop.IJavaPeerable self)
JniPeerMembers+JniInstanceMethods.InvokeVirtualBooleanMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters)
GestureDetector.OnTouchEvent (Android.Views.MotionEvent ev)
CardsViewRenderer.OnTouchEvent (Android.Views.MotionEvent e)
View.n_OnTouchEvent_Landroid_view_MotionEvent_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_e)
(wrapper dynamic-method) System.Object.269ac379-00f3-45e2-9cb9-b16ea4332fe7(intptr,intptr,intptr)

Help with carousel in tabbed page

I am using your carousel in a page within a tabbed page but when i try to swipe the carousel it changes tabs I may be doing something wrong but it would mean a lot if you could help me.
Thanks

ListView within CardView Card

I have been working with CardView to produce a page system and found that having a ListView within a Card on Android has issues with the list items not being scrollable and also that Command binding on the ListView Items templates do not fire.

On iOS the problem does not exist, on further digging I found that the SelectedItemChanged also does not fire on Android.

Any ideas where I should look to patch this?

Binding issue

When I attempt to bind to a property on the main page's view model, it doesn't work. I have created an example here...

https://github.com/robertmiles3/CardsViewBindingIssue

I have your CardsView library as the top example on the MainPage, and I have a CarouselView example below it. I like how your CardsView properly lays out in design mode while CarouselView doesn't layout properly. However, CarouselView properly binds to Stats.Count1 (etc) while I can't get your CardsView to bind like that.

Am I missing something in getting it to bind properly to the Stats property?

Issue with Samsung S7

Hey, I'm currently using your CarouselView as a type of 'Wizard' for my app's checkout. It seems to work fine for the post part, except for on my co-worker's Samsung S7.

The issue is, there are several buttons/tap events inside each view in the carousel, but on his phone (and select emulators), it takes several taps for one to fire (still looking into it for further information).

I've gone down the route of trying to create my checkout in a ScrollView instead, and it works awesomely, except for the fact it seems impossible to only disable touch scrolling. You either disable it all, or allow it all. And I can't have the user able to swipe over to the next screen. View progression is entirely handled via the Wizard.

One thing I was thinking may potentially be causing the issue, is that the pages aren't permanently in the view, is that correct? Don't you actively remove/add views as they're needed?

If there were a setting to always have all views there, and the AbsoluteLayout literally just pans through all of them, I think that may solve my issue.

I have and will always have only 4 views in the carousel, so we don't need to take infinite views into consideration in this particular case.

I'll work on getting you a repro, but I'm not sure I'll have time in the next couple days.

Size only settles after first SizeChanged event

Well, I don't know where the problem is. :-) I received both updates at the same time, yours (1.4.9) and the latest Xamarin Forms (3.1.0.637273). On UWP, all pages that have a CardView on them are a bit oversize, meaning that the bottom 40-50 pixel high strip isn't visible at first (for instance, where we usually put the indicator control). As soon as I move the main window size a little bit, everything snaps into place and works all right.

I know this is pretty vague but before I try to go any further, you might have a hunch based on what you changed in the last upgrade. :-)

BindingContext caching broken

There seems to be a problem with the way the views are being cached.

  1. In your DataTemplate, let's have two buttons, with their Backgrounds bound.
  2. Update button 1 to have a background of Red.
  3. Go to next carousel page, then back to the first page. No problems.
  4. No update button 2 to have a red background, and button 1 to have a grey background.
  5. Go to next carousel page and back again. You will likely see the background of both buttons as red. On occasion, I even saw the background of the button on the second page change. Rarely it works fine.

I was able to fix this by removing the view caching in CardsView.PrepareView:800. That is, I just call temaplte.CreateContent() every time, and ignore _viewsPool, viewsList, etc.

CarouselView IsAutoNavigating Does not work?

Hi there,

THanks for this package.

I have a CarouselView and i set IsAutoNavigating to True, but in the view, the carousel does not move from item to item automatically (without user interaction) as expected. Am I supposed to set something else for this to work or am I misunderstanding the point of IsAutoNavigating?

Please let me know, thanks.

Trouble with ScrollView, ListView

Hello.
When I use CarouselView with ScrollView, it not swiped. Swipe event on CarouselView blocked by Swipe event ScrollView.
Сan i get around it?
Thank.


TapGestureRecognizer, too

How to change the color of indicators ?

All the background images are white backgrounded. So, i need to change the color of indicators, because i need to put the indicators at the end of the image.
You said: " If you want to customize indicators, you need set SelectedIndicatorStyle "

But i don´t understand the steps. Do i need to create a class to style the colors ?

My code:

<Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <cards:CarouselView Grid.Row="0" BackgroundColor="Blue" HorizontalOptions="FillAndExpand" Margin="0"
            Items="{Binding Items}" x:Name="carouselView"
            CurrentIndex="{Binding CurrentIndex}" SlideShowDuration="1500">
            <cards:CarouselView.ItemTemplate>
                <DataTemplate>
                    <ContentView>
                        <Grid Padding="0" Margin="0">
                            <ffimage:CachedImage Source="{Binding Source}" VerticalOptions="FillAndExpand"/>
                            <controls:IndicatorsControl VerticalOptions="End" HorizontalOptions="Center"/>
                        </Grid>
                    </ContentView>
                </DataTemplate>
            </cards:CarouselView.ItemTemplate>

        </cards:CarouselView>

I am lil bit newbie. Sorry if the question is stupid...

Thanks for the attention and the nugget.

Сhanging the list causes an error

Steps to reproduce:
App has 2 screens and typical navigation

  1. List with 2 items (in the cardview) on the first screen
  2. Switch to the second item
  3. Go to the second screen
  4. Delete the second item
  5. Back to the first screen
  6. Set new data to cardview on appeared event
  7. You'll get the exception
   at System.ThrowHelper.ThrowArgumentOutOfRange_IndexException()
   at System.Collections.Generic.List`1.System.Collections.IList.get_Item(Int32 index)
   at PanCardView.CardsView.GetContext(Int32 index, AnimationDirection animationDirection)
   at PanCardView.CardsView.PrepareView(Int32 index, AnimationDirection animationDirection, IEnumerable`1 bookedViews)
   at PanCardView.CardsView.GetViews(AnimationDirection animationDirection, ICardProcessor processor, Int32[] indeces)
   at PanCardView.CardsView.SetupNextView(Boolean canResetContext)
   at PanCardView.CardsView.SetupBackViews()
   at PanCardView.CardsView.<SetCurrentView>d__210.MoveNext()

ListView item selection without gesture recognizers fails on Android

It seems ListView elements won't invoke the ItemSelected and ItemTapped callbacks, and sometime they just do it the first time the item is tapped.

To reproduce the issue change the class BuildCard in CarouselSampleListView.cs as follows:

private object BuildCard(Color color)
{
	var list = new ListView
	{
		BackgroundColor = color,
		ItemTemplate = new DataTemplate(() =>
		{
			var label = new Label
			{
				TextColor = Color.White
			};
			label.SetBinding(Label.TextProperty, nameof(ListItemModel.Text));

			var content = new ContentView();
			content.Content = label;

			var tapGesture = new TapGestureRecognizer();
			tapGesture.SetBinding(TapGestureRecognizer.CommandProperty, nameof(ListItemModel.Command));
			//content.GestureRecognizers.Add(tapGesture); <-- comment this to disable the gesture recognizer

			return new ViewCell
			{
				View = content
			};
		})
	};
	list.SetBinding(ItemsView<Cell>.ItemsSourceProperty, nameof(ListCardModel.Items));

	// add these callbacks
	list.ItemSelected += (sender, e) =>
	{
		var listView = (ListView)sender;
		if (listView.SelectedItem == null)
		{
			return;
		}
		Application.Current.MainPage.DisplayAlert("Selected", null, "Ok");
		listView.SelectedItem = null;
	};
	list.ItemTapped += (sender, e) =>
	{
		Application.Current.MainPage.DisplayAlert("Tapped", null, "Ok");
	};

	return new ContentView
	{
		Margin = new Thickness(30, 20),
		Content = list
	};
}

I'm using Android version 5.0.1 running on an Acer Iconia B1-770 with the version of XF and CardView in the master branch

Updatable Carousel with lazy loading?

Hi Andrei,
I have the following problem: I need a full-page carousel. It should contain dozens (or hundreds) of pages, so it should render the pages only when needed, not all at the start. Additionally each page has a button where a popup opens. On this popup, user could make changes (increase a counter) which should be updated on the current carousel page as soon as the user closes the tab.
I've tried several plugins (including yours), using observables or lists, but with every plugin (or official CarouselPage) I somewhere face problems :-( Do you think that would be possible to do with your Carousel?
Many thanks and have a nice weekend!

Items source won't update

Hi Andrei, currently, your CardView can't update Items collection if it's updated. Is it right? So, I have to dispose current CardView and create the other to init new Items collection.

CarouselView Not Found

I am trying to implement the CarouselView in my app following the instructions outlined but I am getting this runtime error? I am using the sample application as a reference.

{Xamarin.Forms.Xaml.XamlParseException: Position 29:22. Type cards:CarouselView not found in xmlns clr-namespace:PanCardView;assembly=PanCardView at Xamarin.Forms.Xaml.CreateValuesVisitor.Visit (Xamarin.Forms.Xaml.ElementNode node, Xamarin.Forms.Xaml.INode pa…}

KeyNotFoundException on old iPhones and iPads

Version is 1.4.8

ThrowHelper.ThrowKeyNotFoundException (System.Object key)
System.Collections.Generic.KeyNotFoundException: The given key '23b7bacd-396e-4011-a1eb-69236f789c08' was not present in the dictionary.
ThrowHelper.ThrowKeyNotFoundException (System.Object key)
Dictionary`2[TKey,TValue].get_Item (TKey key)
CardsView.RemoveRangeViewsInUse (System.Guid gestureId)
CardsView+<OnTouchEnded>d__233.MoveNext ()
AsyncMethodBuilderCore+<>c.<ThrowAsync>b__6_0 (System.Object state)
UIKitSynchronizationContext+<>c__DisplayClass1_0.<Post>b__0 ()
NSAsyncActionDispatcher.Apply ()
(wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr)
UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName)
Application.Main (System.String[] args)

Appearing a transparente Item on Items collection.

I have a list of Images and using it on the Items Binding.
But when the images are crossing, always has a "empty item" appearing.
The problem happens with local images or links.

var Items = new List<Image>
            {
              new Image { Source = "LINK1" },
              new Image { Source = "LINK2"},
              new Image { Source = "LINK3" }
            };

            carouselView.Items = Items;

<cards:CarouselView HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" Margin="0" Padding="0,3,0,3"
            Items="{Binding Items}"  CurrentIndex="0" IsCyclical="True" x:Name="carouselView" SlideShowDuration="1500">
                <cards:CarouselView.ItemTemplate>
                    <DataTemplate>
                        <ContentView>
                            <ffimage:CachedImage x:Name="imgSlide" Source="{Binding Source}" VerticalOptions="Start" HorizontalOptions="FillAndExpand" Aspect="AspectFill"/>
                        </ContentView>
                    </DataTemplate>
                </cards:CarouselView.ItemTemplate>
                <controls:IndicatorsControl VerticalOptions="End" HorizontalOptions="Center" ToFadeDuration="1500"
                                    SelectedIndicatorStyle="{StaticResource ActiveIndicator}"
                                    UnselectedIndicatorStyle="{StaticResource InactiveIndicator}"/>

            </cards:CarouselView>

Suggestion - not issue

On the CarouselView
It would be nice if ItemTemplate was not required. In my case I have my app's checkout steps are in a carousel, and each page is a different ContentView.
I had to create an ItemTemplate for the carousel for it not to throw an exception.
If your control had a default ItemTemplate of something like:

                    new DataTemplate(() =>
                    {
                        var view = new ContentView();
                        view.SetBinding(ContentView.ContentProperty, nameof(ContentView.Content));
                        return view;
                    })

Then it would just work by letting you set a list of views to the carousel, without having to define the template.
It took some time to figure out that the missing ItemTemplate was my issue, because the last carousel I used didn't require me to define it, I believe it was doing something similar to this.

Is it possible to hide the indicator?

I have a long ItemList, and I am using a "cards:CarouselView"

<cards:CarouselView
Items="{Binding Items}"
SlideShowDuration="0"
CurrentIndex="{Binding CurrentIndex}">

And I would like to know if it is possible to hide the indicador, or show a simple page indicator: "showing 3 of 2500 records" style
thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.