Skip to content

Commit

Permalink
[UIKit] Make P/Invokes related to UIAccessibility have blittable sign…
Browse files Browse the repository at this point in the history
…atures.

Contributes towards xamarin#15684.
  • Loading branch information
rolfbjarne committed Dec 22, 2023
1 parent 51aaac3 commit 208ef6b
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 91 deletions.
106 changes: 43 additions & 63 deletions src/UIKit/UIAccessibility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,21 @@ public enum UIAccessibilityZoomType : long {
public static partial class UIAccessibility {
// UIAccessibility.h
[DllImport (Constants.UIKitLibrary)]
[return: MarshalAs (UnmanagedType.I1)]
extern static /* BOOL */ bool UIAccessibilityIsVoiceOverRunning ();
extern static /* BOOL */ byte UIAccessibilityIsVoiceOverRunning ();

static public bool IsVoiceOverRunning {
get {
return UIAccessibilityIsVoiceOverRunning ();
return UIAccessibilityIsVoiceOverRunning () != 0;
}
}

// UIAccessibility.h
[DllImport (Constants.UIKitLibrary)]
[return: MarshalAs (UnmanagedType.I1)]
extern static /* BOOL */ bool UIAccessibilityIsMonoAudioEnabled ();
extern static /* BOOL */ byte UIAccessibilityIsMonoAudioEnabled ();

static public bool IsMonoAudioEnabled {
get {
return UIAccessibilityIsMonoAudioEnabled ();
return UIAccessibilityIsMonoAudioEnabled () != 0;
}
}

Expand Down Expand Up @@ -85,8 +83,7 @@ public static NSObject FocusedElement (string assistiveTechnologyIdentifier)
[SupportedOSPlatform ("tvos")]
#endif
[DllImport (Constants.UIKitLibrary)]
[return: MarshalAs (UnmanagedType.I1)]
extern static /* BOOL */ bool UIAccessibilityIsShakeToUndoEnabled ();
extern static /* BOOL */ byte UIAccessibilityIsShakeToUndoEnabled ();

#if NET
[SupportedOSPlatform ("ios")]
Expand All @@ -95,40 +92,37 @@ public static NSObject FocusedElement (string assistiveTechnologyIdentifier)
#endif
public static bool IsShakeToUndoEnabled {
get {
return UIAccessibilityIsShakeToUndoEnabled ();
return UIAccessibilityIsShakeToUndoEnabled () != 0;
}
}

// UIAccessibility.h
[DllImport (Constants.UIKitLibrary)]
[return: MarshalAs (UnmanagedType.I1)]
extern static /* BOOL */ bool UIAccessibilityIsClosedCaptioningEnabled ();
extern static /* BOOL */ byte UIAccessibilityIsClosedCaptioningEnabled ();

static public bool IsClosedCaptioningEnabled {
get {
return UIAccessibilityIsClosedCaptioningEnabled ();
return UIAccessibilityIsClosedCaptioningEnabled () != 0;
}
}

// UIAccessibility.h
[DllImport (Constants.UIKitLibrary)]
[return: MarshalAs (UnmanagedType.I1)]
extern static /* BOOL */ bool UIAccessibilityIsInvertColorsEnabled ();
extern static /* BOOL */ byte UIAccessibilityIsInvertColorsEnabled ();

static public bool IsInvertColorsEnabled {
get {
return UIAccessibilityIsInvertColorsEnabled ();
return UIAccessibilityIsInvertColorsEnabled () != 0;
}
}

// UIAccessibility.h
[DllImport (Constants.UIKitLibrary)]
[return: MarshalAs (UnmanagedType.I1)]
extern static /* BOOL */ bool UIAccessibilityIsGuidedAccessEnabled ();
extern static /* BOOL */ byte UIAccessibilityIsGuidedAccessEnabled ();

static public bool IsGuidedAccessEnabled {
get {
return UIAccessibilityIsGuidedAccessEnabled ();
return UIAccessibilityIsGuidedAccessEnabled () != 0;
}
}

Expand Down Expand Up @@ -229,7 +223,7 @@ public static CGRect ConvertFrameToScreenCoordinates (CGRect rect, UIView view)
[SupportedOSPlatform ("tvos")]
#endif
[DllImport (Constants.UIKitLibrary)]
extern unsafe static void UIAccessibilityRequestGuidedAccessSession (/* BOOL */ [MarshalAs (UnmanagedType.I1)] bool enable, /* void(^completionHandler)(BOOL didSucceed) */ BlockLiteral* completionHandler);
extern unsafe static void UIAccessibilityRequestGuidedAccessSession (/* BOOL */ byte enable, /* void(^completionHandler)(BOOL didSucceed) */ BlockLiteral* completionHandler);

#if NET
[SupportedOSPlatform ("ios")]
Expand All @@ -247,7 +241,7 @@ public static void RequestGuidedAccessSession (bool enable, Action<bool> complet
using var block = new BlockLiteral ();
block.SetupBlock (callback, completionHandler);
#endif
UIAccessibilityRequestGuidedAccessSession (enable, &block);
UIAccessibilityRequestGuidedAccessSession (enable ? (byte) 1 : (byte) 0, &block);
}
}

Expand Down Expand Up @@ -287,8 +281,7 @@ static unsafe void TrampolineRequestGuidedAccessSession (IntPtr block, byte enab
[SupportedOSPlatform ("tvos")]
#endif
[DllImport (Constants.UIKitLibrary)]
[return: MarshalAs (UnmanagedType.I1)]
static extern bool UIAccessibilityDarkerSystemColorsEnabled ();
static extern byte UIAccessibilityDarkerSystemColorsEnabled ();

#if NET
[SupportedOSPlatform ("ios")]
Expand All @@ -297,15 +290,15 @@ static unsafe void TrampolineRequestGuidedAccessSession (IntPtr block, byte enab
#endif
public static bool DarkerSystemColorsEnabled {
get {
return UIAccessibilityDarkerSystemColorsEnabled ();
return UIAccessibilityDarkerSystemColorsEnabled () != 0;
}
}

#if !NET
[Obsolete ("Use 'DarkerSystemColorsEnabled' instead.")]
public static bool DarkerSystemColosEnabled {
get {
return UIAccessibilityDarkerSystemColorsEnabled ();
return UIAccessibilityDarkerSystemColorsEnabled () != 0;
}
}
#endif
Expand All @@ -316,8 +309,7 @@ public static bool DarkerSystemColosEnabled {
[SupportedOSPlatform ("tvos")]
#endif
[DllImport (Constants.UIKitLibrary)]
[return: MarshalAs (UnmanagedType.I1)]
static extern bool UIAccessibilityIsBoldTextEnabled ();
static extern byte UIAccessibilityIsBoldTextEnabled ();

#if NET
[SupportedOSPlatform ("ios")]
Expand All @@ -326,7 +318,7 @@ public static bool DarkerSystemColosEnabled {
#endif
public static bool IsBoldTextEnabled {
get {
return UIAccessibilityIsBoldTextEnabled ();
return UIAccessibilityIsBoldTextEnabled () != 0;
}
}

Expand All @@ -340,8 +332,7 @@ public static bool IsBoldTextEnabled {
[MacCatalyst (14, 0)]
#endif
[DllImport (Constants.UIKitLibrary)]
[return: MarshalAs (UnmanagedType.I1)]
static extern bool UIAccessibilityButtonShapesEnabled ();
static extern byte UIAccessibilityButtonShapesEnabled ();

#if NET
[SupportedOSPlatform ("tvos14.0")]
Expand All @@ -352,16 +343,15 @@ public static bool IsBoldTextEnabled {
[iOS (14, 0)]
[MacCatalyst (14, 0)]
#endif
public static bool ButtonShapesEnabled => UIAccessibilityButtonShapesEnabled ();
public static bool ButtonShapesEnabled => UIAccessibilityButtonShapesEnabled () != 0;

#if NET
[SupportedOSPlatform ("ios")]
[SupportedOSPlatform ("maccatalyst")]
[SupportedOSPlatform ("tvos")]
#endif
[DllImport (Constants.UIKitLibrary)]
[return: MarshalAs (UnmanagedType.I1)]
static extern bool UIAccessibilityIsGrayscaleEnabled ();
static extern byte UIAccessibilityIsGrayscaleEnabled ();

#if NET
[SupportedOSPlatform ("ios")]
Expand All @@ -370,7 +360,7 @@ public static bool IsBoldTextEnabled {
#endif
static public bool IsGrayscaleEnabled {
get {
return UIAccessibilityIsGrayscaleEnabled ();
return UIAccessibilityIsGrayscaleEnabled () != 0;
}
}

Expand All @@ -380,8 +370,7 @@ static public bool IsGrayscaleEnabled {
[SupportedOSPlatform ("tvos")]
#endif
[DllImport (Constants.UIKitLibrary)]
[return: MarshalAs (UnmanagedType.I1)]
static extern bool UIAccessibilityIsReduceMotionEnabled ();
static extern byte UIAccessibilityIsReduceMotionEnabled ();

#if NET
[SupportedOSPlatform ("ios")]
Expand All @@ -390,7 +379,7 @@ static public bool IsGrayscaleEnabled {
#endif
static public bool IsReduceMotionEnabled {
get {
return UIAccessibilityIsReduceMotionEnabled ();
return UIAccessibilityIsReduceMotionEnabled () != 0;
}
}

Expand All @@ -404,8 +393,7 @@ static public bool IsReduceMotionEnabled {
[MacCatalyst (14, 0)]
#endif
[DllImport (Constants.UIKitLibrary)]
[return: MarshalAs (UnmanagedType.I1)]
static extern bool UIAccessibilityPrefersCrossFadeTransitions ();
static extern byte UIAccessibilityPrefersCrossFadeTransitions ();

#if NET
[SupportedOSPlatform ("tvos14.0")]
Expand All @@ -416,7 +404,7 @@ static public bool IsReduceMotionEnabled {
[iOS (14, 0)]
[MacCatalyst (14, 0)]
#endif
public static bool PrefersCrossFadeTransitions => UIAccessibilityPrefersCrossFadeTransitions ();
public static bool PrefersCrossFadeTransitions => UIAccessibilityPrefersCrossFadeTransitions () != 0;

#if NET
[SupportedOSPlatform ("ios13.0")]
Expand All @@ -427,8 +415,7 @@ static public bool IsReduceMotionEnabled {
[TV (13, 0)]
#endif
[DllImport (Constants.UIKitLibrary)]
[return: MarshalAs (UnmanagedType.I1)]
static extern bool UIAccessibilityIsVideoAutoplayEnabled ();
static extern byte UIAccessibilityIsVideoAutoplayEnabled ();

#if NET
[SupportedOSPlatform ("ios13.0")]
Expand All @@ -438,16 +425,15 @@ static public bool IsReduceMotionEnabled {
[iOS (13, 0)]
[TV (13, 0)]
#endif
static public bool IsVideoAutoplayEnabled => UIAccessibilityIsVideoAutoplayEnabled ();
static public bool IsVideoAutoplayEnabled => UIAccessibilityIsVideoAutoplayEnabled () != 0;

#if NET
[SupportedOSPlatform ("ios")]
[SupportedOSPlatform ("maccatalyst")]
[SupportedOSPlatform ("tvos")]
#endif
[DllImport (Constants.UIKitLibrary)]
[return: MarshalAs (UnmanagedType.I1)]
static extern bool UIAccessibilityIsReduceTransparencyEnabled ();
static extern byte UIAccessibilityIsReduceTransparencyEnabled ();

#if NET
[SupportedOSPlatform ("ios")]
Expand All @@ -456,7 +442,7 @@ static public bool IsReduceMotionEnabled {
#endif
static public bool IsReduceTransparencyEnabled {
get {
return UIAccessibilityIsReduceTransparencyEnabled ();
return UIAccessibilityIsReduceTransparencyEnabled () != 0;
}
}

Expand All @@ -466,8 +452,7 @@ static public bool IsReduceTransparencyEnabled {
[SupportedOSPlatform ("tvos")]
#endif
[DllImport (Constants.UIKitLibrary)]
[return: MarshalAs (UnmanagedType.I1)]
static extern bool UIAccessibilityIsSwitchControlRunning ();
static extern byte UIAccessibilityIsSwitchControlRunning ();

#if NET
[SupportedOSPlatform ("ios")]
Expand All @@ -476,7 +461,7 @@ static public bool IsReduceTransparencyEnabled {
#endif
static public bool IsSwitchControlRunning {
get {
return UIAccessibilityIsSwitchControlRunning ();
return UIAccessibilityIsSwitchControlRunning () != 0;
}
}

Expand All @@ -486,8 +471,7 @@ static public bool IsSwitchControlRunning {
[SupportedOSPlatform ("tvos")]
#endif
[DllImport (Constants.UIKitLibrary)]
[return: MarshalAs (UnmanagedType.I1)]
static extern bool UIAccessibilityIsSpeakSelectionEnabled ();
static extern byte UIAccessibilityIsSpeakSelectionEnabled ();

#if NET
[SupportedOSPlatform ("ios")]
Expand All @@ -496,7 +480,7 @@ static public bool IsSwitchControlRunning {
#endif
static public bool IsSpeakSelectionEnabled {
get {
return UIAccessibilityIsSpeakSelectionEnabled ();
return UIAccessibilityIsSpeakSelectionEnabled () != 0;
}
}

Expand All @@ -506,8 +490,7 @@ static public bool IsSpeakSelectionEnabled {
[SupportedOSPlatform ("tvos")]
#endif
[DllImport (Constants.UIKitLibrary)]
[return: MarshalAs (UnmanagedType.I1)]
static extern bool UIAccessibilityIsSpeakScreenEnabled ();
static extern byte UIAccessibilityIsSpeakScreenEnabled ();

#if NET
[SupportedOSPlatform ("ios")]
Expand All @@ -516,7 +499,7 @@ static public bool IsSpeakSelectionEnabled {
#endif
static public bool IsSpeakScreenEnabled {
get {
return UIAccessibilityIsSpeakScreenEnabled ();
return UIAccessibilityIsSpeakScreenEnabled () != 0;
}
}

Expand All @@ -526,8 +509,7 @@ static public bool IsSpeakScreenEnabled {
[SupportedOSPlatform ("maccatalyst")]
#endif
[DllImport (Constants.UIKitLibrary)]
[return: MarshalAs (UnmanagedType.I1)]
static extern bool UIAccessibilityIsAssistiveTouchRunning ();
static extern byte UIAccessibilityIsAssistiveTouchRunning ();

#if NET
[SupportedOSPlatform ("ios")]
Expand All @@ -536,7 +518,7 @@ static public bool IsSpeakScreenEnabled {
#endif
public static bool IsAssistiveTouchRunning {
get {
return UIAccessibilityIsAssistiveTouchRunning ();
return UIAccessibilityIsAssistiveTouchRunning () != 0;
}
}

Expand All @@ -549,8 +531,7 @@ public static bool IsAssistiveTouchRunning {
[TV (13, 0)]
#endif
[DllImport (Constants.UIKitLibrary)]
[return: MarshalAs (UnmanagedType.I1)]
static extern bool UIAccessibilityShouldDifferentiateWithoutColor ();
static extern byte UIAccessibilityShouldDifferentiateWithoutColor ();

#if NET
[SupportedOSPlatform ("ios13.0")]
Expand All @@ -560,7 +541,7 @@ public static bool IsAssistiveTouchRunning {
[iOS (13, 0)]
[TV (13, 0)]
#endif
public static bool ShouldDifferentiateWithoutColor => UIAccessibilityShouldDifferentiateWithoutColor ();
public static bool ShouldDifferentiateWithoutColor => UIAccessibilityShouldDifferentiateWithoutColor () != 0;

#if NET
[SupportedOSPlatform ("ios13.0")]
Expand All @@ -571,8 +552,7 @@ public static bool IsAssistiveTouchRunning {
[TV (13, 0)]
#endif
[DllImport (Constants.UIKitLibrary)]
[return: MarshalAs (UnmanagedType.I1)]
static extern bool UIAccessibilityIsOnOffSwitchLabelsEnabled ();
static extern byte UIAccessibilityIsOnOffSwitchLabelsEnabled ();

#if NET
[SupportedOSPlatform ("ios13.0")]
Expand All @@ -582,7 +562,7 @@ public static bool IsAssistiveTouchRunning {
[iOS (13, 0)]
[TV (13, 0)]
#endif
public static bool IsOnOffSwitchLabelsEnabled => UIAccessibilityIsOnOffSwitchLabelsEnabled ();
public static bool IsOnOffSwitchLabelsEnabled => UIAccessibilityIsOnOffSwitchLabelsEnabled () != 0;

#if !TVOS
#if NET
Expand Down
5 changes: 2 additions & 3 deletions src/UIKit/UIContentSizeCategory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ public static NSComparisonResult Compare (UIContentSizeCategory category1, UICon
[SupportedOSPlatform ("maccatalyst")]
#endif
[DllImport (Constants.UIKitLibrary)]
[return: MarshalAs (UnmanagedType.I1)]
static extern bool UIContentSizeCategoryIsAccessibilityCategory (IntPtr /* NSString */ category);
static extern byte UIContentSizeCategoryIsAccessibilityCategory (IntPtr /* NSString */ category);

#if NET
[SupportedOSPlatform ("ios")]
Expand All @@ -55,7 +54,7 @@ static public bool IsAccessibilityCategory (this UIContentSizeCategory self)
if (c1 is null)
throw new ArgumentException ($"Unknown 'UIContentSizeCategory' value");

return UIContentSizeCategoryIsAccessibilityCategory (c1.Handle);
return UIContentSizeCategoryIsAccessibilityCategory (c1.Handle) != 0;
}
}
}
Expand Down
Loading

0 comments on commit 208ef6b

Please sign in to comment.