Skip to content

Commit

Permalink
Menu:: trying tu optimize Menu Render
Browse files Browse the repository at this point in the history
  • Loading branch information
bachtiarpanjaitan committed Sep 27, 2024
1 parent 5adccbb commit f0b405f
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 38 deletions.
2 changes: 1 addition & 1 deletion AppShell.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:layouts="clr-namespace:IhandCashier.Layouts"
Shell.FlyoutBehavior="Disabled" FlyoutIsPresented="False">
Shell.FlyoutBehavior="Disabled" FlyoutIsPresented="true">

<ShellContent ContentTemplate="{DataTemplate layouts:MainLayout}" Route="MainLayout">

Expand Down
1 change: 1 addition & 0 deletions AppShell.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public partial class AppShell : Shell
public AppShell()
{
InitializeComponent();

}
}

8 changes: 2 additions & 6 deletions Bepe/Helpers/MainContent.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
using System;
using View = Microsoft.EntityFrameworkCore.Metadata.Internal.View;

namespace IhandCashier.Bepe.Helpers
{
public class MainContent: ContentView
{
private ContentView CurrentContent = new();
public MainContent()
{

}

public void ChangeContent (ContentView view)
{
Content = view;
Expand Down
38 changes: 27 additions & 11 deletions Bepe/Helpers/MenuCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
using System.Reflection;
using IhandCashier.Bepe.Configs;
using IhandCashier.Bepe.Types;
using IhandCashier.Layouts;
using Newtonsoft.Json;

namespace IhandCashier.Bepe.Helpers
{
public class MenuCreator
{
List<MenuDataType> menuItems = new List<MenuDataType>();
List<MenuBarItem> menuBarItems = new List<MenuBarItem>();
List<MenuDataType> menuItems = new ();
List<MenuBarItem> menuBarItems = new ();
public Dictionary<string, MenuFlyoutItem> ListMenu = new();
private string path;
private MainContent context;

Expand All @@ -19,11 +21,24 @@ public MenuCreator(string path, MainContent context)
this.path = path;
this.context = context;
}

public MenuCreator(MainContent context, IList<MenuBarItem> MenuBar)
{
this.context = context;
CreateMenu(MenuBar);
}

public MenuCreator(IList<MenuBarItem> MenuBar)
{
CreateMenu(MenuBar);
}

public MenuCreator(){}

public async Task<List<MenuBarItem>> CreateMenuAsync()
public Dictionary<string, MenuFlyoutItem> CreateMenu(IList<MenuBarItem> MenuBar)
{
menuItems = await LoadMenuItemsAsync(path);

// menuItems = await LoadMenuItemsAsync(path).ConfigureAwait(false);
menuItems = MenuConfig.GetMenus();
foreach (var item in menuItems)
{
var menuBar = new MenuBarItem { Text = item.Label };
Expand All @@ -41,10 +56,10 @@ public async Task<List<MenuBarItem>> CreateMenuAsync()
}
}
else menuBar.Add(CreateMenuFlyoutItem(item));
menuBarItems.Add(menuBar);
MenuBar.Add(menuBar);
}

return menuBarItems;
return ListMenu;

}

Expand Down Expand Up @@ -82,7 +97,7 @@ private MenuFlyoutSubItem CreateMenuFlyoutSubItem(MenuDataType menuItem)
{
flyoutItem.Add(CreateMenuFlyoutItem(childItem));
}
flyoutItem.Clicked += OnMenuItemClicked;
// flyoutItem.Clicked += OnMenuItemClicked;

}
return flyoutItem;
Expand All @@ -96,8 +111,9 @@ private MenuFlyoutItem CreateMenuFlyoutItem(MenuDataType menuItem)
Text = menuItem.Label,
CommandParameter = menuItem.Class
};

flyoutItem.Clicked += OnMenuItemClicked;
ListMenu.Add(menuItem.Class, flyoutItem);
// flyoutItem.Clicked += OnMenuItemClicked;

return flyoutItem;
}

Expand All @@ -113,7 +129,7 @@ private void OnMenuItemClicked(object sender, EventArgs e)
var type = Type.GetType(AppConfig.PAGES_NAMESPACE + "." + data);
if (type == null) return;
var instance = Activator.CreateInstance(type);
context.ChangeContent((ContentView)instance);
// context.ChangeContent((ContentView)instance);
} catch (Exception ex)
{
Console.WriteLine($"Error Click : {ex.Message}");
Expand Down
2 changes: 2 additions & 0 deletions Bepe/Types/MenuDataType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ public class MenuDataType
public string Class { get; set;}
public List<MenuDataType> Child { get; set; }

public bool Show { get; set; } = true;

public MenuDataType()
{
}
Expand Down
10 changes: 6 additions & 4 deletions IhandCashier.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
<WarningLevel>4</WarningLevel>
<PlatformTarget>ARM64</PlatformTarget>
<MtouchLink>SdkOnly</MtouchLink>
<OutputPath>bin/Debug/net8.0-maccatalyst/maccatalyst-arm64</OutputPath>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<MtouchLink>SdkOnly</MtouchLink>
Expand Down Expand Up @@ -85,7 +84,7 @@
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.Maui.Controls" Version="8.0.71" />
<PackageReference Include="Microsoft.Maui.Core" Version="8.0.80" />
<PackageReference Include="Microsoft.Maui.Core" Version="8.0.82" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.8" />
Expand All @@ -94,6 +93,7 @@
<PackageReference Include="sqlite-net-pcl" Version="1.9.172" />
<PackageReference Include="Syncfusion.Maui.DataForm" Version="26.2.13" />
<PackageReference Include="Syncfusion.Maui.DataGrid" Version="26.2.13" />
<PackageReference Update="Microsoft.Maui.Controls.Compatibility" Version="8.0.80" />
</ItemGroup>
<ItemGroup>
<Folder Include="Bepe\Helpers\Factories\" />
Expand Down Expand Up @@ -140,9 +140,11 @@
<None Remove=".env" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\IhandCashier.Core\IhandCashier.Core.csproj" />
<None Remove="Entitlements.plist.xml" />
</ItemGroup>
<ItemGroup>
<None Remove="Entitlements.plist.xml" />
<Reference Include="IhandCashier.Core">
<HintPath>..\IhandCashier.Core\bin\Release\net8.0-maccatalyst\IhandCashier.Core.dll</HintPath>
</Reference>
</ItemGroup>
</Project>
1 change: 1 addition & 0 deletions Layouts/MainLayout.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
Shell.NavBarIsVisible="True"
x:Class="IhandCashier.Layouts.MainLayout">
<ContentPage.MenuBarItems></ContentPage.MenuBarItems>
<Grid Margin="5" x:Name="GridLayout">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
Expand Down
45 changes: 29 additions & 16 deletions Layouts/MainLayout.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@ public partial class MainLayout : ContentPage
private System.Timers.Timer _timer;
private readonly CultureInfo _cultureInfo = new("id-ID");
private UserSession userSession = new SessionManager().GetSession();
public Dictionary<string, MenuFlyoutItem> ListMenu = new ();
private IList<MenuBarItem> menuBar;
public MainLayout()
{
InitializeComponent();
LoadMenu();
SetupClock();
MenuBarItems.Clear();
ListMenu = new MenuCreator().CreateMenu(MenuBarItems);

Shell.SetNavBarIsVisible(this, DeviceInfo.Platform == DevicePlatform.WinUI);
DatagridProvider.DataGrid.RowHeight = 35;
Expand All @@ -45,29 +48,31 @@ public MainLayout()
new Button.ButtonContentLayout(Button.ButtonContentLayout.ImagePosition.Right, 10);
Container.Content = new PageHome();

}

private void LoadMenu()
{
if (DeviceInfo.Platform == DevicePlatform.MacCatalyst ||DeviceInfo.Platform == DevicePlatform.WinUI)
if (Application.Current.MainPage is AppShell shell)
{
if (Application.Current != null)
foreach (var value in ListMenu.Values)
{
Device.BeginInvokeOnMainThread(() =>
value.Clicked += (sender, args) =>
{
MenuBarItems.Clear();
var menuCreator = new MenuCreator(AppConfig.PATH_FILE_MENU, Container).CreateMenuAsync().Result;
foreach (var item in menuCreator)
if (sender is MenuFlyoutItem menuBarItem)
{
MenuBarItems.Add(item);
try
{
var data = menuBarItem?.CommandParameter as String;
var type = Type.GetType(AppConfig.PAGES_NAMESPACE + "." + data);
if (type == null) return;
var instance = Activator.CreateInstance(type);
Container.ChangeContent((ContentView)instance);
}
catch (Exception ex)
{
Console.WriteLine($"Error Click : {ex.Message}");
}
}
});
};
}
}

LUser.Text = $" {userSession.Username} ";
Copyright.Text = $"\u00a9 {DateTime.Now.Year} HMP Basapadi";
Console.SetOut(new LabelWriter(LogLabel));
}

[Obsolete]
Expand All @@ -77,6 +82,10 @@ private void SetupClock()
_timer.Elapsed += OnTimerElapsed;
_timer.AutoReset = true;
_timer.Enabled = true;

LUser.Text = $" {userSession.Username} ";
Copyright.Text = $"\u00a9 {DateTime.Now.Year} HMP Basapadi";
Console.SetOut(new LabelWriter(LogLabel));
}

[Obsolete]
Expand All @@ -98,4 +107,8 @@ protected override void OnDisappearing()
_timer?.Dispose();
}

protected override void OnAppearing()
{
base.OnAppearing();
}
}

0 comments on commit f0b405f

Please sign in to comment.