Skip to content

Commit

Permalink
[Mobile] Quote - Use nested blocks (#40439)
Browse files Browse the repository at this point in the history
* Mobile - Remove Quote V2 check on registration

* Mobile - Tests - initializes the editor: With inner blocks we need to get the first element which is the main list
  • Loading branch information
Gerardo Pacheco authored Apr 26, 2022
1 parent 8cfeb7c commit 4536cbb
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 22 deletions.
13 changes: 2 additions & 11 deletions packages/block-library/src/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,14 +179,6 @@ const devOnly = ( block ) => ( !! __DEV__ ? block : null );
const iOSOnly = ( block ) =>
Platform.OS === 'ios' ? block : devOnly( block );

// To be removed once Quote V2 is released on the web editor.
function quoteCheck( quoteBlock, blocksFlags ) {
if ( blocksFlags?.__experimentalEnableQuoteBlockV2 ) {
quoteBlock.settings = quoteBlock?.settingsV2;
}
return quoteBlock;
}

// Hide the Classic block and SocialLink block
addFilter(
'blocks.registerBlockType',
Expand Down Expand Up @@ -238,10 +230,9 @@ addFilter(
*
* registerCoreBlocks();
* ```
* @param {Object} [blocksFlags] Experimental flags
*
*/
export const registerCoreBlocks = ( blocksFlags ) => {
export const registerCoreBlocks = () => {
// When adding new blocks to this list please also consider updating /src/block-support/supported-blocks.json in the Gutenberg-Mobile repo
[
paragraph,
Expand All @@ -254,7 +245,7 @@ export const registerCoreBlocks = ( blocksFlags ) => {
nextpage,
separator,
list,
quoteCheck( quote, blocksFlags ),
quote,
mediaText,
preformatted,
gallery,
Expand Down
4 changes: 1 addition & 3 deletions packages/edit-post/src/test/editor.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ const unsupportedBlock = `
jest.useFakeTimers( 'legacy' );

describe( 'Editor', () => {
beforeAll( () => {
registerCoreBlocks();
} );
beforeAll( registerCoreBlocks );

it( 'detects unsupported block and sends hasUnsupportedBlocks true to native', () => {
RNReactNativeGutenbergBridge.editorDidMount = jest.fn();
Expand Down
11 changes: 4 additions & 7 deletions packages/react-native-editor/src/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,9 @@ const gutenbergSetup = () => {

const setupInitHooks = () => {
addAction( 'native.pre-render', 'core/react-native-editor', ( props ) => {
const capabilities = props.capabilities ?? {};
const blocksFlags = {
__experimentalEnableQuoteBlockV2: props?.quoteBlockV2,
};
registerBlocks();

registerBlocks( blocksFlags );
const capabilities = props.capabilities ?? {};

// Unregister non-supported blocks by capabilities
if (
Expand Down Expand Up @@ -119,12 +116,12 @@ const setupInitHooks = () => {
};

let blocksRegistered = false;
const registerBlocks = ( blocksFlags ) => {
const registerBlocks = () => {
if ( blocksRegistered ) {
return;
}

registerCoreBlocks( blocksFlags );
registerCoreBlocks();

blocksRegistered = true;
};
Expand Down
3 changes: 2 additions & 1 deletion packages/react-native-editor/src/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@ describe( 'Register Gutenberg', () => {
{},
{ component: EditorComponent }
);
const blockList = screen.getByTestId( 'block-list-wrapper' );
// Inner blocks create BlockLists so let's take into account selecting the main one
const blockList = screen.getAllByTestId( 'block-list-wrapper' )[ 0 ];

expect( blockList ).toBeVisible();
expect( console ).toHaveLoggedWith( 'Hermes is: true' );
Expand Down

0 comments on commit 4536cbb

Please sign in to comment.