Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RNMobile] BlockDraggable component #39617

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
a779e95
Use animated scroll handler in KeyboardAwareFlatList
fluiddot Mar 17, 2022
b71b308
Add hook for scrolling the block list while dragging
fluiddot Mar 17, 2022
faea4cf
Improve scroll animation in useScrollWhenDragging
fluiddot Mar 18, 2022
799f077
Add draggable chip component
fluiddot Mar 18, 2022
6aaae21
Add block draggable component
fluiddot Mar 18, 2022
f0bd8c0
Remove icon prop from draggable chip component
fluiddot Mar 21, 2022
64708c5
Add draggable placeholder
fluiddot Mar 21, 2022
778b10a
Fix draggable chip location
fluiddot Mar 21, 2022
3822b27
Wrap BlockListItemCell with BlockDraggable
fluiddot Mar 21, 2022
3688013
Fix block draggable placeholder style
fluiddot Mar 21, 2022
14a9d6b
Animate scale property instead of opacity of draggable chip
fluiddot Mar 21, 2022
90838fd
Fix draggable placeholder container height calculation
fluiddot Mar 21, 2022
ab337ef
Fix BlockDraggable height animation
fluiddot Mar 22, 2022
ee179a9
Move draggable to BlockDraggableWrapper
fluiddot Mar 23, 2022
f173ab8
Disable isDragging when long-press gesture ends
fluiddot Mar 23, 2022
95fd2e1
Fix onLayout calculation in block list item cell
fluiddot Mar 23, 2022
593644d
Add findBlockLayoutByPosition helper
fluiddot Mar 23, 2022
a910072
Set up dragging block by position
fluiddot Mar 23, 2022
0ddca86
Remove animate scroll velocity
fluiddot Mar 23, 2022
1492550
Remove useScrollWhenDragging hook
fluiddot Mar 23, 2022
2bd4e66
Remove react-native-reanimated mock
fluiddot Mar 24, 2022
9a2ae54
Rename CHIP_OFFSET_TO_TOUCH_POSITION constant
fluiddot Mar 24, 2022
fd0883e
Remove unused shared values of chip component
fluiddot Mar 24, 2022
6bef485
Stop dragging when no block is found
fluiddot Mar 24, 2022
ad016ed
Fix drag position calculation
fluiddot Mar 24, 2022
7fac2ec
Update html text input styles
fluiddot Mar 25, 2022
5c6e21a
Unify container component within html text input
fluiddot Mar 25, 2022
55e62f1
Use only a single client id in block draggable
fluiddot Mar 28, 2022
258eaf3
Add documentation to block draggable components
fluiddot Mar 28, 2022
78da359
Add documentation to block draggable chip component
fluiddot Mar 28, 2022
8cac264
Add documentation to findBlockLayoutByPosition
fluiddot Mar 28, 2022
1612b48
Update scrollOffsetTarget calculation
fluiddot Mar 28, 2022
b7e800a
Fix typos in block draggable
fluiddot Mar 28, 2022
8c79ad3
Add draggable wrapper container style
fluiddot Mar 28, 2022
e9ce4e3
Add dark mode styles for draggable chip
fluiddot Mar 28, 2022
4060e1a
Add dark mode styles for block draggable
fluiddot Mar 28, 2022
d16ce15
Get container height from blocks layout data
fluiddot Mar 29, 2022
842b09b
Replace inline callback functions with useCallback hook
fluiddot Mar 29, 2022
bda7b24
Update collapse/expand animation when dragging a block
fluiddot Mar 29, 2022
b886b66
Force draggable chip to be displayed upfront
fluiddot Mar 29, 2022
d66fb3d
Remove refs from dependencies arrays
fluiddot Mar 29, 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/**
* External dependencies
*/
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',
shadowOffset: {
width: 0,
height: 2,
},
shadowOpacity: 0.25,
shadowRadius: 3.84,

elevation: 5,
};
Comment on lines +21 to +31
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I defined the shadow style properties here because these properties are not recognized in SCSS.


/**
* Block draggable chip component
*
* @return {JSX.Element} Chip component.
*/
export default function BlockDraggableChip() {
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,
};
} );
Comment on lines +44 to +54
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought of passing the blockIcon from the BlockDraggable component (i.e. its parent component) but I experienced downgrades in the performance due to re-renders caused by Redux state updates. For this reason, I finally decided to retrieve the blockIcon directly here.


return (
<View style={ [ containerStyle, shadowStyle ] }>
<BlockIcon icon={ dragHandle } />
<BlockIcon icon={ blockIcon } />
</View>
);
}
Loading