How is it possible that the sensitivity of the mobile slideshow is malfunctioning specifically when accessed through the Chrome browser in React?

My React web app features a carousel component that functions perfectly on Firefox. However, in Chrome on mobile devices, when I swipe down the page, it interprets it as a horizontal swipe and switches slides on the slideshow. The library I am using is called react-material-ui-carouse, which only offers props to enable or disable sliding functionality. I couldn't find any information in the documentation about adjusting slide sensitivity. Is there a feasible solution to resolve this issue, or would it be more advisable to avoid using this library? You can visit the website to experience the problem firsthand on a mobile device.

Slideshow.jsx

function Slideshow() {
  const fadeImages = [
    {
      src: "/images/allie-pic.webp",
      title: "First Slide",
      caption:
        "Slide1",
    },
    {
      src: "/images/image-2.jpg",
      title: "Second Slide",
      caption:
        "Slide2",
    },
    {
      src: "/images/image-3.webp",
      title: "Third Slide",
      caption:
        "Slide3",
    },
  ];

  return (
    <Carousel
      swipe={true}
      autoPlay={false}
      fullHeightHover={false}  
     
    >
      {fadeImages.map((img, i) => (
        <Item key={i} img={img} />
      ))}
    </Carousel>
  );
}

function Item({ img }) {
  return (
    <Stack alignItems="center">
      <Typography variant="h1">
        {img.title}
      </Typography>
      <Typography variant="body1">{img.caption}</Typography>
      <img     
        src={img.src}
      ></img>
    </Stack>
  );
}
export default Slideshow;

Answer №1

If you find yourself in a situation similar to the original poster and me, where you've spent time customizing react-material-ui-carousel and don't want to switch to another library, here is a workaround that I came up with. It may not be ideal (since react-material-ui-carousel lacks a sensitivity setting), but it gets the job done.

The solution involves incorporating react-swipeable to intercept the swipe action (disabling swipe on the carousel) and then directing the action to click on the navigation buttons within the carousel. To make this work, the buttons must be specified with a ref. Check out the example below.

import { useRef } from 'react';

import { BiLeftArrowAlt, BiRightArrowAlt } from 'react-icons/bi';
import { VscCircleFilled } from 'react-icons/vsc';
import Carousel from 'react-material-ui-carousel';
import { useSwipeable } from 'react-swipeable';

const SWIPE_SENSITIVITY = 75;

export const SwipeableCarousel = ({ children }) => {

  const prev = useRef(null);
  const next = useRef(null);

  const swipeHandlers = useSwipeable({
    onSwipedRight: () => prev?.current?.click(),
    onSwipedLeft: () => next?.current?.click(),
    delta: SWIPE_SENSITIVITY,
  });

  return (
    <div {...swipeHandlers}>
      <Carousel
        swipe={false}
        fullHeightHover={false}
        animation="slide"
        autoPlay={false}
        navButtonsAlwaysVisible
        PrevIcon={
          <div ref={prev} style={{ height: '30px' }}>
            <BiLeftArrowAlt />
          </div>
        }
        NextIcon={
          <div ref={next} style={{ height: '30px' }}>
            <BiRightArrowAlt />
          </div>
        }
      >
        {...children}
      </Carousel>
    </div>
  );
};

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

Despite enabling CORS in Express, I am still encountering CORS errors

Utilizing both React and Express, below is the code snippet in Express: const express = require("express") const bodyParser = require("body-parser") const { connection } = require("./db/connection") const user = require(" ...

What is the best way to show a confirmation message in a pop-up after submitting a contact form?

I've been struggling to create a contact form that shows a thank you message upon submission, rather than redirecting to the contact.php file with no styling. You can see an example of what I'm trying to achieve on this link: http://madaxedesign. ...

Choose only the values that start with a letter in the autocomplete list

I am currently utilizing the datalist feature for my autocomplete field. Everything is functioning properly. In my list, I have the values james, reeta, and mary. For example, if I type in "r" in the autocomplete box, it shows both reeta and mary because ...

Codeigniter's email functionality struggles to successfully deliver HTML-rendered content to Yahoo and LiveMail

Our codeigniter site utilizes the CI mail library to send emails. While Gmail displays the emails properly formatted, Hotmail and Yahoo only show the raw HTML code. The HTML template is called from a file named: emailer_temp.php <!DOCTYPE> < ...

Utilize v-for to dynamically showcase a variety of images on your

My goal is to showcase several JPG pictures located in the src/assets/images folder by utilizing the v-for directive. However, it seems like the browser is having trouble locating them. Interestingly, manually adding the pictures with the same paths works ...

Generating a file using buffer information in node.js

From the front-end client side, I am sending a file to the server. On the server-side, the data received looks something like this: { name: 'CV-FILIPECOSTA.pdf', data: <Buffer 25 50 44 46 2d 31 2e 35 0d 25 e2 e3 cf d3 0d 0a 31 20 30 20 6f 6 ...

Executing an HTTP request with JavaScript to interact with Salesforce

Looking to connect Salesforce with Recosence, an external system. The scenario involves Recosense pushing data to Salesforce for storage. I have successfully created a post HTTP service and tested it in Postman, which generates an access token and records ...

Tips for creating a versatile generic function in javascript that covers all arguments sizes

When working with node.js, a tcp server typically has several methods for listening: server.listen(port, [host], [backlog], [listeningListener]) server.listen(path, [listeningListener]) server.listen(handle, [listeningListener]) In the context of creatin ...

Set a value for the getter

In the component, I have a getter that looks like this: public get canSave(): boolean { const isValid = this.rows.every(r => r.phoneControl.valid); if (!isValid) { return false; } const changes = this.managePhonesPopupServic ...

Adjusting the size, position, and dimensions of image and text divs as the browser window is resized

I am struggling to find a solution to what seems like a common question but unfortunately haven't been able to locate an answer on Google. Any assistance would be greatly appreciated. My website features a full-size resizable background image using t ...

Is there a way to intercept and control mousewheel scrolling before it occurs?

I am in search of a way to intercept the event triggered by a mousewheel scroll right before it occurs, in order to prevent the scroll action, execute certain tasks, and then allow the user to regain control. Currently, I have the following code set up to ...

What steps can be taken to address the JavaScript error that states: Error : TypeError: $("j2t-temp-div").down(".j2t_ajax_message") is not defined?

If you want to see the issue in action, please visit this link. To replicate this error, choose a "Color" and "Size", then click "Add to Cart". While the "loading..." dialog box is still visible, click on the shade to close it. Quickly click on any other ...

Rails 3.2 - form mistakenly submitted repeatedly

I am working on a project involving the Box model, which includes many box_videos. I have created an edit form to allow users to add box_videos to the box after it has been created: <%= form_tag "/box_videos", { method: :post, id: "new_box_videos", rem ...

The conclusion of jQuery's nested animation

Functioning, But Page Transitions Inconsistent What I Believe to be the Correct Approach, But Event Triggering Issue Currently, I am experimenting with page transitions and utilizing bind() to detect the end of the CSS event transition. When a class is ad ...

What is the best way to fill a div on the parent HTML/PHP page using data from an AJAX-loaded child

Imagine you have an index.php file with HTML content like this: <div id="navigation"> <ul> <li id="registerLink"><a href="#">Register</a></li> </ul> </div> <div id="mainContent"> </div> ...

``It appears that there is an issue with the functionality of react-bootstrap-multiselect at

import React from 'react'; import Multiselect from 'react-bootstrap-multiselect'; class Test2 extends React.Component { constructor(props){ super(props) this.state = { list: [{value:'One',selected:true},{value ...

An error occurred in Typescript's map() function: The element is implicitly of type 'any' because the expression 'string' cannot be used to index the type

I am currently working with an array (iotDatas) that consists of the following interface: interface iotData { id: string; device_id: string; color: number; ph: number created_at: string; } Within my state, I have a selector to choose between the &apo ...

Utilizing Angular 9's inherent Ng directives to validate input components within child elements

In my current setup, I have a text control input component that serves as the input field for my form. This component is reused for various types of input data such as Name, Email, Password, etc. The component has been configured to accept properties like ...

Having trouble sending a GET request from the client to my backend route using axios in a React-Node.js/Express setup. Where did I go wrong?

Struggling with making an API request from my backend route (using nodes/express). I'm making an axios request from the client site using React. The express backend route works fine, so the issue must be in my client-side code. I've been stuck on ...

Having an issue with my Django model not properly saving data when receiving a POST

Just dipping my toes into the world of ajax and Django, so please bear with me for my messy code. I'm facing an issue where my Django model is not saving the response even after receiving a POST request. I'm attempting to create a simple like/di ...