public UIDropProposal SessionDidUpdate(UIDropInteraction interaction, IUIDropSession session) { UIDropOperation operation = UIDropOperation.Cancel; if (session.LocalDragSession == null) { return(new UIDropProposal(operation)); } if (interaction.View is IVisualElementRenderer renderer) { DataPackage package = null; if (session.LocalDragSession.Items.Length > 0 && session.LocalDragSession.Items[0].LocalObject is CustomLocalStateData cdi) { package = cdi.DataPackage; } if (HandleDragOver((View)renderer.Element, package)) { operation = UIDropOperation.Copy; } } return(new UIDropProposal(operation)); }
public override void SessionDidExit(UIDropInteraction interaction, IUIDropSession session) { Console.WriteLine($"SessionDidExit ({interaction}, {session})"); BeginInvokeOnMainThread(() => { dropView.BackgroundColor = dropView.defaultColor; }); }
public virtual void PerformDrop(UIDropInteraction interaction, IUIDropSession session) { if (PerformDropOperation == null) { throw new NullReferenceException("The PerformDropOperation delegate must be defined before calling the 'PerformDrop' method"); } PerformDropOperation(interaction, session); }
public UIDropProposal SessionDidUpdate(UIDropInteraction interaction, IUIDropSession session) { if (session.LocalDragSession == null) { return(new UIDropProposal(UIDropOperation.Forbidden)); } return(new UIDropProposal(UIDropOperation.Move)); }
public override void SessionDidEnter(UIDropInteraction interaction, IUIDropSession session) { Console.WriteLine($"SessionDidEnter ({interaction}, {session})"); BeginInvokeOnMainThread(() => { dropView.BackgroundColor = UIColor.Yellow; }); }
public void PerformDrop(UIDropInteraction interaction, IUIDropSession session) { // Get the drag items (UIImage in this case). session.LoadObjects <UIImage> (images => { ImageView.Image = images?.First(); }); var dropLocation = session.LocationInView(View); UpdateLayers(dropLocation); }
public virtual UIDropProposal SessionDidUpdate(UIDropInteraction interaction, IUIDropSession session) { if (ResolveDropOperation == null) { throw new NullReferenceException("The ResolveDropOperation delegate must be defined before calling the 'SessionDidUpdate' method"); } return(new UIDropProposal(ResolveDropOperation(this, interaction, session))); }
public override void PerformDrop(UIDropInteraction interaction, IUIDropSession session) { Console.WriteLine($"PerformDrop ({interaction}, {session})"); INSItemProviderReading objectType = new StringReader(); session.Completion(objectType, (objects) => { Console.WriteLine($"PerformDropCompletion ({objects.Length})"); dropView.BackgroundColor = UIColor.Green; }); }
public UITargetedDragPreview GetPreviewForDroppingItem(UIDropInteraction interaction, UIDragItem item, UITargetedDragPreview defaultPreview) { if (item.LocalObject == null) { return(null); } else { DropPoint = defaultPreview.View.Center; var target = new UIDragPreviewTarget(View, DropPoint); // HACK: why is this null? //return defaultPreview.GetRetargetedPreview(target); return(defaultPreview); } }
public void SessionDidExit(UIDropInteraction interaction, IUIDropSession session) { DataPackage package = null; if (session.LocalDragSession.Items.Length > 0 && session.LocalDragSession.Items[0].LocalObject is CustomLocalStateData cdi) { package = cdi.DataPackage; } if (HandleDragLeave((View)_viewHandler.VirtualView, package)) { } }
public UIDropProposal SessionDidUpdate(UIDropInteraction interaction, IUIDropSession session) { UIDropOperation operation; if (session.LocalDragSession == null) { operation = UIDropOperation.Copy; } else { operation = UIDropOperation.Move; } return(new UIDropProposal(operation)); }
public void PerformDrop(UIDropInteraction interaction, IUIDropSession session) { if (session.LocalDragSession == null) { return; } if (session.LocalDragSession.Items.Length > 0 && session.LocalDragSession.Items[0].LocalObject is CustomLocalStateData cdi && _viewHandler.VirtualView is View view) { HandleDrop(view, cdi.DataPackage); HandleDropCompleted(cdi.View); } }
public bool CanHandleSession(UIDropInteraction interaction, IUIDropSession session) { if (session.LocalDragSession == null) { return(false); } if (session.LocalDragSession.Items.Length > 0 && session.LocalDragSession.Items[0].LocalObject is CustomLocalStateData) { return(true); } return(false); }
public void PerformDrop(UIDropInteraction interaction, IUIDropSession session) { if (session.LocalDragSession == null) { DropPoint = session.LocationInView(interaction.View); foreach (var dragItem in session.Items) { LoadImage(dragItem.ItemProvider, DropPoint); } } else { MovePoint = session.LocationInView(interaction.View); } }
public void SessionDidExit(UIDropInteraction interaction, IUIDropSession session) { if (interaction.View is IVisualElementRenderer renderer) { DataPackage package = null; if (session.LocalDragSession.Items.Length > 0 && session.LocalDragSession.Items[0].LocalObject is CustomLocalStateData cdi) { package = cdi.DataPackage; } if (HandleDragLeave((View)renderer.Element, package)) { } } }
public void PerformDrop(UIDropInteraction interaction, IUIDropSession session) { var label = interaction == oddDropInteraction ? OddNumbersLabel : EvenNumbersLabel; session.LoadObjects <NSString>(strings => { if (String.IsNullOrEmpty(label.Text)) { label.Text = strings[0]; } else { label.Text = $"{strings[0]}, {label.Text}"; } }); GenerateNumber(); }
public UIDropProposal SessionDidUpdate(UIDropInteraction interaction, IUIDropSession session) { UIDropProposal proposal; var isEven = (session.Items[0].LocalObject as NSNumber).BoolValue; if (interaction == oddDropInteraction && !isEven) { proposal = new UIDropProposal(UIDropOperation.Copy); } else if (interaction == evenDropInteraction && isEven) { proposal = new UIDropProposal(UIDropOperation.Copy); } else { proposal = new UIDropProposal(UIDropOperation.Forbidden); } return(proposal); }
protected void SetupDragAndDrop() { NumberLabel.UserInteractionEnabled = true; EvenNumbersLabel.UserInteractionEnabled = true; OddNumbersLabel.UserInteractionEnabled = true; var numberDragInteraction = new UIDragInteraction(this); NumberLabel.AddInteraction(numberDragInteraction); // On iPad, this defaults to true. On iPhone, this defaults to // false. Since this app should work on the iPhone, enable the the // drag interaction. numberDragInteraction.Enabled = true; evenDropInteraction = new UIDropInteraction(this); EvenNumbersLabel.AddInteraction(evenDropInteraction); oddDropInteraction = new UIDropInteraction(this); OddNumbersLabel.AddInteraction(oddDropInteraction); }
public UIDropProposal SessionDidUpdate(UIDropInteraction interaction, IUIDropSession session) { var dropLocation = session.LocationInView(View); UpdateLayers(dropLocation); var operation = new UIDropOperation(); if (ImageView.Frame.Contains(dropLocation)) { operation = session.LocalDragSession == null ? UIDropOperation.Copy : UIDropOperation.Move; } else { // Cancel dropping if it's not inside the image view. operation = UIDropOperation.Cancel; } return(new UIDropProposal(operation)); }
public void WillAnimateDrop(UIDropInteraction interaction, UIDragItem item, IUIDragAnimating animator) { animator.AddAnimations(() => { FadeItems(new UIDragItem[] { item }, 0f); }); var movePoint = MovePoint; //DropPoint animator.AddCompletion((err) => { var index = item.LocalObject as NSNumber; if (index != null) { var i = index.Int32Value; if (i >= 0) { Views[i].Center = movePoint; Views[i].Alpha = 1f; } } }); }
public override void ViewDidLoad() { base.ViewDidLoad(); ImageView.Layer.BorderColor = UIColor.Green.CGColor; ImageView.Layer.BorderWidth = 0.0f; View.Layer.BorderColor = UIColor.Red.CGColor; // 'UserInteractionEnabled' is needed for drag and drop. ImageView.UserInteractionEnabled = true; // Allow dragging. var dragInteraction = new UIDragInteraction(this); ImageView.AddInteraction(dragInteraction); // Allow dropping. var dropInteraction = new UIDropInteraction(this); View.AddInteraction(dropInteraction); }
public UIDropProposal SessionDidUpdate(UIDropInteraction interaction, IUIDropSession session) { UIDropOperation operation = UIDropOperation.Cancel; if (session.LocalDragSession == null) { return(new UIDropProposal(operation)); } DataPackage package = null; if (session.LocalDragSession.Items.Length > 0 && session.LocalDragSession.Items[0].LocalObject is CustomLocalStateData cdi) { package = cdi.DataPackage; } if (HandleDragOver((View)_viewHandler.VirtualView, package)) { operation = UIDropOperation.Copy; } return(new UIDropProposal(operation)); }
void LoadRecognizers() { if (ElementGestureRecognizers == null) { return; } #if __MOBILE__ if (_shouldReceiveTouch == null) { // Cache this so we don't create a new UITouchEventArgs instance for every recognizer _shouldReceiveTouch = ShouldReceiveTouch; } #endif #if __MOBILE__ UIDragInteraction uIDragInteraction = null; UIDropInteraction uIDropInteraction = null; if (_dragAndDropDelegate != null) { foreach (var interaction in _renderer.NativeView.Interactions) { if (interaction is UIDragInteraction uIDrag && uIDrag.Delegate == _dragAndDropDelegate) { uIDragInteraction = uIDrag; } if (interaction is UIDropInteraction uiDrop && uiDrop.Delegate == _dragAndDropDelegate) { uIDropInteraction = uiDrop; } } } bool dragFound = false; bool dropFound = false; #endif for (int i = 0; i < ElementGestureRecognizers.Count; i++) { IGestureRecognizer recognizer = ElementGestureRecognizers[i]; if (_gestureRecognizers.ContainsKey(recognizer)) { continue; } var nativeRecognizer = GetNativeRecognizer(recognizer); if (nativeRecognizer != null && _handler != null) { #if __MOBILE__ nativeRecognizer.ShouldReceiveTouch = _shouldReceiveTouch; #endif _handler.AddGestureRecognizer(nativeRecognizer); _gestureRecognizers[recognizer] = nativeRecognizer; } #if __MOBILE__ if (Forms.IsiOS11OrNewer && recognizer is DragGestureRecognizer) { dragFound = true; _dragAndDropDelegate = _dragAndDropDelegate ?? new DragAndDropDelegate(); if (uIDragInteraction == null) { var interaction = new UIDragInteraction(_dragAndDropDelegate); interaction.Enabled = true; _renderer.NativeView.AddInteraction(interaction); } } if (Forms.IsiOS11OrNewer && recognizer is DropGestureRecognizer) { dropFound = true; _dragAndDropDelegate = _dragAndDropDelegate ?? new DragAndDropDelegate(); if (uIDropInteraction == null) { var interaction = new UIDropInteraction(_dragAndDropDelegate); _renderer.NativeView.AddInteraction(interaction); } } #endif } #if __MOBILE__ if (!dragFound && uIDragInteraction != null) { _renderer.NativeView.RemoveInteraction(uIDragInteraction); } if (!dropFound && uIDropInteraction != null) { _renderer.NativeView.RemoveInteraction(uIDropInteraction); } #endif var toRemove = _gestureRecognizers.Keys.Where(key => !ElementGestureRecognizers.Contains(key)).ToArray(); for (int i = 0; i < toRemove.Length; i++) { IGestureRecognizer gestureRecognizer = toRemove[i]; var uiRecognizer = _gestureRecognizers[gestureRecognizer]; _gestureRecognizers.Remove(gestureRecognizer); _handler.RemoveGestureRecognizer(uiRecognizer); uiRecognizer.Dispose(); } }
public void SessionDidEnter(UIDropInteraction interaction, IUIDropSession session) { Alpha = 1.0f; }
public override UIDropProposal SessionDidUpdate(UIDropInteraction interaction, IUIDropSession session) { Console.WriteLine($"SessionDidUpdate ({interaction}, {session})"); return(new UIDropProposal(UIDropOperation.Copy)); }
public void SessionDidEnd(UIDropInteraction interaction, IUIDropSession session) { Alpha = 0.5f; }
public bool CanHandleSession(UIDropInteraction interaction, IUIDropSession session) { return(session.CanLoadObjects(typeof(UIImage))); }
public override bool CanHandleSession(UIDropInteraction interaction, IUIDropSession session) { Console.WriteLine($"CanHandleSession ({interaction}, {session})"); return(session.CanLoadObjectsOfClass(new Class(typeof(NSString)))); }
void LoadRecognizers() { if (ElementGestureRecognizers == null) { return; } if (_shouldReceiveTouch == null) { // Cache this so we don't create a new UITouchEventArgs instance for every recognizer _shouldReceiveTouch = ShouldReceiveTouch; } CalculateUserInteractionEnabled(); UIDragInteraction?uIDragInteraction = null; UIDropInteraction?uIDropInteraction = null; if (_dragAndDropDelegate != null && _platformView != null) { if (PlatformVersion.IsAtLeast(11)) { foreach (var interaction in _platformView.Interactions) { if (interaction is UIDragInteraction uIDrag && uIDrag.Delegate == _dragAndDropDelegate) { uIDragInteraction = uIDrag; } if (interaction is UIDropInteraction uiDrop && uiDrop.Delegate == _dragAndDropDelegate) { uIDropInteraction = uiDrop; } } } } bool dragFound = false; bool dropFound = false; if (_platformView != null && _handler.VirtualView is View v && v.TapGestureRecognizerNeedsDelegate() && (_platformView.AccessibilityTraits & UIAccessibilityTrait.Button) != UIAccessibilityTrait.Button) { _platformView.AccessibilityTraits |= UIAccessibilityTrait.Button; _addedFlags |= UIAccessibilityTrait.Button; if (PlatformVersion.IsAtLeast(13)) { _defaultAccessibilityRespondsToUserInteraction = _platformView.AccessibilityRespondsToUserInteraction; _platformView.AccessibilityRespondsToUserInteraction = true; } } for (int i = 0; i < ElementGestureRecognizers.Count; i++) { IGestureRecognizer recognizer = ElementGestureRecognizers[i]; if (_gestureRecognizers.ContainsKey(recognizer)) { continue; } var nativeRecognizer = GetPlatformRecognizer(recognizer); if (nativeRecognizer != null && _platformView != null) { nativeRecognizer.ShouldReceiveTouch = _shouldReceiveTouch; _platformView.AddGestureRecognizer(nativeRecognizer); _gestureRecognizers[recognizer] = nativeRecognizer; } if (PlatformVersion.IsAtLeast(11) && recognizer is DragGestureRecognizer) { dragFound = true; _dragAndDropDelegate = _dragAndDropDelegate ?? new DragAndDropDelegate(_handler); if (uIDragInteraction == null && _handler.PlatformView != null) { var interaction = new UIDragInteraction(_dragAndDropDelegate); interaction.Enabled = true; _handler.PlatformView.AddInteraction(interaction); } } if (PlatformVersion.IsAtLeast(11) && recognizer is DropGestureRecognizer) { dropFound = true; _dragAndDropDelegate = _dragAndDropDelegate ?? new DragAndDropDelegate(_handler); if (uIDropInteraction == null && _handler.PlatformView != null) { var interaction = new UIDropInteraction(_dragAndDropDelegate); _handler.PlatformView.AddInteraction(interaction); } } } if (PlatformVersion.IsAtLeast(11)) { if (!dragFound && uIDragInteraction != null && _handler.PlatformView != null) { _handler.PlatformView.RemoveInteraction(uIDragInteraction); } if (!dropFound && uIDropInteraction != null && _handler.PlatformView != null) { _handler.PlatformView.RemoveInteraction(uIDropInteraction); } } var toRemove = new List <IGestureRecognizer>(); foreach (var key in _gestureRecognizers.Keys) { if (!ElementGestureRecognizers.Contains(key)) { toRemove.Add(key); } } for (int i = 0; i < toRemove.Count; i++) { IGestureRecognizer gestureRecognizer = toRemove[i]; var uiRecognizer = _gestureRecognizers[gestureRecognizer]; _gestureRecognizers.Remove(gestureRecognizer); if (_platformView != null) { _platformView.RemoveGestureRecognizer(uiRecognizer); } uiRecognizer.Dispose(); } }
private void SetupDrop() { UserInteractionEnabled = true; DropInteraction = new UIDropInteraction(this); AddInteraction(DropInteraction); }