diff --git a/BottomSheet/BottomSheetFoodOrder/App.xaml b/BottomSheet/BottomSheetFoodOrder/App.xaml new file mode 100644 index 0000000..ae1ccb5 --- /dev/null +++ b/BottomSheet/BottomSheetFoodOrder/App.xaml @@ -0,0 +1,14 @@ + + + + + + + + + + + diff --git a/BottomSheet/BottomSheetFoodOrder/App.xaml.cs b/BottomSheet/BottomSheetFoodOrder/App.xaml.cs new file mode 100644 index 0000000..b412937 --- /dev/null +++ b/BottomSheet/BottomSheetFoodOrder/App.xaml.cs @@ -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()); + } + } +} \ No newline at end of file diff --git a/BottomSheet/BottomSheetFoodOrder/AppShell.xaml b/BottomSheet/BottomSheetFoodOrder/AppShell.xaml new file mode 100644 index 0000000..f0ce7ef --- /dev/null +++ b/BottomSheet/BottomSheetFoodOrder/AppShell.xaml @@ -0,0 +1,15 @@ + + + + + + diff --git a/BottomSheet/BottomSheetFoodOrder/AppShell.xaml.cs b/BottomSheet/BottomSheetFoodOrder/AppShell.xaml.cs new file mode 100644 index 0000000..7e5e4ba --- /dev/null +++ b/BottomSheet/BottomSheetFoodOrder/AppShell.xaml.cs @@ -0,0 +1,10 @@ +namespace BottomSheetFoodOrder +{ + public partial class AppShell : Shell + { + public AppShell() + { + InitializeComponent(); + } + } +} diff --git a/BottomSheet/BottomSheetFoodOrder/BottomSheetBehavior.cs b/BottomSheet/BottomSheetFoodOrder/BottomSheetBehavior.cs new file mode 100644 index 0000000..df2c251 --- /dev/null +++ b/BottomSheet/BottomSheetFoodOrder/BottomSheetBehavior.cs @@ -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 + { + ListView? _listView; + ItemViewModel? _itemViewModel; + SfBottomSheet? _bottomSheet; + SfEffectsView? _decreaseQuantity; + SfEffectsView? _increaseQuantity; + SfEffectsView? _closeIcon; + CheckBox? _extraOne; + CheckBox? _extraTwo; + Grid? grid; + + /// + /// You can override this method to subscribe to AssociatedObject events and initialize properties. + /// + /// SampleView type parameter named as bindable. + protected override void OnAttachedTo(ContentPage bindable) + { + _listView = bindable.FindByName("ListView"); + _listView.ItemTapped += ListView_ItemTapped; + _itemViewModel = new ItemViewModel(); + bindable.BindingContext = _itemViewModel; + _bottomSheet = bindable.FindByName("BottomSheet"); + _bottomSheet.StateChanged += OnStateChanged; + _decreaseQuantity = bindable.FindByName("DecreaseQuantity"); + _increaseQuantity = bindable.FindByName("IncreaseQuantity"); + _closeIcon = bindable.FindByName("CloseIcon"); + _extraOne = bindable.FindByName("ExtraCheese"); + _extraTwo = bindable.FindByName("ExtraDoubleCheese"); + grid = bindable.FindByName("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(); + } + } + + /// + /// You can override this method while View was detached from window + /// + /// SampleView type parameter named as bindable + protected override void OnDetachingFrom(ContentPage bindable) + { + _listView = null; + _itemViewModel = null; + base.OnDetachingFrom(bindable); + } + } +} diff --git a/BottomSheet/BottomSheetFoodOrder/BottomSheetFoodOrder.csproj b/BottomSheet/BottomSheetFoodOrder/BottomSheetFoodOrder.csproj new file mode 100644 index 0000000..bdc301c --- /dev/null +++ b/BottomSheet/BottomSheetFoodOrder/BottomSheetFoodOrder.csproj @@ -0,0 +1,77 @@ + + + + net9.0-android;net9.0-ios;net9.0-maccatalyst + $(TargetFrameworks);net9.0-windows10.0.19041.0 + + + + + + + Exe + BottomSheetFoodOrder + true + true + enable + enable + + + BottomSheetFoodOrder + + + com.companyname.bottomsheetfoodorder + + + 1.0 + 1 + + + None + + 15.0 + 15.0 + 21.0 + 10.0.17763.0 + 10.0.17763.0 + 6.5 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + MSBuild:Compile + + + MSBuild:Compile + + + + diff --git a/BottomSheet/BottomSheetFoodOrder/BottomSheetFoodOrder.csproj.user b/BottomSheet/BottomSheetFoodOrder/BottomSheetFoodOrder.csproj.user new file mode 100644 index 0000000..a5eec38 --- /dev/null +++ b/BottomSheet/BottomSheetFoodOrder/BottomSheetFoodOrder.csproj.user @@ -0,0 +1,44 @@ + + + + False + net9.0-windows10.0.19041.0 + Windows Machine + Emulator + pixel_5_-_api_34 + + + ProjectDebugger + + + + Designer + + + Designer + + + + + Designer + + + Designer + + + Designer + + + Designer + + + Designer + + + Designer + + + Designer + + + \ No newline at end of file diff --git a/BottomSheet/BottomSheetFoodOrder/BottomSheetFoodOrder.sln b/BottomSheet/BottomSheetFoodOrder/BottomSheetFoodOrder.sln new file mode 100644 index 0000000..2617b83 --- /dev/null +++ b/BottomSheet/BottomSheetFoodOrder/BottomSheetFoodOrder.sln @@ -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 diff --git a/BottomSheet/BottomSheetFoodOrder/GettingStartedDesktop.xaml b/BottomSheet/BottomSheetFoodOrder/GettingStartedDesktop.xaml new file mode 100644 index 0000000..7188dac --- /dev/null +++ b/BottomSheet/BottomSheetFoodOrder/GettingStartedDesktop.xaml @@ -0,0 +1,152 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +