Skip to content

Commit

Permalink
🐛 Mobile | Settings page issues (#932)
Browse files Browse the repository at this point in the history
  • Loading branch information
AntPolkanov committed May 29, 2024
1 parent b7d2721 commit 6379c01
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/MobileUI/MauiProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Mopups.Hosting;
using SkiaSharp.Views.Maui.Controls.Hosting;
using ZXing.Net.Maui.Controls;
using SSW.Rewards.Mobile.Renderers;

[assembly: XamlCompilation(XamlCompilationOptions.Compile)]
namespace SSW.Rewards.Mobile;
Expand Down Expand Up @@ -36,7 +37,11 @@ public static MauiApp CreateMauiApp()
.ConfigureMopups()
.UseSkiaSharp()
.UsePageResolver()
.UseBarcodeReader();
.UseBarcodeReader()
.ConfigureMauiHandlers((handlers) =>
{
handlers.AddHandler(typeof(TableView), typeof(CustomTableViewRenderer));
});

AppCenter.Start($"android={Constants.AppCenterAndroidId};" +
$"ios={Constants.AppCenterIOSId};",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using Android.Content;
using Android.Graphics.Drawables;
using Android.Views;
using Android.Widget;
using Microsoft.Maui.Controls.Compatibility.Platform.Android;
using Microsoft.Maui.Controls.Platform;
using TableViewModelRenderer = Microsoft.Maui.Controls.Handlers.Compatibility.TableViewModelRenderer;
using TableViewRenderer = Microsoft.Maui.Controls.Handlers.Compatibility.TableViewRenderer;

namespace SSW.Rewards.Mobile.Renderers;

public class CustomTableViewRenderer : TableViewRenderer
{
public CustomTableViewRenderer(Context context) : base(context)
{
}

protected override void OnElementChanged(ElementChangedEventArgs<TableView> e)
{
base.OnElementChanged(e);
if (Control == null)
return;

var listView = Control as Android.Widget.ListView;
listView.Divider = new ColorDrawable(Colors.Transparent.ToAndroid());
}

protected override TableViewModelRenderer GetModelRenderer(Android.Widget.ListView listView, TableView view)
{
return new CustomHeaderTableViewModelRenderer(Context, listView, view);
}

private class CustomHeaderTableViewModelRenderer : TableViewModelRenderer
{
public CustomHeaderTableViewModelRenderer(Context context, Android.Widget.ListView listView, TableView view) :
base(context, listView, view)
{
}

public override Android.Views.View GetView(int position, Android.Views.View convertView, ViewGroup parent)
{
var view = base.GetView(position, convertView, parent);

var element = GetCellForPosition(position);

// section header will be a TextCell
if (element.GetType() == typeof(TextCell))
{
try
{
// get the divider below the header
var divider = (view as LinearLayout).GetChildAt(1);

// Set the color
divider.SetBackgroundColor(Colors.Transparent.ToAndroid());
}
catch (Exception) { }
}

return view;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using Microsoft.Maui.Controls.Handlers.Compatibility;

namespace SSW.Rewards.Mobile.Renderers;

public class CustomTableViewRenderer : TableViewRenderer
{

}

0 comments on commit 6379c01

Please sign in to comment.