Skip to content

Commit

Permalink
Add "hasPicker" prop to the LinkSettings to determine if open link pi…
Browse files Browse the repository at this point in the history
…cker
  • Loading branch information
dratwas committed Nov 2, 2020
1 parent e4c51a3 commit 0b3a196
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 14 deletions.
1 change: 1 addition & 0 deletions packages/block-library/src/button/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ class ButtonEdit extends Component {
onClose={ this.dismissSheet }
setAttributes={ setAttributes }
withBottomSheet={ ! isCompatibleWithSettings }
hasPicker
actions={ actions }
options={ options }
showIcon={ ! isCompatibleWithSettings }
Expand Down
55 changes: 42 additions & 13 deletions packages/components/src/mobile/link-settings/index.native.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
/**
* External dependencies
*/
import { Clipboard } from 'react-native';
import { Clipboard, Platform } from 'react-native';
/**
* WordPress dependencies
*/
import { compose } from '@wordpress/compose';
import { withSelect } from '@wordpress/data';
import { isURL, prependHTTP } from '@wordpress/url';
import { useEffect, useState, useRef } from '@wordpress/element';
import { external } from '@wordpress/icons';
import { useEffect, useState, useRef, useContext } from '@wordpress/element';
import { link, external } from '@wordpress/icons';

/**
* Internal dependencies
*/
/**
* Internal dependencies
*/
import BottomSheet from '../bottom-sheet';
import { BottomSheetContext } from '../bottom-sheet/bottom-sheet-context';
import PanelBody from '../../panel/body';
import TextControl from '../../text-control';
import ToggleControl from '../../toggle-control';
Expand Down Expand Up @@ -89,6 +87,13 @@ function LinkSettings( {
const [ linkRelInputValue, setLinkRelInputValue ] = useState( '' );
const prevEditorSidebarOpenedRef = useRef();

const { onHandleClosingBottomSheet } = useContext( BottomSheetContext );
useEffect( () => {
if ( ! onLinkCellPressed ) {
onHandleClosingBottomSheet( onCloseSettingsSheet );
}
}, [ urlInputValue, labelInputValue, linkRelInputValue ] );

useEffect( () => {
prevEditorSidebarOpenedRef.current = editorSidebarOpened;
} );
Expand Down Expand Up @@ -163,6 +168,13 @@ function LinkSettings( {
setLinkRelInputValue( value );
}

function onChangeURL( value ) {
if ( ! value && onEmptyURL ) {
onEmptyURL();
}
setUrlInputValue( value );
}

async function getURLFromClipboard() {
const clipboardText = await Clipboard.getString();

Expand All @@ -180,13 +192,30 @@ function LinkSettings( {
function getSettings() {
return (
<>
{ options.url && (
<BottomSheet.LinkCell
showIcon={ showIcon }
value={ url }
onPress={ onLinkCellPressed }
/>
) }
{ options.url &&
( onLinkCellPressed ? (
<BottomSheet.LinkCell
showIcon={ showIcon }
value={ url }
onPress={ onLinkCellPressed }
/>
) : (
<TextControl
icon={ showIcon && link }
label={ options.url.label }
value={ urlInputValue }
valuePlaceholder={ options.url.placeholder }
onChange={ onChangeURL }
onSubmit={ onCloseSettingsSheet }
autoCapitalize="none"
autoCorrect={ false }
// eslint-disable-next-line jsx-a11y/no-autofocus
autoFocus={
Platform.OS === 'ios' && options.url.autoFocus
}
keyboardType="url"
/>
) ) }
{ options.linkLabel && (
<TextControl
label={ options.linkLabel.label }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ const LinkSettingsScreen = ( props ) => {
return useMemo( () => {
return (
<LinkSettings
onLinkCellPressed={ onLinkCellPressed }
onLinkCellPressed={
props.hasPicker ? onLinkCellPressed : undefined
}
urlValue={ inputValue }
{ ...props }
/>
Expand Down

0 comments on commit 0b3a196

Please sign in to comment.