[mobile] Fixed swipe animation of view current comment

This commit is contained in:
JuliaSvinareva 2021-03-09 19:29:06 +03:00
parent 1c899fb7ed
commit c9e5a41954
2 changed files with 32 additions and 68 deletions

View file

@ -645,86 +645,50 @@ const ViewCommentSheet = ({closeCurComments}) => {
const { t } = useTranslation(); const { t } = useTranslation();
const _t = t('Common.Collaboration', {returnObjects: true}); const _t = t('Common.Collaboration', {returnObjects: true});
const appHeight = f7.height;
//const [sheetHeight, setSheetHeight] = useState('45%');
let swipeStart,
swipeChange;
useEffect(() => { useEffect(() => {
f7.sheet.open('#view-comment-sheet'); f7.sheet.open('#view-comment-sheet');
const swipeHandler = document.getElementById('swipe-handler');
swipeHandler.addEventListener('touchstart', handleTouchStart);
swipeHandler.addEventListener('touchmove', handleTouchMove);
swipeHandler.addEventListener('touchend', handleTouchEnd);
}); });
const [stateHeight, setHeight] = useState('45%');
const [stateOpacity, setOpacity] = useState(1);
const [stateStartY, setStartY] = useState();
const [isNeedClose, setNeedClose] = useState(false);
const handleTouchStart = (event) => { const handleTouchStart = (event) => {
console.log('start');
const touchObj = event.changedTouches[0]; const touchObj = event.changedTouches[0];
swipeStart = parseInt(touchObj.clientY); setStartY(parseInt(touchObj.clientY));
swipeChange = parseInt(touchObj.clientY);
}; };
const handleTouchMove = (event) => { const handleTouchMove = (event) => {
console.log('move');
const touchObj = event.changedTouches[0]; const touchObj = event.changedTouches[0];
const dist = parseInt(touchObj.clientY) - swipeStart; const dist = parseInt(touchObj.clientY) - stateStartY;
const height = (appHeight - parseInt(touchObj.clientY)).toString(); if (dist < 0) { // to top
document.getElementById('view-comment-sheet').style.setProperty('height', `${height}px`); setHeight('90%');
/*if (dist < 0) { setOpacity(1);
newHeight = '100%'; setNeedClose(false);
me.swipeFull = true; } else if (dist < 80) {
me.closeCommentPicker = false; setHeight('45%');
if (window.SSE) { setOpacity(1);
if ($('.container-view-comment').hasClass('onHide')) { setNeedClose(false);
$('.container-view-comment').removeClass('onHide');
}
} else {
$('.container-view-comment').css('opacity', '1');
}
} else if (dist < 100) {
newHeight = '50%';
me.swipeFull = false;
me.closeCommentPicker = false;
if (window.SSE) {
if ($('.container-view-comment').hasClass('onHide')) {
$('.container-view-comment').removeClass('onHide');
}
} else {
$('.container-view-comment').css('opacity', '1');
}
} else { } else {
me.closeCommentPicker = true; setNeedClose(true);
if (window.SSE) { setOpacity(0.6);
if (!$('.container-view-comment').hasClass('onHide')) {
$('.container-view-comment').addClass('onHide');
}
} else {
$('.container-view-comment').css('opacity', '0.6');
}
} }
$('.container-view-comment').css('height', newHeight);
me.swipeHeight = newHeight;
e.preventDefault();*/
}; };
const handleTouchEnd = () => { const handleTouchEnd = (event) => {
console.log('end'); console.log('end');
/*var touchobj = e.changedTouches[0]; const touchObj = event.changedTouches[0];
var swipeEnd = parseInt(touchobj.clientY); const swipeEnd = parseInt(touchObj.clientY);
var dist = swipeEnd - me.swipeStart; const dist = swipeEnd - stateStartY;
if (me.closeCommentPicker) { if (isNeedClose) {
uiApp.closeModal(); f7.sheet.close('#view-comment-sheet');
me.modalViewComment.remove(); closeCurComments();
} else if (me.swipeFull) { } else if (stateHeight === '90%' && dist > 20) {
if (dist > 20) { setHeight('45%');
$('.container-view-comment').css('height', '50%');
}
} }
me.swipeHeight = undefined;
me.swipeChange = undefined;
me.closeCommentPicker = undefined;*/
}; };
return ( return (
<Sheet id='view-comment-sheet'> <Sheet id='view-comment-sheet' style={{height: `${stateHeight}`, opacity: `${stateOpacity}`}}>
<Toolbar position='bottom'> <Toolbar position='bottom'>
<Link className='btn-add-reply' href='#'>{_t.textAddReply}</Link> <Link className='btn-add-reply' href='#'>{_t.textAddReply}</Link>
<div className='comment-navigation row'> <div className='comment-navigation row'>
@ -732,7 +696,7 @@ const ViewCommentSheet = ({closeCurComments}) => {
<Link href='#'><Icon slot='media' icon='icon-next'/></Link> <Link href='#'><Icon slot='media' icon='icon-next'/></Link>
</div> </div>
</Toolbar> </Toolbar>
<div id='swipe-handler' className='swipe-container'> <div id='swipe-handler' className='swipe-container' onTouchStart={handleTouchStart} onTouchMove={handleTouchMove} onTouchEnd={handleTouchEnd}>
<Icon icon='icon-swipe'/> <Icon icon='icon-swipe'/>
</div> </div>
<CommentList /> <CommentList />

View file

@ -113,8 +113,8 @@
border-top-right-radius: 4px; border-top-right-radius: 4px;
height: 45%; height: 45%;
box-shadow: 0 1px 10px rgba(0, 0, 0, 0.2), 0 4px 5px rgba(0, 0, 0, 0.12); box-shadow: 0 1px 10px rgba(0, 0, 0, 0.2), 0 4px 5px rgba(0, 0, 0, 0.12);
//-webkit-transition: height 100ms; webkit-transition: height 200ms;
//transition: height 120ms; transition: height 200ms;
.top { .top {
height: 90%; height: 90%;
} }