Skip to content

Commit

Permalink
attempt
Browse files Browse the repository at this point in the history
  • Loading branch information
IeuanWalker committed Mar 2, 2020
1 parent 0a54447 commit 4823a11
Show file tree
Hide file tree
Showing 19 changed files with 306 additions and 61 deletions.
37 changes: 29 additions & 8 deletions Breadcrumb/Breadcrumb.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Xamarin.Forms;
Expand Down Expand Up @@ -37,7 +38,7 @@ public ScrollBarVisibility ScrollBarVisibility
}

// Text Color
public static readonly BindableProperty TextColorProperty = BindableProperty.Create(nameof(TextColor), typeof(Color), typeof(Breadcrumb), Color.Black);
public static readonly BindableProperty TextColorProperty = BindableProperty.Create(nameof(TextColor), typeof(Color), typeof(Breadcrumb), Color.Black, BindingMode.TwoWay);
public Color TextColor
{
get => (Color)GetValue(TextColorProperty);
Expand Down Expand Up @@ -198,27 +199,45 @@ private PancakeView BreadCrumbLabelCreator(Page page, bool isLast, bool isFirst)
}
else
{
stackLayout.Children.Add(new Label
var breadcrumbContent = new Label
{
Text = page.Title,
FontSize = 15,
TextColor = isLast ? LastBreadcrumbTextColor : TextColor,
VerticalOptions = LayoutOptions.Center,
VerticalTextAlignment = TextAlignment.Center
});
};
if (isLast)
{
breadcrumbContent.SetBinding(TextColorProperty, new Binding(nameof(LastBreadcrumbTextColor)));
}
else
{
breadcrumbContent.SetBinding(TextColorProperty, new Binding(nameof(TextColor)));
}
stackLayout.Children.Add(breadcrumbContent);
}


// Create PancakeView, and add StackLayout containing the selectedPage title
return new PancakeView
var breadcrumbContainer = new PancakeView
{
Padding = 10,
VerticalOptions = LayoutOptions.Center,
CornerRadius = isLast ? LastBreadcrumbCornerRadius : CornerRadius,
BackgroundColor = isLast ? LastBreadcrumbBackgroundColor : BreadcrumbBackgroundColor,
Content = stackLayout,
Margin = BreadcrumbMargin
};

if (isLast)
{
breadcrumbContainer.SetBinding(BackgroundColorProperty, new Binding(nameof(LastBreadcrumbBackgroundColor)));
}
else
{
breadcrumbContainer.SetBinding(BackgroundColorProperty, new Binding(nameof(BreadcrumbBackgroundColor)));
}

return breadcrumbContainer;
}

/// <summary>
Expand All @@ -230,7 +249,9 @@ private void AnimatedStack_ChildAdded(object sender, ElementEventArgs e)
{
Device.BeginInvokeOnMainThread(async () =>
{
// iOS scroll to end fix
if (!BreadCrumbContainer.Children.Any()) return;
//! iOS scroll to end fix
if (Device.RuntimePlatform.Equals(Device.iOS))
{
await BreadCrumbsScrollView.ScrollToAsync(BreadCrumbContainer.Children.LastOrDefault(), ScrollToPosition.MakeVisible, false);
Expand Down
5 changes: 1 addition & 4 deletions DemoApp/DemoApp/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Application.Resources>
<OnPlatform x:Key="FontAwesome"
x:TypeArguments="x:String"
Android="fa-solid-900.ttf#Font Awesome 5 Free"
iOS="FontAwesome5Free-Solid" />
<ResourceDictionary Source="/Styles/LightTheme.xaml" />
</Application.Resources>
</Application>
5 changes: 3 additions & 2 deletions DemoApp/DemoApp/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Xamarin.Forms;
using DemoApp.Pages;
using Xamarin.Forms;

namespace DemoApp
{
Expand All @@ -8,7 +9,7 @@ public App()
{
InitializeComponent();

MainPage = new NavigationPage(new MainPage());
MainPage = new NavigationPage(new TestPage1());
}

protected override void OnStart()
Expand Down
19 changes: 19 additions & 0 deletions DemoApp/DemoApp/DemoApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>8.0</LangVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
Expand All @@ -18,6 +19,21 @@
<ProjectReference Include="..\..\Breadcrumb\Breadcrumb.csproj" />
</ItemGroup>

<ItemGroup>
<Compile Update="Styles\Text.xaml.cs">
<DependentUpon>Text.xaml</DependentUpon>
</Compile>
<Compile Update="Styles\BaseStyles.xaml.cs">
<DependentUpon>BaseStyles.xaml</DependentUpon>
</Compile>
<Compile Update="Styles\DefaultTheme.xaml.cs">
<DependentUpon>DefaultTheme.xaml</DependentUpon>
</Compile>
<Compile Update="Styles\LightTheme.xaml.cs">
<DependentUpon>LightTheme.xaml</DependentUpon>
</Compile>
</ItemGroup>

<ItemGroup>
<EmbeddedResource Update="Pages\BasePage.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
Expand All @@ -31,5 +47,8 @@
<EmbeddedResource Update="Pages\TestPage3.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
<EmbeddedResource Update="Styles\DarkTheme.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
</ItemGroup>
</Project>
16 changes: 0 additions & 16 deletions DemoApp/DemoApp/MainPage.xaml

This file was deleted.

23 changes: 0 additions & 23 deletions DemoApp/DemoApp/MainPage.xaml.cs

This file was deleted.

42 changes: 36 additions & 6 deletions DemoApp/DemoApp/Pages/BasePage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,45 @@
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:breadcrumb="clr-namespace:Breadcrumb;assembly=Xamarin.Forms.Breadcrumb"
xmlns:icons="clr-namespace:DemoApp">
xmlns:icons="clr-namespace:DemoApp.Styles"
BackgroundColor="{DynamicResource BackgroundColour}">
<ContentPage.ToolbarItems>
<ToolbarItem x:Name="ThemeToggle"
Clicked="ThemeToggle_Clicked"
Text="Light" />
</ContentPage.ToolbarItems>
<ContentPage.Content>
<StackLayout>
<!-- Breadcrumb -->
<Label Text="Default" />
<breadcrumb:Breadcrumb Padding="15" VerticalOptions="Start" />
<Label Text="Default" TextColor="{DynamicResource Text}" />
<breadcrumb:Breadcrumb Padding="15"
TextColor="{DynamicResource Text}"
VerticalOptions="Start" />

<!-- Dynamic test -->
<Label Text="Dynamic Tests" TextColor="{DynamicResource Text}" />
<breadcrumb:Breadcrumb Grid.Row="0"
Grid.Column="1"
Margin="0"
Padding="0"
BackgroundColor="Transparent"
BreadcrumbBackgroundColor="{DynamicResource BreadcrumBackground}"
CornerRadius="6"
LastBreadcrumbBackgroundColor="{DynamicResource LastBreadcrumBackground}"
LastBreadcrumbCornerRadius="6"
LastBreadcrumbTextColor="{DynamicResource LastBreadcrumTextColour}"
TextColor="{DynamicResource BreadcrumTextColour}"
VerticalOptions="Start">
<breadcrumb:Breadcrumb.Separator>
<FontImageSource FontFamily="{StaticResource FontAwesome}"
Glyph="{x:Static icons:IconFont.ChevronRight}"
Size="12"
Color="{DynamicResource Primary}" />
</breadcrumb:Breadcrumb.Separator>
</breadcrumb:Breadcrumb>

<!-- FontImageSource -->
<Label Text="Icon - FontAwesome" />
<Label Text="Icon - FontAwesome" TextColor="{DynamicResource Text}" />
<breadcrumb:Breadcrumb Padding="15" VerticalOptions="Start">
<breadcrumb:Breadcrumb.Separator>
<FontImageSource FontFamily="{StaticResource FontAwesome}"
Expand All @@ -22,15 +52,15 @@
</breadcrumb:Breadcrumb>

<!-- UriImageSource -->
<Label Text="Image - URL" />
<Label Text="Image - URL" TextColor="{DynamicResource Text}" />
<breadcrumb:Breadcrumb Padding="15" VerticalOptions="Start">
<breadcrumb:Breadcrumb.Separator>
<UriImageSource Uri="https://cdn.iconscout.com/icon/free/png-256/xamarin-4-599473.png" />
</breadcrumb:Breadcrumb.Separator>
</breadcrumb:Breadcrumb>

<!-- FileImageSource -->
<Label Text="Image - Embedded" />
<Label Text="Image - Embedded" TextColor="{DynamicResource Text}" />
<breadcrumb:Breadcrumb Padding="15" VerticalOptions="Start">
<breadcrumb:Breadcrumb.Separator>
<FileImageSource File="exampleImage.png" />
Expand Down
26 changes: 25 additions & 1 deletion DemoApp/DemoApp/Pages/BasePage.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using DemoApp.Styles;
using System.Collections.Generic;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;

Expand All @@ -13,5 +14,28 @@ public BasePage()
{
InitializeComponent();
}

private void ThemeToggle_Clicked(object sender, System.EventArgs e)
{
if (ThemeToggle == null)
return;

switch (ThemeToggle.Text)
{
case nameof(ThemeEnum.Light):
Application.Current.Resources = new DarkTheme();
ThemeToggle.Text = nameof(ThemeEnum.Dark);
break;
default:
Application.Current.Resources = new LightTheme();
ThemeToggle.Text = nameof(ThemeEnum.Light);
break;
}
}
}

public enum ThemeEnum {
Light,
Dark
}
}
66 changes: 66 additions & 0 deletions DemoApp/DemoApp/Styles/BaseStyles.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?xml version="1.0" encoding="UTF-8" ?>
<ResourceDictionary x:Class="DemoApp.Styles.BaseStyles"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml">
<Style x:Key="ButtonInfo" TargetType="Grid">
<Setter Property="Padding" Value="20" />
<Setter Property="Margin" Value="0" />
<Setter Property="RowSpacing" Value="0" />
<Setter Property="BackgroundColor" Value="#01383f" />
</Style>

<OnPlatform x:Key="FormMargins"
x:TypeArguments="Thickness"
Default="20,0,20,0" />

<Style x:Key="FormWrapper" TargetType="FlexLayout">
<Setter Property="Margin" Value="20,0,20,0" />
</Style>
<Style x:Key="FormWrapperStack" TargetType="StackLayout">
<Setter Property="Margin" Value="20,0,20,0" />
</Style>

<OnPlatform x:Key="InputMargins"
x:TypeArguments="Thickness"
Android="7,3,7,3"
iOS="5,15,5,15" />


<OnPlatform x:Key="PickerMargins"
x:TypeArguments="Thickness"
Android="15,5,5,5"
iOS="15,15,15,15" />


<OnPlatform x:Key="ButtonPadding"
x:TypeArguments="Thickness"
Android="10,5,10,5"
iOS="10,15,10,15" />


<OnPlatform x:Key="IconRadius"
x:TypeArguments="CornerRadius"
Android="28"
iOS="20" />
<OnPlatform x:Key="ListTopMargins"
x:TypeArguments="Thickness"
Android="0,0,0,0"
iOS="0,0,0,25" />
<OnPlatform x:Key="ListMargins"
x:TypeArguments="Thickness"
Android="0,0,0,10"
iOS="0,0,0,10" />

<OnPlatform x:Key="SectionMargin"
x:TypeArguments="Thickness"
Android="0"
iOS="0,2,0,0" />


<OnPlatform x:Key="PickerRow"
x:TypeArguments="Thickness"
Android="0,-27,0,0"
iOS="0,-13,0,0" />


</ResourceDictionary>
14 changes: 14 additions & 0 deletions DemoApp/DemoApp/Styles/BaseStyles.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Xamarin.Forms;
using Xamarin.Forms.Xaml;

namespace DemoApp.Styles
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class BaseStyles : ResourceDictionary
{
public BaseStyles()
{
InitializeComponent();
}
}
}
15 changes: 15 additions & 0 deletions DemoApp/DemoApp/Styles/DarkTheme.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8" ?>
<ResourceDictionary x:Class="DemoApp.Styles.DarkTheme"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
Source="DefaultTheme.xaml">
<Color x:Key="BackgroundColour">#121212</Color>
<Color x:Key="Primary">#bb86fc</Color>

<Color x:Key="Text">#fff</Color>

<Color x:Key="BreadcrumBackground">#37474f</Color>
<Color x:Key="LastBreadcrumBackground">#000</Color>
<Color x:Key="BreadcrumTextColour">#bdbdbd</Color>
<Color x:Key="LastBreadcrumTextColour">#fff</Color>
</ResourceDictionary>
Loading

0 comments on commit 4823a11

Please sign in to comment.