Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a new example for bottom sheet #7

Merged
merged 1 commit into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions BottomSheet/BottomSheetFoodOrder/App.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version = "1.0" encoding = "UTF-8" ?>
<Application xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:BottomSheetFoodOrder"
x:Class="BottomSheetFoodOrder.App">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Resources/Styles/Colors.xaml" />
<ResourceDictionary Source="Resources/Styles/Styles.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
15 changes: 15 additions & 0 deletions BottomSheet/BottomSheetFoodOrder/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace BottomSheetFoodOrder
{
public partial class App : Application
{
public App()
{
InitializeComponent();
}

protected override Window CreateWindow(IActivationState? activationState)
{
return new Window(new AppShell());
}
}
}
15 changes: 15 additions & 0 deletions BottomSheet/BottomSheetFoodOrder/AppShell.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Shell
x:Class="BottomSheetFoodOrder.AppShell"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:BottomSheetFoodOrder"
Shell.FlyoutBehavior="Flyout"
Title="BottomSheetFoodOrder">

<ShellContent
Title="Home"
ContentTemplate="{DataTemplate local:MainPage}"
Route="MainPage" />

</Shell>
10 changes: 10 additions & 0 deletions BottomSheet/BottomSheetFoodOrder/AppShell.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace BottomSheetFoodOrder
{
public partial class AppShell : Shell
{
public AppShell()
{
InitializeComponent();
}
}
}
159 changes: 159 additions & 0 deletions BottomSheet/BottomSheetFoodOrder/BottomSheetBehavior.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
using Syncfusion.Maui.Toolkit.BottomSheet;
using Syncfusion.Maui.Toolkit.EffectsView;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BottomSheetFoodOrder
{
public class BottomSheetBehavior : Behavior<ContentPage>
{
ListView? _listView;
ItemViewModel? _itemViewModel;
SfBottomSheet? _bottomSheet;
SfEffectsView? _decreaseQuantity;
SfEffectsView? _increaseQuantity;
SfEffectsView? _closeIcon;
CheckBox? _extraOne;
CheckBox? _extraTwo;
Grid? grid;

/// <summary>
/// You can override this method to subscribe to AssociatedObject events and initialize properties.
/// </summary>
/// <param name="bindable">SampleView type parameter named as bindable.</param>
protected override void OnAttachedTo(ContentPage bindable)
{
_listView = bindable.FindByName<ListView>("ListView");
_listView.ItemTapped += ListView_ItemTapped;
_itemViewModel = new ItemViewModel();
bindable.BindingContext = _itemViewModel;
_bottomSheet = bindable.FindByName<SfBottomSheet>("BottomSheet");
_bottomSheet.StateChanged += OnStateChanged;
_decreaseQuantity = bindable.FindByName<SfEffectsView>("DecreaseQuantity");
_increaseQuantity = bindable.FindByName<SfEffectsView>("IncreaseQuantity");
_closeIcon = bindable.FindByName<SfEffectsView>("CloseIcon");
_extraOne = bindable.FindByName<CheckBox>("ExtraCheese");
_extraTwo = bindable.FindByName<CheckBox>("ExtraDoubleCheese");
grid = bindable.FindByName<Grid>("Grid");

TapGestureRecognizer decreaseTapped = new TapGestureRecognizer();
decreaseTapped.Tapped += OnDecreaseTapped;
_decreaseQuantity.GestureRecognizers.Add(decreaseTapped);

TapGestureRecognizer increaseTapped = new TapGestureRecognizer();
increaseTapped.Tapped += OnIncreaseTapped;
_increaseQuantity.GestureRecognizers.Add(increaseTapped);

TapGestureRecognizer closeIconTapped = new TapGestureRecognizer();
closeIconTapped.Tapped += OnCloseIconTapped;
_closeIcon.GestureRecognizers.Add(closeIconTapped);

_extraOne.CheckedChanged += ExtraOne_CheckedChanged;
_extraTwo.CheckedChanged += ExtraTwo_CheckedChanged;

base.OnAttachedTo(bindable);
}

private void ExtraTwo_CheckedChanged(object? sender, CheckedChangedEventArgs e)
{
if (_extraTwo is not null && _bottomSheet is not null && grid is not null)
{
if (_extraTwo.IsChecked && _extraOne is not null)
{
_extraOne.IsChecked = false;
var item = (Item)grid.BindingContext;
item.TotalPrice = (item.Price + 4) * item.Quantity;
}
else
{
var item = (Item)grid.BindingContext;
item.TotalPrice = item.Price * item.Quantity;
}
}
}

private void ExtraOne_CheckedChanged(object? sender, CheckedChangedEventArgs e)
{
if (_extraOne is not null && _bottomSheet is not null && grid is not null)
{
if (_extraOne.IsChecked && _extraTwo is not null)
{
_extraTwo.IsChecked = false;
var item = (Item)grid.BindingContext;
item.TotalPrice = (item.Price + 2) * item.Quantity;
}
else
{
var item = (Item)grid.BindingContext;
item.TotalPrice = item.Price * item.Quantity;
}
}
}

private void OnStateChanged(object? sender, StateChangedEventArgs e)
{
if (_bottomSheet is not null && _bottomSheet.State is BottomSheetState.Hidden && grid is not null)
{
grid.BindingContext = null;
}
}

private void ListView_ItemTapped(object? sender, ItemTappedEventArgs e)
{
var selectedItem = (Item)e.Item;
if (_bottomSheet is not null && grid is not null)
{
grid.BindingContext = selectedItem;
if (_bottomSheet.IsOpen)
{
_bottomSheet.State = BottomSheetState.HalfExpanded;
}

_bottomSheet.Show();
}
}

private void OnDecreaseTapped(object? sender, TappedEventArgs e)
{
if (_bottomSheet is not null && grid is not null)
{
var temp = (Item)grid.BindingContext;
if (temp.Quantity > 1)
{
temp.Quantity--;
}
}
}

private void OnIncreaseTapped(object? sender, TappedEventArgs e)
{
if (_bottomSheet is not null && grid is not null)
{
var temp = (Item)grid.BindingContext;
temp.Quantity++;
}
}

private void OnCloseIconTapped(object? sender, TappedEventArgs e)
{
if (_bottomSheet is not null)
{
_bottomSheet.Close();
}
}

/// <summary>
/// You can override this method while View was detached from window
/// </summary>
/// <param name="bindable">SampleView type parameter named as bindable</param>
protected override void OnDetachingFrom(ContentPage bindable)
{
_listView = null;
_itemViewModel = null;
base.OnDetachingFrom(bindable);
}
}
}
77 changes: 77 additions & 0 deletions BottomSheet/BottomSheetFoodOrder/BottomSheetFoodOrder.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net9.0-android;net9.0-ios;net9.0-maccatalyst</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net9.0-windows10.0.19041.0</TargetFrameworks>
<!-- Uncomment to also build the tizen app. You will need to install tizen by following this: https://github.com/Samsung/Tizen.NET -->
<!-- <TargetFrameworks>$(TargetFrameworks);net9.0-tizen</TargetFrameworks> -->

<!-- Note for MacCatalyst:
The default runtime is maccatalyst-x64, except in Release config, in which case the default is maccatalyst-x64;maccatalyst-arm64.
When specifying both architectures, use the plural <RuntimeIdentifiers> instead of the singular <RuntimeIdentifier>.
The Mac App Store will NOT accept apps with ONLY maccatalyst-arm64 indicated;
either BOTH runtimes must be indicated or ONLY macatalyst-x64. -->
<!-- For example: <RuntimeIdentifiers>maccatalyst-x64;maccatalyst-arm64</RuntimeIdentifiers> -->

<OutputType>Exe</OutputType>
<RootNamespace>BottomSheetFoodOrder</RootNamespace>
<UseMaui>true</UseMaui>
<SingleProject>true</SingleProject>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<!-- Display name -->
<ApplicationTitle>BottomSheetFoodOrder</ApplicationTitle>

<!-- App Identifier -->
<ApplicationId>com.companyname.bottomsheetfoodorder</ApplicationId>

<!-- Versions -->
<ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
<ApplicationVersion>1</ApplicationVersion>

<!-- To develop, package, and publish an app to the Microsoft Store, see: https://aka.ms/MauiTemplateUnpackaged -->
<WindowsPackageType>None</WindowsPackageType>

<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">15.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">15.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">21.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</SupportedOSPlatformVersion>
<TargetPlatformMinVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</TargetPlatformMinVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'tizen'">6.5</SupportedOSPlatformVersion>
</PropertyGroup>

<ItemGroup>
<!-- App Icon -->
<MauiIcon Include="Resources\AppIcon\appicon.svg" ForegroundFile="Resources\AppIcon\appiconfg.svg" Color="#512BD4" />

<!-- Splash Screen -->
<MauiSplashScreen Include="Resources\Splash\splash.svg" Color="#512BD4" BaseSize="128,128" />

<!-- Images -->
<MauiImage Include="Resources\Images\*" />
<MauiImage Update="Resources\Images\dotnet_bot.png" Resize="True" BaseSize="300,185" />

<!-- Custom Fonts -->
<MauiFont Include="Resources\Fonts\*" />

<!-- Raw Assets (also remove the "Resources\Raw" prefix) -->
<MauiAsset Include="Resources\Raw\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiVersion)" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="9.0.0" />
<PackageReference Include="Syncfusion.Maui.Toolkit" Version="*" />
</ItemGroup>

<ItemGroup>
<MauiXaml Update="GettingStartedDesktop.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
<MauiXaml Update="GettingStartedMobile.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
</ItemGroup>

</Project>
44 changes: 44 additions & 0 deletions BottomSheet/BottomSheetFoodOrder/BottomSheetFoodOrder.csproj.user
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<IsFirstTimeProjectOpen>False</IsFirstTimeProjectOpen>
<ActiveDebugFramework>net9.0-windows10.0.19041.0</ActiveDebugFramework>
<ActiveDebugProfile>Windows Machine</ActiveDebugProfile>
<SelectedPlatformGroup>Emulator</SelectedPlatformGroup>
<DefaultDevice>pixel_5_-_api_34</DefaultDevice>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net9.0-android|AnyCPU'">
<DebuggerFlavor>ProjectDebugger</DebuggerFlavor>
</PropertyGroup>
<ItemGroup>
<MauiXaml Update="GettingStartedDesktop.xaml">
<SubType>Designer</SubType>
</MauiXaml>
<MauiXaml Update="GettingStartedMobile.xaml">
<SubType>Designer</SubType>
</MauiXaml>
</ItemGroup>
<ItemGroup>
<None Update="App.xaml">
<SubType>Designer</SubType>
</None>
<None Update="AppShell.xaml">
<SubType>Designer</SubType>
</None>
<None Update="MainPage.xaml">
<SubType>Designer</SubType>
</None>
<None Update="Platforms\Windows\App.xaml">
<SubType>Designer</SubType>
</None>
<None Update="Platforms\Windows\Package.appxmanifest">
<SubType>Designer</SubType>
</None>
<None Update="Resources\Styles\Colors.xaml">
<SubType>Designer</SubType>
</None>
<None Update="Resources\Styles\Styles.xaml">
<SubType>Designer</SubType>
</None>
</ItemGroup>
</Project>
22 changes: 22 additions & 0 deletions BottomSheet/BottomSheetFoodOrder/BottomSheetFoodOrder.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.12.35506.116 d17.12
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BottomSheetFoodOrder", "BottomSheetFoodOrder.csproj", "{462D8B5B-ADF0-427B-BE4D-BE33B419007C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{462D8B5B-ADF0-427B-BE4D-BE33B419007C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{462D8B5B-ADF0-427B-BE4D-BE33B419007C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{462D8B5B-ADF0-427B-BE4D-BE33B419007C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{462D8B5B-ADF0-427B-BE4D-BE33B419007C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
Loading
Loading