public OnControlScrollChangedListener( AndroidHorizontalListViewRenderer nativeView, HorizontalListView element) { _weakNativeView = new WeakReference <AndroidHorizontalListViewRenderer>(nativeView); _element = element; }
private async Task UpdateCurrentIndexAsync( AndroidHorizontalListViewRenderer nativeView, CancellationToken token) { await Task.Delay(500); if (token.IsCancellationRequested) { return; } if (nativeView?.LinearLayoutManager == null || _element == null) { return; } nativeView._isCurrentIndexUpdateBackfire = true; try { _element.CurrentIndex = nativeView.LinearLayoutManager.FindFirstVisibleItemPosition(); _element.ScrollBeganCommand?.Execute(null); InternalLogger.Info($"CurrentIndex: {_element.CurrentIndex}"); } finally { nativeView._isCurrentIndexUpdateBackfire = false; } }
private void UpdateCurrentIndex( AndroidHorizontalListViewRenderer nativeView, CancellationToken token) { if (token.IsCancellationRequested) { return; } if (nativeView?.LinearLayoutManager == null || _element == null) { return; } nativeView._isCurrentIndexUpdateBackfire = true; try { _element.CurrentIndex = nativeView.LinearLayoutManager.FindFirstVisibleItemPosition(); InternalLogger.Info($"CurrentIndex: {_element.CurrentIndex}"); } finally { nativeView._isCurrentIndexUpdateBackfire = false; } }
private void UpdateCurrentIndex( AndroidHorizontalListViewRenderer nativeView, CancellationToken token) { if (token.IsCancellationRequested) { return; } if (nativeView?.LinearLayoutManager == null || _element == null) { return; } nativeView._isCurrentIndexUpdateBackfire = true; try { int newIndex = -1; if (_element.SnapStyle != SnapStyle.None) { newIndex = nativeView.CurrentSnapIndex; } else { newIndex = nativeView.LinearLayoutManager.FindFirstCompletelyVisibleItemPosition(); if (newIndex == -1) { newIndex = nativeView.LinearLayoutManager.FindFirstVisibleItemPosition(); } } if (newIndex == -1) { InternalLogger.Warn( "Failed to find the current index: UpdateCurrentIndex returns nothing"); return; } _element.CurrentIndex = newIndex; InternalLogger.Info($"CurrentIndex: {_element.CurrentIndex}"); } finally { nativeView._isCurrentIndexUpdateBackfire = false; } }
private async Task UpdateCurrentIndexAsync( AndroidHorizontalListViewRenderer nativeView, CancellationToken token) { await Task.Delay(500); if (token.IsCancellationRequested) { return; } nativeView._isCurrentIndexUpdateBackfire = true; try { _element.CurrentIndex = nativeView.LinearLayoutManager.FindFirstVisibleItemPosition(); _element.ScrollBeganCommand?.Execute(null); // System.Diagnostics.Debug.WriteLine($"DEBUG_SCROLL: CurrentIndex: {_element.CurrentIndex}"); } finally { nativeView._isCurrentIndexUpdateBackfire = false; } }
private void UpdateCurrentIndex( AndroidHorizontalListViewRenderer nativeView, CancellationToken token) { if (token.IsCancellationRequested) { return; } if (nativeView?.LinearLayoutManager == null || _element == null) { return; } nativeView._isCurrentIndexUpdateBackfire = true; try { int newIndex = -1; if (_element.SnapStyle == SnapStyle.Center) { int firstIndex = nativeView.LinearLayoutManager.FindFirstCompletelyVisibleItemPosition(); if (firstIndex == 0) { // Check if first item is fully visible, if true don't snap. newIndex = 0; } int lastIndex = nativeView.LinearLayoutManager.FindLastCompletelyVisibleItemPosition(); if (lastIndex == nativeView.Control.GetAdapter().ItemCount - 1) { // Check if first item is fully visible, if true don't snap. newIndex = lastIndex; } if (newIndex == -1) { int firstItemIndex = nativeView.LinearLayoutManager.FindFirstVisibleItemPosition(); int lastItemIndex = nativeView.LinearLayoutManager.FindLastVisibleItemPosition(); newIndex = firstItemIndex + (lastItemIndex - firstItemIndex) / 2; } } else { newIndex = nativeView.LinearLayoutManager.FindFirstVisibleItemPosition(); } if (newIndex == -1) { InternalLogger.Warn( "Failed to find the current index: UpdateCurrentIndex returns nothing"); return; } _element.CurrentIndex = newIndex; InternalLogger.Info($"CurrentIndex: {_element.CurrentIndex}"); } finally { nativeView._isCurrentIndexUpdateBackfire = false; } }
public StartSnapHelper(AndroidHorizontalListViewRenderer nativeView) : base(nativeView) { }
public CenterSnapHelper(AndroidHorizontalListViewRenderer nativeView) { WeakNativeView = new WeakReference <AndroidHorizontalListViewRenderer>(nativeView); }