Skip to content

Commit

Permalink
Sheet now auto closes (#126)
Browse files Browse the repository at this point in the history
* Added auto close

* Made sure the sheet does not close if min is set to more than 0.05

* Removed Picker-control from samples because we dont have one

* Removed comments and added other comments

* Removed comment
  • Loading branch information
haavamoa authored Feb 5, 2020
1 parent 6747172 commit 570ce6d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
24 changes: 13 additions & 11 deletions src/DIPS.Xamarin.UI/Controls/Sheet/SheetBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ private static void OnSheetContentPropertyChanged(BindableObject bindable, objec
nameof(MinPosition),
typeof(double),
typeof(SheetBehavior),
0.1,
0.05,
BindingMode.TwoWay);

/// <summary>
Expand Down Expand Up @@ -213,6 +213,7 @@ private static void OnSheetContentPropertyChanged(BindableObject bindable, objec
ColorPalette.QuinaryAir);

private bool m_fromIsDraggingContext;
private double m_autoCloseThreshold = 0.05;

/// <summary>
/// Determines the position of the sheet when it appears.
Expand Down Expand Up @@ -559,7 +560,7 @@ private async void ToggleSheetVisibility()
};

//Set position based on size of content
if (Position <= 0)
if (Position <= m_autoCloseThreshold)
{
//Calculate what size the content needs if the position is set to 0
var newPosition = m_sheetView.SheetContentHeightRequest / m_modalityLayout.Height;
Expand All @@ -568,8 +569,6 @@ private async void ToggleSheetVisibility()
else //Set position from input
{
await TranslateBasedOnPosition(Position);
//OnOpenCommand?.Execute(OnOpenCommandParameter);
//OnOpen?.Invoke(this, EventArgs.Empty);
}
}
else
Expand Down Expand Up @@ -597,24 +596,27 @@ private async Task TranslateBasedOnPosition(double newPosition)
if (m_modalityLayout == null) return;
if (m_sheetView == null) return;

if (MinPosition <= 0 || MinPosition > 1)
if (MinPosition < m_autoCloseThreshold || MinPosition > MaxPosition) //Min position should be bigger than the auto close threshold and max position
{
MinPosition = (double)MinPositionProperty.DefaultValue;
}

if (MaxPosition <= 0 || MaxPosition > 1)
if (MaxPosition <= 0 || MaxPosition > 1) //Max position should be should be between 0-1
{
MaxPosition = (double)MaxPositionProperty.DefaultValue;
}

if (MinPosition > MaxPosition)
{
MinPosition = (double)MinPositionProperty.DefaultValue;
}

if (newPosition < MinPosition)
{
Position = MinPosition;
if (MinPosition > m_autoCloseThreshold) //Do not auto- close if the minimum position set by the consumer is bigger than the auto close threshold
{
Position = MinPosition;
}
else //Auto close
{
IsOpen = false;
}
return; //Return when we set property because it will lead to recursively calling this method
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@
Command="{Binding NavigateToCommand}"
CommandParameter="TrendGraph"
Text="Trend graph" />
<Button
Command="{Binding NavigateToCommand}"
CommandParameter="Picker"
Text="Picker" />
<Button
Command="{Binding NavigateToCommand}"
CommandParameter="ContentControl"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class SheetPageViewModel : INotifyPropertyChanged
private ContentAlignment m_verticalContentAlignment;
private double m_position;
private double m_maxPosition = 1;
private double m_minPosition = 0.1;
private double m_minPosition = 0.05;
private string m_stateText;

public SheetPageViewModel()
Expand Down

0 comments on commit 570ce6d

Please sign in to comment.