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] Add support for Xcode 15. #19120

Merged
merged 15 commits into from
Oct 25, 2023
Merged
14 changes: 12 additions & 2 deletions src/UIKit/UIEnums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1101,6 +1101,8 @@ public enum UIUserInterfaceIdiom : long {
[Watch (7, 0), TV (14, 0), iOS (14, 0)]
[MacCatalyst (14, 0)]
Mac = 5,
[Watch (10, 0), TV (17, 0), iOS (17, 0), MacCatalyst (17, 0)]
Vision = 6,
}

// NSInteger -> UIApplication.h
Expand Down Expand Up @@ -2449,6 +2451,8 @@ public enum UINavigationItemLargeTitleDisplayMode : long {
Automatic,
Always,
Never,
[iOS (17, 0), NoTV, MacCatalyst (17, 0)]
Inline,
}

[NoWatch]
Expand Down Expand Up @@ -2576,6 +2580,8 @@ public enum UIMenuOptions : ulong {
Destructive = 1uL << 1,
[iOS (15, 0), TV (15, 0), NoWatch, MacCatalyst (15, 0)]
SingleSelection = 1uL << 5,
[iOS (17, 0), TV (17, 0), NoWatch, MacCatalyst (17, 0)]
DisplayAsPalette = 1uL << 7,
}

[NoWatch, NoTV, iOS (13, 0)]
Expand Down Expand Up @@ -2713,6 +2719,10 @@ public enum UIMenuIdentifier {
[Field ("UIMenuDocument")]
Document,

[TV (17, 0), iOS (17, 0), MacCatalyst (17, 0)]
[Field ("UIMenuAutoFill")]
AutoFill,

}

[iOS (13, 0), TV (13, 0), Watch (6, 0)]
Expand Down Expand Up @@ -3191,7 +3201,7 @@ public enum UIContentInsetsReference : long {
ReadableContent,
}

[NoWatch, NoTV, iOS (14, 0)]
[NoWatch, TV (17, 0), iOS (14, 0)]
[MacCatalyst (14, 0)]
[Native]
public enum UIContextMenuInteractionAppearance : long {
Expand Down Expand Up @@ -3383,7 +3393,7 @@ public enum UIBandSelectionInteractionState : long {
Ended,
}

[NoWatch, NoTV, iOS (15, 0), MacCatalyst (15, 0)]
[NoWatch, TV (17, 0), iOS (15, 0), MacCatalyst (15, 0)]
[Native]
public enum UIBehavioralStyle : ulong {
Automatic = 0,
Expand Down
55 changes: 55 additions & 0 deletions src/UIKit/UIGraphics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,59 @@ public static class UIGraphics {
[DllImport (Constants.UIKitLibrary, EntryPoint = "UIRectClip")]
public extern static void RectClip (CGRect rect);

#if NET
[SupportedOSPlatform ("ios")]
[SupportedOSPlatform ("tvos")]
[SupportedOSPlatform ("maccatalyst")]
[UnsupportedOSPlatform ("ios17.0")]
[UnsupportedOSPlatform ("tvos17.0")]
[UnsupportedOSPlatform ("maccatalyst17.0")]
#else
[Deprecated (PlatformName.iOS, 17, 0)]
[Deprecated (PlatformName.TvOS, 17, 0)]
#endif
[DllImport (Constants.UIKitLibrary, EntryPoint = "UIGraphicsBeginImageContext")]
public extern static void BeginImageContext (CGSize size);

#if NET
[SupportedOSPlatform ("ios")]
[SupportedOSPlatform ("tvos")]
[SupportedOSPlatform ("maccatalyst")]
[UnsupportedOSPlatform ("ios17.0")]
[UnsupportedOSPlatform ("tvos17.0")]
[UnsupportedOSPlatform ("maccatalyst17.0")]
#else
[Deprecated (PlatformName.iOS, 17, 0)]
[Deprecated (PlatformName.TvOS, 17, 0)]
#endif
[DllImport (Constants.UIKitLibrary, EntryPoint = "UIGraphicsBeginImageContextWithOptions")]
public extern static void BeginImageContextWithOptions (CGSize size, [MarshalAs (UnmanagedType.I1)] bool opaque, nfloat scale);

#if NET
[SupportedOSPlatform ("ios")]
[SupportedOSPlatform ("tvos")]
[SupportedOSPlatform ("maccatalyst")]
[UnsupportedOSPlatform ("ios17.0")]
[UnsupportedOSPlatform ("tvos17.0")]
[UnsupportedOSPlatform ("maccatalyst17.0")]
#else
[Deprecated (PlatformName.iOS, 17, 0)]
[Deprecated (PlatformName.TvOS, 17, 0)]
#endif
[DllImport (Constants.UIKitLibrary)]
static extern IntPtr UIGraphicsGetImageFromCurrentImageContext ();

#if NET
[SupportedOSPlatform ("ios")]
[SupportedOSPlatform ("tvos")]
[SupportedOSPlatform ("maccatalyst")]
[UnsupportedOSPlatform ("ios17.0")]
[UnsupportedOSPlatform ("tvos17.0")]
[UnsupportedOSPlatform ("maccatalyst17.0")]
#else
[Deprecated (PlatformName.iOS, 17, 0)]
[Deprecated (PlatformName.TvOS, 17, 0)]
#endif
[DllImport (Constants.UIKitLibrary, EntryPoint = "UIGraphicsEndImageContext")]
public extern static void EndImageContext ();

Expand Down Expand Up @@ -148,6 +192,17 @@ public static void EndPDFContext ()
public static void EndPDFContent () => EndPDFContext ();
#endif

#if NET
[SupportedOSPlatform ("ios")]
[SupportedOSPlatform ("tvos")]
[SupportedOSPlatform ("maccatalyst")]
[UnsupportedOSPlatform ("ios17.0")]
[UnsupportedOSPlatform ("tvos17.0")]
[UnsupportedOSPlatform ("maccatalyst17.0")]
#else
[Deprecated (PlatformName.iOS, 17, 0)]
[Deprecated (PlatformName.TvOS, 17, 0)]
#endif
public static UIImage GetImageFromCurrentImageContext ()
{
using (var pool = new NSAutoreleasePool ()) {
Expand Down
38 changes: 30 additions & 8 deletions src/UIKit/UIImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
using ObjCRuntime;
using CoreGraphics;

#nullable enable

namespace UIKit {

partial class UIImage {
Expand All @@ -29,7 +31,7 @@ partial class UIImage {

public void SaveToPhotosAlbum (SaveStatus status)
{
UIImageStatusDispatcher dis = null;
UIImageStatusDispatcher? dis = null;
UIApplication.EnsureUIThread ();

if (status is not null)
Expand All @@ -42,25 +44,25 @@ public void SaveToPhotosAlbum (SaveStatus status)
[DllImport (Constants.UIKitLibrary)]
extern static /* NSData */ IntPtr UIImagePNGRepresentation (/* UIImage */ IntPtr image);

public NSData AsPNG ()
public NSData? AsPNG ()
{
using (var pool = new NSAutoreleasePool ())
return (NSData) Runtime.GetNSObject (UIImagePNGRepresentation (Handle));
return Runtime.GetNSObject<NSData> (UIImagePNGRepresentation (Handle));
}

[DllImport (Constants.UIKitLibrary)]
extern static /* NSData */ IntPtr UIImageJPEGRepresentation (/* UIImage */ IntPtr image, /* CGFloat */ nfloat compressionQuality);

public NSData AsJPEG ()
public NSData? AsJPEG ()
{
using (var pool = new NSAutoreleasePool ())
return (NSData) Runtime.GetNSObject (UIImageJPEGRepresentation (Handle, 1.0f));
return Runtime.GetNSObject<NSData> (UIImageJPEGRepresentation (Handle, 1.0f));
}

public NSData AsJPEG (nfloat compressionQuality)
public NSData? AsJPEG (nfloat compressionQuality)
{
using (var pool = new NSAutoreleasePool ())
return (NSData) Runtime.GetNSObject (UIImageJPEGRepresentation (Handle, compressionQuality));
return Runtime.GetNSObject<NSData> (UIImageJPEGRepresentation (Handle, compressionQuality));
}

public UIImage Scale (CGSize newSize, nfloat scaleFactor)
Expand Down Expand Up @@ -89,7 +91,7 @@ public UIImage Scale (CGSize newSize)

// required because of GetCallingAssembly (if we ever inline across assemblies)
[MethodImpl (MethodImplOptions.NoInlining)]
public static UIImage FromResource (Assembly assembly, string name)
public static UIImage? FromResource (Assembly assembly, string name)
{
if (name is null)
throw new ArgumentNullException ("name");
Expand All @@ -108,6 +110,26 @@ public static UIImage FromResource (Assembly assembly, string name)
}
}
}
#if NET
[SupportedOSPlatform ("ios17.0")]
[SupportedOSPlatform ("tvos17.0")]
[SupportedOSPlatform ("maccatalyst17.0")]
#else
[Watch (10, 0), TV (17, 0), iOS (17, 0)]
#endif
[DllImport (Constants.UIKitLibrary)]
static extern /* NSData */ IntPtr UIImageHEICRepresentation (/* UIImage */ IntPtr image);

#if NET
[SupportedOSPlatform ("ios17.0")]
[SupportedOSPlatform ("tvos17.0")]
[SupportedOSPlatform ("maccatalyst17.0")]
#else
[Watch (10, 0), TV (17, 0), iOS (17, 0)]
#endif
public NSData? HeicRepresentation
=> Runtime.GetNSObject<NSData> (UIImageHEICRepresentation (Handle));


// that was used (03be3e0d43085dfef2e732494216d9b2bf8fc079) to implement FromResource but that code
// was changed later (d485b61793b0d986f416c8d6154fb92c7a57d79d) making it unused AFAICS
Expand Down
Loading
Loading