Skip to content
Prev Previous commit
Next Next commit
Clean up refactor
  • Loading branch information
stacimc committed May 27, 2021
commit 5888c97858126d69264b5182c3860a8371066baa
2 changes: 1 addition & 1 deletion packages/block-library/src/button/controls.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function WidthPanel( { selectedWidth, setAttributes } ) {
);
}

export default function Controls ( {
export default function Controls( {
attributes,
setAttributes,
clientId,
Expand Down
41 changes: 17 additions & 24 deletions packages/block-library/src/button/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { View, AccessibilityInfo, Platform, Text } from 'react-native';
/**
* WordPress dependencies
*/
import { withInstanceId, compose } from '@wordpress/compose';
import { withInstanceId, compose, usePrevious } from '@wordpress/compose';
import { __ } from '@wordpress/i18n';
import {
RichText,
Expand Down Expand Up @@ -37,16 +37,6 @@ const MIN_WIDTH_MARGINS = {
25: styles.button25?.marginLeft,
};

const usePrevious = ( value ) => {
const ref = useRef();

useEffect( () => {
ref.current = value;
}, [ value ] );

return ref.current;
};

const ButtonEdit = ( {
attributes,
colors,
Expand Down Expand Up @@ -81,16 +71,6 @@ const ButtonEdit = ( {
const wasEditorSidebarOpened = usePrevious( editorSidebarOpened );
const wasLinkSheetVisible = usePrevious( isLinkSheetVisible );

const onClearSettings = () => {
setAttributes( {
url: '',
rel: '',
linkTarget: '',
} );

onHideLinkSettings();
};

const linkSettingsActions = [
{
label: __( 'Remove link' ),
Expand Down Expand Up @@ -141,7 +121,11 @@ const ButtonEdit = ( {
( ! wasEditorSidebarOpened && editorSidebarOpened ) ||
( ! wasLinkSheetVisible && isLinkSheetVisible )
) {
if ( Platform.OS === 'android' && richTextRef && richTextRef.current ) {
if (
Platform.OS === 'android' &&
richTextRef &&
richTextRef.current
) {
richTextRef.current.blur();
onToggleButtonFocus( false );
}
Expand Down Expand Up @@ -170,14 +154,13 @@ const ButtonEdit = ( {
wasSelected,
wasEditorSidebarOpened,
wasLinkSheetVisible,
richTextRef.current
richTextRef.current,
] );

const setRef = ( nodeRef ) => {
richTextRef.current = nodeRef;
};


const getBackgroundColor = () => {
// Return named gradient value if available.
const gradientValue = getGradientValueBySlug( gradients, gradient );
Expand Down Expand Up @@ -238,6 +221,16 @@ const ButtonEdit = ( {
setIsLinkSheetVisible( false );
};

const onClearSettings = () => {
setAttributes( {
url: '',
rel: '',
linkTarget: '',
} );

onHideLinkSettings();
};

const onToggleButtonFocus = ( value ) => {
if ( value !== isButtonFocused ) {
setIsButtonFocused( value );
Expand Down