Skip to content

Commit

Permalink
SIDEMENU:: memperbaiki memory leak di sidemenu dan memperbarui animas…
Browse files Browse the repository at this point in the history
…i side menu.
  • Loading branch information
bachtiarpanjaitan committed Oct 4, 2024
1 parent ff40de2 commit 7c0c220
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 44 deletions.
23 changes: 12 additions & 11 deletions Bepe/Components/SideMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace IhandCashier.Bepe.Components
{
public class SideMenu
{
public event EventHandler<EventHandlerPageArgs> ItemTapped;
// public event EventHandler<EventHandlerPageArgs> ItemTapped;
public Dictionary<string, MenuItemPage> MenuItems;
public Dictionary<string, Button> MenuButtons = new();

Expand Down Expand Up @@ -49,9 +49,10 @@ private HorizontalStackLayout ItemMenu(MenuItemPage item)
TextColor = item.TextColor,
IsEnabled = item.Enable,
BorderColor = Colors.Transparent,
CommandParameter = item.Page
};

button.Clicked += (s, e) => OnCLickItem(s, e, item.Page);
// button.Clicked += (s, e) => OnCLickItem(s, e, item.Page);
MenuButtons.Add(item.Page, button);

return new HorizontalStackLayout()
Expand All @@ -65,15 +66,15 @@ private HorizontalStackLayout ItemMenu(MenuItemPage item)
};
}

private async void OnCLickItem(object sender, EventArgs e, string page)
{
var btn = sender as Button;
if (btn == null) return;
// Animasi: skala frame saat diklik
await btn.ScaleTo(1, 5, Easing.CubicIn);
await btn.ScaleTo(1, 5, Easing.CubicOut);
ItemTapped?.Invoke(this, new EventHandlerPageArgs(sender, e, page));
}
// private static async void OnCLickItem(object sender, EventArgs e, string page)
// {
// var btn = sender as Button;
// if (btn == null) return;
// // Animasi: skala frame saat diklik
// await btn.ScaleTo(1, 5, Easing.CubicIn);
// await btn.ScaleTo(1, 5, Easing.CubicOut);
// ItemTapped?.Invoke(this, new EventHandlerPageArgs(sender, e, page));
// }

public void SetMenuItems(Dictionary<string, MenuItemPage> items)
{
Expand Down
70 changes: 39 additions & 31 deletions Bepe/Controllers/PageController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,44 +18,52 @@ public void DefineLayoutTwoColumn()
{
var sm = new SideMenu();
sm.SetMenuItems(SideMenus);
sm.ItemTapped += (sender, args) =>
VerticalStackLayout sideMenu = sm.CreateSideMenu();
_layout.SetSideMenu(sideMenu);
foreach (var menu in sm.MenuButtons)
{
var btn = args.Sender as Button;
btn.TextColor = Colors.OrangeRed;
btn.FontSize = 16;
var type = Type.GetType(args.Page);
if(type != null)
menu.Value.BackgroundColor = Colors.Transparent;
menu.Value.FontSize = 14;
menu.Value.TextColor = Colors.Black;
menu.Value.HorizontalOptions = LayoutOptions.Fill;
menu.Value.Clicked += (sender, args) =>
{
try
var btn = sender as Button;
foreach (var item in sm.MenuButtons)
{
_contentView = (ContentView)Activator.CreateInstance(type);
_layout.SetContent(_contentView);
}
catch (TargetInvocationException ex)
{
Console.WriteLine("Cannot create layout " + ex.InnerException?.Message);
}
}
if (item.Key != btn.CommandParameter.ToString())
{
item.Value.IsEnabled = true;
item.Value.TextColor = Colors.Black;
item.Value.BorderWidth = 0;
}
else
{
item.Value.IsEnabled = false;
item.Value.BackgroundColor = Colors.Transparent;
item.Value.TextColor = Colors.DarkOrange;
item.Value.BorderWidth = 1;
item.Value.BorderColor = Colors.DarkOrange;

var menuitems = sender as SideMenu;

foreach (var m in menuitems.MenuButtons)
{
if (m.Key != args.Page)
{
m.Value.TextColor = Colors.DarkOrange;
m.Value.FontSize = 14;
m.Value.IsEnabled = true;
}
}
else

var type = Type.GetType(menu.Key);
if(type != null)
{
m.Value.IsEnabled = false;
m.Value.BackgroundColor = Colors.Transparent;
try
{
_contentView = (ContentView)Activator.CreateInstance(type);
_layout.SetContent(_contentView);
}
catch (TargetInvocationException ex)
{
Console.WriteLine("Cannot create layout " + ex.InnerException?.Message);
}
}
}
};
VerticalStackLayout sideMenu = sm.CreateSideMenu();
_layout.SetSideMenu(sideMenu);
};
}

Content = _layout.GenerateFrame();
}
}
Expand Down
2 changes: 1 addition & 1 deletion Bepe/Types/MenuItemPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class MenuItemPage
public string Name { get; set; }
public string Icon { get; set; }
public bool Enable { get; set; } = true;
public Color TextColor { get; set; } = Colors.Orange;
public Color TextColor { get; set; } = Colors.Black;
public MenuItemPage()
{

Expand Down
3 changes: 2 additions & 1 deletion IhandCashier.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,12 @@
<WarningLevel>4</WarningLevel>
<PlatformTarget>ARM64</PlatformTarget>
<MtouchLink>SdkOnly</MtouchLink>
<CodesignKey>iPhone Developer</CodesignKey>
<CodesignKey>Apple Development: [email protected] (53TNH3S72W)</CodesignKey>
<MtouchDebug>true</MtouchDebug>
<Optimize>true</Optimize>
<CheckForOverflowUnderflow>true</CheckForOverflowUnderflow>
<MtouchEnableSGenConc>true</MtouchEnableSGenConc>
<IOSDebugOverWiFi>true</IOSDebugOverWiFi>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|maccatalyst-x64' ">
<MtouchEnableSGenConc>true</MtouchEnableSGenConc>
Expand Down

0 comments on commit 7c0c220

Please sign in to comment.