Skip to content

Commit

Permalink
Merge pull request #790 from wordpress-mobile/hotfix/v1.1.2
Browse files Browse the repository at this point in the history
Fix `hasUnsupportedBlocks` check.
  • Loading branch information
etoledom authored Mar 28, 2019
2 parents 0b22a15 + 3b7c8ec commit acd6854
Show file tree
Hide file tree
Showing 7 changed files with 158 additions and 107 deletions.
100 changes: 50 additions & 50 deletions bundle/android/App.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion bundle/android/App.js.map

Large diffs are not rendered by default.

100 changes: 50 additions & 50 deletions bundle/ios/App.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion bundle/ios/App.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gutenberg-mobile",
"version": "1.1.1",
"version": "1.1.2",
"private": true,
"config": {
"jsfiles": "./*.js src/*.js src/**/*.js src/**/**/*.js",
Expand Down
15 changes: 11 additions & 4 deletions src/app/AppContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,6 @@ class AppContainer extends React.Component<PropsType> {
}

componentDidMount() {
const blocks = this.props.blocks;
const hasUnsupportedBlocks = ! isEmpty( blocks.filter( ( { name } ) => name === UnsupportedBlock.name ) );
RNReactNativeGutenbergBridge.editorDidMount( hasUnsupportedBlocks );

this.subscriptionParentGetHtml = subscribeParentGetHtml( () => {
this.serializeToNativeAction();
} );
Expand Down Expand Up @@ -149,6 +145,17 @@ class AppContainer extends React.Component<PropsType> {
switchMode( mode === 'visual' ? 'text' : 'visual' );
}

componentDidUpdate( prevProps ) {
if ( ! prevProps.isReady && ( prevProps.isReady !== this.props.isReady ) ) {
const { blocks } = this.props;
const isUnsupportedBlock = ( { name } ) => name === UnsupportedBlock.name;
const unsupportedBlocks = blocks.filter( isUnsupportedBlock );
const hasUnsupportedBlocks = ! isEmpty( unsupportedBlocks );

RNReactNativeGutenbergBridge.editorDidMount( hasUnsupportedBlocks );
}
}

render() {
const {
blocks,
Expand Down
44 changes: 44 additions & 0 deletions src/app/AppContainer.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/** @format */

/**
* External dependencies
*/
import renderer from 'react-test-renderer';

/**
* Internal dependencies
*/
import { bootstrapEditor } from '..';
import AppContainer from './AppContainer';
import RNReactNativeGutenbergBridge from 'react-native-gutenberg-bridge';

const unsupportedBlock = `
<!-- wp:notablock -->
<p>Not supported</p>
<!-- /wp:notablock -->
`;

describe( 'AppContainer', () => {
beforeAll( bootstrapEditor );

it( 'detects unsupported block and sends hasUnsupportedBlocks true to native', () => {
RNReactNativeGutenbergBridge.editorDidMount = jest.fn();

const appContainer = renderAppContainerWith( unsupportedBlock );
appContainer.unmount();

expect( RNReactNativeGutenbergBridge.editorDidMount ).toHaveBeenCalledTimes( 1 );
expect( RNReactNativeGutenbergBridge.editorDidMount ).toHaveBeenCalledWith( true );
} );
} );

// Utilities
const renderAppContainerWith = ( content ) => {
return renderer.create(
<AppContainer
initialHtml={ content }
initialHtmlModeEnabled={ false }
initialTitle={ '' }
/>
);
};

0 comments on commit acd6854

Please sign in to comment.