Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Next Next commit
Mobile - Fix - Drag & drop chip issue with RTL languages
  • Loading branch information
Gerardo committed May 13, 2022
commit 90377c076371fc58f1b1e71888313c558eeed134
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
* External dependencies
*/
import { AccessibilityInfo } from 'react-native';
import {
useSafeAreaInsets,
useSafeAreaFrame,
} from 'react-native-safe-area-context';
import Animated, {
runOnJS,
runOnUI,
Expand Down Expand Up @@ -61,10 +65,11 @@ const DEFAULT_IOS_LONG_PRESS_MIN_DURATION =
*
* @param {Object} props Component props.
* @param {JSX.Element} props.children Children to be rendered.
* @param {boolean} props.isRTL Check if current locale is RTL.
*
* @return {Function} Render function that passes `onScroll` event handler.
*/
const BlockDraggableWrapper = ( { children } ) => {
const BlockDraggableWrapper = ( { children, isRTL } ) => {
const [ draggedBlockIcon, setDraggedBlockIcon ] = useState();

const {
Expand All @@ -75,6 +80,10 @@ const BlockDraggableWrapper = ( { children } ) => {

const { scrollRef } = useBlockListContext();
const animatedScrollRef = useAnimatedRef();
const { left, right } = useSafeAreaInsets();
const { width } = useSafeAreaFrame();
const safeAreaOffset = left + right;
const maxWidth = width - safeAreaOffset;
animatedScrollRef( scrollRef );

const scroll = {
Expand Down Expand Up @@ -198,9 +207,16 @@ const BlockDraggableWrapper = ( { children } ) => {
};

const chipDynamicStyles = useAnimatedStyle( () => {
const chipOffset = chip.width.value / 2;
const translateX = ! isRTL
? chip.x.value - chipOffset
: -( maxWidth - ( chip.x.value + chipOffset ) );

return {
transform: [
{ translateX: chip.x.value - chip.width.value / 2 },
{
translateX,
},
{
translateY:
chip.y.value -
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ export class BlockList extends Component {
}

render() {
const { isRootList } = this.props;
const { isRootList, isRTL } = this.props;
// Use of Context to propagate the main scroll ref to its children e.g InnerBlocks.
const blockList = isRootList ? (
<BlockListProvider
Expand All @@ -198,7 +198,7 @@ export class BlockList extends Component {
scrollRef: this.scrollViewRef,
} }
>
<BlockDraggableWrapper>
<BlockDraggableWrapper isRTL={ isRTL }>
{ ( { onScroll } ) => this.renderList( { onScroll } ) }
</BlockDraggableWrapper>
</BlockListProvider>
Expand Down Expand Up @@ -438,6 +438,8 @@ export default compose( [

const isFloatingToolbarVisible =
!! selectedBlockClientId && hasRootInnerBlocks;
const isRTL = getSettings().isRTL;

return {
blockClientIds,
blockCount,
Expand All @@ -448,6 +450,7 @@ export default compose( [
isFloatingToolbarVisible,
isStackedHorizontally,
maxWidth,
isRTL,
};
}
),
Expand Down