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

[ios11-beta1] Initial UIKit Drag and Drop support #2190

Merged
merged 11 commits into from Jul 10, 2017
2 changes: 2 additions & 0 deletions src/.gitignore
Expand Up @@ -11,3 +11,5 @@ xammac.csproj
xamtvos.csproj
xamwatch.csproj
generator-ikvm.csproj
~.pmcs-*
*~
252 changes: 251 additions & 1 deletion src/UIKit/UIEnums.cs
Expand Up @@ -183,6 +183,8 @@ public enum UIControlContentHorizontalAlignment : nint {
Left = 1,
Right = 2,
Fill = 3,
Leading = 4,
Trailing = 5
}

// NSUInteger -> UIControl.h
Expand Down Expand Up @@ -297,7 +299,8 @@ public enum UIButtonType : nint {
InfoLight,
InfoDark,
ContactAdd,
System = RoundedRect
Plain,
System = RoundedRect,
}

// NSInteger -> UIStringDrawing.h
Expand Down Expand Up @@ -880,6 +883,7 @@ public enum UIModalPresentationStyle : nint {
OverCurrentContext,
[NoTV]
Popover,
BlurOverFullScreen,
None = -1
}

Expand Down Expand Up @@ -1248,6 +1252,10 @@ public enum NSLayoutFormatOptions : nuint_compat_int {
DirectionLeadingToTrailing = 0 << 16, // default
DirectionLeftToRight = 1 << 16,
DirectionRightToLeft = 2 << 16,

SpacingEdgeToEdge = 0 << 19,
SpacingBaselineToBaseline = 1 << 19,
SpacingMask = 1 << 19,

DirectionMask = 0x3 << 16,
}
Expand Down Expand Up @@ -1988,4 +1996,246 @@ public enum UIScrollViewIndexDisplayMode : nint {
Automatic,
AlwaysHidden
}

[TV (11,0), iOS (11,0)]
[Native]
public enum UIScrollViewContentInsetAdjustmentBehavior : nint
{
Automatic,
ScrollableAxes,
Never,
Always
}

[iOS (11,0)]
[Native]
public enum UIAccessibilityContainerType : nint
{
None = 0,
DataTable,
List,
Landmark
}

[iOS (11,0)]
[Native]
public enum UITextSmartQuotesType : nint
{
Default,
No,
Yes
}

[iOS (11,0)]
[Native]
public enum UITextSmartDashesType : nint
{
Default,
No,
Yes
}

[iOS (11,0)]
[Native]
public enum UITextSmartInsertDeleteType : nint
{
Default,
No,
Yes
}

[iOS (11,0)]
[Native]
public enum UIAccessibilityCustomSystemRotorType : nint
{
None = 0,
Link,
VisitedLink,
Heading,
HeadingLevel1,
HeadingLevel2,
HeadingLevel3,
HeadingLevel4,
HeadingLevel5,
HeadingLevel6,
BoldText,
ItalicText,
UnderlineText,
MisspelledWord,
Image,
TextField,
Table,
List,
Landmark
}

[NoWatch, NoTV, iOS (11,0)]
[Native]
public enum UIDropOperation : nuint
{
Cancel = 0,
Forbidden = 1,
Copy = 2,
Move = 3
}

[NoWatch, NoTV, iOS (11,0)]
[Native]
[Flags]
public enum UITextDragOptions : nint
{
None = 0,
StripTextColorFromPreviews = (1 << 0)
}

[NoWatch, NoTV, iOS (11,0)]
[Native]
public enum UITextDropAction : nuint
{
Insert = 0,
ReplaceSelection,
ReplaceAll
}

[NoWatch, NoTV, iOS (11,0)]
[Native]
public enum UITextDropProgressMode : nuint
{
System = 0,
Custom
}

[NoWatch, NoTV, iOS (11,0)]
[Native]
public enum UITextDropEditability : nuint
{
No = 0,
Temporary,
Yes
}

[NoWatch, NoTV, iOS (11,0)]
[Native]
public enum UICollectionViewReorderingCadence : nint
{
Immediate,
Fast,
Slow
}

[NoWatch, NoTV, iOS (11,0)]
[Native]
public enum UICollectionViewDropIntent : nint
{
Unspecified,
InsertAtDestinationIndexPath,
InsertIntoDestinationIndexPath
}

[NoWatch, NoTV, iOS (11,0)]
[Native]
public enum UICollectionViewCellDragState : nint
{
None,
Lifting,
Dragging
}

[NoTV, iOS (11,0)]
[Native]
public enum UIImagePickerControllerImageUrlExportPreset : nint
{
Compatible = 0,
Current
}

[NoTV, iOS (11,0)]
[Native]
public enum UIContextualActionStyle : nint
{
Normal,
Destructive
}

[NoWatch, NoTV, iOS (11,0)]
[Native]
public enum UITableViewCellDragState : nint
{
None,
Lifting,
Dragging
}

[TV (11,0), iOS (11,0)]
[Native]
public enum UITableViewSeparatorInsetReference : nint
{
CellEdges,
AutomaticInsets
}

[NoWatch, NoTV, iOS (11,0)]
[Native]
public enum UITableViewDropIntent : nint
{
Unspecified,
InsertAtDestinationIndexPath,
InsertIntoDestinationIndexPath,
Automatic
}

[TV (11,0), iOS (11,0)]
[Native]
public enum UISplitViewControllerPrimaryEdge : nint
{
Leading,
Trailing
}

[NoWatch, NoTV, iOS (11,0)]
[Native]
public enum UIDropSessionProgressIndicatorStyle : nuint
{
None,
Default
}

[NoWatch, NoTV, iOS (11,0)]
[Native]
public enum UISpringLoadedInteractionEffectState : nint
{
Inactive,
Possible,
Activating,
Activated
}

[NoTV, iOS (11,0)]
[Native]
public enum UIDocumentBrowserImportMode : nuint
{
None,
Copy,
Move
}

[NoTV, iOS (11,0)]
[Native]
public enum UIDocumentBrowserUserInterfaceStyle : nuint
{
White = 0,
Light,
Dark
}

[NoTV, iOS (11,0)]
[Native]
[Flags]
public enum UIDocumentBrowserActionAvailability : nint
{
Menu = 1,
NavigationBar = 1 << 1
}


}
40 changes: 40 additions & 0 deletions src/foundation.cs
Expand Up @@ -237,6 +237,17 @@ partial interface NSAttributedString : NSCoding, NSMutableCopying, NSSecureCodin
[Wrap ("this (data, options == null ? null : options.Dictionary, out resultDocumentAttributes, ref error)")]
IntPtr Constructor (NSData data, NSAttributedStringDocumentAttributes options, out NSDictionary resultDocumentAttributes, ref NSError error);

// From the NSItemProviderReading protocol, a special constructor.
[Export ("initWithItemProviderData:typeIdentifier:error:")]
[iOS (11,0), NoWatch, NoTV, Mac(10,13)]
IntPtr Constructor (NSData providerData, string typeIdentifier, out NSError outError);

// From the NSItemProviderReading protocol, a static method.
[Static]
[Export ("readableTypeIdentifiersForItemProvider", ArgumentSemantic.Copy)]
[iOS (11,0), NoWatch, NoTV, Mac(10,13)]
string[] ReadableTypeIdentifiersForItemProvider { get; }

[Since (7,0)]
[Export ("dataFromRange:documentAttributes:error:")]
NSData GetDataFromRange (NSRange range, NSDictionary attributes, ref NSError error);
Expand Down Expand Up @@ -8780,6 +8791,35 @@ partial interface NSItemProvider : NSCopying {
#endif
}

interface INSItemProviderReading {}

[Watch (4,0), TV (11,0), Mac (10,13), iOS (11,0)]
[Protocol]
interface NSItemProviderReading
{
//
// This static method has to be implemented on each class that implements
// this, this is not a capability that exists in C#.
// We are inlining these on each class that implements NSItemProviderReading
// for the sake of the method being callable from C#, for user code, the
// user needs to manually [Export] the selector on a static method, like
// they do for the "layer" property on CALayer subclasses.
//
//[Static, Abstract]
//[Export ("readableTypeIdentifiersForItemProvider", ArgumentSemantic.Copy)]
//string[] ReadableTypeIdentifiersForItemProvider { get; }

//
// This is a constructor that various classes must implement
// NSAttributedString, UIColor and UIImage need to have this constructor
// for user-defined implementations of this interface, we are going to
// need to something special
//
//[Abstract]
//[Export ("initWithItemProviderData:typeIdentifier:error:")]
//INSItemProviderReading CreateFrom (NSData providerData, string typeIdentifier, [NullAllowed] NSError outError);
Copy link
Contributor

@timrisi timrisi Jun 22, 2017

Choose a reason for hiding this comment

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

Why is the method being bound separately in the different classes instead of having the classes implement INSItemProviderReading?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See bug: https://bugzilla.xamarin.com/show_bug.cgi?id=57650 for details.

The runtime needs some changes to support the idiom.

Copy link
Member

Choose a reason for hiding this comment

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

As I've stated on the bug I believe the runtime doesn't need changes to make it work, so this can be uncommented (and the CreateFrom method should be a proper Constructor, not a method).

The registrars can provide some help for users, but it needs these methods properly defined in order to have enough information to help users.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What this patch does is to inline the constructor in all three places that conform to this procotol.

I tried doing what you suggested (a) removing the above line, and (b) removing the inlined constructors that this patch contains everywhere and (c) making those classes adopt the NSItemProviderReading interface, but that does not inline the constructor anywhere, nor does the interface gain anything out of having this method declared here.

The result is thus a step backwards, the patch to that is here:

https://gist.github.com/migueldeicaza/e22f44007e7ac093a0076276187dcb16

So I am not sure what is that you are suggesting I do with this.

Copy link
Member

Choose a reason for hiding this comment

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

I meant only uncommenting the code here, inside NSItemProviderReading, not removing the inlined members elsewhere.

In any case I can fix this when I look at the corresponding bug.

}

#if XAMCORE_2_0
[Static]
#endif
Expand Down