This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CarouselLayout : ScrollView | |
{ | |
public enum IndicatorStyleEnum | |
{ | |
None, | |
Dots, | |
Tabs | |
} | |
readonly StackLayout _stack; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static readonly BindableProperty ItemsSourceProperty = | |
BindableProperty.Create<CarouselLayout, IList> ( | |
view => view.ItemsSource, | |
null, | |
propertyChanging: (bindableObject, oldValue, newValue) => { | |
((CarouselLayout)bindableObject).ItemsSourceChanging (); | |
}, | |
propertyChanged: (bindableObject, oldValue, newValue) => { | |
((CarouselLayout)bindableObject).ItemsSourceChanged (); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void SnapScroll () | |
{ | |
var roughIndex = (float)_scrollView.ScrollX / _scrollView.Width; | |
var targetIndex = | |
_deltaX < 0 ? Math.Floor (roughIndex) | |
: _deltaX > 0 ? Math.Ceil (roughIndex) | |
: Math.Round (roughIndex); | |
ScrollToIndex ((int)targetIndex); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void NativeScrolled (object sender, EventArgs e) | |
{ | |
var center = _native.ContentOffset.X + (_native.Bounds.Width / 2); | |
((CarouselLayout)Element).SelectedIndex = ((int)center) / ((int)_native.Bounds.Width); | |
} | |
void ElementPropertyChanged(object sender, PropertyChangedEventArgs e) { | |
if (e.PropertyName == CarouselLayout.SelectedIndexProperty.PropertyName && !Dragging) { | |
ScrollToSelection (false); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public enum IndicatorStyleEnum | |
{ | |
None, | |
Dots, | |
Tabs | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void ItemsSourceChanged () | |
{ | |
if (ItemsSource == null) return; | |
var countDelta = ItemsSource.Count - Children.Count; | |
if (countDelta > 0) { | |
for (var i = 0; i < countDelta; i++) | |
{ | |
CreateDot(); |
OlderNewer