Skip to content

Commit 4165cc0

Browse files
author
Mike Pham
committed
Added color properties for FloatingButton.
1 parent dfe8a24 commit 4165cc0

27 files changed

+312
-91
lines changed

src/Demo/Demo.Droid/MainActivity.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
using Xamarin.Forms;
1111

12-
[Activity(ConfigurationChanges = AppConfig, MainLauncher = true, Theme = CompatTheme)]
12+
[Activity(ConfigurationChanges = AppConfig, MainLauncher = true, Theme = CompatThemeLightDarkActionBar)]
1313
public class MainActivity : AppCompatFormsApplicationActivity
1414
{
1515
private const ConfigChanges AppConfig = ConfigChanges.Orientation | ConfigChanges.ScreenSize;

src/Demo/Demo/Demo.csproj

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@
6767
<Compile Include="Views\NestNavigationView.xaml.cs">
6868
<DependentUpon>NestNavigationView.xaml</DependentUpon>
6969
</Compile>
70+
<Compile Include="Views\Shared\MenuHeaderView.xaml.cs">
71+
<DependentUpon>MenuHeaderView.xaml</DependentUpon>
72+
</Compile>
7073
</ItemGroup>
7174
<ItemGroup>
7275
<Reference Include="PropertyChanged, Version=1.50.1.0, Culture=neutral, PublicKeyToken=ee3ee20bcf148ddd">
@@ -128,6 +131,12 @@
128131
<SubType>Designer</SubType>
129132
</EmbeddedResource>
130133
</ItemGroup>
134+
<ItemGroup>
135+
<EmbeddedResource Include="Views\Shared\MenuHeaderView.xaml">
136+
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
137+
<SubType>Designer</SubType>
138+
</EmbeddedResource>
139+
</ItemGroup>
131140
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
132141
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
133142
<PropertyGroup>

src/Demo/Demo/ViewModels/MainViewModel.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
{
33
using System.Windows.Input;
44

5-
using NativeCode.Mobile.AppCompat.Controls;
65
using NativeCode.Mobile.AppCompat.Controls.Platforms;
76

87
using PropertyChanged;
@@ -23,6 +22,12 @@ public MainViewModel()
2322
this.Title = "Main";
2423
}
2524

25+
public double Elevation { get; set; }
26+
27+
public double Radius { get; set; }
28+
29+
public int Padding { get; set; }
30+
2631
[DoNotNotify]
2732
public ICommand FloatingButtonCommand { get; private set; }
2833

src/Demo/Demo/Views/ChooserView.xaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
x:Class="Demo.Views.ChooserView">
66
<controls:NavigationLayout>
77
<controls:NavigationLayout.Children>
8-
<controls:NavigationLayoutMenu Command="{Binding MasterDetailPatternOneCommand}" Text="Master Detail Pattern One" />
9-
<controls:NavigationLayoutMenu Command="{Binding MasterDetailPatternTwoCommand}" Text="Master Detail Pattern Two" />
10-
<controls:NavigationLayoutMenu Command="{Binding NavigationCommand}" Text="Navigation Pattern" />
11-
<controls:NavigationLayoutMenu Command="{Binding TabbedCommand}" Text="Tabbed Navigation" />
8+
<controls:NavigationLayoutMenu Command="{Binding NavigationCommand}" Group="0" Text="Navigation Pattern" />
9+
<controls:NavigationLayoutMenu Command="{Binding TabbedCommand}" Group="0" Text="Tabbed Navigation" />
10+
<controls:NavigationLayoutMenu Command="{Binding MasterDetailPatternOneCommand}" Group="1" Text="Master Detail Pattern One" />
11+
<controls:NavigationLayoutMenu Command="{Binding MasterDetailPatternTwoCommand}" Group="1" Text="Master Detail Pattern Two" />
1212
</controls:NavigationLayout.Children>
1313
</controls:NavigationLayout>
1414
</ContentPage>

src/Demo/Demo/Views/MainView.xaml

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
44
xmlns:controls="clr-namespace:NativeCode.Mobile.AppCompat.Controls;assembly=NativeCode.Mobile.AppCompat.Controls"
5-
x:Class="Demo.Views.MainView" IsBusy="{Binding IsBusy}" Title="{Binding Title}">
5+
xmlns:shared="clr-namespace:Demo.Views.Shared;assembly=Demo"
6+
x:Class="Demo.Views.MainView" BackgroundColor="Gray" IsBusy="{Binding IsBusy}" Title="{Binding Title}">
67
<ScrollView>
78
<StackLayout Padding="20">
89
<Picker>
@@ -18,33 +19,36 @@
1819
<x:String>Item 9</x:String>
1920
</Picker.Items>
2021
</Picker>
21-
<controls:Card Padding="40" Radius="20">
22-
<controls:Card.Content>
23-
<StackLayout>
24-
<Button Command="{Binding ShowSnackBar}" Text="Hit me!" />
25-
<StackLayout Orientation="Horizontal">
26-
<Label Text="Switch On/Off" />
27-
<Switch />
28-
</StackLayout>
29-
<StackLayout Orientation="Horizontal">
30-
<Label Text="Entry Field" />
31-
<Entry HorizontalOptions="FillAndExpand" />
32-
</StackLayout>
22+
<Label Text="Elevation" />
23+
<Slider Minimum="0" Maximum="5" Value="{Binding Elevation}" />
24+
<Label Text="Radius" />
25+
<Slider Minimum="0" Maximum="20" Value="{Binding Radius}" />
26+
<Label Text="Padding" />
27+
<Slider Minimum="0" Maximum="20" Value="{Binding Padding}" />
28+
<controls:Card BackgroundColor="White" Elevation="{Binding Elevation}" Padding="{Binding Padding}" Radius="{Binding Radius}">
29+
<StackLayout>
30+
<Button Command="{Binding ShowSnackBar}" Text="Hit me!" />
31+
<StackLayout Orientation="Horizontal">
32+
<Label Text="Switch On/Off" />
33+
<Switch />
3334
</StackLayout>
34-
</controls:Card.Content>
35-
</controls:Card>
36-
<controls:Card>
37-
<controls:Card.Content>
3835
<StackLayout Orientation="Horizontal">
39-
<controls:FloatingButton ButtonSize="Mini" Color="Green" Command="{Binding FloatingButtonCommand}" Icon="launcher" />
40-
<controls:FloatingButton ButtonSize="Normal" Color="Green" Command="{Binding FloatingButtonCommand}" Icon="launcher" />
36+
<Label Text="Entry Field" />
37+
<Entry HorizontalOptions="FillAndExpand" />
4138
</StackLayout>
42-
</controls:Card.Content>
39+
</StackLayout>
40+
</controls:Card>
41+
<controls:Card BackgroundColor="White" Elevation="{Binding Elevation}" Padding="{Binding Padding}" Radius="{Binding Radius}">
42+
<StackLayout Orientation="Horizontal">
43+
<controls:FloatingButton ButtonSize="Mini" Color="Black" Command="{Binding FloatingButtonCommand}" Icon="launcher" />
44+
<controls:FloatingButton ButtonSize="Normal" Command="{Binding FloatingButtonCommand}" Icon="launcher" />
45+
</StackLayout>
46+
</controls:Card>
47+
<controls:Card BackgroundColor="White" Command="{Binding ShowSnackBar}" Elevation="{Binding Elevation}" Padding="{Binding Padding}" Radius="{Binding Radius}">
48+
<Label Text="Clickable CardView" />
4349
</controls:Card>
44-
<controls:Card Command="{Binding ShowSnackBar}">
45-
<controls:Card.Content>
46-
<Label Text="Clickable CardView" />
47-
</controls:Card.Content>
50+
<controls:Card BackgroundColor="White" Elevation="{Binding Elevation}" Padding="{Binding Padding}" Radius="{Binding Radius}">
51+
<shared:MenuHeaderView />
4852
</controls:Card>
4953
</StackLayout>
5054
</ScrollView>

src/Demo/Demo/Views/MenuView.xaml

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,20 @@
22

33
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
44
xmlns:controls="clr-namespace:NativeCode.Mobile.AppCompat.Controls;assembly=NativeCode.Mobile.AppCompat.Controls"
5+
xmlns:shared="clr-namespace:Demo.Views.Shared;assembly=Demo"
56
x:Class="Demo.Views.MenuView" IsBusy="{Binding IsBusy}" Title="{Binding Title}">
67
<StackLayout>
78

89
<controls:NavigationLayout HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
910

1011
<controls:NavigationLayout.HeaderView>
11-
<ContentView>
12-
<RelativeLayout x:Name="Header">
13-
<Image x:Name="HeaderImage" Source="navbackground" IsOpaque="True" Opacity="0.75" />
14-
<StackLayout
15-
RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToView, ElementName=HeaderImage, Constant=0, Factor=1, Property=Height}"
16-
RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToParent, Constant=0, Factor=0, Property=Y}"
17-
Padding="10">
18-
<Image Source="launcher" HeightRequest="64" WidthRequest="64" HorizontalOptions="Start" VerticalOptions="Start" />
19-
<Label HorizontalOptions="Start" VerticalOptions="EndAndExpand" Text="test@testable.com" />
20-
</StackLayout>
21-
</RelativeLayout>
22-
</ContentView>
12+
<shared:MenuHeaderView />
2313
</controls:NavigationLayout.HeaderView>
2414

2515
<controls:NavigationLayout.Children>
26-
<controls:NavigationLayoutMenu Command="{Binding HomeCommand}" Text="Home" />
27-
<controls:NavigationLayoutMenu Command="{Binding LoremIpsumCommand}" Group="2" Text="Lorem Ipsum" />
28-
<controls:NavigationLayoutMenu Command="{Binding NavigationCommand}" Group="2" Text="Nested Navigation" />
16+
<controls:NavigationLayoutMenu Command="{Binding HomeCommand}" Group="0" Text="Home" />
17+
<controls:NavigationLayoutMenu Command="{Binding LoremIpsumCommand}" Group="1" Text="Lorem Ipsum" />
18+
<controls:NavigationLayoutMenu Command="{Binding NavigationCommand}" Group="1" Text="Nested Navigation" />
2919
</controls:NavigationLayout.Children>
3020

3121
</controls:NavigationLayout>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
3+
<controls:NavigationLayoutHeader xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4+
xmlns:controls="clr-namespace:NativeCode.Mobile.AppCompat.Controls;assembly=NativeCode.Mobile.AppCompat.Controls"
5+
x:Class="Demo.Views.Shared.MenuHeaderView" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
6+
<Image x:Name="HeaderImage" Source="navbackground" IsOpaque="True" Opacity="0.75" />
7+
</controls:NavigationLayoutHeader>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace Demo.Views.Shared
2+
{
3+
using NativeCode.Mobile.AppCompat.Controls;
4+
5+
public partial class MenuHeaderView : NavigationLayoutHeader
6+
{
7+
public MenuHeaderView()
8+
{
9+
this.InitializeComponent();
10+
}
11+
}
12+
}

src/NativeCode.Mobile.AppCompat.Controls/Card.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@ public class Card : ContentView, ICommandProvider
1212
x => x.CommandParameter,
1313
default(object));
1414

15-
public static readonly BindableProperty RadiusProperty = BindableProperty.Create<Card, double>(x => x.Radius, 20.0d);
15+
public static readonly BindableProperty ElevationProperty = BindableProperty.Create<Card, double>(x => x.Elevation, default(double));
16+
17+
public static readonly BindableProperty RadiusProperty = BindableProperty.Create<Card, double>(x => x.Radius, 5.0d);
1618

1719
public Card()
1820
{
19-
this.Padding = new Thickness(20);
21+
this.Padding = new Thickness(5);
2022
}
2123

2224
/// <summary>
@@ -37,6 +39,12 @@ public object CommandParameter
3739
set { this.SetValue(CommandParameterProperty, value); }
3840
}
3941

42+
public double Elevation
43+
{
44+
get { return (double)this.GetValue(ElevationProperty); }
45+
set { this.SetValue(ElevationProperty, value); }
46+
}
47+
4048
public double Radius
4149
{
4250
get { return (double)this.GetValue(RadiusProperty); }

src/NativeCode.Mobile.AppCompat.Controls/FloatingButton.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ public class FloatingButton : View, ICommandProvider
1414
default(FloatingButtonSize),
1515
BindingMode.OneWayToSource);
1616

17-
public static readonly BindableProperty ColorProperty = BindableProperty.Create<FloatingButton, Color>(x => x.Color, default(Color));
17+
public static readonly BindableProperty ColorProperty = BindableProperty.Create<FloatingButton, Color>(x => x.Color, Color.Accent);
18+
19+
public static readonly BindableProperty ColorPressedProperty = BindableProperty.Create<FloatingButton, Color>(x => x.ColorPressed, Color.Accent);
1820

1921
public static readonly BindableProperty CommandProperty = BindableProperty.Create<FloatingButton, ICommand>(x => x.Command, default(ICommand));
2022

@@ -42,6 +44,12 @@ public Color Color
4244
set { this.SetValue(ColorProperty, value); }
4345
}
4446

47+
public Color ColorPressed
48+
{
49+
get { return (Color)this.GetValue(ColorPressedProperty); }
50+
set { this.SetValue(ColorPressedProperty, value); }
51+
}
52+
4553
/// <summary>
4654
/// Gets or sets the command.
4755
/// </summary>

src/NativeCode.Mobile.AppCompat.Controls/NativeCode.Mobile.AppCompat.Controls.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
<Compile Include="NavigationLayout.cs" />
4444
<Compile Include="NavigationLayoutMenu.cs" />
4545
<Compile Include="Platforms\IUserNotifier.cs" />
46+
<Compile Include="NavigationLayoutHeader.cs" />
4647
<Compile Include="Properties\AssemblyInfo.cs" />
4748
</ItemGroup>
4849
<ItemGroup>

src/NativeCode.Mobile.AppCompat.Controls/NavigationLayout.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
namespace NativeCode.Mobile.AppCompat.Controls
22
{
3+
using NativeCode.Mobile.AppCompat.Controls.Platforms;
4+
35
using Xamarin.Forms;
46

57
public class NavigationLayout : Layout<NavigationLayoutMenu>
68
{
7-
public static readonly BindableProperty HeaderViewProperty = BindableProperty.Create<NavigationLayout, ContentView>(
9+
public static readonly BindableProperty HeaderViewProperty = BindableProperty.Create<NavigationLayout, NavigationLayoutHeader>(
810
x => x.HeaderView,
9-
default(ContentView));
11+
default(NavigationLayoutHeader));
1012

11-
public ContentView HeaderView
13+
public NavigationLayoutHeader HeaderView
1214
{
13-
get { return (ContentView)this.GetValue(HeaderViewProperty); }
15+
get { return (NavigationLayoutHeader)this.GetValue(HeaderViewProperty); }
1416
set { this.SetValue(HeaderViewProperty, value); }
1517
}
1618

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace NativeCode.Mobile.AppCompat.Controls
2+
{
3+
using Xamarin.Forms;
4+
5+
public class NavigationLayoutHeader : ContentView
6+
{
7+
}
8+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
namespace NativeCode.Mobile.AppCompat.Renderers.Helpers
2+
{
3+
using Android.Views;
4+
5+
internal static class MeasureSpecFactory
6+
{
7+
public static int MakeMeasureSpec(int size, MeasureSpecMode mode)
8+
{
9+
return (int)(size + mode);
10+
}
11+
12+
public static int GetSize(int measureSpec)
13+
{
14+
return measureSpec & 1073741823;
15+
}
16+
}
17+
}

src/NativeCode.Mobile.AppCompat.Renderers/NativeCode.Mobile.AppCompat.Renderers.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
<Compile Include="Extensions\CommandExtensions.cs" />
7979
<Compile Include="Extensions\ElementExtensions.cs" />
8080
<Compile Include="Extensions\EntryExtensions.cs" />
81+
<Compile Include="Helpers\MeasureSpecFactory.cs" />
8182
<Compile Include="Platforms\UserNotifier.cs" />
8283
<Compile Include="Renderers\AppCompatButtonRenderer.cs" />
8384
<Compile Include="Renderers\AppCompatEntryRenderer.cs" />
@@ -88,6 +89,7 @@
8889
<Compile Include="Renderers\Controls\AppCompatEntryEditText.cs" />
8990
<Compile Include="FormsAppCompat.cs" />
9091
<Compile Include="Renderers\FloatingButtonRenderer.cs" />
92+
<Compile Include="Renderers\NavigationLayoutHeaderRenderer.cs" />
9193
<Compile Include="Renderers\NavigationLayoutRenderer.cs" />
9294
<Compile Include="Resources\Resource.Designer.cs" />
9395
<Compile Include="Properties\AssemblyInfo.cs" />

src/NativeCode.Mobile.AppCompat.Renderers/Renderers/CardRenderer.cs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ namespace NativeCode.Mobile.AppCompat.Renderers.Renderers
22
{
33
using System.ComponentModel;
44

5-
using Android.OS;
65
using Android.Support.V7.Widget;
76
using Android.Widget;
87

@@ -36,14 +35,8 @@ protected override void OnElementChanged(ElementChangedEventArgs<Card> e)
3635

3736
if (this.Control == null)
3837
{
39-
var lollipop = Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop;
4038
var context = this.Context.GetAppCompatThemedContext();
41-
var control = new CardView(context) { PreventCornerOverlap = !lollipop, UseCompatPadding = lollipop };
42-
43-
var @params = new LinearLayout.LayoutParams(LayoutParamsHelper.MatchParent, LayoutParamsHelper.WrapContent);
44-
var elevation = (int)control.CardElevation;
45-
@params.SetMargins(elevation, elevation, elevation, elevation);
46-
control.LayoutParameters = @params;
39+
var control = new CardView(context);
4740

4841
if (this.Element.Command != null)
4942
{
@@ -55,6 +48,7 @@ protected override void OnElementChanged(ElementChangedEventArgs<Card> e)
5548

5649
this.UpdateCardBackgroundColor();
5750
this.UpdateContentPadding();
51+
this.UpdateElevation();
5852
this.UpdateRadius();
5953
}
6054
}
@@ -71,6 +65,10 @@ protected override void OnElementPropertyChanged(object sender, PropertyChangedE
7165
{
7266
this.UpdateContentPadding();
7367
}
68+
else if (e.PropertyName == Card.ElevationProperty.PropertyName)
69+
{
70+
this.UpdateElevation();
71+
}
7472
else if (e.PropertyName == Card.RadiusProperty.PropertyName)
7573
{
7674
this.UpdateRadius();
@@ -92,6 +90,15 @@ private void UpdateContentPadding()
9290
this.Control.SetContentPadding(left, top, right, bottom);
9391
}
9492

93+
private void UpdateElevation()
94+
{
95+
this.Control.CardElevation = (float)this.Element.Elevation;
96+
var @params = new LinearLayout.LayoutParams(LayoutParamsHelper.MatchParent, LayoutParamsHelper.WrapContent);
97+
var elevation = (int)this.Control.CardElevation;
98+
@params.SetMargins(elevation, elevation, elevation, elevation);
99+
this.Control.LayoutParameters = @params;
100+
}
101+
95102
private void UpdateRadius()
96103
{
97104
this.Control.Radius = (float)this.Element.Radius;

0 commit comments

Comments
 (0)