@@ -43,7 +43,7 @@ function Plane({ position }) {
4343 ) ;
4444}
4545
46- function Box ( { position, rotation } ) {
46+ function Box ( { position, rotation, onDrag , onDragStop } ) {
4747 const { size, viewport } = useThree ( ) ;
4848 const [ dragging , setDragging ] = useState ( false ) ;
4949 const aspect = size . width / viewport . width ;
@@ -69,7 +69,7 @@ function Box({ position, rotation }) {
6969 } else {
7070 bodyRef . current . wakeUp ( ) ;
7171 }
72- } , [ dragging ] ) ;
72+ } , [ dragging , onDrag , onDragStop ] ) ;
7373
7474 const bindDrag = useDrag (
7575 // eslint-disable-next-line
@@ -84,8 +84,10 @@ function Box({ position, rotation }) {
8484 ) ;
8585
8686 if ( dragging ) {
87+ onDrag ( ) ;
8788 setDragging ( true ) ;
8889 } else {
90+ onDragStop ( ) ;
8991 setDragging ( false ) ;
9092 }
9193
@@ -105,6 +107,15 @@ function Box({ position, rotation }) {
105107
106108export default function App ( { boxes, showPlane } ) {
107109 const [ prop , set ] = useSpring ( ( ) => ( { intensity : 0.6 , color : '#fff' } ) ) ;
110+ const [ dragging , setDragging ] = React . useState ( false ) ;
111+
112+ const setDraggingTrue = React . useCallback ( ( ) => {
113+ setDragging ( true ) ;
114+ } , [ ] ) ;
115+
116+ const setDraggingFalse = React . useCallback ( ( ) => {
117+ setDragging ( false ) ;
118+ } , [ ] ) ;
108119
109120 useEffect ( ( ) => {
110121 if ( ! boxes . length ) {
@@ -127,6 +138,7 @@ export default function App({ boxes, showPlane }) {
127138 right : 0 ,
128139 bottom : 0 ,
129140 zIndex : 0 ,
141+ touchAction : dragging ? 'none' : 'initial' ,
130142 } }
131143 >
132144 < Canvas
@@ -152,6 +164,8 @@ export default function App({ boxes, showPlane }) {
152164
153165 { boxes . map ( pos => (
154166 < Box
167+ onDrag = { setDraggingTrue }
168+ onDragStop = { setDraggingFalse }
155169 key = { pos . key }
156170 position = { pos . position }
157171 rotation = { pos . rotation }
0 commit comments