The panup and pandown events in Ionic 2 seem to be malfunctioning

In my Ionic 2 project, I am currently working on implementing a drag and drop feature. To achieve this, I have utilized the following event in Ionic 2:

<div  (press) = "onDragInit(item, $event)"
      (panstart)="dragStart($event)"
      (panup)="onDrag($event)"
      (pandown)="onDrag($event)"
      (panend)="onDragEnd($event)"
      (pressup)="pressUpEvent($event)">
</div>

The issue that arises is that the panup and pandown events do not function correctly initially.

If we perform a horizontal movement first, both events work as expected. However, if we execute a vertical movement first, neither event works until a horizontal movement is performed. Have any of you encountered this problem?

Below is an excerpt from my .ts file:

public onDragInit(doc, event): void {
    if(!doc.isSelected){
        return;
    }

    // Hide selected documents when initiating drag
    this.docs.forEach( (doc: any) => {
        if(doc.isSelected){
            doc.dragging = true;
            this.draggingDocs.push(doc);
        }else{
            doc.dragging = false;
        }
    });
    this.dragPoint = this.getDragPoint(event.center.x, event.center.y);
    this.docDragging = true;
    this.destination = this.getDroppableDoc(event.center.x,event.center.y);

    event.preventDefault()
}

public dragStart(event: any): void {
    if(!this.docDragging){
        return ;
    }
    event.preventDefault();
}

public onDrag(event: any):void {
    if(!this.docDragging){
        return ;
    }

    this.dragPoint = this.getDragPoint(event.center.x, event.center.y);
    let placeForDrop = this.getDroppableCar(event.center.x, event.center.y);
    if(placeForDrop != null && placeForDrop.doc != null){
        this.destination = placeForDrop;
    }

    event.preventDefault();
}

public onDragEnd(event: any): void {
    if(this.destination && this.destination.doc){
        this.onDrop.emit({draggingDocs: this.draggingDocs,destination: this.destination});
    }

    this.cancelDragging();
    event.preventDefault();
}

public pressUpEvent(event: any): void {
    this.cancelDragging();
    event.preventDefault();
}

Answer №1

After much research, I have discovered a solution to this issue. Angular 2 offers a token known as HAMMER_GESTURE_CONFIG which is capable of accepting a type called HammerGestureConfig.

To implement this solution, we can simply create an extension of the HammerGestureConfig like so:

// Customize default hammer.js settings.

import { HammerGestureConfig } from "@angular/platform-browser";

export class CustomHammerConfig extends HammerGestureConfig {
  public overrides = {
    "pan": { direction: 30 },
    "press": { time: 300 }
  };
}

Don't forget to include this in the providers section:

providers: [
    { provide: HAMMER_GESTURE_CONFIG, useClass: CustomHammerConfig },
  ]

For more information, you can refer to this article on Angular 2 events.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is it possible that Angular 1.0.8 code is incompatible with version 1.6.5?

Just started dabbling in angular-js today and decided to experiment with some older examples. I have a backend api that provides me with a json list. I am trying to fetch this data and display it on my webpage. The examples I found were built using versi ...

Convert all relative path URLs in images to absolute paths using either PHP, javascript, or jQuery

I am looking to transform any relative URL found on a webpage, with the main intention of resolving issues related to images not being displayed. The goal is to convert these relative URLs into absolute URLs. For example: From <img src="/folder/folder ...

Change the anchor text dynamically with JQuery

The page contains href links with incomplete text. For example, the link text displayed on the page is "link1", but it should actually be "link1 - Module33". Both the page text and actual text start with the same initial text ("link1" in this case). I retr ...

In ReactJS, the process of rendering a functional component differs from that of a class component

I have a class component that looks like this: import { Component } from 'react'; import { DEFAULT_HPP, DEFAULT_PAGE, DEFAULT_QUERY, PARAM_HPP, PARAM_PAGE, PARAM_SEARCH, PATH_BASE, PATH_SEARCH, } from '../../constants'; ...

Step-by-step guide on deploying your Nestjs API on Google App Engine

Encountering a hurdle while trying to deploy my nestjs api on Google App Engine has left me puzzled. Despite initializing my google cloud project with the google sdk, an error thwarted my progress. To tackle this challenge, I made key adjustments in my cod ...

What is the best way to implement a Semantic UI radio group in a React component using the State Hook?

I've been attempting to create a radio button group using Semantic UI within React. While I was able to successfully implement the Radio Group example from the Radio page by extending Component, I encountered challenges when trying to rewrite it using ...

Steps for canceling a promise using $resource in AngularJS version 1.5

I am currently using angular 1.5.7 and I am facing an issue where a delete operation on a resource is taking too long to complete. I am working with a MEAN stack and there are times when the delete operation appears to be pending, making me wonder if Mongo ...

The Radio Button's value appears in a distinct way on Ionic Angular

I am currently working with the Ionic framework and I am trying to display data values on radio buttons. However, I am facing difficulties in retrieving the correct value and setting it appropriately. index.html <td> <label>{{learn ...

Transforming Json strings with html tags into usable html with Firebase

After spending nearly 2 hours researching, I still haven't found a simple solution to convert a JSON string containing HTML tags so that it can be displayed on a webpage without showing the tags in raw format. Even though this string <h1>Magazi ...

When working with React and trying to update data using the useEffect hook, I encountered an issue with an Array data. Unfortunately, using map or Object.keys(data).map did not produce the desired results. Can anyone provide guidance on

After using the useEffect hook to update the data, I noticed that the data is an array when inspected in the DEV tools. However, when attempting to traverse the data using the map function, an error stating 'data.map is not a function' is returne ...

Exploring Protractor testing with Bootstrap modals

I'm having an issue testing a bootstrap modal. Here's the scenario: Click on a button to display the modal The modal body has a list of buttons When I click on one of them, it doesn't do anything My Protractor code snippet: element(by. ...

What is the method for selecting an element using CSS code in Protractor?

Having trouble clicking on the element with CSS Selector: <button _ngcontent-c16="" class="btn btn-flat btn-no-text btn-kebab-view"> <i _ngcontent-c16="" class="zmdi zmdi-more-vert"></i> </button> This is what I've t ...

The function of React's useState is not available

https://i.sstatic.net/ltglP.png This error is new to me and I'm unsure why my code isn't working correctly. I noticed a similar example on the React.js Org website. Can someone please explain what's happening in my code? Any help would be ...

Error message: The requested resource in Golang does not have an 'Access-Control-Allow-Origin' header present, which means that the origin 'null' is not permitted to access it

I am currently experimenting with checking if a domain A client can send a domain B cookie to domain B. Here is the Go code I am using: package main import ( "fmt" "net/http" "log" "time" "encoding/json" ) func setCookie(w http.Resp ...

What is the method for enlarging an element without regard to surrounding elements?

I am working on a code where I want the element to zoom in when hovered, completely disregarding its normal flow. By "ignoring its flow," I mean that other elements like tags might obstruct parts of its content. https://i.sstatic.net/NBoez.png https:// ...

Unexpected issue encountered for identifiers beginning with a numerical digit

Is it possible to select an element from a page with an id that begins with a number? $('#3|assets_main|ast_module|start-iso-date') Upon attempting to do so, the following error occurs: Uncaught Error: Syntax error, unrecognized expression: ...

Node.js and Express: Delivering Seamless Video Streaming via HTTP 206 Partial Content

Having a binary file like an mp4 video in a MarkLogic database, I am utilizing the Node.js API of the database to stream this document in segments. The structure is as follows: html document <video controls="controls" width="600"> <source src= ...

Determine the total number of arrays present in the JSON data

I'm currently working on a straightforward AngularJS project, and here's the code I have so far: This is my view: <tr ng-repeat="metering in meterings"> <td>1</td> <td>{{metering.d.SerialNumber}}</td> ...

What are the best techniques for achieving flawless ring geometry in three.js?

I'm struggling to achieve perfect ring geometry in three.js, similar to the image here: https://i.sstatic.net/ArxKa.png After spending over a day troubleshooting, my code currently looks like this: var scene = new THREE.Scene(); var camera = new TH ...

Select an option from the dropdown menu to populate the contents of the second dropdown list

The provided code dynamically populates the initial dropdown list with unique pants brands: $.each(pantsBrands, function(i){ var li = $('<li>') .appendTo(pantsList); var aaa = $('<a>') .text(pantsBra ...