From bbfcf7e46fe1cafc12ab4191549423f014aef391 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E4=BA=91?= <609237304@qq.com> Date: Wed, 3 Mar 2021 11:12:47 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E7=A7=BB=E5=8A=A8?= =?UTF-8?q?=E5=92=8C=E7=BC=A9=E6=94=BE=E7=9A=84=E5=9F=BA=E6=9C=AC=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- example/src/App.js | 1 + src/components/ControlBar/index.js | 35 +++++++++- src/index.js | 100 +++++++++++++++++++++++------ 3 files changed, 117 insertions(+), 19 deletions(-) diff --git a/example/src/App.js b/example/src/App.js index 706c942..06d5f43 100644 --- a/example/src/App.js +++ b/example/src/App.js @@ -46,6 +46,7 @@ const App = () => { hintOnStartup hintText="Drag to view" /> + tridiRef.current.prev()}>Prev tridiRef.current.next()}>Next tridiRef.current.toggleAutoplay(!isAutoPlayRunning)}> diff --git a/src/components/ControlBar/index.js b/src/components/ControlBar/index.js index 0d4b672..e28d6a2 100644 --- a/src/components/ControlBar/index.js +++ b/src/components/ControlBar/index.js @@ -10,6 +10,7 @@ import PlayIcon from '../../assets/icons/play.svg'; const ControlBar = ({ isPlaying, isRecording, + isMoveing, setIsPlaying, setIsRecording, onPlay, @@ -17,7 +18,11 @@ const ControlBar = ({ onNext, onPrev, onRecordStart, - onRecordStop + onRecordStop, + onZoomout, + onZoomin, + onStartMoveing, + onStopMoveing }) => { const playHandler = () => { setIsPlaying(true); @@ -39,6 +44,14 @@ const ControlBar = ({ onRecordStop(); }; + const moveStartHandler = () => { + onStartMoveing(); + }; + + const moveStopHandler = () => { + onStopMoveing(); + }; + return ( + + + + + + + + + + + {!isMoveing && ( + + + + )} + {isMoveing && ( + + + + )} ); }; diff --git a/src/index.js b/src/index.js index 9a693f1..a3af70d 100644 --- a/src/index.js +++ b/src/index.js @@ -91,18 +91,26 @@ const Tridi = forwardRef( onFrameChange, onRecordStart, onRecordStop, - onPinClick + onPinClick, + onZoom, + maxZoom, + minZoom }, ref ) => { const [moveBuffer, setMoveBuffer] = useState([]); const [hintVisible, setHintVisible] = useState(hintOnStartup); const [currentImageIndex, setCurrentImageIndex] = useState(0); + const [zoom, setZoom] = useState(1); const [isDragging, setIsDragging] = useState(false); const [isAutoPlayRunning, setIsAutoPlayRunning] = useState(false); const [isRecording, setIsRecording] = useState(false); const [recordingSessionId, setRecordingSessionId] = useState(null); const [isPlaying, setIsPlaying] = useState(false); + const [isMoveing, setIsMoveing] = useState(false); + + const [viewerImageOfset, setViewerImageOfset] = useState({ x: 0, y: 0 }); + const [moveingMouseDownPoint, setMoveingMouseDownPoint] = useState(null); const _count = Array.isArray(images) ? images.length : Number(count); const _images = TridiUtils.normalizedImages(images, format, location, _count); @@ -203,7 +211,14 @@ const Tridi = forwardRef( startDragging(); rotateViewerImage(e); } - + if (isMoveing) { + const clientX = e.clientX; + const clientY = e.clientY; + setMoveingMouseDownPoint({ + x: clientX - viewerImageOfset.x, + y: clientY - viewerImageOfset.y + }); + } if (isAutoPlayRunning && stopAutoplayOnClick) { toggleAutoplay(false); } @@ -215,9 +230,21 @@ const Tridi = forwardRef( stopDragging(); resetMoveBuffer(); } + if (moveingMouseDownPoint) { + setMoveingMouseDownPoint(null); + } }; const imageViewerMouseMoveHandler = (e) => { + if (isDragging && isMoveing && moveingMouseDownPoint) { + const clientX = e.clientX; + const clientY = e.clientY; + setViewerImageOfset({ + x: clientX - moveingMouseDownPoint.x, + y: clientY - moveingMouseDownPoint.y + }); + return; + } if (_draggable && isDragging) { rotateViewerImage(e); } @@ -440,10 +467,34 @@ const Tridi = forwardRef( onMouseLeave={imageViewerMouseLeaveHandler} onMouseEnter={imageViewerMouseEnterHandler} onClick={imageViewerClickHandler} - style={{ width: '100%' }} + style={{ + width: '100%' + }} > - {_images?.length > 0 && renderImages()} + + {_images?.length > 0 && renderImages()} + + + + {showStatusBar && ( )} @@ -451,27 +502,38 @@ const Tridi = forwardRef( { + toggleRecording(false); + setIsMoveing(true); + }} + onStopMoveing={() => { + setIsMoveing(false); + }} onPlay={() => toggleAutoplay(true)} onPause={() => toggleAutoplay(false)} onNext={() => nextMove()} onPrev={() => prevMove()} - onRecordStart={() => toggleRecording(true)} + onRecordStart={() => { + toggleRecording(true); + setIsMoveing(false); + }} onRecordStop={() => toggleRecording(false)} + onZoomout={() => { + const newZoom = Math.max(minZoom, zoom - 0.1); + setZoom(newZoom); + onZoom(newZoom); + }} + onZoomin={() => { + const newZoom = Math.min(maxZoom, zoom + 0.1); + setZoom(newZoom); + onZoom(newZoom); + }} /> )} - ); } @@ -553,7 +615,8 @@ Tridi.defaultProps = { renderPin: undefined, setPins: () => {}, renderHint: undefined, - + maxZoom: 3, + minZoom: 0.3, onHintHide: () => {}, onAutoplayStart: () => {}, onAutoplayStop: () => {}, @@ -566,7 +629,8 @@ Tridi.defaultProps = { onFrameChange: () => {}, onRecordStart: () => {}, onRecordStop: () => {}, - onPinClick: () => {} + onPinClick: () => {}, + onZoom: () => {} }; export default Tridi; From afcffd3c35fa47bcd4e1ed5fa67c0064aaae4380 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E4=BA=91?= <609237304@qq.com> Date: Thu, 4 Mar 2021 11:02:25 +0800 Subject: [PATCH 2/5] Fix the inaccuracy of scaling record coordinates --- src/index.js | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/src/index.js b/src/index.js index a3af70d..9c8b41b 100644 --- a/src/index.js +++ b/src/index.js @@ -325,12 +325,17 @@ const Tridi = forwardRef( const imageViewerClickHandler = (e) => { if (isRecording) { - const clientX = e.clientX; - const clientY = e.clientY; const viewerWidth = _viewerImageRef.current.clientWidth; const viewerHeight = _viewerImageRef.current.clientHeight; + const clientX = + (e.clientX - viewerImageOfset.x - (viewerWidth - viewerWidth * zoom) / 2) / + zoom; + const clientY = + (e.clientY - viewerImageOfset.y - (viewerHeight - viewerHeight * zoom) / 2) / + zoom; const viewerOffsetLeft = _viewerImageRef.current.getBoundingClientRect().left; const viewerOffsetTop = _viewerImageRef.current.getBoundingClientRect().top; + const x = ((clientX - viewerOffsetLeft) / viewerWidth).toFixed(6); const y = ((clientY - viewerOffsetTop) / viewerHeight).toFixed(6); const pin = { @@ -480,19 +485,18 @@ const Tridi = forwardRef( }} > {_images?.length > 0 && renderImages()} + - - {showStatusBar && ( From 081c28027917a9d486a780aea7c6b11963ac28d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E4=BA=91?= <609237304@qq.com> Date: Thu, 4 Mar 2021 16:58:25 +0800 Subject: [PATCH 3/5] update controlBar icons --- src/assets/icons/drag.svg | 8 ++++++++ src/assets/icons/move.svg | 3 +++ src/assets/icons/next.svg | 10 +++------- src/assets/icons/pause.svg | 7 ++----- src/assets/icons/play.svg | 8 +++----- src/assets/icons/previous.svg | 8 -------- src/assets/icons/stop.svg | 8 +++----- src/assets/icons/target.svg | 8 +++----- src/assets/icons/zoomIn.svg | 3 +++ src/assets/icons/zoomOut.svg | 3 +++ src/components/ControlBar/index.js | 19 +++++++++++++------ src/index.js | 3 ++- 12 files changed, 46 insertions(+), 42 deletions(-) create mode 100644 src/assets/icons/drag.svg create mode 100644 src/assets/icons/move.svg mode change 100755 => 100644 src/assets/icons/next.svg mode change 100755 => 100644 src/assets/icons/pause.svg mode change 100755 => 100644 src/assets/icons/play.svg delete mode 100755 src/assets/icons/previous.svg mode change 100755 => 100644 src/assets/icons/stop.svg mode change 100755 => 100644 src/assets/icons/target.svg create mode 100644 src/assets/icons/zoomIn.svg create mode 100644 src/assets/icons/zoomOut.svg diff --git a/src/assets/icons/drag.svg b/src/assets/icons/drag.svg new file mode 100644 index 0000000..276072e --- /dev/null +++ b/src/assets/icons/drag.svg @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/src/assets/icons/move.svg b/src/assets/icons/move.svg new file mode 100644 index 0000000..b2a8bb8 --- /dev/null +++ b/src/assets/icons/move.svg @@ -0,0 +1,3 @@ + + + diff --git a/src/assets/icons/next.svg b/src/assets/icons/next.svg old mode 100755 new mode 100644 index 6f247fc..2704f4a --- a/src/assets/icons/next.svg +++ b/src/assets/icons/next.svg @@ -1,8 +1,4 @@ - - - - - - - + + + diff --git a/src/assets/icons/pause.svg b/src/assets/icons/pause.svg old mode 100755 new mode 100644 index f478533..355b393 --- a/src/assets/icons/pause.svg +++ b/src/assets/icons/pause.svg @@ -1,6 +1,3 @@ - - - - - + + diff --git a/src/assets/icons/play.svg b/src/assets/icons/play.svg old mode 100755 new mode 100644 index b75a18a..1bb24bf --- a/src/assets/icons/play.svg +++ b/src/assets/icons/play.svg @@ -1,6 +1,4 @@ - - - - - + + + diff --git a/src/assets/icons/previous.svg b/src/assets/icons/previous.svg deleted file mode 100755 index 8d061c3..0000000 --- a/src/assets/icons/previous.svg +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - diff --git a/src/assets/icons/stop.svg b/src/assets/icons/stop.svg old mode 100755 new mode 100644 index 23de266..c6393c5 --- a/src/assets/icons/stop.svg +++ b/src/assets/icons/stop.svg @@ -1,6 +1,4 @@ - - - - - + + + diff --git a/src/assets/icons/target.svg b/src/assets/icons/target.svg old mode 100755 new mode 100644 index 03376ef..213ff3d --- a/src/assets/icons/target.svg +++ b/src/assets/icons/target.svg @@ -1,6 +1,4 @@ - - - - - + + + diff --git a/src/assets/icons/zoomIn.svg b/src/assets/icons/zoomIn.svg new file mode 100644 index 0000000..21dcc3c --- /dev/null +++ b/src/assets/icons/zoomIn.svg @@ -0,0 +1,3 @@ + + + diff --git a/src/assets/icons/zoomOut.svg b/src/assets/icons/zoomOut.svg new file mode 100644 index 0000000..dde27ab --- /dev/null +++ b/src/assets/icons/zoomOut.svg @@ -0,0 +1,3 @@ + + + diff --git a/src/components/ControlBar/index.js b/src/components/ControlBar/index.js index e28d6a2..b0707f6 100644 --- a/src/components/ControlBar/index.js +++ b/src/components/ControlBar/index.js @@ -1,11 +1,14 @@ import React from 'react'; import styles from './styles.module.css'; + import TargetIcon from '../../assets/icons/target.svg'; import StopIcon from '../../assets/icons/stop.svg'; import NextIcon from '../../assets/icons/next.svg'; -import PrevIcon from '../../assets/icons/previous.svg'; import PauseIcon from '../../assets/icons/pause.svg'; import PlayIcon from '../../assets/icons/play.svg'; +import ZoomInIcon from '../../assets/icons/zoomIn.svg'; +import ZoomOutIcon from '../../assets/icons/zoomOut.svg'; +import MoveIcon from '../../assets/icons/move.svg'; const ControlBar = ({ isPlaying, @@ -77,8 +80,12 @@ const ControlBar = ({ )} - - + + @@ -86,16 +93,16 @@ const ControlBar = ({ - + - + {!isMoveing && ( - + )} {isMoveing && ( diff --git a/src/index.js b/src/index.js index 9c8b41b..433dc36 100644 --- a/src/index.js +++ b/src/index.js @@ -9,6 +9,7 @@ import React, { } from 'react'; import PropTypes from 'prop-types'; import styles from './styles.module.css'; +import DragIcon from './assets/icons/drag.svg'; import useInterval from './hooks/useInterval'; import useTridiKeyPressHandler from './hooks/useTridiKeyPressHandler'; @@ -438,7 +439,7 @@ const Tridi = forwardRef( > {!renderHint && ( - + {hintText && ( {hintText} )} From 45c748ecb044f0c453cae97cea64d7e6f3b1b3c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E4=BA=91?= <609237304@qq.com> Date: Sun, 7 Mar 2021 21:42:42 +0800 Subject: [PATCH 4/5] add hideRecord fix occasionally not showing pins --- src/components/ControlBar/index.js | 7 +++--- src/index.js | 38 ++++++++++++++++++++---------- 2 files changed, 29 insertions(+), 16 deletions(-) diff --git a/src/components/ControlBar/index.js b/src/components/ControlBar/index.js index b0707f6..6f72379 100644 --- a/src/components/ControlBar/index.js +++ b/src/components/ControlBar/index.js @@ -25,7 +25,8 @@ const ControlBar = ({ onZoomout, onZoomin, onStartMoveing, - onStopMoveing + onStopMoveing, + hideRecord }) => { const playHandler = () => { setIsPlaying(true); @@ -60,12 +61,12 @@ const ControlBar = ({ className={`tridi-control-bar ${styles['tridi-control-bar']}`} onClick={(e) => e.stopPropagation()} > - {!isRecording && ( + {!hideRecord && !isRecording && ( )} - {isRecording && ( + {!hideRecord && isRecording && ( diff --git a/src/index.js b/src/index.js index 433dc36..4bea169 100644 --- a/src/index.js +++ b/src/index.js @@ -95,7 +95,8 @@ const Tridi = forwardRef( onPinClick, onZoom, maxZoom, - minZoom + minZoom, + hideRecord }, ref ) => { @@ -112,6 +113,7 @@ const Tridi = forwardRef( const [viewerImageOfset, setViewerImageOfset] = useState({ x: 0, y: 0 }); const [moveingMouseDownPoint, setMoveingMouseDownPoint] = useState(null); + const [viewerSize, setViewerSize] = useState(null); const _count = Array.isArray(images) ? images.length : Number(count); const _images = TridiUtils.normalizedImages(images, format, location, _count); @@ -413,7 +415,12 @@ const Tridi = forwardRef( next: () => nextMove(), prev: () => prevMove() })); - + useEffect(() => { + setViewerSize({ + width: _viewerImageRef?.current?.clientWidth, + height: _viewerImageRef?.current?.clientHeight + }); + }, [setViewerSize]); useTridiKeyPressHandler({ nextMove, prevMove }); // render component helpers @@ -486,17 +493,19 @@ const Tridi = forwardRef( }} > {_images?.length > 0 && renderImages()} - + {viewerSize ? ( + + ) : null} @@ -505,6 +514,7 @@ const Tridi = forwardRef( )} {showControlBar && ( {}, From 7fe5b00232873d38f0440990f1651cad44d95c5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E4=BA=91?= <609237304@qq.com> Date: Mon, 8 Mar 2021 02:30:19 +0800 Subject: [PATCH 5/5] fix occasionally not showing pins --- src/index.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/index.js b/src/index.js index 4bea169..0410954 100644 --- a/src/index.js +++ b/src/index.js @@ -415,12 +415,16 @@ const Tridi = forwardRef( next: () => nextMove(), prev: () => prevMove() })); - useEffect(() => { - setViewerSize({ - width: _viewerImageRef?.current?.clientWidth, - height: _viewerImageRef?.current?.clientHeight - }); - }, [setViewerSize]); + + const loadImage = () => { + if (!viewerSize) { + setViewerSize({ + width: _viewerImageRef?.current?.clientWidth, + height: _viewerImageRef?.current?.clientHeight + }); + } + }; + useTridiKeyPressHandler({ nextMove, prevMove }); // render component helpers @@ -429,6 +433,7 @@ const Tridi = forwardRef(