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

[UIKit] Update bindings to Xcode 12 Beta 2 #8992

Merged
merged 10 commits into from
Jul 10, 2020
14 changes: 14 additions & 0 deletions src/UIKit/UIAccessibility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,13 @@ public static bool IsBoldTextEnabled {
}
}

[TV (14,0), iOS (14,0)]
[DllImport (Constants.UIKitLibrary)]
static extern bool UIAccessibilityButtonShapesEnabled ();

[TV (14,0), iOS (14,0)]
public static bool ButtonShapesEnabled => UIAccessibilityButtonShapesEnabled ();

[iOS (8,0)]
[DllImport (Constants.UIKitLibrary)]
static extern bool UIAccessibilityIsGrayscaleEnabled ();
Expand All @@ -283,6 +290,13 @@ static public bool IsReduceMotionEnabled {
}
}

[TV (14,0), iOS (14,0)]
[DllImport (Constants.UIKitLibrary)]
static extern bool UIAccessibilityPrefersCrossFadeTransitions ();

[TV (14,0), iOS (14,0)]
public static bool PrefersCrossFadeTransitions => UIAccessibilityPrefersCrossFadeTransitions ();

[iOS (13,0), TV (13,0)]
[DllImport (Constants.UIKitLibrary)]
static extern bool UIAccessibilityIsVideoAutoplayEnabled ();
Expand Down
111 changes: 111 additions & 0 deletions src/UIKit/UICellAccessory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
//
// UICellAccessory.cs
//
// Authors:
// Alex Soto <[email protected]>
//
// Copyright (c) Microsoft Corporation.
//

using System;
using System.Runtime.InteropServices;
using Foundation;
using ObjCRuntime;

#nullable enable
#if !WATCH

namespace UIKit {

public partial class UICellAccessory {

[TV (14,0), iOS (14,0)]
[DllImport (Constants.UIKitLibrary)]
static extern IntPtr UICellAccessoryPositionBeforeAccessoryOfClass (IntPtr accessoryCls);

[TV (14,0), iOS (14,0)]
[return: DelegateProxy (typeof (SDUICellAccessoryPosition))]
[BindingImpl (BindingImplOptions.Optimizable)]
public static UICellAccessoryPosition GetPositionBeforeAccessory (Class accessoryClass)
rolfbjarne marked this conversation as resolved.
Show resolved Hide resolved
{
if (accessoryClass == null)
throw new ArgumentNullException (nameof (accessoryClass));
var ret = UICellAccessoryPositionBeforeAccessoryOfClass (accessoryClass.Handle);
return NIDUICellAccessoryPosition.Create (ret)!;
}

[TV (14,0), iOS (14,0)]
[return: DelegateProxy (typeof (SDUICellAccessoryPosition))]
[BindingImpl (BindingImplOptions.Optimizable)]
public static UICellAccessoryPosition GetPositionBeforeAccessory (Type accessoryType) => GetPositionBeforeAccessory (new Class (accessoryType));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No tests.


[TV (14,0), iOS (14,0)]
[DllImport (Constants.UIKitLibrary)]
static extern IntPtr UICellAccessoryPositionAfterAccessoryOfClass (IntPtr accessoryCls);

[TV (14,0), iOS (14,0)]
[return: DelegateProxy (typeof (SDUICellAccessoryPosition))]
[BindingImpl (BindingImplOptions.Optimizable)]
public static UICellAccessoryPosition GetPositionAfterAccessory (Class accessoryClass)
rolfbjarne marked this conversation as resolved.
Show resolved Hide resolved
{
if (accessoryClass == null)
throw new ArgumentNullException (nameof (accessoryClass));
var ret = UICellAccessoryPositionAfterAccessoryOfClass (accessoryClass.Handle);
return NIDUICellAccessoryPosition.Create (ret)!;
}

[TV (14,0), iOS (14,0)]
[return: DelegateProxy (typeof (SDUICellAccessoryPosition))]
[BindingImpl (BindingImplOptions.Optimizable)]
public static UICellAccessoryPosition GetPositionAfterAccessory (Type accessoryType) => GetPositionAfterAccessory (new Class (accessoryType));
rolfbjarne marked this conversation as resolved.
Show resolved Hide resolved
} /* class UICellAccessory */

[UnmanagedFunctionPointerAttribute (CallingConvention.Cdecl)]
[UserDelegateType (typeof (UICellAccessoryPosition))]
internal delegate nuint DUICellAccessoryPosition (IntPtr block, IntPtr accessories);

//
// This class bridges native block invocations that call into C#
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder how complicated it would be to implement support for generating the supporting code for blocks by adding support in the generator for a [GenerateBlockCode] attribute to delegates:

[GenerateBlockCode]
delegate nuint UICellAccessoryPosition (UICellAccessory [] accessories);

//
static internal class SDUICellAccessoryPosition {
static internal readonly DUICellAccessoryPosition Handler = Invoke;

[MonoPInvokeCallback (typeof (DUICellAccessoryPosition))]
static unsafe nuint Invoke (IntPtr block, IntPtr accessories)
{
var descriptor = (BlockLiteral *) block;
var del = (UICellAccessoryPosition) (descriptor->Target);
nuint retval = del (NSArray.ArrayFromHandle<UICellAccessory> (accessories));
return retval;
}
} /* class SDUICellAccessoryPosition */

internal sealed class NIDUICellAccessoryPosition : TrampolineBlockBase {
DUICellAccessoryPosition invoker;

[BindingImpl (BindingImplOptions.Optimizable)]
public unsafe NIDUICellAccessoryPosition (BlockLiteral *block) : base (block)
{
invoker = block->GetDelegateForBlock<DUICellAccessoryPosition> ();
}
Comment on lines +87 to +90
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same, can we use ref?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's a copy/paste of generated code and, to remain optimizable, it should follow the exact same pattern


[Preserve (Conditional = true)]
[BindingImpl (BindingImplOptions.Optimizable)]
public unsafe static UICellAccessoryPosition? Create (IntPtr block)
{
if (block == IntPtr.Zero)
return null;
var del = (UICellAccessoryPosition) GetExistingManagedDelegate (block);
return del ?? new NIDUICellAccessoryPosition ((BlockLiteral *) block).Invoke;
Comment on lines +98 to +99
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move unsafe inside with an unsafe block:

Suggested change
var del = (UICellAccessoryPosition) GetExistingManagedDelegate (block);
return del ?? new NIDUICellAccessoryPosition ((BlockLiteral *) block).Invoke;
var del = (UICellAccessoryPosition) GetExistingManagedDelegate (block);
unsafe {
return del ?? new NIDUICellAccessoryPosition ((BlockLiteral *) block).Invoke;
}

}

[BindingImpl (BindingImplOptions.Optimizable)]
nuint Invoke (UICellAccessory [] accessories)
{
using var nsa_accessories = accessories == null ? null : NSArray.FromNSObjects (accessories);

return invoker (BlockPointer, nsa_accessories.GetHandle ());
}
} /* class NIDUICellAccessoryPosition */
}
#endif // WATCH
86 changes: 86 additions & 0 deletions src/UIKit/UIConfigurationColorTransformer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
//
// UIConfigurationColorTransformer.cs
//
// Authors:
// Alex Soto <[email protected]>
//
// Copyright (c) Microsoft Corporation.
//

using System;
using System.Runtime.InteropServices;
using Foundation;
using ObjCRuntime;

#nullable enable
#if !WATCH

namespace UIKit {

public static partial class UIConfigurationColorTransformer {

[BindingImpl (BindingImplOptions.Optimizable)]
public static UIConfigurationColorTransformerHandler Grayscale {
[return: DelegateProxy (typeof (SDUIConfigurationColorTransformerHandler))]
get => NIDUIConfigurationColorTransformerHandler.Create (_Grayscale)!;
}

[BindingImpl (BindingImplOptions.Optimizable)]
public static UIConfigurationColorTransformerHandler PreferredTint {
[return: DelegateProxy (typeof (SDUIConfigurationColorTransformerHandler))]
get => NIDUIConfigurationColorTransformerHandler.Create (_PreferredTint)!;
}

[BindingImpl (BindingImplOptions.Optimizable)]
public static UIConfigurationColorTransformerHandler MonochromeTint {
[return: DelegateProxy (typeof (SDUIConfigurationColorTransformerHandler))]
get => NIDUIConfigurationColorTransformerHandler.Create (_MonochromeTint)!;
}
} /* class UIConfigurationColorTransformer */

[UnmanagedFunctionPointerAttribute (CallingConvention.Cdecl)]
[UserDelegateType (typeof (UIConfigurationColorTransformerHandler))]
internal delegate IntPtr DUIConfigurationColorTransformerHandler (IntPtr block, IntPtr color);

//
// This class bridges native block invocations that call into C#
//
static internal class SDUIConfigurationColorTransformerHandler {
static internal readonly DUIConfigurationColorTransformerHandler Handler = Invoke;

[MonoPInvokeCallback (typeof (DUIConfigurationColorTransformerHandler))]
static unsafe IntPtr Invoke (IntPtr block, IntPtr color) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ref BlockLiteral? We get unsafe out.

var descriptor = (BlockLiteral *) block;
var del = (UIConfigurationColorTransformerHandler) (descriptor->Target);
var retval = del (Runtime.GetNSObject<UIColor> (color));
return retval != null ? retval.Handle : IntPtr.Zero;
}
} /* class SDUIConfigurationColorTransformerHandler */

internal sealed class NIDUIConfigurationColorTransformerHandler : TrampolineBlockBase {
DUIConfigurationColorTransformerHandler invoker;

[BindingImpl (BindingImplOptions.Optimizable)]
public unsafe NIDUIConfigurationColorTransformerHandler (BlockLiteral *block) : base (block)
{
invoker = block->GetDelegateForBlock<DUIConfigurationColorTransformerHandler> ();
}

[Preserve (Conditional = true)]
[BindingImpl (BindingImplOptions.Optimizable)]
public unsafe static UIConfigurationColorTransformerHandler? Create (IntPtr block)
{
if (block == IntPtr.Zero)
return null;
var del = (UIConfigurationColorTransformerHandler) GetExistingManagedDelegate (block);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same, remove unsafe from the signature, use an usafe block.

return del ?? new NIDUIConfigurationColorTransformerHandler ((BlockLiteral *) block).Invoke;
}

[BindingImpl (BindingImplOptions.Optimizable)]
UIColor Invoke (UIColor color)
{
return Runtime.GetNSObject<UIColor> (invoker (BlockPointer, color.GetHandle ()));
}
} /* class NIDUIConfigurationColorTransformerHandler */
}
#endif // WATCH
Loading