Add touch backend for mobile devices
This commit is contained in:
@@ -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}
|
||||
|
||||
Reference in New Issue
Block a user