-
Notifications
You must be signed in to change notification settings - Fork 31
Discussion: Should one use the 3rd party CarouselView or Xamarin Forms' implementation #33
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <packages> | ||
| <package id="Xamarin.Forms" version="2.4.0.266-pre1" targetFramework="xamarinios10" /> | ||
| <package id="Xamarin.Forms" version="4.4.0.991220-pre3" targetFramework="net" /> | ||
| </packages> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,9 @@ | ||
| using CarouselView.FormsPlugin.Abstractions; | ||
| using System; | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Collections.ObjectModel; | ||
| using System.ComponentModel; | ||
| using System.Linq; | ||
| using System.Reflection; | ||
| using Xam.Plugin.TabView.Converters; | ||
| using Xamarin.Forms; | ||
|
|
||
|
|
@@ -18,13 +18,7 @@ public class PositionChangingEventArgs : EventArgs | |
| public int NewPosition { get; set; } | ||
| public int OldPosition { get; set; } | ||
| } | ||
|
|
||
| public class PositionChangedEventArgs : EventArgs | ||
| { | ||
| public int NewPosition { get; set; } | ||
| public int OldPosition { get; set; } | ||
| } | ||
|
|
||
|
|
||
| static class TabDefaults | ||
| { | ||
| public static readonly Color DefaultColor = Color.White; | ||
|
|
@@ -36,8 +30,9 @@ public class TabViewControl : ContentView | |
| { | ||
| private StackLayout _mainContainerSL; | ||
| private Grid _headerContainerGrid; | ||
| private CarouselViewControl _carouselView; | ||
| private CarouselView _carouselView; | ||
| private ScrollView _tabHeadersContainerSv; | ||
| private ConstructorInfo _positionChangedEventArgsInfo; | ||
|
|
||
| public event PositionChangingEventHandler PositionChanging; | ||
| public event PositionChangedEventHandler PositionChanged; | ||
|
|
@@ -124,10 +119,10 @@ private void _carouselView_PropertyChanged(object sender, PropertyChangedEventAr | |
| if (positionChangingArgs != null && positionChangingArgs.Canceled) | ||
| { | ||
| _supressCarouselViewPositionChangedEvent = true; | ||
| _carouselView.PositionSelected -= _carouselView_PositionSelected; | ||
| _carouselView.PositionChanged -= _carouselView_PositionSelected; | ||
| _carouselView.PropertyChanged -= _carouselView_PropertyChanged; | ||
| _carouselView.Position = SelectedTabIndex; | ||
| _carouselView.PositionSelected += _carouselView_PositionSelected; | ||
| _carouselView.PositionChanged += _carouselView_PositionSelected; | ||
| _carouselView.PropertyChanged += _carouselView_PropertyChanged; | ||
| _supressCarouselViewPositionChangedEvent = false; | ||
| } | ||
|
|
@@ -158,18 +153,23 @@ private void Init() | |
| HorizontalOptions = LayoutOptions.FillAndExpand | ||
| }; | ||
|
|
||
| _carouselView = new CarouselViewControl | ||
| _carouselView = new CarouselView() | ||
| { | ||
| HorizontalOptions = LayoutOptions.FillAndExpand, | ||
| VerticalOptions = LayoutOptions.FillAndExpand, | ||
| HeightRequest = ContentHeight, | ||
| ShowArrows = false, | ||
| ShowIndicators = false, | ||
| BindingContext = this | ||
| BindingContext = this, | ||
| ItemTemplate = new DataTemplate(() => | ||
| { | ||
| ContentView c = new ContentView(); | ||
| c.SetBinding(ContentView.ContentProperty, "Content"); | ||
| return c; | ||
| }) | ||
| }; | ||
|
|
||
| _positionChangedEventArgsInfo = typeof(PositionChangedEventArgs).GetTypeInfo().DeclaredConstructors.First(); | ||
|
|
||
| _carouselView.PropertyChanged += _carouselView_PropertyChanged; | ||
| _carouselView.PositionSelected += _carouselView_PositionSelected; | ||
| _carouselView.PositionChanged += _carouselView_PositionSelected; | ||
|
|
||
| _mainContainerSL = new StackLayout | ||
| { | ||
|
|
@@ -199,11 +199,11 @@ protected override void OnBindingContextChanged() | |
| } | ||
| } | ||
|
|
||
| private void _carouselView_PositionSelected(object sender, PositionSelectedEventArgs e) | ||
| private void _carouselView_PositionSelected(object sender, PositionChangedEventArgs e) | ||
| { | ||
| if (_carouselView.Position != e.NewValue || SelectedTabIndex != e.NewValue) | ||
| if (_carouselView.Position != e.CurrentPosition || SelectedTabIndex != e.CurrentPosition) | ||
| { | ||
| SetPosition(e.NewValue); | ||
| SetPosition(e.CurrentPosition); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -291,7 +291,7 @@ private void AddTabToView(TabItem tab) | |
| }; | ||
| headerItemSL.GestureRecognizers.Add(tapRecognizer); | ||
| _headerContainerGrid.Children.Add(headerItemSL, _headerContainerGrid.ColumnDefinitions.Count - 1, 0); | ||
| _carouselView.ItemsSource = ItemSource.Select(t => t.Content); | ||
| _carouselView.ItemsSource = ItemSource; | ||
| } | ||
|
|
||
| #region IsSwipingEnabled | ||
|
|
@@ -548,9 +548,9 @@ public void SetPosition(int position, bool initialRun = false) | |
| { | ||
| if (_carouselView.Position != position || initialRun) | ||
| { | ||
| _carouselView.PositionSelected -= _carouselView_PositionSelected; | ||
| _carouselView.PositionChanged -= _carouselView_PositionSelected; | ||
| _carouselView.Position = position; | ||
| _carouselView.PositionSelected += _carouselView_PositionSelected; | ||
| _carouselView.PositionChanged += _carouselView_PositionSelected; | ||
| } | ||
| if (oldPosition != position) | ||
| { | ||
|
|
@@ -565,11 +565,9 @@ public void SetPosition(int position, bool initialRun = false) | |
| } | ||
| } | ||
|
|
||
| var positionChangedArgs = new PositionChangedEventArgs() | ||
| { | ||
| NewPosition = SelectedTabIndex, | ||
| OldPosition = oldPosition | ||
| }; | ||
| var positionChangedArgs = _positionChangedEventArgsInfo.Invoke( | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. PositionChangedEventArgs has an internal constructor so this is a "hacky" way to call it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @kapseliboi you do not have to remove the PositionChangedEventArgs definition in the Xam.Plugin.TabView namespace nor to use the internal constructor: Just use the fully qualified name "Xamarin.Forms.PositionChangedEventArgs" in the _carouselView_PositionSelected method parameter and continue using Xam.Plugin.TabView.PositionChangedEventArgs for the rest (fully qualified name is not required for this one i think) That would prevent the API breakage |
||
| new object[] { oldPosition, SelectedTabIndex }) as PositionChangedEventArgs; | ||
|
|
||
| OnPositionChanged(positionChangedArgs); | ||
| } | ||
|
|
||
|
|
@@ -623,7 +621,8 @@ public void RemoveTab(int position = -1) | |
| _headerContainerGrid.Children.RemoveAt(_headerContainerGrid.Children.Count - 1); | ||
| _headerContainerGrid.ColumnDefinitions.Remove(_headerContainerGrid.ColumnDefinitions.Last()); | ||
| } | ||
| _carouselView.ItemsSource = ItemSource.Select(t => t.Content); | ||
|
|
||
| _carouselView.ItemsSource = ItemSource; | ||
| SelectedTabIndex = position >= 0 && position < ItemSource.Count ? position : ItemSource.Count - 1; | ||
| } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was unable to build the sample app without this line.