Skip to content

Commit

Permalink
Moved property from sheetbehavior to ModalityLayout with handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Eirik Hemstad committed Aug 23, 2021
1 parent 6badb28 commit 4d36636
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 31 deletions.
24 changes: 24 additions & 0 deletions src/DIPS.Xamarin.UI/Controls/Modality/ModalityLayout.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ public partial class ModalityLayout : ContentView
typeof(Color),
typeof(ModalityLayout),
Color.Gray);

/// <summary>
/// <see cref="ShouldCloseOpenedModals"/>
/// </summary>
public static readonly BindableProperty ShouldCloseOpenedModalsProperty = BindableProperty.Create(
nameof(ShouldCloseOpenedModals),
typeof(bool),
typeof(ModalityLayout),
true);

private View? m_currentView;

Expand All @@ -61,6 +70,16 @@ public View MainContent
set => SetValue(MainContentProperty, value);
}

/// <summary>
/// Determines if the modality layout should close any open modals when opening a new one.
/// This is a bindable property.
/// </summary>
public bool ShouldCloseOpenedModals
{
get => (bool)GetValue(ShouldCloseOpenedModalsProperty);
set => SetValue(ShouldCloseOpenedModalsProperty, value);
}

/// <summary>
/// The color of the overlay when a modality component is showing
/// This is a bindable property.
Expand Down Expand Up @@ -165,6 +184,11 @@ private Frame CreateOverlay()
/// <remarks>Using relative to parent with the constraints will give you the <see cref="ModalityLayout"/></remarks>
public void Show(IModalityHandler modalityHandler, View view, Constraint? xConstraint = null, Constraint? yConstraint = null, Constraint? widthConstraint = null, Constraint? heightConstraint = null)
{
if (ShouldCloseOpenedModals && CurrentShowingModalityLayout != modalityHandler)
{
HideCurrentShowingModality();
}

CurrentShowingModalityLayout = modalityHandler;
m_currentView = view;

Expand Down
16 changes: 0 additions & 16 deletions src/DIPS.Xamarin.UI/Controls/Sheet/SheetBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -253,12 +253,6 @@ public double ActionButtonSize
/// </summary>
public static readonly BindableProperty ShouldAutoCloseProperty = BindableProperty.Create(nameof(ShouldAutoClose), typeof(bool), typeof(SheetBehavior), true);

public static readonly BindableProperty ShouldCloseOpenSheetsProperty = BindableProperty.Create(
nameof(ShouldCloseOpenSheets),
typeof(bool),
typeof(SheetBehavior),
true);

/// <summary>
/// <see cref="ShouldRememberPosition" />
/// </summary>
Expand Down Expand Up @@ -629,16 +623,6 @@ public bool ShouldAutoClose
get => (bool)GetValue(ShouldAutoCloseProperty);
set => SetValue(ShouldAutoCloseProperty, value);
}

/// <summary>
/// Determines if the sheet should close other open sheets when it's opened.
/// This is a bindable property.
/// </summary>
public bool ShouldCloseOpenSheets
{
get => (bool)GetValue(ShouldCloseOpenSheetsProperty);
set => SetValue(ShouldCloseOpenSheetsProperty, value);
}

/// <summary>
/// Determines if the sheet should remember its position when it is opened and closed.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,68 @@
<?xml version="1.0"
encoding="utf-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
<ContentPage x:Name="GitHub287"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:dxui="http://dips.xamarin.ui.com"
mc:Ignorable="d"
x:Class="DIPS.Xamarin.Forms.IssuesRepro.Github287.Github287">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<dxui:ModalityLayout>
<dxui:ModalityLayout.Behaviors>
<dxui:SheetBehavior IsOpen="True"
IsDraggable="True"
Position="0.5">
<Label Text="The bug is fixed if you can only see one handle and the app doesn't freeze"/>
</dxui:SheetBehavior>
</dxui:ModalityLayout.Behaviors>
</dxui:ModalityLayout>
</Grid>
<ContentPage.ToolbarItems>
<ToolbarItem Text="A"
Command="{Binding Source={x:Reference sheetA}, Path=OpenCommand}">
</ToolbarItem>
<ToolbarItem Text="B"
Command="{Binding Source={x:Reference sheetB}, Path=OpenCommand}">
</ToolbarItem>
</ContentPage.ToolbarItems>
<dxui:ModalityLayout BindingContext="{x:Reference Name=GitHub287}"
ShouldCloseOpenedModals="{Binding IsCloseEnabled}">
<dxui:ModalityLayout.Behaviors>
<dxui:SheetBehavior x:Name="sheetA"
Title="Sheet A"
Position="0.5"
IsDraggable="True"
VerticalContentAlignment="SameAsSheet">
<dxui:SheetBehavior.SheetContentTemplate>
<DataTemplate>
<Label Text="Sheet A"/>
</DataTemplate>
</dxui:SheetBehavior.SheetContentTemplate>
</dxui:SheetBehavior>
<dxui:SheetBehavior x:Name="sheetB"
BindingContext="{x:Reference Name=GitHub287}"
Title="Sheet B"
IsDraggable="True"
Position="0.5"
VerticalContentAlignment="SameAsSheet">
<dxui:SheetBehavior.SheetContentTemplate>
<DataTemplate>
<Label Text="Sheet B"/>
</DataTemplate>
</dxui:SheetBehavior.SheetContentTemplate>
</dxui:SheetBehavior>
</dxui:ModalityLayout.Behaviors>
<StackLayout Margin="16">
<Label Text="Toggle 'ShouldClosenOpenModals'"
HorizontalOptions="Center"/>
<Switch BindingContext="{x:Reference Name=GitHub287}"
HorizontalOptions="Center"
Margin="16"
IsToggled="{Binding IsCloseEnabled}"/>
<Button Text="Show Popup">
<Button.Behaviors>
<dxui:PopupBehavior Direction="Above">
<Frame>
<StackLayout>
<Label Text="Hello!"/>
<Button Text="Close" dxui:Modality.CloseOnClick="True"/>
</StackLayout>
</Frame>
</dxui:PopupBehavior>
</Button.Behaviors>
</Button>
</StackLayout>

</dxui:ModalityLayout>
</ContentPage>
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
Expand All @@ -13,9 +14,54 @@ namespace DIPS.Xamarin.Forms.IssuesRepro.Github287
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class Github287 : ContentPage
{
private bool m_isSheetAOpen;
private bool m_isSheetBOpen;
private bool m_isCloseEnabled;

public Github287()
{
InitializeComponent();
IsCloseEnabled = true;
}

public bool IsSheetAOpen
{
get => m_isSheetAOpen;
set
{
m_isSheetAOpen = value;
OnPropertyChanged(nameof(IsSheetAOpen));
}
}

public bool IsSheetBOpen
{
get => m_isSheetBOpen;
set
{
m_isSheetBOpen = value;
OnPropertyChanged(nameof(IsSheetBOpen));
}
}

public bool IsCloseEnabled
{
get => m_isCloseEnabled;
set
{
m_isCloseEnabled = value;
OnPropertyChanged(nameof(IsCloseEnabled));
}
}

private void MenuItemA_OnClicked(object sender, EventArgs e)
{
IsSheetAOpen = true;
}

private void MenuItemB_OnClicked(object sender, EventArgs e)
{
IsSheetAOpen = !IsSheetAOpen;
}
}
}

0 comments on commit 4d36636

Please sign in to comment.