When quickly swiping, the button may not respond to the initial click

I'm currently developing an angular application that features a responsive navigation using the angular navbar. To ensure smooth navigation, I have implemented swipe gestures by utilizing hammer.js. Swiping right reveals the menu, while swiping left hides it.

However, I've encountered an issue where if the user swipes quickly to the right (at a normal smartphone speed), the navigation buttons don't respond to the first click, only registering on the second attempt. Interestingly, when the swipe is performed slowly, the buttons function as expected. Additionally, manually toggling the menu using the toggle button works without any problems.

See this example gif for reference (first slow, then fast): https://i.sstatic.net/c2bYe.gif

This bug seems to occur specifically when using the "toggle device toolbar" in Chrome and selecting a device, as well as on my Android 9 device with Chrome for Android. It does not happen when simply resizing the browser window.

The app.component.html code snippet:

<mat-sidenav-container>
  <mat-sidenav #sidenav fxLayout="column" mode="side" opened="false" class="hidelarge sidenav">
    <mat-nav-list fxLayout="column">
      <!-- Navigation links here -->
    </mat-nav-list>
  </mat-sidenav>
  <mat-sidenav-content fxFlexFill  (swiperight)="sidenav.open()" (swipeleft)="sidenav.close()" >
    <app-header (navToggle)="sidenav.toggle()">

    </app-header>
    <main class="minheight">
      <router-outlet></router-outlet>
    </main>
    <app-footer>

    </app-footer>

  </mat-sidenav-content>
</mat-sidenav-container>

And in my app.module.ts file:

...
export class MyHammerConfig extends HammerGestureConfig {
  overrides = <any>{
    // Customized hammerjs configuration
    'swipe': { direction: Hammer.DIRECTION_HORIZONTAL },
    'pinch': { enable: false },
    'rotate': { enable: false },
    'pan': { enable: false },
    'tap': { enable: false },
    'press':{enable:false},
    'doubletap':{enable:false},
  };
}
...
providers: [
    { provide: HAMMER_GESTURE_CONFIG, useClass: MyHammerConfig }
  ],
...

I imported hammer.js in my main.ts like so:

import 'hammerjs';

Answer №1

I recently faced a similar issue and found a solution that may work for you as well. When swiping, it triggers a click event which shifts the focus to the right side of the view. For example, clicking on 'Music' causes the view to shift focus from the right back to the 'Music' button. You can try preventing this by adjusting the click event based on the swipe movement. Although the code is from AngularJs, it should have a similar effect.

<div ng-swipe-left="swipeFunc(); swiping=true;" ng-click="swiping ? ( swiping = false ) : clickFunc();">
  ...
</div>

Check out this answer on stackoverflow
Feel free to let me know if this solution works for your scenario.

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

Why Does Angular's ngIf Always Result in a Negation to True?

Can someone please clarify this for me? I'm having trouble understanding why the *ngIf condition and else statement always evaluate to true unless I am completely mistaken. Here is the situation: I have an icon that should turn the background color t ...

Upon successfully logging into the app, Azure AD B2C integrated with MSAL and Angular will automatically redirect users to the login page

I recently updated my Angular app to make it accessible to customers by switching from ADAL to MSAL for authentication. I configured the app with Azure AD B2C credentials and everything seems to be working smoothly, except for one issue. When I try to logi ...

Is there a way to determine the return type without using a type variable?

I am striving to develop a function that can clone an array while maintaining the original data types. The current issue I am facing is that TypeScript is declaring the return type as any: export function cloneArray(inputArray) { return [...inputArray ...

Combining Vue2 with Typescript can sometimes result in a missing field in an object when assigning a Prop to

If I am using TypeScript version 4.1 and have a component structured like this. @Component export default class Test extends Vue { @Prop() private msg!: string; private testObj={ msg: this.msg, test: 123 } created(){ console.log(JSON. ...

Does it follow standard practice for Array.filter to have the capability to also perform mapping on an array of objects?

While experimenting with Array.filter, I made an interesting discovery. By forgetting to include an equality check, my array was unexpectedly mapped instead of filtered. Here is the code snippet that led to this result: const x = [{ name: 'user' ...

Transform Text into Numeric Value/Date or Null if Text is Invalid

Consider the TypeScript interface below: export interface Model { numberValue: number; dateValue: Date; } I have initialized instances of this interface by setting the properties to empty strings: let model1: Model = { numberValue: +'', ...

What is the reason behind Angular Material sort buttons showing arrows, yet failing to actually sort the columns?

Looking to make my table sortable, I've been using the https://material.angular.io/components/sort/overview. The "Sort Header" feature is working on other tables in the web-app, I've gone through the documentation, watched tutorials, but for some ...

Merge two functions that are alike into a single function

I am faced with a challenge of combining two similar functions that have some minor differences: private filterByOperationType() { let operationBuffer: IProductOperation[] = []; if (this.filterConditions[0].selected.length > 0) { operation ...

Guide to starting the Angular 2 server within ASP.NET MVC

As a newcomer to Angular 2, I am following the quickstart tutorial step by step which can be found here: this In my learning process, I have come across the concept of starting the server when using Angular 2 with the following command: npm start This a ...

Refresh menu when automatically logged in using Firebase on Ionic/Angular

I currently have a slide menu set up in my app.component that includes a Link to a login page and a logout button. The visibility of these buttons is toggled using *ngIf, which checks whether there is a user logged in by utilizing firebase.auth().currentUs ...

Can you suggest a way to revise this in order to include the type of property (string)?

Here is a snippet of working code that raises a question about refactoring to improve the readability and functionality. Consider renaming the method to isPropValueSame. import * as _ from 'lodash'; const diff = _.differenceWith(sourceList, comp ...

Exploring nested JSON responses in Angular 2 with TypeScript

Below is the JSON response I received from the REST endpoint: {"image_2_11_0-51-upgrade.iso": {"model": "somemodel", "hostnames": ["abc.com", "abcd,com"], "upload_status": false, "version": "2.11.0-51"}, "image_2_11_0-51-upgrade.iso": {"model": "newmo ...

Tips for testing FormGroupDirective within a component

I am facing difficulties in testing a component with FormGroupDirective in the viewProviders section. I am unable to create a mock of the parent and set an empty formGroup. The component code is as follows: @Component({ (...) viewProviders: [ ...

Is there a way to prevent the user from proceeding to the next step if they haven't finished the initial one?

After successfully creating a multi-step form using shadcn, react-hook form, and zod, I encountered an issue. Even if I haven't completed the input fields, I can still proceed to the next step by clicking the next button. Appointment.ts export const ...

Change the http observable response to an array that can be used with ngFor

My goal is to dynamically load select options based on an API response, using observables in Angular 5 for HTTP requests. However, when trying to parse the response into select options, I encountered the following error: Cannot find a differ supporting o ...

Assign Angular FromControl value to set the value of a select input

Seeking assistance on setting the initial value of the select dropdown below. I have attempted to do so through my formControl, but the value in the form is accurate while not reflecting in the view. HTML : <mat-form-field> <mat-select name="an ...

Utilizing NgRx 8 Actions in Conjunction with NgRx 7 Reducers: An Implementation

In the development of my new Angular 8 project, I have incorporated the NgRx library. It was mentioned to me that actions are created using createAction in NgRx 8, but reducers are built using NgRx 7. Initially, I implemented my reducer with NgRx 8, but no ...

Type validation in TypeScript through cross-referencing variables

Can TypeScript be used to define a variable that determines the type of other variables? I want to simplify the process by only needing to check one variable, stateIndicator, which is dependent on other variables to infer their types. type A = {prop1: st ...

RXJS buffering with intermittent intervals

Situation: I am receiving audio data as an array and need to play it in sequence. The data is coming in continuously, so I am using an observable to handle it. Since the data arrives faster than it can be played, I want to use a buffer to store the data w ...

Can Observable subscriptions in Angular be tested?

I'm a newcomer to angular and I'm currently working on creating unit tests for the function below. HomeComponent.ts ngOnInit() { this.msalBroadcastService.inProgress$ .pipe( filter((status: InteractionStatus) => status === ...