Skip to content

Commit 1506d85

Browse files
committed
Support swipe gesture to minimize or maximize the pane
1 parent c958be2 commit 1506d85

File tree

1 file changed

+25
-20
lines changed
  • packages/edit-post/src/components/layout

1 file changed

+25
-20
lines changed

packages/edit-post/src/components/layout/index.js

+25-20
Original file line numberDiff line numberDiff line change
@@ -219,29 +219,34 @@ function MetaBoxesMain( { isLegacy } ) {
219219
}
220220
};
221221
const [ isDragging, setIsDragging ] = useState( false );
222-
const bindDragGesture = useDrag( ( { movement, first, last, memo } ) => {
223-
if ( first ) {
224-
setIsDragging( true );
225-
if ( heightRef.current === undefined ) {
226-
const fromHeight = metaBoxesMainRef.current.offsetHeight;
227-
return { fromHeight };
222+
const bindDragGesture = useDrag(
223+
( { movement, first, last, memo, swipe } ) => {
224+
if ( first ) {
225+
setIsDragging( true );
226+
if ( heightRef.current === undefined ) {
227+
const fromHeight = metaBoxesMainRef.current.offsetHeight;
228+
return { fromHeight };
229+
}
230+
if ( heightRef.current > max ) {
231+
// Starts from max in case shortening the window has imposed it.
232+
return { fromHeight: max };
233+
}
234+
return { fromHeight: heightRef.current };
228235
}
229-
if ( heightRef.current > max ) {
230-
// Starts from max in case shortening the window has imposed it.
231-
return { fromHeight: max };
236+
const [ , yMovement ] = movement;
237+
if ( ! first && ! last ) {
238+
applyHeight( memo.fromHeight - yMovement );
239+
return memo;
240+
}
241+
setIsDragging( false );
242+
const [ , swipeY ] = swipe;
243+
if ( swipeY ) {
244+
applyHeight( swipeY === -1 ? max : min, true );
245+
} else if ( yMovement !== 0 ) {
246+
applyHeight( heightRef.current, true );
232247
}
233-
return { fromHeight: heightRef.current };
234-
}
235-
const [ , yMovement ] = movement;
236-
if ( ! first && ! last ) {
237-
applyHeight( memo.fromHeight - yMovement );
238-
return memo;
239-
}
240-
setIsDragging( false );
241-
if ( yMovement !== 0 ) {
242-
applyHeight( heightRef.current, true );
243248
}
244-
} );
249+
);
245250

246251
if ( ! hasAnyVisible ) {
247252
return;

0 commit comments

Comments
 (0)