private void OnDrag(DragGestureRecognizer rec) { if (InputRegistry.shared.MayHandle(InputType.Touch | InputType.Click, this)) { MoveCamera(CameraUtils.ScreenToWorldDistance(camera, -rec.DragDelta)); } }
TView AddDragGesture <TView>(TView view) where TView : View { var dragRecognizer = new DragGestureRecognizer() { CanDrag = true }; dragRecognizer.DragStarting += (_, args) => { DraggingColor = Color.Purple; OnPropertyChanged(nameof(DraggingColor)); if (view is StackDrag sd) { args.Data.Image = "coffee.png"; } }; dragRecognizer.DropCompleted += (_, __) => { DraggingColor = Color.Default; OnPropertyChanged(nameof(DraggingColor)); }; view.GestureRecognizers.Add(dragRecognizer); return(view); }
/// <summary> /// The Unity Update() method. /// </summary> public void Update() { DragGestureRecognizer.Update(); PinchGestureRecognizer.Update(); TwoFingerDragGestureRecognizer.Update(); TapGestureRecognizer.Update(); TwistGestureRecognizer.Update(); }
private void OnDragStarting(object sender, DragStartingEventArgs e) { DragGestureRecognizer card = (sender as DragGestureRecognizer); INoteModel DaNote = (card.BindingContext as HLinkNoteModel).DeRef; e.Data.Text = DaNote.GetDefaultText; }
public void TextPackageCorrectlyExtractedFromCompatibleElement(Type fieldType, string result) { var dragRec = new DragGestureRecognizer(); var element = (VisualElement)Activator.CreateInstance(fieldType); Assert.IsTrue(element.TrySetValue(result)); var args = dragRec.SendDragStarting((IView)element); Assert.AreEqual(result, args.Data.Text); }
/// <summary> /// The Unity Update() method. /// </summary> public void Update() { if (canManipulate) { DragGestureRecognizer.Update(); PinchGestureRecognizer.Update(); TwoFingerDragGestureRecognizer.Update(); TapGestureRecognizer.Update(); TwistGestureRecognizer.Update(); } }
public void DragStartingCommandFires() { var dragRec = new DragGestureRecognizer(); var parameter = new Object(); object commandExecuted = null; Command cmd = new Command(() => commandExecuted = parameter); dragRec.DragStartingCommand = cmd; dragRec.DragStartingCommandParameter = parameter; dragRec.SendDragStarting(new Label()); Assert.AreEqual(commandExecuted, parameter); }
public void DropCompletedCommandFiresOnce() { int counter = 0; var dragRec = new DragGestureRecognizer(); Command cmd = new Command(() => counter++); dragRec.SendDragStarting(new Label()); dragRec.DropCompletedCommand = cmd; dragRec.SendDropCompleted(new DropCompletedEventArgs()); dragRec.SendDropCompleted(new DropCompletedEventArgs()); dragRec.SendDropCompleted(new DropCompletedEventArgs()); Assert.AreEqual(1, counter); }
private void DisconnectFromRecognizers() { if (ManipulationSystem.Instance == null) { Debug.LogError("Manipulation system not found in scene."); return; } DragGestureRecognizer dragGestureRecognizer = ManipulationSystem.Instance.DragGestureRecognizer; if (dragGestureRecognizer != null) { dragGestureRecognizer.onGestureStarted -= OnGestureStarted; } PinchGestureRecognizer pinchGestureRecognizer = ManipulationSystem.Instance.PinchGestureRecognizer; if (pinchGestureRecognizer != null) { pinchGestureRecognizer.onGestureStarted -= OnGestureStarted; } TapGestureRecognizer tapGestureRecognizer = ManipulationSystem.Instance.TapGestureRecognizer; if (tapGestureRecognizer != null) { tapGestureRecognizer.onGestureStarted -= OnGestureStarted; } TwistGestureRecognizer twistGestureRecognizer = ManipulationSystem.Instance.TwistGestureRecognizer; if (twistGestureRecognizer != null) { twistGestureRecognizer.onGestureStarted -= OnGestureStarted; } TwoFingerDragGestureRecognizer twoFingerDragGestureRecognizer = ManipulationSystem.Instance.TwoFingerDragGestureRecognizer; if (twoFingerDragGestureRecognizer != null) { twoFingerDragGestureRecognizer.onGestureStarted -= OnGestureStarted; } }
public void UserSpecifiedTextIsntOverwritten() { var dragRec = new DragGestureRecognizer(); var element = new Label() { Text = "WRONG TEXT" }; dragRec.DragStarting += (_, args) => { args.Data.Text = "Right Text"; }; var returnedArgs = dragRec.SendDragStarting(element); Assert.AreEqual("Right Text", returnedArgs.Data.Text); }
public void HandledTest() { string testString = "test String"; var dragRec = new DragGestureRecognizer(); var element = new Label() { Text = testString }; element.Text = "Text Shouldn't change"; var args = new DragStartingEventArgs(); args.Handled = true; args.Data.Text = "Text Shouldn't change"; dragRec.SendDragStarting(element); Assert.AreNotEqual(args.Data.Text, testString); }
public void PropertySetters() { var dragRec = new DragGestureRecognizer(); Command cmd = new Command(() => { }); var parameter = new Object(); dragRec.CanDrag = true; dragRec.DragStartingCommand = cmd; dragRec.DragStartingCommandParameter = parameter; dragRec.DropCompletedCommand = cmd; dragRec.DropCompletedCommandParameter = parameter; Assert.AreEqual(true, dragRec.CanDrag); Assert.AreEqual(cmd, dragRec.DragStartingCommand); Assert.AreEqual(parameter, dragRec.DragStartingCommandParameter); Assert.AreEqual(cmd, dragRec.DropCompletedCommand); Assert.AreEqual(parameter, dragRec.DropCompletedCommandParameter); }
public void UserSpecifiedImageIsntOverwritten() { var dragRec = new DragGestureRecognizer(); var element = new Image() { Source = "http://www.someimage.com" }; FileImageSource fileImageSource = new FileImageSource() { File = "yay.jpg" }; dragRec.DragStarting += (_, args) => { args.Data.Image = fileImageSource; }; var returnedArgs = dragRec.SendDragStarting(element); Assert.AreEqual(fileImageSource, returnedArgs.Data.Image); }
protected override void Init() { Label testResult = new Label() { AutomationId = "Result", Text = "Running" }; var drag = new DragGestureRecognizer(); drag.DropCompleted += (_, __) => { if (testResult.Text == "Running") { testResult.Text = "Success"; } }; BoxView boxView = new BoxView() { HeightRequest = 200, WidthRequest = 1000, BackgroundColor = Color.Purple, GestureRecognizers = { drag }, AutomationId = "DragBox" }; var dropGestureRecognizer = new DropGestureRecognizer(); dropGestureRecognizer.DragOver += (_, args) => { args.AcceptedOperation = DataPackageOperation.None; }; dropGestureRecognizer.Drop += (_, args) => { testResult.Text = "Fail"; }; BoxView boxView2 = new BoxView() { HeightRequest = 200, WidthRequest = 1000, BackgroundColor = Color.Pink, AutomationId = "DropBox" }; boxView2.GestureRecognizers.Add(dropGestureRecognizer); Content = new StackLayout() { Children = { boxView, boxView2, new Label() { Text = "Drag the top box to the bottom one. The drop operation for the bottom box should be disabled.", AutomationId = "TestLoaded" }, testResult } }; }
public static DragGestureRecognizer DropCompletedCommandParameter(this DragGestureRecognizer drag, object parameter) { drag.DropCompletedCommandParameter = parameter; return(drag); }
public static DragGestureRecognizer DropCompletedCommand(this DragGestureRecognizer drag, ICommand command, object parameter) { return(drag.DropCompletedCommand(command).DropCompletedCommandParameter(parameter)); }
public static DragGestureRecognizer CanDrag(this DragGestureRecognizer drag, bool canDrag) { drag.CanDrag = canDrag; return(drag); }
private void OnDraging(DragGestureRecognizer gesture) { OnDrag(gesture.MoveDelta); }
public EnablingAndDisablingGestureTests() { Title = "Enabling and Disabling Gestures"; StackLayout stackLayout = new StackLayout(); CollectionView collectionView = new CollectionView(); collectionView.ItemsUpdatingScrollMode = ItemsUpdatingScrollMode.KeepScrollOffset; ObservableCollection <string> observableCollection = new ObservableCollection <string>(); collectionView.ItemsSource = observableCollection; Image imageSource = new Image() { Source = "coffee.png", BackgroundColor = Color.Green }; Image imageDestination = new Image() { BackgroundColor = Color.Purple, HeightRequest = 50, WidthRequest = 50 }; Button addRemoveDragGesture = new Button() { Text = "Add/Remove Drag Gesture", Command = new Command(() => { var dragGestureRecognizer = imageSource.GestureRecognizers.OfType <DragGestureRecognizer>() .FirstOrDefault(); if (dragGestureRecognizer != null) { imageSource.GestureRecognizers.Remove(dragGestureRecognizer); } else { var dragGesture = new DragGestureRecognizer() { CanDrag = true }; dragGesture.DragStarting += (_, args) => { observableCollection.Insert(0, $"DragStarting"); }; dragGesture.DropCompleted += (_, args) => { observableCollection.Insert(0, $"DropCompleted"); }; imageSource.GestureRecognizers.Add(dragGesture); } }) }; Button toggleCanDrag = new Button() { Text = "Toggle Can Drag", Command = new Command(() => { var dragGestureRecognizer = imageSource.GestureRecognizers.OfType <DragGestureRecognizer>() .FirstOrDefault(); if (dragGestureRecognizer != null) { dragGestureRecognizer.CanDrag = !dragGestureRecognizer.CanDrag; } }) }; Button addRemoveDropGesture = new Button() { Text = "Add/Remove Drop Gesture", Command = new Command(() => { var dropGestureRecognizer = imageDestination.GestureRecognizers.OfType <DropGestureRecognizer>() .FirstOrDefault(); if (dropGestureRecognizer != null) { imageDestination.GestureRecognizers.Remove(dropGestureRecognizer); } else { var dropGesture = new DropGestureRecognizer() { AllowDrop = true }; dropGesture.Drop += (_, args) => { observableCollection.Insert(0, $"Drop"); }; dropGesture.DragOver += (_, args) => { observableCollection.Insert(0, $"DragOver"); args.AcceptedOperation = DataPackageOperation.Copy; }; imageDestination.GestureRecognizers.Add(dropGesture); } }) }; Button toggleCanDrop = new Button() { Text = "Toggle Can Drop", Command = new Command(() => { var dropGestureRecognizer = imageDestination.GestureRecognizers.OfType <DropGestureRecognizer>() .FirstOrDefault(); if (dropGestureRecognizer != null) { dropGestureRecognizer.AllowDrop = !dropGestureRecognizer.AllowDrop; } }) }; stackLayout.Children.Add(imageSource); stackLayout.Children.Add(addRemoveDragGesture); stackLayout.Children.Add(toggleCanDrag); stackLayout.Children.Add(imageDestination); stackLayout.Children.Add(addRemoveDropGesture); stackLayout.Children.Add(toggleCanDrop); stackLayout.Children.Add(collectionView); Content = stackLayout; }
public static DragGestureRecognizer DropCompletedCommand(this DragGestureRecognizer drag, ICommand command) { drag.DropCompletedCommand = command; return(drag); }
protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.View> e) { base.OnElementChanged(e); var viewGesture = (ViewGestures)Element; var tapGestureRecognizer = new TapGestureRecognizer() { OnTouchesBegan = ((x, y) => viewGesture.OnTouchBegan(x, y)), OnTouchesEnded = (() => viewGesture.OnTouchEnded()), OnTap = ((x, y) => viewGesture.OnTap(x, y)), }; var longPressGestureRecognizer = new LongPressGestureRecognizer(() => viewGesture.OnLongTap()) { OnTouchesBegan = ((x, y) => viewGesture.OnTouchBegan(x, y)), OnTouchesEnded = (() => viewGesture.OnTouchEnded()), }; #region SwipeGestureRecognizer var swipeLeftGestureRecognizer = new SwipeGestureRecognizer(() => viewGesture.OnSwipeLeft()) { Direction = UISwipeGestureRecognizerDirection.Left, OnTouchesBegan = ((x, y) => viewGesture.OnTouchBegan(x, y)), OnTouchesEnded = (() => viewGesture.OnTouchEnded()), }; var swipeRightGestureRecognizer = new SwipeGestureRecognizer(() => viewGesture.OnSwipeRight()) { Direction = UISwipeGestureRecognizerDirection.Right, OnTouchesBegan = ((x, y) => viewGesture.OnTouchBegan(x, y)), OnTouchesEnded = (() => viewGesture.OnTouchEnded()), }; var swipeUpGestureRecognizer = new SwipeGestureRecognizer(() => viewGesture.OnSwipeUp()) { Direction = UISwipeGestureRecognizerDirection.Up, OnTouchesBegan = ((x, y) => viewGesture.OnTouchBegan(x, y)), OnTouchesEnded = (() => viewGesture.OnTouchEnded()), }; var swipeDownGestureRecognizer = new SwipeGestureRecognizer(() => viewGesture.OnSwipeDown()) { Direction = UISwipeGestureRecognizerDirection.Down, OnTouchesBegan = ((x, y) => viewGesture.OnTouchBegan(x, y)), OnTouchesEnded = (() => viewGesture.OnTouchEnded()), }; #endregion #region DragGestureRecognizer var dragGestureRecognizer = new DragGestureRecognizer() { OnTouchesBegan = ((x, y) => viewGesture.OnTouchBegan(x, y)), OnTouchesEnded = (() => viewGesture.OnTouchEnded()), OnDrag = ((x, y) => viewGesture.OnDrag(x, y)), }; //from iOS Developer Library (Gesture Recognizers) //...For your view to recognize both swipes and pans, you want the swipe gesture recognizer to analyze the touch event before the pan gesture recognizer does... if ((viewGesture.SupportGestures & ViewGestures.GestureType.gtSwipeLeft) != 0) dragGestureRecognizer.RequireGestureRecognizerToFail(swipeLeftGestureRecognizer); if ((viewGesture.SupportGestures & ViewGestures.GestureType.gtSwipeRight) != 0) dragGestureRecognizer.RequireGestureRecognizerToFail(swipeRightGestureRecognizer); if ((viewGesture.SupportGestures & ViewGestures.GestureType.gtSwipeUp) != 0) dragGestureRecognizer.RequireGestureRecognizerToFail(swipeUpGestureRecognizer); if ((viewGesture.SupportGestures & ViewGestures.GestureType.gtSwipeDown) != 0) dragGestureRecognizer.RequireGestureRecognizerToFail(swipeDownGestureRecognizer); #endregion if (e.NewElement == null) { if (tapGestureRecognizer != null) this.RemoveGestureRecognizer(tapGestureRecognizer); if (longPressGestureRecognizer != null) this.RemoveGestureRecognizer(longPressGestureRecognizer); if (swipeLeftGestureRecognizer != null) this.RemoveGestureRecognizer(swipeLeftGestureRecognizer); if (swipeRightGestureRecognizer != null) this.RemoveGestureRecognizer(swipeRightGestureRecognizer); if (swipeUpGestureRecognizer != null) this.RemoveGestureRecognizer(swipeUpGestureRecognizer); if (swipeDownGestureRecognizer != null) this.RemoveGestureRecognizer(swipeDownGestureRecognizer); if (dragGestureRecognizer != null) this.RemoveGestureRecognizer(dragGestureRecognizer); } if (e.OldElement == null) { this.AddGestureRecognizer(tapGestureRecognizer); this.AddGestureRecognizer(longPressGestureRecognizer); this.AddGestureRecognizer(swipeLeftGestureRecognizer); this.AddGestureRecognizer(swipeRightGestureRecognizer); this.AddGestureRecognizer(swipeUpGestureRecognizer); this.AddGestureRecognizer(swipeDownGestureRecognizer); this.AddGestureRecognizer(dragGestureRecognizer); } }
public static DragGestureRecognizer DragStartingCommand(this DragGestureRecognizer drag, ICommand command) { drag.DragStartingCommand = command; return(drag); }