Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix macOS RadioButton behavior #48

Merged
merged 1 commit into from
Apr 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions macOS/Forms/Renderers/MacOSRadioButtonRenderer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;

using AppKit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.MacOS;

//TODO: Remove after release of https://github.com/xamarin/Xamarin.Forms/pull/14139
[assembly: ExportRenderer(typeof(Xamarin.Forms.RadioButton), typeof(Jammit.Forms.Renderers.MacOSRadioButtonRenderer))]
namespace Jammit.Forms.Renderers
{
public class MacOSRadioButtonRenderer : RadioButtonRenderer
{
void HandleActivated(object sender, EventArgs args)
{
if (Element == null || sender == null)
{
return;
}

Element.IsChecked = (sender as NSButton).State == NSCellStateValue.On;
}

protected override void Dispose(bool disposing)
{
if (Control != null)
Control.Activated -= HandleActivated;

base.Dispose(disposing);
}

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

if (Control != null)
Control.Activated += HandleActivated;
}
}
}
1 change: 1 addition & 0 deletions macOS/Unjammit.macOS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
<Compile Include="Forms\Renderers\MacOSVerticalSliderRenderer.cs" />
<Compile Include="Forms\Renderers\MacOSDisabledScrollViewRenderer.cs" />
<Compile Include="Forms\MacOSLocaleSwitcher.cs" />
<Compile Include="Forms\Renderers\MacOSRadioButtonRenderer.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Core\Unjammit.Core.csproj">
Expand Down