From e515b5ca04c1d6cc7ad96bb9493dc388531cc33b Mon Sep 17 00:00:00 2001 From: janwiebe-jump <64576907+janwiebe-jump@users.noreply.github.com> Date: Mon, 22 Aug 2022 14:04:06 +0200 Subject: [PATCH] Fix #9996 and #15622 (#15642) As discussed in #9996 the CPListSection constructors are not fully correct, since the CPListImageRowItem can't be added to it, which is possible in the native iOS SDK. This PR fixes that. With that, also #15622 seems to be fixed. Co-authored-by: Manuel de la Pena Co-authored-by: Alex Soto Co-authored-by: Chris Hamons Co-authored-by: Rolf Bjarne Kvinge --- src/ObjCRuntime/ObsoleteConstants.cs | 2 ++ src/carplay.cs | 28 +++++++++++++++++++++++++--- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/ObjCRuntime/ObsoleteConstants.cs b/src/ObjCRuntime/ObsoleteConstants.cs index 5d37e8ae35d2..9af119ff7172 100644 --- a/src/ObjCRuntime/ObsoleteConstants.cs +++ b/src/ObjCRuntime/ObsoleteConstants.cs @@ -27,5 +27,7 @@ partial class Constants { internal const string RemovedFromChip = "This API has been removed from the 'CHIP' framework."; + internal const string BrokenBinding = "This API was incorrectly bound and does not work correctly. Use the new version indicated in the associated Obsolete attribute."; + } } diff --git a/src/carplay.cs b/src/carplay.cs index e4f0c5a0d38e..a50f77e692ca 100644 --- a/src/carplay.cs +++ b/src/carplay.cs @@ -572,11 +572,23 @@ interface CPListItem : CPSelectableListItem, NSSecureCoding { [DisableDefaultCtor] interface CPListSection : NSSecureCoding { - [Export ("initWithItems:header:sectionIndexTitle:")] +#if !XAMCORE_5_0 + [Wrap ("base (true ? throw new InvalidOperationException (Constants.BrokenBinding) : NSObjectFlag.Empty)")] + [Obsolete ("Use '.ctor (ICPListTemplateItem [], string, string)' constructor instead. Warning: this will throw InvalidOperationException at runtime.")] NativeHandle Constructor (CPListItem [] items, [NullAllowed] string header, [NullAllowed] string sectionIndexTitle); +#endif - [Export ("initWithItems:")] +#if !XAMCORE_5_0 + [Wrap ("base (true ? throw new InvalidOperationException (Constants.BrokenBinding) : NSObjectFlag.Empty)")] + [Obsolete ("Use '.ctor (ICPListTemplateItem [], string, string)' constructor instead. Warning: this will throw InvalidOperationException at runtime.")] NativeHandle Constructor (CPListItem [] items); +#endif + + [Export ("initWithItems:header:sectionIndexTitle:")] + NativeHandle Constructor (ICPListTemplateItem [] items, [NullAllowed] string header, [NullAllowed] string sectionIndexTitle); + + [Export ("initWithItems:")] + NativeHandle Constructor (ICPListTemplateItem [] items); [iOS (15,0), MacCatalyst (15,0)] [Export ("initWithItems:header:headerSubtitle:headerImage:headerButton:sectionIndexTitle:")] @@ -588,8 +600,18 @@ interface CPListSection : NSSecureCoding { [NullAllowed, Export ("sectionIndexTitle")] string SectionIndexTitle { get; } - [Export ("items", ArgumentSemantic.Copy)] +#if !XAMCORE_5_0 + [Wrap ("true ? throw new InvalidOperationException (Constants.BrokenBinding) : new NSArray ()", IsVirtual = true)] + [Obsolete ("Use 'Items2 : ICPListTemplateItem []' instead.")] CPListItem [] Items { get; } +#endif + + [Export ("items", ArgumentSemantic.Copy)] +#if !XAMCORE_5_0 + ICPListTemplateItem [] Items2 { get; } +#else + ICPListTemplateItem [] Items { get; } +#endif [iOS (14,0)] [Export ("indexOfItem:")]