public void PanGestureRecognizer_PanUpdated(System.Object sender, Xamarin.Forms.PanUpdatedEventArgs e) { // Handle the pan switch (e.StatusType) { case GestureStatus.Running: // Translate and ensure we don't y + e.TotalY pan beyond the wrapped user interface element bounds. var translateY = Math.Max(Math.Min(0, y + e.TotalY), -Math.Abs((Height * .25) - Height)); BottomSheet.TranslateTo(BottomSheet.X, translateY, 20); break; case GestureStatus.Completed: // Store the translation applied during the pan y = BottomSheet.TranslationY; // At the end of the event - snap to the closest location var finalTranslation = Math.Max(Math.Min(0, -1000), -Math.Abs(GetClosestLockState(e.TotalY + y))); // Depending on Swipe Up or Down - change the snapping animation if (IsSwipeUp(e)) { BottomSheet.TranslateTo(BottomSheet.X, finalTranslation, 250, Easing.SpringIn); } else { BottomSheet.TranslateTo(BottomSheet.X, finalTranslation, 250, Easing.SpringOut); } // Dismiss the keyboard after a transition y = BottomSheet.TranslationY; break; } }
private async void GamePage_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { if (e.PropertyName == nameof(GameViewModel.Progress)) { AdjustTemp(((GameViewModel)BindingContext).Progress); } else if (e.PropertyName == nameof(GameViewModel.VictoryMode)) { bool state = ((GameViewModel)BindingContext).VictoryMode; Shell.Current.FlyoutBehavior = state ? FlyoutBehavior.Disabled : FlyoutBehavior.Flyout; if (state) { OldImage.Opacity = 1; HamburgerButton.FadeTo(0, 800u, Easing.CubicOut); await BottomSheet.TranslateTo(0, Height, 800u, Easing.CubicOut); Darkener.FadeTo(0.4); VictoryView.FadeTo(1); } else { Darkener.FadeTo(0); await VictoryView.FadeTo(0); await OldImage.FadeTo(0, easing : Easing.CubicIn); await Task.Delay(250); HamburgerButton.FadeTo(0.85); await BottomSheet.TranslateTo(0, positions[1], 350u, Easing.CubicOut); } } else if (e.PropertyName == nameof(GameViewModel.IsDone)) { if (((GameViewModel)BindingContext).IsDone) { TempFinisher.FadeTo(1); } else { TempFinisher.FadeTo(0); } } }
private void SnapToNearest(double vel) { int indexRight = 1; while (indexRight < positions.Length && BottomSheet.TranslationY > positions[indexRight]) { ++indexRight; } int indexLeft = indexRight - 1; double newTrans; if (Math.Abs(vel) < 3) { newTrans = (positions[indexRight] - BottomSheet.TranslationY <= BottomSheet.TranslationY - positions[indexLeft]) ? positions[indexRight] : positions[indexLeft]; } else { newTrans = vel < 0 ? positions[indexLeft] : positions[indexRight]; } BottomSheet.TranslateTo(0, newTrans, 350u, Easing.CubicOut); }