From 726c997e5cbb49b0a5dd5cdaa1f6c7a3f2796d92 Mon Sep 17 00:00:00 2001 From: dodikk Date: Mon, 4 Apr 2022 14:36:39 +0300 Subject: [PATCH 1/7] [lock states] add console logs --- Xam.Plugin.SimpleBottomDrawer/BottomDrawer.cs | 143 ++++++++++++++++-- 1 file changed, 127 insertions(+), 16 deletions(-) diff --git a/Xam.Plugin.SimpleBottomDrawer/BottomDrawer.cs b/Xam.Plugin.SimpleBottomDrawer/BottomDrawer.cs index f72b3cb..86c43e7 100644 --- a/Xam.Plugin.SimpleBottomDrawer/BottomDrawer.cs +++ b/Xam.Plugin.SimpleBottomDrawer/BottomDrawer.cs @@ -115,7 +115,10 @@ public double ExpandedPercentage /// /// Make sure we collapse the view on orientation change /// - protected override void OnSizeAllocated(double width, double height) + protected override void OnSizeAllocated( + double width + , double height + ) { base.OnSizeAllocated(width, height); if (width != _width || height != _height) @@ -137,16 +140,25 @@ protected override void OnSizeAllocated(double width, double height) /// The bindable object /// The old value /// The new value - private static void IsExpandedPropertyChanged(BindableObject bindable, object o, object n) + private static void IsExpandedPropertyChanged( + BindableObject bindable + , object o + , object n) { if (n is bool isExpanded && bindable is BottomDrawer drawer) { if (!drawer.isDragging) { if (!isExpanded) + { + System.Console.WriteLine("[BottomDrawer] IsExpandedPropertyChanged() ==> Dismiss()"); drawer.Dismiss(); + } else + { + System.Console.WriteLine("[BottomDrawer] IsExpandedPropertyChanged() ==> Open()"); drawer.Open(); + } } } } @@ -157,17 +169,44 @@ private static void IsExpandedPropertyChanged(BindableObject bindable, object o, /// The bindable object /// The old value /// The new value - private static void ExpandedPercentageChanged(BindableObject bindable, object o, object n) + private static void ExpandedPercentageChanged( + BindableObject bindable + , object o + , object n) { if (n is double expandValue && bindable is BottomDrawer drawer) { if (!drawer.isDragging) { - var finalTranslation = Math.Max(Math.Min(0, -1000), -Math.Abs(drawer.getProportionCoordinate(expandValue))); + double proportionY = drawer.getProportionCoordinate(expandValue); + + var finalTranslation = + Math.Max( + Math.Min(0, -1000) + , -Math.Abs(proportionY) + ); + + System.Console.WriteLine( + $"[BottomDrawer] ExpandedPercentageChanged() ==> proportionY=={proportionY} | finalTranslation=={finalTranslation}"); + if (expandValue < 0) - drawer.TranslateTo(drawer.X, finalTranslation, 250, Easing.SpringIn); + { + drawer.TranslateTo( + x: drawer.X + , y: finalTranslation + , length: 250 + , easing: Easing.SpringIn + ); + } else - drawer.TranslateTo(drawer.X, finalTranslation, 250, Easing.SpringOut); + { + drawer.TranslateTo( + x: drawer.X + , y: finalTranslation + , length: 250 + , easing: Easing.SpringOut + ); + } } } } @@ -175,11 +214,16 @@ private static void ExpandedPercentageChanged(BindableObject bindable, object o, /// /// On pan gesture changed /// - private void OnPanChanged(object sender, PanUpdatedEventArgs e) + private void OnPanChanged( + object sender + , PanUpdatedEventArgs e + ) { switch (e.StatusType) { case GestureStatus.Running: + System.Console.WriteLine("[BottomDrawer] OnPanChanged() - Running"); + isDragging = true; var Y = (Device.RuntimePlatform == Device.Android ? this.TranslationY : translationYStart) + e.TotalY; // Translate and ensure we don't y + e.TotalY pan beyond the wrapped user interface element bounds. @@ -187,25 +231,51 @@ private void OnPanChanged(object sender, PanUpdatedEventArgs e) this.TranslateTo(this.X, translateY, 1); ExpandedPercentage = GetPropertionDistance(Y); break; + case GestureStatus.Completed: + System.Console.WriteLine("[BottomDrawer] OnPanChanged() - Completed"); + // At the end of the event - snap to the closest location var finalTranslation = Math.Max(Math.Min(0, -1000), -Math.Abs(getProportionCoordinate(GetClosestLockState(e.TotalY + this.TranslationY)))); // Depending on Swipe Up or Down - change the snapping animation if (DetectSwipeUp(e)) - this.TranslateTo(this.X, finalTranslation, 250, Easing.SpringIn); + { + System.Console.WriteLine("[BottomDrawer] OnPanChanged() - DetectSwipeUp()==true"); + + this.TranslateTo( + x: this.X + , y: finalTranslation + , length: 250 + , easing: Easing.SpringIn); + } else - this.TranslateTo(this.X, finalTranslation, 250, Easing.SpringOut); + { + System.Console.WriteLine("[BottomDrawer] OnPanChanged() - DetectSwipeUp()==false"); + + this.TranslateTo( + x: this.X + , y: finalTranslation + , length: 250 + , easing: Easing.SpringOut); + } + ExpandedPercentage = GetClosestLockState(e.TotalY + this.TranslationY); isDragging = false; break; + case GestureStatus.Started: - translationYStart = this.TranslationY; + System.Console.WriteLine("[BottomDrawer] OnPanChanged() - Started"); + + translationYStart = this.TranslationY; break; } if (ExpandedPercentage > LockStates[LockStates.Length - 1]) + { ExpandedPercentage = LockStates[LockStates.Length - 1]; + } + IsExpanded = ExpandedPercentage > 0; } @@ -214,9 +284,17 @@ private void OnPanChanged(object sender, PanUpdatedEventArgs e) /// private void OnTapped(object sender, EventArgs e) { + System.Console.WriteLine("[BottomDrawer] OnTapped()"); + if (!IsExpanded) { - ExpandedPercentage = LockStates[1]; + if (this.LockStates.Length >= 2) + { + // TODO: [alex-d] why hard-coded [1] index? + // - + ExpandedPercentage = LockStates[1]; + } + IsExpanded = ExpandedPercentage > 0; } } @@ -252,7 +330,10 @@ private double GetClosestLockState(double TranslationY) } } - return LockStates[closestIndex]; + double result = LockStates[closestIndex]; + System.Console.WriteLine($"[BottomDrawer] GetClosestLockState() | result=={result} | index=={closestIndex}"); + + return result; } /// @@ -281,8 +362,23 @@ private double getProportionCoordinate(double proportion) /// public void Dismiss() { - var finalTranslation = Math.Max(Math.Min(0, -1000), -Math.Abs(getProportionCoordinate(LockStates[0]))); - this.TranslateTo(this.X, finalTranslation, 450, Device.RuntimePlatform == Device.Android ? Easing.SpringOut : null); + System.Console.WriteLine("[BottomDrawer] Dismiss()"); + + var finalTranslation = + Math.Max( + Math.Min(0, -1000) + , -Math.Abs(getProportionCoordinate(LockStates[0])) + ); + + this.TranslateTo( + x: this.X + , y: finalTranslation + , length: 450 + , easing: + Device.RuntimePlatform == Device.Android + ? Easing.SpringOut + : null + ); } /// @@ -290,8 +386,23 @@ public void Dismiss() /// public void Open() { - var finalTranslation = Math.Max(Math.Min(0, -1000), -Math.Abs(getProportionCoordinate(LockStates[LockStates.Length - 1]))); - this.TranslateTo(this.X, finalTranslation, 150, Device.RuntimePlatform == Device.Android ? Easing.SpringIn : null); + System.Console.WriteLine("[BottomDrawer] Open()"); + + var finalTranslation = + Math.Max( + Math.Min(0, -1000) + , -Math.Abs(getProportionCoordinate(LockStates[LockStates.Length - 1])) + ); + + this.TranslateTo( + x: this.X + , y: finalTranslation + , length: 150 + , easing: + Device.RuntimePlatform == Device.Android + ? Easing.SpringIn + : null + ); } #endregion Public From b7f2300ca61c5ce35322bc9bfb1111747baeee3a Mon Sep 17 00:00:00 2001 From: dodikk Date: Mon, 4 Apr 2022 14:36:59 +0300 Subject: [PATCH 2/7] [lock states] apply lock states from viewmodel --- .../Xam.Plugin.SimpleBottomDrawer.Samples/MainPage.xaml | 1 + 1 file changed, 1 insertion(+) diff --git a/Samples/Xam.Plugin.SimpleBottomDrawer.Samples/Xam.Plugin.SimpleBottomDrawer.Samples/MainPage.xaml b/Samples/Xam.Plugin.SimpleBottomDrawer.Samples/Xam.Plugin.SimpleBottomDrawer.Samples/MainPage.xaml index ee2dfe0..98c5849 100644 --- a/Samples/Xam.Plugin.SimpleBottomDrawer.Samples/Xam.Plugin.SimpleBottomDrawer.Samples/MainPage.xaml +++ b/Samples/Xam.Plugin.SimpleBottomDrawer.Samples/Xam.Plugin.SimpleBottomDrawer.Samples/MainPage.xaml @@ -50,6 +50,7 @@ ExpandedPercentage="{Binding ExpandedPercentage}" IsExpanded="{Binding IsExpanded}" IsVisible="{Binding IsVisible}" + LockStates="{Binding LockStates}" RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height, Factor=1, From 374d1b2e6e26d7f839b4c369b954b9540e15f519 Mon Sep 17 00:00:00 2001 From: dodikk Date: Mon, 4 Apr 2022 14:37:25 +0300 Subject: [PATCH 3/7] [lock states] fail with four values --- .../ViewModel/MainPageViewModel.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Samples/Xam.Plugin.SimpleBottomDrawer.Samples/Xam.Plugin.SimpleBottomDrawer.Samples/ViewModel/MainPageViewModel.cs b/Samples/Xam.Plugin.SimpleBottomDrawer.Samples/Xam.Plugin.SimpleBottomDrawer.Samples/ViewModel/MainPageViewModel.cs index 6b0f18a..36ab667 100644 --- a/Samples/Xam.Plugin.SimpleBottomDrawer.Samples/Xam.Plugin.SimpleBottomDrawer.Samples/ViewModel/MainPageViewModel.cs +++ b/Samples/Xam.Plugin.SimpleBottomDrawer.Samples/Xam.Plugin.SimpleBottomDrawer.Samples/ViewModel/MainPageViewModel.cs @@ -38,8 +38,10 @@ public class MainPageViewModel : ObservableObject /// /// The bottom drawer lock states + /// + /// Note: [alex-d] works incorrectly when more than 3 values /// - private double[] _LockStates = new double[] { 0, .50, 0.75 }; + private double[] _LockStates = new double[] { 0, .30, 0.6, 0.95 }; #endregion From c8c1d38bba95f8309ce20fea8c46bc927b144f74 Mon Sep 17 00:00:00 2001 From: dodikk Date: Mon, 4 Apr 2022 14:50:59 +0300 Subject: [PATCH 4/7] [lock states] coordinate details in logs --- Xam.Plugin.SimpleBottomDrawer/BottomDrawer.cs | 56 ++++++++++++++----- 1 file changed, 41 insertions(+), 15 deletions(-) diff --git a/Xam.Plugin.SimpleBottomDrawer/BottomDrawer.cs b/Xam.Plugin.SimpleBottomDrawer/BottomDrawer.cs index 86c43e7..05f9242 100644 --- a/Xam.Plugin.SimpleBottomDrawer/BottomDrawer.cs +++ b/Xam.Plugin.SimpleBottomDrawer/BottomDrawer.cs @@ -222,21 +222,37 @@ object sender switch (e.StatusType) { case GestureStatus.Running: - System.Console.WriteLine("[BottomDrawer] OnPanChanged() - Running"); - isDragging = true; - var Y = (Device.RuntimePlatform == Device.Android ? this.TranslationY : translationYStart) + e.TotalY; + var Y = (Device.RuntimePlatform == Device.Android + ? this.TranslationY // Frame.TranslationY + : this.translationYStart) + + e.TotalY; // 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), -Math.Abs((Height * .25) - Height)); - this.TranslateTo(this.X, translateY, 1); - ExpandedPercentage = GetPropertionDistance(Y); + var translateY = + Math.Max( + Math.Min(0, Y) + , -Math.Abs((Height * .25) - Height) + ); + + this.TranslateTo(x: this.X, y: translateY, length: 1); + this.ExpandedPercentage = GetPropertionDistance(Y); + + System.Console.WriteLine($"[BottomDrawer] OnPanChanged() - Running | ExpandedPercentage=={ExpandedPercentage} | translateY=={translateY}"); break; case GestureStatus.Completed: System.Console.WriteLine("[BottomDrawer] OnPanChanged() - Completed"); // At the end of the event - snap to the closest location - var finalTranslation = Math.Max(Math.Min(0, -1000), -Math.Abs(getProportionCoordinate(GetClosestLockState(e.TotalY + this.TranslationY)))); + double finalTranslation = + Math.Max( + Math.Min(0, -1000) + , -Math.Abs( + getProportionCoordinate( + GetClosestLockState(e.TotalY + this.TranslationY) + ) + ) + ); // Depending on Swipe Up or Down - change the snapping animation if (DetectSwipeUp(e)) @@ -260,23 +276,33 @@ object sender , easing: Easing.SpringOut); } - ExpandedPercentage = GetClosestLockState(e.TotalY + this.TranslationY); - isDragging = false; + this.ExpandedPercentage = GetClosestLockState(e.TotalY + this.TranslationY); + this.isDragging = false; + + System.Console.WriteLine($"[BottomDrawer] OnPanChanged() - Completed | ExpandedPercentage=={ExpandedPercentage} | finalTranslation=={finalTranslation}"); break; case GestureStatus.Started: - System.Console.WriteLine("[BottomDrawer] OnPanChanged() - Started"); + this.translationYStart = this.TranslationY; + + System.Console.WriteLine($"[BottomDrawer] OnPanChanged() - Started | translationYStart=={translationYStart}"); + break; + } - translationYStart = this.TranslationY; - break; + if (LockStates.Length <= 0) + { + return; } - if (ExpandedPercentage > LockStates[LockStates.Length - 1]) + int indexOfLastLockState = LockStates.Length - 1; + double lastLockState = LockStates[indexOfLastLockState]; + + if (ExpandedPercentage > lastLockState) { - ExpandedPercentage = LockStates[LockStates.Length - 1]; + ExpandedPercentage = lastLockState; } - IsExpanded = ExpandedPercentage > 0; + IsExpanded = (ExpandedPercentage > 0); } /// From b19bb3a2423a3cedc7ad6ffb5b639b6b00257907 Mon Sep 17 00:00:00 2001 From: dodikk Date: Mon, 4 Apr 2022 15:02:33 +0300 Subject: [PATCH 5/7] [lock states] more coordinates in logs --- Xam.Plugin.SimpleBottomDrawer/BottomDrawer.cs | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Xam.Plugin.SimpleBottomDrawer/BottomDrawer.cs b/Xam.Plugin.SimpleBottomDrawer/BottomDrawer.cs index 05f9242..df50cb3 100644 --- a/Xam.Plugin.SimpleBottomDrawer/BottomDrawer.cs +++ b/Xam.Plugin.SimpleBottomDrawer/BottomDrawer.cs @@ -312,16 +312,16 @@ private void OnTapped(object sender, EventArgs e) { System.Console.WriteLine("[BottomDrawer] OnTapped()"); - if (!IsExpanded) + if (!this.IsExpanded) { if (this.LockStates.Length >= 2) { // TODO: [alex-d] why hard-coded [1] index? // - - ExpandedPercentage = LockStates[1]; + this.ExpandedPercentage = LockStates[1]; } - IsExpanded = ExpandedPercentage > 0; + this.IsExpanded = (this.ExpandedPercentage > 0); } } @@ -357,7 +357,7 @@ private double GetClosestLockState(double TranslationY) } double result = LockStates[closestIndex]; - System.Console.WriteLine($"[BottomDrawer] GetClosestLockState() | result=={result} | index=={closestIndex}"); + System.Console.WriteLine($"[BottomDrawer] GetClosestLockState() | current=={current} | result=={result} | index=={closestIndex} | TranslationY=={TranslationY}"); return result; } @@ -388,9 +388,7 @@ private double getProportionCoordinate(double proportion) /// public void Dismiss() { - System.Console.WriteLine("[BottomDrawer] Dismiss()"); - - var finalTranslation = + double finalTranslation = Math.Max( Math.Min(0, -1000) , -Math.Abs(getProportionCoordinate(LockStates[0])) @@ -405,6 +403,8 @@ public void Dismiss() ? Easing.SpringOut : null ); + + System.Console.WriteLine($"[BottomDrawer] Dismiss() | finalTranslation=={finalTranslation}"); } /// @@ -412,9 +412,7 @@ public void Dismiss() /// public void Open() { - System.Console.WriteLine("[BottomDrawer] Open()"); - - var finalTranslation = + double finalTranslation = Math.Max( Math.Min(0, -1000) , -Math.Abs(getProportionCoordinate(LockStates[LockStates.Length - 1])) @@ -429,6 +427,8 @@ public void Open() ? Easing.SpringIn : null ); + + System.Console.WriteLine($"[BottomDrawer] Open() | finalTranslation=={finalTranslation}"); } #endregion Public From 6de5a7733c15114b591cae9c66aadac00521f5af Mon Sep 17 00:00:00 2001 From: dodikk Date: Mon, 4 Apr 2022 20:22:36 +0300 Subject: [PATCH 6/7] [lock state] slide to top workaround --- Xam.Plugin.SimpleBottomDrawer/BottomDrawer.cs | 111 +++++++++++++++--- 1 file changed, 92 insertions(+), 19 deletions(-) diff --git a/Xam.Plugin.SimpleBottomDrawer/BottomDrawer.cs b/Xam.Plugin.SimpleBottomDrawer/BottomDrawer.cs index df50cb3..f2f2aab 100644 --- a/Xam.Plugin.SimpleBottomDrawer/BottomDrawer.cs +++ b/Xam.Plugin.SimpleBottomDrawer/BottomDrawer.cs @@ -104,7 +104,23 @@ public bool IsExpanded public double ExpandedPercentage { get => (double)GetValue(ExpandedPercentageProperty); - set => SetValue(ExpandedPercentageProperty, value); + set + { +#if DEBUG + if (value > 0.8) + { + // > 360.0 / 640.0 + // 0.5625 + // --- + // > 0.5625 + (1 - 0.5625) / 2 + // 0.78125 + // - + System.Console.WriteLine("[BottomDrawer] debug drag to top"); + } +#endif + + SetValue(ExpandedPercentageProperty, value); + } } #endregion @@ -151,12 +167,16 @@ BindableObject bindable { if (!isExpanded) { +#if DEBUG System.Console.WriteLine("[BottomDrawer] IsExpandedPropertyChanged() ==> Dismiss()"); +#endif drawer.Dismiss(); } else { +#if DEBUG System.Console.WriteLine("[BottomDrawer] IsExpandedPropertyChanged() ==> Open()"); +#endif drawer.Open(); } } @@ -182,12 +202,14 @@ BindableObject bindable var finalTranslation = Math.Max( - Math.Min(0, -1000) + Math.Min(0, -1000) , -Math.Abs(proportionY) ); +#if DEBUG System.Console.WriteLine( $"[BottomDrawer] ExpandedPercentageChanged() ==> proportionY=={proportionY} | finalTranslation=={finalTranslation}"); +#endif if (expandValue < 0) { @@ -219,14 +241,20 @@ object sender , PanUpdatedEventArgs e ) { + double Y = + (Device.RuntimePlatform == Device.Android + ? this.TranslationY // Frame.TranslationY + : this.translationYStart) + + e.TotalY; + double tmpExpandedPercentage = GetPropertionDistance(Y); + + switch (e.StatusType) { case GestureStatus.Running: isDragging = true; - var Y = (Device.RuntimePlatform == Device.Android - ? this.TranslationY // Frame.TranslationY - : this.translationYStart) - + e.TotalY; + + // Translate and ensure we don't y + e.TotalY pan beyond the wrapped user interface element bounds. var translateY = Math.Max( @@ -235,29 +263,39 @@ object sender ); this.TranslateTo(x: this.X, y: translateY, length: 1); - this.ExpandedPercentage = GetPropertionDistance(Y); - + this.ExpandedPercentage = tmpExpandedPercentage; +#if DEBUG System.Console.WriteLine($"[BottomDrawer] OnPanChanged() - Running | ExpandedPercentage=={ExpandedPercentage} | translateY=={translateY}"); +#endif break; case GestureStatus.Completed: +#if DEBUG System.Console.WriteLine("[BottomDrawer] OnPanChanged() - Completed"); +#endif + + double dragDistanceY1 = e.TotalY + this.TranslationY; +#if DEBUG + System.Console.WriteLine($"[BottomDrawer] OnPanChanged() - call#1 GetClosestLockState({dragDistanceY1})"); +#endif + // Note: [alex-d] when calculated value was used, there was an issue of not expanding to full screen + // - + double tmpLockState = GetClosestLockStatePercentage(this.ExpandedPercentage); + double tmpLockStateY = getProportionCoordinate(tmpLockState); // At the end of the event - snap to the closest location double finalTranslation = Math.Max( Math.Min(0, -1000) - , -Math.Abs( - getProportionCoordinate( - GetClosestLockState(e.TotalY + this.TranslationY) - ) - ) + , -Math.Abs(tmpLockStateY) ); // Depending on Swipe Up or Down - change the snapping animation if (DetectSwipeUp(e)) { +#if DEBUG System.Console.WriteLine("[BottomDrawer] OnPanChanged() - DetectSwipeUp()==true"); +#endif this.TranslateTo( x: this.X @@ -267,7 +305,9 @@ object sender } else { +#if DEBUG System.Console.WriteLine("[BottomDrawer] OnPanChanged() - DetectSwipeUp()==false"); +#endif this.TranslateTo( x: this.X @@ -276,16 +316,27 @@ object sender , easing: Easing.SpringOut); } - this.ExpandedPercentage = GetClosestLockState(e.TotalY + this.TranslationY); + // Note: [alex-d] this.TranslationY might change due to this.TranslateTo() + // - + double dragDistanceY2 = e.TotalY + this.TranslationY; + +#if DEBUG + System.Console.WriteLine($"[BottomDrawer] OnPanChanged() - call#2 GetClosestLockState({dragDistanceY2})"); +#endif + this.ExpandedPercentage = GetClosestLockStateAbsolute(dragDistanceY2); this.isDragging = false; +#if DEBUG System.Console.WriteLine($"[BottomDrawer] OnPanChanged() - Completed | ExpandedPercentage=={ExpandedPercentage} | finalTranslation=={finalTranslation}"); +#endif break; case GestureStatus.Started: this.translationYStart = this.TranslationY; +#if DEBUG System.Console.WriteLine($"[BottomDrawer] OnPanChanged() - Started | translationYStart=={translationYStart}"); +#endif break; } @@ -296,6 +347,7 @@ object sender int indexOfLastLockState = LockStates.Length - 1; double lastLockState = LockStates[indexOfLastLockState]; + double expandedPercentageBeforeLock = ExpandedPercentage; if (ExpandedPercentage > lastLockState) { @@ -303,15 +355,23 @@ object sender } IsExpanded = (ExpandedPercentage > 0); + +#if DEBUG + System.Console.WriteLine($"[BottomDrawer] OnPanChanged() - [END] | ExpandedPercentage=={ExpandedPercentage} | expandedPercentageBeforeLock=={expandedPercentageBeforeLock}"); +#endif } /// /// On tapped event /// - private void OnTapped(object sender, EventArgs e) + private void OnTapped( + object sender + , EventArgs e + ) { +#if DEBUG System.Console.WriteLine("[BottomDrawer] OnTapped()"); - +#endif if (!this.IsExpanded) { if (this.LockStates.Length >= 2) @@ -336,11 +396,19 @@ private bool DetectSwipeUp(PanUpdatedEventArgs e) /// /// Find the closest lock state when swip is finished /// - private double GetClosestLockState(double TranslationY) + private double GetClosestLockStateAbsolute(double TranslationY) { // Play with these values to adjust the locking motions - this will change depending on the amount of content ona apge double current = GetPropertionDistance(TranslationY); + double result = GetClosestLockStatePercentage(current); + return result; + } + + private double GetClosestLockStatePercentage(double currentPercentageVisible) + { + double current = currentPercentageVisible; + // Calculate which lockstate it's the closest to var smallestDistance = 10000.0; var closestIndex = 0; @@ -357,8 +425,9 @@ private double GetClosestLockState(double TranslationY) } double result = LockStates[closestIndex]; +#if DEBUG System.Console.WriteLine($"[BottomDrawer] GetClosestLockState() | current=={current} | result=={result} | index=={closestIndex} | TranslationY=={TranslationY}"); - +#endif return result; } @@ -404,7 +473,9 @@ public void Dismiss() : null ); +#if DEBUG System.Console.WriteLine($"[BottomDrawer] Dismiss() | finalTranslation=={finalTranslation}"); +#endif } /// @@ -414,7 +485,7 @@ public void Open() { double finalTranslation = Math.Max( - Math.Min(0, -1000) + Math.Min(0, -1000) , -Math.Abs(getProportionCoordinate(LockStates[LockStates.Length - 1])) ); @@ -428,7 +499,9 @@ public void Open() : null ); +#if DEBUG System.Console.WriteLine($"[BottomDrawer] Open() | finalTranslation=={finalTranslation}"); +#endif } #endregion Public From b570b4f2378fb07d09b86bba9cf0903975f2f010 Mon Sep 17 00:00:00 2001 From: dodikk Date: Mon, 4 Apr 2022 20:37:25 +0300 Subject: [PATCH 7/7] [lock state] move malformed array under comment --- .../ViewModel/MainPageViewModel.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Samples/Xam.Plugin.SimpleBottomDrawer.Samples/Xam.Plugin.SimpleBottomDrawer.Samples/ViewModel/MainPageViewModel.cs b/Samples/Xam.Plugin.SimpleBottomDrawer.Samples/Xam.Plugin.SimpleBottomDrawer.Samples/ViewModel/MainPageViewModel.cs index 36ab667..946c6a6 100644 --- a/Samples/Xam.Plugin.SimpleBottomDrawer.Samples/Xam.Plugin.SimpleBottomDrawer.Samples/ViewModel/MainPageViewModel.cs +++ b/Samples/Xam.Plugin.SimpleBottomDrawer.Samples/Xam.Plugin.SimpleBottomDrawer.Samples/ViewModel/MainPageViewModel.cs @@ -40,8 +40,10 @@ public class MainPageViewModel : ObservableObject /// The bottom drawer lock states /// /// Note: [alex-d] works incorrectly when more than 3 values + /// private double[] _LockStates = new double[] { 0, .30, 0.6, 0.95 }; /// - private double[] _LockStates = new double[] { 0, .30, 0.6, 0.95 }; + private double[] _LockStates = new double[] { 0, .50, 0.75 }; + #endregion