Skip to content

Commit

Permalink
merged
Browse files Browse the repository at this point in the history
  • Loading branch information
haavamoa committed Feb 11, 2020
2 parents 1165af7 + e9e7a95 commit de4b9da
Show file tree
Hide file tree
Showing 9 changed files with 130 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,19 @@ public class FloatingActionMenuBehaviour : Behavior<ModalityLayout>
60.0);

/// <summary>
/// <see cref="FontSize" />
/// <see cref="ExpandButtonFontSize" />
/// </summary>
public static readonly BindableProperty FontSizeProperty = BindableProperty.Create(
nameof(FontSize),
public static readonly BindableProperty ExpandButtonFontSizeProperty = BindableProperty.Create(
nameof(ExpandButtonFontSize),
typeof(double),
typeof(Internal.Xaml.FloatingActionMenu),
12.0);

/// <summary>
/// <see cref="FontFamily" />
/// <see cref="ExpandButtonFontFamily" />
/// </summary>
public static readonly BindableProperty FontFamilyProperty = BindableProperty.Create(
nameof(FontFamily),
public static readonly BindableProperty ExpandButtonFontFamilyProperty = BindableProperty.Create(
nameof(ExpandButtonFontFamily),
typeof(string),
typeof(Internal.Xaml.FloatingActionMenu));

Expand Down Expand Up @@ -75,6 +75,7 @@ public class FloatingActionMenuBehaviour : Behavior<ModalityLayout>

private Internal.Xaml.FloatingActionMenu? m_floatingActionMenu;
private ModalityLayout? m_modaliyLayout;
private bool m_first = true;

/// <summary>
/// Describes the current state of the menu.
Expand Down Expand Up @@ -117,7 +118,7 @@ public List<MenuButton> Children
/// <summary>
/// The Y-position of the control. Is proportional to the Layout it's added to. Values between 0-1.
/// </summary>
public double YConstraint { get; set; }
public double YPosition { get; set; }

/// <summary>
/// The text color of the text in the expand button.
Expand Down Expand Up @@ -153,10 +154,10 @@ public string ExpandButtonText
/// FontFamily of the text in the expand button.
/// This is a bindable property.
/// </summary>
public string FontFamily
public string ExpandButtonFontFamily
{
get => (string)GetValue(FontFamilyProperty);
set => SetValue(FontFamilyProperty, value);
get => (string)GetValue(ExpandButtonFontFamilyProperty);
set => SetValue(ExpandButtonFontFamilyProperty, value);
}

/// <summary>
Expand All @@ -173,15 +174,18 @@ public double Size
/// FontSize of the text in the expand button.
/// This is a bindable property.
/// </summary>
public double FontSize
public double ExpandButtonFontSize
{
get => (double)GetValue(FontSizeProperty);
set => SetValue(FontSizeProperty, value);
get => (double)GetValue(ExpandButtonFontSizeProperty);
set => SetValue(ExpandButtonFontSizeProperty, value);
}

private static void IsOpenPropertyChanged(BindableObject bindable, object oldvalue, object newvalue)
{
if (bindable is FloatingActionMenuBehaviour menuBehaviour) menuBehaviour.m_floatingActionMenu?.ShowMenu((bool)newvalue);
if (bindable is FloatingActionMenuBehaviour menuBehaviour)
{
menuBehaviour.m_floatingActionMenu?.ShowMenu((bool)newvalue);
}
}

/// <inheritdoc />
Expand All @@ -198,6 +202,7 @@ protected override void OnAttachedTo(ModalityLayout modalityLayout)
protected override void OnDetachingFrom(ModalityLayout bindable)
{
base.OnDetachingFrom(bindable);
if (m_modaliyLayout == null) return;
m_modaliyLayout.SizeChanged -= OnModalityLayoutSizeChanged;
m_modaliyLayout.BindingContextChanged -= OnModalityLayoutBindingContextChanged;
}
Expand All @@ -209,7 +214,11 @@ private void OnModalityLayoutBindingContextChanged(object sender, EventArgs e)

private void OnModalityLayoutSizeChanged(object sender, EventArgs e)
{
if (sender is ModalityLayout modality) m_floatingActionMenu?.AddTo(modality);
if (m_modaliyLayout != null && m_first)
{
m_first = false;
m_floatingActionMenu?.AddTo(m_modaliyLayout);
}
}
}
}
12 changes: 11 additions & 1 deletion src/DIPS.Xamarin.UI/Controls/FloatingActionMenu/MenuButton.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,22 @@
HasShadow="False"
VerticalOptions="Center"
HorizontalOptions="End">
<Label Text="{Binding Title}"
<Label x:Name="TitleLabel"
Text="{Binding Title}"
TextColor="{Binding TitleTextColor}"
FontSize="{Binding TitleFontSize}"
FontFamily="{Binding FontFamily}"
VerticalOptions="Center"
HorizontalOptions="End" />

<Frame.Triggers>
<DataTrigger TargetType="Frame"
Binding="{Binding Source={x:Reference TitleLabel}, Path=Text.Length}"
Value="0">
<Setter Property="IsVisible"
Value="False" />
</DataTrigger>
</Frame.Triggers>
</Frame>

<Button x:Name="button"
Expand Down
37 changes: 22 additions & 15 deletions src/DIPS.Xamarin.UI/Controls/FloatingActionMenu/MenuButton.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@ public partial class MenuButton : ContentView
string.Empty);

/// <summary>
/// <see cref="TapCommand" />
/// <see cref="Command" />
/// </summary>
public static readonly BindableProperty TapCommandProperty = BindableProperty.Create(
nameof(TapCommand),
public static readonly BindableProperty CommandProperty = BindableProperty.Create(
nameof(Command),
typeof(ICommand),
typeof(MenuButton));

/// <summary>
/// <see cref="TapCommandParameter" />
/// <see cref="CommandParameter" />
/// </summary>
public static readonly BindableProperty TapCommandParameterProperty = BindableProperty.Create(
nameof(TapCommandParameter),
public static readonly BindableProperty CommandParameterProperty = BindableProperty.Create(
nameof(CommandParameter),
typeof(object),
typeof(MenuButton));

Expand Down Expand Up @@ -195,23 +195,23 @@ public Color TitleTextColor
}

/// <summary>
/// The parameter sent with the <see cref="TapCommand" />.
/// The parameter sent with the <see cref="Command" />.
/// This is a bindable property.
/// </summary>
public object TapCommandParameter
public object CommandParameter
{
get => GetValue(TapCommandParameterProperty);
set => SetValue(TapCommandParameterProperty, value);
get => GetValue(CommandParameterProperty);
set => SetValue(CommandParameterProperty, value);
}

/// <summary>
/// The command that is executed when the button is tapped.
/// This is a bindable property.
/// </summary>
public ICommand TapCommand
public ICommand Command
{
get => (ICommand)GetValue(TapCommandProperty);
set => SetValue(TapCommandProperty, value);
get => (ICommand)GetValue(CommandProperty);
set => SetValue(CommandProperty, value);
}

/// <summary>
Expand All @@ -226,8 +226,15 @@ public string Title

private void MenuButton_OnClicked(object sender, EventArgs e)
{
if (FloatingActionMenuParent != null) FloatingActionMenuParent.m_behaviour.IsOpen = false;
if (TapCommand != null && IsEnabled) TapCommand?.Execute(TapCommandParameter);
if (FloatingActionMenuParent != null)
{
FloatingActionMenuParent.m_behaviour.IsOpen = false;
}

if (Command != null && IsEnabled)
{
Command?.Execute(CommandParameter);
}
}
}
}
7 changes: 7 additions & 0 deletions src/DIPS.Xamarin.UI/Controls/Modality/ModalityLayout.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<ContentView xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="DIPS.Xamarin.UI.Controls.Modality.ModalityLayout"
<<<<<<< HEAD
IsClippedToBounds="True"
x:Name="modalityLayout">

Expand All @@ -11,4 +12,10 @@
HorizontalOptions="{Binding Source={x:Reference modalityLayout}, Path=HorizontalOptions}"
VerticalOptions="{Binding Source={x:Reference modalityLayout}, Path=VerticalOptions}"
/>
=======
IsClippedToBounds="True">
<RelativeLayout x:Name="relativeLayout"
ChildRemoved="OnChildRemoved"
x:FieldModifier="internal" />
>>>>>>> e9e7a95f5a3c6ff28b41ec055f3f63b249d59c59
</ContentView>
48 changes: 21 additions & 27 deletions src/DIPS.Xamarin.UI/Controls/Modality/ModalityLayout.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace DIPS.Xamarin.UI.Controls.Modality
public partial class ModalityLayout : ContentView
{
private readonly TapGestureRecognizer m_closeModalityRecognizer;
private readonly Lazy<Frame> m_overLay;
private readonly Frame m_overLay;

private IModalityHandler? m_currentShowingModalityHandler;

Expand Down Expand Up @@ -48,7 +48,9 @@ public ModalityLayout()
{
InitializeComponent();
m_closeModalityRecognizer = new TapGestureRecognizer { Command = new Command(HideCurrentShowingModality) };
m_overLay = new Lazy<Frame>(CreateOverlay);
//m_overLay = new Lazy<Frame>(CreateOverlay);
m_overLay = new Frame { BackgroundColor = OverlayColor, IsVisible = true, Opacity = 0.0 , InputTransparent = true};
m_overLay.GestureRecognizers.Add(m_closeModalityRecognizer);
}

/// <summary>
Expand Down Expand Up @@ -86,6 +88,12 @@ private static void OnMainContentPropertyChanged(BindableObject bindable, object
Constraint.RelativeToParent(parent => parent.Y),
Constraint.RelativeToParent(parent => parent.Width),
Constraint.RelativeToParent(parent => parent.Height));
modalityLayout.relativeLayout.Children.Add(
modalityLayout.m_overLay,
Constraint.RelativeToParent(parent => parent.X),
Constraint.RelativeToParent(parent => parent.Y),
Constraint.RelativeToParent(parent => parent.Width),
Constraint.RelativeToParent(parent => parent.Height));
}
}

Expand Down Expand Up @@ -114,13 +122,13 @@ private void HideCurrentShowingModality()
m_currentShowingModalityHandler?.Hide();
}

private Frame CreateOverlay()
{
var overlayFrame = new Frame { BackgroundColor = OverlayColor, IsVisible = true, Opacity = 0.0 };
//private Frame CreateOverlay()
//{
// var overlayFrame = new Frame { BackgroundColor = OverlayColor, IsVisible = true, Opacity = 0.0 };

overlayFrame.GestureRecognizers.Add(m_closeModalityRecognizer);
return overlayFrame;
}
// overlayFrame.GestureRecognizers.Add(m_closeModalityRecognizer);
// return overlayFrame;
//}

/// <summary>
/// Shows a view relative to a another view inside of a modality layout
Expand Down Expand Up @@ -158,16 +166,8 @@ public void Show(IModalityHandler modalityHandler, View view, Constraint? xConst
/// <param name="view">The view that's over he overlay</param>
public void Show(IModalityHandler modalityHandler, View view)
{
var indexOf = relativeLayout.Children.IndexOf(view);
m_currentShowingModalityHandler = modalityHandler;
var overlay = m_overLay.Value;
overlay.FadeTo(0.5);
RelativeLayout.SetWidthConstraint(overlay, Constraint.RelativeToParent(r => r.Width));
RelativeLayout.SetHeightConstraint(overlay, Constraint.RelativeToParent(r => r.Height));
RelativeLayout.SetXConstraint(overlay, Constraint.RelativeToParent(r => 0.0));
RelativeLayout.SetYConstraint(overlay, Constraint.RelativeToParent(r => 0.0));

relativeLayout.Children.Insert(indexOf, m_overLay.Value);
ShowOverlay();
}

private void ContentSizeChanged(object sender, EventArgs e)
Expand All @@ -177,15 +177,9 @@ private void ContentSizeChanged(object sender, EventArgs e)

private void ShowOverlay()
{
var overlay = m_overLay.Value;
var overlay = m_overLay;
overlay.FadeTo(0.5);

relativeLayout.Children.Add(
m_overLay.Value,
widthConstraint: Constraint.RelativeToParent(r => r.Width),
heightConstraint: Constraint.RelativeToParent(r => r.Height),
xConstraint: Constraint.RelativeToParent(r => 0.0),
yConstraint: Constraint.RelativeToParent(r => 0.0));
overlay.InputTransparent = false;
}

/// <summary>
Expand All @@ -209,9 +203,9 @@ public async void Hide(View view)

internal async Task HideOverlay()
{
var overlay = m_overLay.Value;
var overlay = m_overLay;
m_overLay.InputTransparent = true;
await overlay.FadeTo(0);
relativeLayout.Children.Remove(overlay);
}

private void OnChildRemoved(object sender, ElementEventArgs e)
Expand Down
5 changes: 3 additions & 2 deletions src/DIPS.Xamarin.UI/Internal/Xaml/FloatingActionMenu.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
xmlns:ValueConverters="clr-namespace:DIPS.Xamarin.UI.Converters.ValueConverters"
mc:Ignorable="d"
x:Name="CodeBehind"
BackgroundColor="Blue"
x:Class="DIPS.Xamarin.UI.Internal.Xaml.FloatingActionMenu">

<ContentView.Content>
Expand All @@ -19,10 +20,10 @@
BackgroundColor="{Binding ExpandButtonBackgroundColor}"
BorderColor="White"
BorderWidth="3"
FontSize="{Binding FontSize}"
FontSize="{Binding ExpandButtonFontSize}"
Text="{Binding ExpandButtonText}"
TextColor="{Binding ExpandButtonTextColor}"
FontFamily="{Binding FontFamily}"
FontFamily="{Binding ExpandButtonFontFamily}"
Clicked="ExpandButton_OnClicked" />
</ContentView.Content>
</ContentView>
16 changes: 11 additions & 5 deletions src/DIPS.Xamarin.UI/Internal/Xaml/FloatingActionMenu.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,15 @@ private void HideOverlay()

private async void ExpandButton_OnClicked(object sender, EventArgs e)
{
if (m_first) AdjustXPositions();
if (m_first)
{
AdjustXPositions();
}

if (m_animationComplete) await AnimateAll();
if (m_animationComplete)
{
await AnimateAll();
}
m_behaviour.IsOpen = m_isExpanded;

Children.ForEach(mb => mb.InputTransparent = !m_isExpanded);
Expand Down Expand Up @@ -119,13 +125,13 @@ private void AddButtonsToRelative(RelativeLayout parent)
parent.Children.Add(
child,
Constraint.RelativeToParent(p => p.Width * m_behaviour.XPosition),
Constraint.RelativeToParent(p => p.Height * m_behaviour.YConstraint));
Constraint.RelativeToParent(p => (p.Height * m_behaviour.YPosition) - ExpandButton.HeightRequest));
}

parent.Children.Add(
ExpandButton,
Constraint.RelativeToParent(p => p.Width * m_behaviour.XPosition),
Constraint.RelativeToParent(p => p.Height * m_behaviour.YConstraint));
Constraint.RelativeToParent(p => (p.Width * m_behaviour.XPosition) - ExpandButton.WidthRequest),
Constraint.RelativeToParent(p => (p.Height * m_behaviour.YPosition) - ExpandButton.HeightRequest));
}

private void AdjustXPositions()
Expand Down
Loading

0 comments on commit de4b9da

Please sign in to comment.