Skip to content

Commit

Permalink
CI and Renderer Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
PureWeen committed Aug 20, 2023
1 parent 7ac09f9 commit 6dfd78e
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 2 deletions.
10 changes: 8 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,17 @@ jobs:

steps:
- uses: actions/checkout@v3
- name: Setup .NET
- name: Setup .NET 7.0
uses: actions/setup-dotnet@v2
with:
dotnet-version: 7.0.x
- name: Install .NET MAUI
- name: Install .NET MAUI 7.0
run: dotnet workload install maui
- name: Setup .NET 8.0
uses: actions/setup-dotnet@v2
with:
dotnet-version: 8.0.x
- name: Install .NET MAUI 8.0
run: dotnet workload install maui
- name: Restore dependencies
run: dotnet restore ShanedlerSamples.sln
Expand Down
120 changes: 120 additions & 0 deletions ShanedlerSamples/Library/Shanandlers/ButtonRenderer.Android.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
#if ANDROID && NET8_0_OR_GREATER
using Android.Content;
using Android.Content.Res;
using Android.Graphics.Drawables;
using Google.Android.Material.Button;
using Microsoft.Maui.Controls.Platform;
using AView = Android.Views.View;
using Microsoft.Maui.Graphics;
using Android.Views;
using Microsoft.Maui.Platform;
using Microsoft.Maui.Handlers;
using Microsoft.Maui.Controls.Handlers.Compatibility;

namespace PureWeen.Maui.Controls.Handlers.Compatibility
{
#pragma warning disable RS0016 // Add public types and members to the declared API
public class ButtonRenderer : ViewRenderer<Button, MauiMaterialButton>,
IButtonHandler, IImageSourcePartSetter, AView.IOnClickListener, AView.IOnTouchListener

{
public static IPropertyMapper<Button, IButtonHandler> Mapper
= new PropertyMapper<Button, IButtonHandler>(ButtonHandler.Mapper);

public static CommandMapper<Button, IButtonHandler> CommandMapper
= new CommandMapper<Button, IButtonHandler>(ButtonHandler.CommandMapper);

bool _isDisposed;

public ButtonRenderer(Context context) : base(context/*, Mapper, CommandMapper*/)
{
AutoPackage = false;
}

IButton IButtonHandler.VirtualView => Element!;

MaterialButton IButtonHandler.PlatformView => Control!;

ImageSourcePartLoader? _imageSourcePartLoader;
public ImageSourcePartLoader ImageSourceLoader =>
_imageSourcePartLoader ??= new ImageSourcePartLoader(this);

ImageSourcePartLoader IButtonHandler.ImageSourceLoader => ImageSourceLoader;


static ColorStateList TransparentColorStateList = Colors.Transparent.ToDefaultColorStateList();
protected override MauiMaterialButton CreateNativeControl()
{
return new MauiMaterialButton(Context!)
{
IconGravity = MaterialButton.IconGravityTextStart,
IconTintMode = Android.Graphics.PorterDuff.Mode.Add,
IconTint = TransparentColorStateList,
SoundEffectsEnabled = false
};
}

protected override void Dispose(bool disposing)
{
if (_isDisposed)
return;

_isDisposed = true;

if (disposing)
{
if (Control != null)
{
Control.SetOnClickListener(null);
Control.SetOnTouchListener(null);
}
}

base.Dispose(disposing);
}

public void SetImageSource(Drawable? obj)
{
Control!.Icon = obj;
}

protected override void OnElementChanged(ElementChangedEventArgs<Button> e)
{
base.OnElementChanged(e);

if (e.NewElement != null)
{
if (Control == null)
{
var button = CreateNativeControl();

button.SetOnClickListener(this);
button.SetOnTouchListener(this);

SetNativeControl(button);
}
}
}

void IOnClickListener.OnClick(AView? v) => (Element as IButton)?.Clicked();

bool IOnTouchListener.OnTouch(AView? v, MotionEvent? e)
{
var button = (Element as IButton);
switch (e?.ActionMasked)
{
case MotionEventActions.Down:
button?.Pressed();
break;
case MotionEventActions.Cancel:
case MotionEventActions.Up:
button?.Released();
break;
}

return false;
}
}
#pragma warning restore RS0016 // Add public types and members to the declared API
}
#endif

0 comments on commit 6dfd78e

Please sign in to comment.