Skip to content

Commit

Permalink
Merge branch 'develop' into feature/rich-text-formats
Browse files Browse the repository at this point in the history
  • Loading branch information
hypest committed Feb 8, 2019
2 parents e151053 + 890ebf4 commit 41f1708
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 27 deletions.
2 changes: 1 addition & 1 deletion gutenberg
Submodule gutenberg updated 140 files
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** @flow
* @format */

import { AppRegistry } from 'react-native';
import App from './src/app/App';
AppRegistry.registerComponent( 'gutenberg', () => App );
import { setupApp } from './src';

setupApp();
2 changes: 1 addition & 1 deletion ios/gutenberg/MediaUploadCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class MediaUploadCoordinator: NSObject {
} else if progress.fractionCompleted >= 1 {
timer.invalidate()
if successfull {
gutenberg.mediaUploadUpdate(id: mediaID, state: .failed, progress: 1, url: mediaURL, serverID: 123)
gutenberg.mediaUploadUpdate(id: mediaID, state: .succeeded, progress: 1, url: mediaURL, serverID: 123)
activeUploads[mediaID] = nil
} else {
progress.setUserInfoObject("Network upload failed", forKey: .mediaError)
Expand Down
2 changes: 1 addition & 1 deletion react-native-gutenberg-bridge/ios/Gutenberg.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public class Gutenberg: NSObject {
if let serverID = serverID {
data["mediaServerId"] = serverID
}
bridgeModule.sendEvent(withName: EventName.mediaUpload, body: data)
bridgeModule.sendEventIfNeeded(name: EventName.mediaUpload, body: data)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
public class RNReactNativeGutenbergBridge: RCTEventEmitter {
weak var delegate: GutenbergBridgeDelegate?
private var isJSLoading = true

private var hasObservers = false
// MARK: - Messaging methods

@objc
Expand Down Expand Up @@ -54,6 +54,28 @@ public class RNReactNativeGutenbergBridge: RCTEventEmitter {
self.delegate?.gutenbergDidLayout()
}
}

override public func startObserving() {
super.startObserving()
hasObservers = true
}

override public func stopObserving() {
super.stopObserving()
hasObservers = false
}


/// Sends events to the JS side only if there is observers listening
///
/// - Parameters:
/// - name: name of the event
/// - body: data for the event
public func sendEventIfNeeded(name: String, body: Any!) {
if ( hasObservers ) {
self.sendEvent(withName: name, body: body)
}
}
}

// MARK: - RCTBridgeModule delegate
Expand Down
20 changes: 0 additions & 20 deletions src/app/App.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,10 @@
/** @flow
* @format */

import '../globals';

import React from 'react';

// Gutenberg imports
import { registerCoreBlocks } from '@wordpress/block-library';
import { registerBlockType, setUnregisteredTypeHandlerName, unregisterBlockType } from '@wordpress/blocks';

import AppContainer from './AppContainer';
import initialHtml from './initial-html';

import * as UnsupportedBlock from '../block-types/unsupported-block/';
import '@wordpress/format-library';

registerCoreBlocks();
registerBlockType( UnsupportedBlock.name, UnsupportedBlock.settings );
setUnregisteredTypeHandlerName( UnsupportedBlock.name );

// disable Code and More blocks for release
if ( ! __DEV__ ) {
unregisterBlockType( 'core/code' );
unregisterBlockType( 'core/more' );
}

type PropsType = {
initialData: string,
initialHtmlModeEnabled: boolean,
Expand Down
3 changes: 3 additions & 0 deletions src/app/App.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

import renderer from 'react-test-renderer';

import { setupApp } from '..';
import App from './App';
import BlockHolder from '../block-management/block-holder';
import { dispatch, select } from '@wordpress/data';

describe( 'App', () => {
beforeAll( setupApp );

it( 'renders without crashing', () => {
const app = renderer.create( <App /> );
const rendered = app.toJSON();
Expand Down
48 changes: 48 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// External dependencies
import { AppRegistry } from 'react-native';

// Setting up environment
import './globals';

const gutenbergSetup = () => {
const apiFetch = require( '@wordpress/api-fetch' ).default;
const wpData = require( '@wordpress/data' );

// wp-api-fetch
apiFetch.use( apiFetch.createRootURLMiddleware( 'https://public-api.wordpress.com/' ) );

// wp-data
const userId = 1;
const storageKey = 'WP_DATA_USER_' + userId;
wpData.use( wpData.plugins.persistence, { storageKey: storageKey } );
wpData.use( wpData.plugins.controls );
};

const editorSetup = () => {
const wpBlockLibrary = require( '@wordpress/block-library' );
const wpBlocks = require( '@wordpress/blocks' );
const registerCoreBlocks = wpBlockLibrary.registerCoreBlocks;
const registerBlockType = wpBlocks.registerBlockType;
const setUnregisteredTypeHandlerName = wpBlocks.setUnregisteredTypeHandlerName;
const unregisterBlockType = wpBlocks.unregisterBlockType;
const UnsupportedBlock = require( './block-types/unsupported-block' );

// register and setup blocks
registerCoreBlocks();
registerBlockType( UnsupportedBlock.name, UnsupportedBlock.settings );
setUnregisteredTypeHandlerName( UnsupportedBlock.name );

// disable Code and More blocks for release
if ( ! __DEV__ ) {
unregisterBlockType( 'core/code' );
unregisterBlockType( 'core/more' );
}
};

export function setupApp() {
gutenbergSetup();
editorSetup();

// Making sure the environment is set up before loading any Component
AppRegistry.registerComponent( 'gutenberg', () => require( './app/App' ).default );
}

0 comments on commit 41f1708

Please sign in to comment.