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

Mobile Release v1.76.1 #41196

Merged
merged 13 commits into from
May 23, 2022
Merged
Show file tree
Hide file tree
Changes from 10 commits
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
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 All @@ -11,7 +15,6 @@ import Animated, {
withDelay,
withTiming,
ZoomInEasyDown,
ZoomOutEasyDown,
} from 'react-native-reanimated';

/**
Expand Down Expand Up @@ -61,10 +64,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 +79,10 @@ const BlockDraggableWrapper = ( { children } ) => {

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

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

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

return {
transform: [
{ translateX: chip.x.value - chip.width.value / 2 },
{
translateX,
},
{
translateY:
chip.y.value -
Expand All @@ -215,6 +230,34 @@ const BlockDraggableWrapper = ( { children } ) => {
styles[ 'draggable-chip__wrapper' ],
];

const exitingAnimation = ( { currentHeight, currentWidth } ) => {
'worklet';
const translateX = ! isRTL ? 0 : currentWidth * -1;
const duration = 150;
const animations = {
transform: [
{
translateY: withTiming( currentHeight, {
duration,
} ),
},
{
translateX: withTiming( translateX, {
duration,
} ),
},
{ scale: withTiming( 0, { duration } ) },
],
};
const initialValues = {
transform: [ { translateY: 0 }, { translateX }, { scale: 1 } ],
};
return {
initialValues,
animations,
};
};

return (
<>
<DroppingInsertionPoint
Expand All @@ -238,7 +281,7 @@ const BlockDraggableWrapper = ( { children } ) => {
{ draggedBlockIcon && (
<Animated.View
entering={ ZoomInEasyDown.duration( 200 ) }
exiting={ ZoomOutEasyDown.duration( 150 ) }
exiting={ exitingAnimation }
>
<DraggableChip icon={ draggedBlockIcon } />
</Animated.View>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { useEffect, useCallback } from '@wordpress/element';
*/
import { useBlockListContext } from './block-list-context';

function BlockListItemCell( { children, clientId, rootClientId } ) {
function BlockListItemCell( { children, clientId, rootClientId, onLayout } ) {
const { blocksLayouts, updateBlocksLayouts } = useBlockListContext();

useEffect( () => {
Expand All @@ -25,18 +25,25 @@ function BlockListItemCell( { children, clientId, rootClientId } ) {
};
}, [] );

const onLayout = useCallback(
( { nativeEvent: { layout } } ) => {
const onCellLayout = useCallback(
( event ) => {
const {
nativeEvent: { layout },
} = event;
updateBlocksLayouts( blocksLayouts, {
clientId,
rootClientId,
...layout,
} );

if ( onLayout ) {
onLayout( event );
}
},
[ clientId, rootClientId, updateBlocksLayouts ]
[ clientId, rootClientId, updateBlocksLayouts, onLayout ]
);

return <View onLayout={ onLayout }>{ children }</View>;
return <View onLayout={ onCellLayout }>{ children }</View>;
}

export default BlockListItemCell;
10 changes: 7 additions & 3 deletions packages/block-editor/src/components/block-list/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,13 @@ export class BlockList extends Component {
return this.extraData;
}

getCellRendererComponent( { children, item } ) {
getCellRendererComponent( { children, item, onLayout } ) {
const { rootClientId } = this.props;
return (
<BlockListItemCell
children={ children }
clientId={ item }
onLayout={ onLayout }
rootClientId={ rootClientId }
/>
);
Expand All @@ -189,7 +190,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 +199,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 +439,8 @@ export default compose( [

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

return {
blockClientIds,
blockCount,
Expand All @@ -448,6 +451,7 @@ export default compose( [
isFloatingToolbarVisible,
isStackedHorizontally,
maxWidth,
isRTL,
};
}
),
Expand Down
72 changes: 64 additions & 8 deletions packages/block-editor/src/components/plain-text/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { TextInput, Platform, Dimensions } from 'react-native';
* WordPress dependencies
*/
import { Component } from '@wordpress/element';
import { getPxFromCssUnit } from '@wordpress/block-editor';
import { RichText, getPxFromCssUnit } from '@wordpress/block-editor';

/**
* Internal dependencies
Expand All @@ -18,6 +18,9 @@ export default class PlainText extends Component {
constructor() {
super( ...arguments );
this.isAndroid = Platform.OS === 'android';

this.onChangeTextInput = this.onChangeTextInput.bind( this );
this.onChangeRichText = this.onChangeRichText.bind( this );
}

componentDidMount() {
Expand All @@ -44,7 +47,7 @@ export default class PlainText extends Component {

componentDidUpdate( prevProps ) {
if ( ! this.props.isSelected && prevProps.isSelected ) {
this._input.blur();
this._input?.blur();
}
}

Expand All @@ -55,11 +58,11 @@ export default class PlainText extends Component {
}

focus() {
this._input.focus();
this._input?.focus();
}

blur() {
this._input.blur();
this._input?.blur();
}

getFontSize() {
Expand All @@ -79,20 +82,73 @@ export default class PlainText extends Component {
};
}

replaceLineBreakTags( value ) {
return value?.replace( RegExp( '<br>', 'gim' ), '\n' );
}

onChangeTextInput( event ) {
const { onChange } = this.props;
onChange( event.nativeEvent.text );
}

onChangeRichText( value ) {
const { onChange } = this.props;
// The <br> tags have to be replaced with new line characters
// as the content of plain text shouldn't contain HTML tags.
onChange( this.replaceLineBreakTags( value ) );
}

render() {
const { style } = this.props;
const {
style,
__experimentalVersion,
onFocus,
...otherProps
} = this.props;
const textStyles = [
style || styles[ 'block-editor-plain-text' ],
this.getFontSize(),
];

if ( __experimentalVersion === 2 ) {
const disableFormattingProps = {
withoutInteractiveFormatting: true,
disableEditingMenu: true,
__unstableDisableFormats: true,
disableSuggestions: true,
};

const forcePlainTextProps = {
preserveWhiteSpace: true,
__unstablePastePlainText: true,
multiline: false,
};

const fontProps = {
fontFamily: style?.fontFamily,
fontSize: style?.fontSize,
fontWeight: style?.fontWeight,
};

return (
<RichText
{ ...otherProps }
{ ...disableFormattingProps }
{ ...forcePlainTextProps }
{ ...fontProps }
identifier="content"
style={ style }
onChange={ this.onChangeRichText }
unstableOnFocus={ onFocus }
/>
);
}

return (
<TextInput
{ ...this.props }
ref={ ( x ) => ( this._input = x ) }
onChange={ ( event ) => {
this.props.onChange( event.nativeEvent.text );
} }
onChange={ this.onChangeTextInput }
onFocus={ this.props.onFocus } // Always assign onFocus as a props.
onBlur={ this.props.onBlur } // Always assign onBlur as a props.
fontFamily={
Expand Down
2 changes: 2 additions & 0 deletions packages/block-editor/src/components/rich-text/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ function removeNativeProps( props ) {
'minWidth',
'maxWidth',
'setRef',
'disableSuggestions',
'disableAutocorrection',
] );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ function RichTextWrapper(
maxWidth,
onBlur,
setRef,
disableSuggestions,
disableAutocorrection,
...props
},
forwardedRef
Expand Down Expand Up @@ -635,6 +637,8 @@ function RichTextWrapper(
maxWidth={ maxWidth }
onBlur={ onBlur }
setRef={ setRef }
disableSuggestions={ disableSuggestions }
disableAutocorrection={ disableAutocorrection }
// Props to be set on the editable container are destructured on the
// element itself for web (see below), but passed through rich text
// for native.
Expand Down
Loading