Skip to content

Commit

Permalink
[RNMobile][Embed block] Fix URL update when edited after setting a ba…
Browse files Browse the repository at this point in the history
…d URL of a provider (#35013)

* Add state variable to control embed bottom sheet visibility

* Add comment about URL update call order

* Use npm install in RN E2E tests

* Revert "Use npm install in RN E2E tests"

This reverts commit cfc8f74.
  • Loading branch information
fluiddot authored Sep 24, 2021
1 parent 4f0a24f commit 4cfd3fc
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions packages/block-library/src/embed/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ const EmbedEdit = ( props ) => {
const [ isEditingURL, setIsEditingURL ] = useState(
isSelected && wasBlockJustInserted && ! url
);
const [ showEmbedBottomSheet, setShowEmbedBottomSheet ] = useState(
isEditingURL
);
const { invalidateResolution } = useDispatch( coreStore );

const {
Expand Down Expand Up @@ -192,6 +195,10 @@ const EmbedEdit = ( props ) => {
}
}, [ preview, isEditingURL ] );

useEffect( () => setShowEmbedBottomSheet( isEditingURL ), [
isEditingURL,
] );

const blockProps = useBlockProps();

if ( fetching ) {
Expand Down Expand Up @@ -287,11 +294,14 @@ const EmbedEdit = ( props ) => {
<EmbedBottomSheet
value={ url }
label={ bottomSheetLabel }
isVisible={ isEditingURL }
onClose={ () => setIsEditingURL( false ) }
isVisible={ showEmbedBottomSheet }
onClose={ () => setShowEmbedBottomSheet( false ) }
onSubmit={ ( value ) => {
setIsEditingURL( false );
// The order of the following calls is important, we need to update the URL attribute before changing `isEditingURL`,
// otherwise the side-effect that potentially replaces the block when updating the local state won't use the new URL
// for creating the new block.
setAttributes( { url: value } );
setIsEditingURL( false );
} }
/>
</>
Expand Down

0 comments on commit 4cfd3fc

Please sign in to comment.