Skip to content

Commit

Permalink
Merge pull request #242 from wordpress-mobile/fix/bridge
Browse files Browse the repository at this point in the history
Send `changed` to the native bridge if html changed since last time
  • Loading branch information
Tug committed Nov 15, 2018
2 parents 082203a + 4f568e3 commit 66f244b
Show file tree
Hide file tree
Showing 3 changed files with 1,268 additions and 20 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@
"jsc-android": "224109.x.x",
"jsdom-jscore": "git+https://github.com/iamcco/jsdom-jscore-rn.git#6eac88dd5d5e7c21ce6382abde7dbc376d7f7f59",
"jsx-to-string": "^1.3.1",
"md5": "^2.2.1",
"memize": "^1.0.5",
"moment": "^2.22.1",
"moment-timezone": "^0.5.16",
Expand Down
10 changes: 8 additions & 2 deletions src/app/AppContainer.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
/** @flow
* @format */

import MainApp from './MainApp';
import React from 'react';
import { parse, serialize } from '@wordpress/blocks';
import { withDispatch, withSelect } from '@wordpress/data';
import { compose } from '@wordpress/compose';
import RNReactNativeGutenbergBridge from 'react-native-gutenberg-bridge';

import MainApp from './MainApp';
import type { BlockType } from '../store/types';

type PropsType = {
Expand All @@ -26,10 +27,14 @@ type PropsType = {
};

class AppContainer extends React.Component<PropsType> {
lastHtmlSent: ?string

constructor( props: PropsType ) {
super( props );

this.parseBlocksAction( props.initialHtml );

this.lastHtmlSent = null;
}

onChange = ( clientId, attributes ) => {
Expand Down Expand Up @@ -63,7 +68,8 @@ class AppContainer extends React.Component<PropsType> {

serializeToNativeAction = () => {
const html = serialize( this.props.blocks );
RNReactNativeGutenbergBridge.provideToNative_Html( html );
RNReactNativeGutenbergBridge.provideToNative_Html( html, this.lastHtmlSent !== html );
this.lastHtmlSent = html;
};

mergeBlocksAction = ( blockOneClientId, blockTwoClientId ) => {
Expand Down
Loading

0 comments on commit 66f244b

Please sign in to comment.