Add touch backend for mobile devices

This commit is contained in:
Aarni Halinen
2022-07-22 01:52:09 +03:00
parent 9c6e771b1c
commit 9fe0390f0d
4 changed files with 34 additions and 2 deletions
@@ -1,6 +1,7 @@
import React from "react";
import { DndProvider } from "react-dnd";
import { HTML5Backend } from "react-dnd-html5-backend";
import { TouchBackend } from "react-dnd-touch-backend";
import styled from "styled-components";
import shortid from "shortid";
import colors from "@theme/colors";
@@ -62,9 +63,20 @@ const SignupQuestionsWidget: React.FC<SignupQuestionsWidgetProps> = ({ value, on
const questions: SignupFormQuestion[] = JSON.parse(value);
// simple way to check whether the device support touch (it doesn't check all fallback, it supports only modern browsers)
const isTouchDevice = () => {
if ("ontouchstart" in window) {
return true;
}
return false;
};
// Assigning backend based on touch support on the device
const backendForDND = isTouchDevice() ? TouchBackend : HTML5Backend;
return (
<Widget>
<DndProvider backend={HTML5Backend}>
<DndProvider backend={backendForDND}>
<QuestionList
questions={questions}
onChange={onValueChange}