Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
a51e773
[Mobile] - Drag & drop blocks - Fetch and share blocks layout size an…
Mar 17, 2022
20dc6ff
Merge branch 'trunk' into rnmobile/feature/drag-and-drop
fluiddot Mar 17, 2022
0793b47
Merge branch 'trunk' into rnmobile/feature/drag-and-drop
Mar 18, 2022
4e5f5f7
[Mobile] - Draggable component (#39551)
Mar 22, 2022
76f8096
[RNMobile] `BlockDraggable` component (#39617)
fluiddot Mar 30, 2022
f8e4e0e
[RNMobile] Add `useScrollWhenDragging` hook (#39705)
fluiddot Mar 30, 2022
0b3940e
[RNMobile] Prevent draggable gesture when any text input is focused (…
fluiddot Mar 31, 2022
dfd29e2
[Mobile] Adds useBlockDropZone and DroppingInsertionPoint (#39891)
Mar 31, 2022
a908ece
[RNMobile] Add `useOnBlockDrop` hook to update blocks order when drop…
fluiddot Apr 7, 2022
22ff474
[RNMobile] Update drag & drop animations (#40104)
fluiddot Apr 8, 2022
2eb5f32
Merge branch 'trunk' into rnmobile/feature/drag-and-drop
fluiddot Apr 18, 2022
2ff70a4
[RNMobile] Disable text editing when long-pressing a block in favor o…
fluiddot Apr 19, 2022
951103c
Merge branch 'trunk' into rnmobile/feature/drag-and-drop
fluiddot Apr 20, 2022
3996c65
[RNMobile] Refactor draggable logic and introduce `DraggableTrigger` …
fluiddot Apr 20, 2022
48da045
[RNMobile] Update animation of drag & drop chip component (#40409)
fluiddot Apr 20, 2022
8547f80
Mobile - DroppingInsertionPoint - Update indicator position for selec…
Apr 22, 2022
a4f52e3
[RNMobile] Add haptic feedback to drag & drop feature (#40423)
fluiddot Apr 22, 2022
1320c03
[RNMobile] Fix issues related to editing text and dragging gesture (#…
fluiddot Apr 27, 2022
d147f60
Mobile - Draggable - Disable multiple touches (#40519)
Apr 27, 2022
fa3d10b
Mobile - DroppingInsertionPoint - Hide indicator when it overflows ou…
Apr 28, 2022
d0f14ba
Mobile - Disable long press event in media blocks (#40651)
Apr 28, 2022
4c671e4
Merge branch 'trunk' into rnmobile/feature/drag-and-drop
Apr 28, 2022
bc82fb7
Mobile - DraggingInsertionPoint - Prevent crash when accessing a null…
Apr 29, 2022
3929ae8
Mobile - Draggable - Add onTouchesCancelled to handle manually ending…
May 3, 2022
adcd420
[RNMobile] Fix Android crash when closing the editor while dragging (…
fluiddot May 5, 2022
3714b15
Merge branch 'trunk' into rnmobile/feature/drag-and-drop
May 5, 2022
0c34e55
Mobile - AztecView - Trigger notifyInputChange on focus/blur (#40788)
May 6, 2022
1d87dc6
[RNMobile] Disable dragging when a screen reader is enabled (#40852)
fluiddot May 6, 2022
27f2ba7
[RNMobile] Allow dragging from block toolbar (#40886)
fluiddot May 9, 2022
4806774
Update Podfile.lock
fluiddot May 10, 2022
8760a37
Update react-native-editor changelog
fluiddot May 10, 2022
f7a9e51
Merge branch 'trunk' into rnmobile/feature/drag-and-drop
fluiddot May 10, 2022
decf119
Fix text block query locator in Android E2E tests
fluiddot May 11, 2022
7292638
Fix Cover block E2E test
fluiddot May 11, 2022
fd9a3bf
Fix Spacer block E2E test
fluiddot May 11, 2022
73e22b5
Merge branch 'trunk' into rnmobile/feature/drag-and-drop
fluiddot May 11, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[RNMobile] Update animation of drag & drop chip component (#40409)
* Use layout animations when rendering the chip component

Additionally, the block icon is now provided from the BlockDraggable component.

* Fix chip layout calculation

* Set block icon as state value

* Update enter/exit animation duration of chip component
  • Loading branch information
fluiddot authored Apr 20, 2022
commit 48da04590b305a24c5049a2c6d36bc8c5621a07c
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,13 @@ import { View } from 'react-native';
* WordPress dependencies
*/
import { dragHandle } from '@wordpress/icons';
import { useSelect } from '@wordpress/data';
import { getBlockType } from '@wordpress/blocks';
import { usePreferredColorSchemeStyle } from '@wordpress/compose';

/**
* Internal dependencies
*/
import BlockIcon from '../block-icon';
import styles from './style.scss';
import { store as blockEditorStore } from '../../store';

const shadowStyle = {
shadowColor: '#000',
Expand All @@ -33,30 +30,20 @@ const shadowStyle = {
/**
* Block draggable chip component
*
* @param {Object} props Component props.
* @param {Object} [props.icon] Block icon.
* @return {JSX.Element} Chip component.
*/
export default function BlockDraggableChip() {
export default function BlockDraggableChip( { icon } ) {
const containerStyle = usePreferredColorSchemeStyle(
styles[ 'draggable-chip__container' ],
styles[ 'draggable-chip__container--dark' ]
);

const { blockIcon } = useSelect( ( select ) => {
const { getBlockName, getDraggedBlockClientIds } = select(
blockEditorStore
);
const draggedBlockClientIds = getDraggedBlockClientIds();
const blockName = getBlockName( draggedBlockClientIds[ 0 ] );

return {
blockIcon: getBlockType( blockName )?.icon,
};
} );

return (
<View style={ [ containerStyle, shadowStyle ] }>
<BlockIcon icon={ dragHandle } />
<BlockIcon icon={ blockIcon } />
{ icon && <BlockIcon icon={ icon } /> }
</View>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,18 @@ import Animated, {
useSharedValue,
withDelay,
withTiming,
ZoomInEasyDown,
ZoomOutEasyDown,
} from 'react-native-reanimated';
import TextInputState from 'react-native/Libraries/Components/TextInput/TextInputState';

/**
* WordPress dependencies
*/
import { Draggable, DraggableTrigger } from '@wordpress/components';
import { useSelect, useDispatch } from '@wordpress/data';
import { select, useSelect, useDispatch } from '@wordpress/data';
import { useEffect, useRef, useState, Platform } from '@wordpress/element';
import { getBlockType } from '@wordpress/blocks';

/**
* Internal dependencies
Expand Down Expand Up @@ -54,7 +57,7 @@ const DEFAULT_IOS_LONG_PRESS_MIN_DURATION =
* @return {Function} Render function that passes `onScroll` event handler.
*/
const BlockDraggableWrapper = ( { children } ) => {
const [ currentClientId, setCurrentClientId ] = useState();
const [ draggedBlockIcon, setDraggedBlockIcon ] = useState();

const {
selectBlock,
Expand All @@ -74,7 +77,6 @@ const BlockDraggableWrapper = ( { children } ) => {
y: useSharedValue( 0 ),
width: useSharedValue( 0 ),
height: useSharedValue( 0 ),
scale: useSharedValue( 0 ),
};
const isDragging = useSharedValue( false );

Expand Down Expand Up @@ -109,35 +111,47 @@ const BlockDraggableWrapper = ( { children } ) => {
};
}, [] );

const setDraggedBlockIconByClientId = ( clientId ) => {
const blockName = select( blockEditorStore ).getBlockName( clientId );
const blockIcon = getBlockType( blockName )?.icon;
if ( blockIcon ) {
setDraggedBlockIcon( blockIcon );
}
};

const onStartDragging = ( { clientId, position } ) => {
if ( clientId ) {
startDraggingBlocks( [ clientId ] );
setCurrentClientId( clientId );
setDraggedBlockIconByClientId( clientId );
runOnUI( startScrolling )( position.y );
} else {
// We stop dragging if no block is found.
runOnUI( stopDragging )();
}
};

const onStopDragging = () => {
if ( currentClientId ) {
const onStopDragging = ( { clientId } ) => {
if ( clientId ) {
onBlockDrop( {
// Dropping is only allowed at root level
srcRootClientId: '',
srcClientIds: [ currentClientId ],
srcClientIds: [ clientId ],
type: 'block',
} );
selectBlock( currentClientId );
setCurrentClientId( undefined );
selectBlock( clientId );
setDraggedBlockIcon( undefined );
}
onBlockDragEnd();
stopDraggingBlocks();
};

const onChipLayout = ( { nativeEvent: { layout } } ) => {
chip.width.value = layout.width;
chip.height.value = layout.height;
if ( layout.width > 0 ) {
chip.width.value = layout.width;
}
if ( layout.height > 0 ) {
chip.height.value = layout.height;
}
};

const startDragging = ( { x, y, id } ) => {
Expand All @@ -148,7 +162,6 @@ const BlockDraggableWrapper = ( { children } ) => {

isDragging.value = true;

chip.scale.value = withTiming( 1 );
runOnJS( onStartDragging )( { clientId: id, position: dragPosition } );
};

Expand All @@ -164,13 +177,12 @@ const BlockDraggableWrapper = ( { children } ) => {
scrollOnDragOver( dragPosition.y );
};

const stopDragging = () => {
const stopDragging = ( { id } ) => {
'worklet';
isDragging.value = false;

chip.scale.value = withTiming( 0 );
stopScrolling();
runOnJS( onStopDragging )();
runOnJS( onStopDragging )( { clientId: id } );
};

const chipDynamicStyles = useAnimatedStyle( () => {
Expand All @@ -183,8 +195,6 @@ const BlockDraggableWrapper = ( { children } ) => {
chip.height.value -
CHIP_OFFSET_TO_TOUCH_POSITION,
},
{ scaleX: chip.scale.value },
{ scaleY: chip.scale.value },
],
};
} );
Expand Down Expand Up @@ -212,7 +222,14 @@ const BlockDraggableWrapper = ( { children } ) => {
style={ chipStyles }
pointerEvents="none"
>
<DraggableChip />
{ draggedBlockIcon && (
<Animated.View
entering={ ZoomInEasyDown.duration( 200 ) }
exiting={ ZoomOutEasyDown.duration( 150 ) }
>
<DraggableChip icon={ draggedBlockIcon } />
</Animated.View>
) }
</Animated.View>
</>
);
Expand Down Expand Up @@ -253,13 +270,13 @@ const BlockDraggable = ( { clientId, children, enabled = true } ) => {
};

const { isDraggable, isBeingDragged, canDragBlock } = useSelect(
( select ) => {
( _select ) => {
const {
getBlockRootClientId,
getTemplateLock,
isBlockBeingDragged,
hasSelectedBlock,
} = select( blockEditorStore );
} = _select( blockEditorStore );
const rootClientId = getBlockRootClientId( clientId );
const templateLock = rootClientId
? getTemplateLock( rootClientId )
Expand Down