Skip to content

Commit

Permalink
Support swipe gesture to minimize or maximize the pane
Browse files Browse the repository at this point in the history
  • Loading branch information
stokesman committed Nov 5, 2024
1 parent c958be2 commit 1506d85
Showing 1 changed file with 25 additions and 20 deletions.
45 changes: 25 additions & 20 deletions packages/edit-post/src/components/layout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,29 +219,34 @@ function MetaBoxesMain( { isLegacy } ) {
}
};
const [ isDragging, setIsDragging ] = useState( false );
const bindDragGesture = useDrag( ( { movement, first, last, memo } ) => {
if ( first ) {
setIsDragging( true );
if ( heightRef.current === undefined ) {
const fromHeight = metaBoxesMainRef.current.offsetHeight;
return { fromHeight };
const bindDragGesture = useDrag(
( { movement, first, last, memo, swipe } ) => {
if ( first ) {
setIsDragging( true );
if ( heightRef.current === undefined ) {
const fromHeight = metaBoxesMainRef.current.offsetHeight;
return { fromHeight };
}
if ( heightRef.current > max ) {
// Starts from max in case shortening the window has imposed it.
return { fromHeight: max };
}
return { fromHeight: heightRef.current };
}
if ( heightRef.current > max ) {
// Starts from max in case shortening the window has imposed it.
return { fromHeight: max };
const [ , yMovement ] = movement;
if ( ! first && ! last ) {
applyHeight( memo.fromHeight - yMovement );
return memo;
}
setIsDragging( false );
const [ , swipeY ] = swipe;
if ( swipeY ) {
applyHeight( swipeY === -1 ? max : min, true );
} else if ( yMovement !== 0 ) {
applyHeight( heightRef.current, true );
}
return { fromHeight: heightRef.current };
}
const [ , yMovement ] = movement;
if ( ! first && ! last ) {
applyHeight( memo.fromHeight - yMovement );
return memo;
}
setIsDragging( false );
if ( yMovement !== 0 ) {
applyHeight( heightRef.current, true );
}
} );
);

if ( ! hasAnyVisible ) {
return;
Expand Down

0 comments on commit 1506d85

Please sign in to comment.