Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into feature/rich-text-f…
Browse files Browse the repository at this point in the history
…ormats
  • Loading branch information
Tug committed Dec 19, 2018
2 parents 3b3034b + 040ec9a commit d8ac9cf
Show file tree
Hide file tree
Showing 15 changed files with 199 additions and 158 deletions.
83 changes: 42 additions & 41 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.

89 changes: 48 additions & 41 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": "0.2.5",
"version": "0.2.6",
"private": true,
"config": {
"jsfiles": "./*.js src/*.js src/**/*.js src/**/**/*.js",
Expand Down
2 changes: 1 addition & 1 deletion react-native-aztec
16 changes: 15 additions & 1 deletion react-native-gutenberg-bridge/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
/** @format */

import { NativeModules, NativeEventEmitter } from 'react-native';
import { NativeModules, NativeEventEmitter, Platform } from 'react-native';

const { RNReactNativeGutenbergBridge } = NativeModules;
const isIOS = Platform.OS === 'ios';

const gutenbergBridgeEvents = new NativeEventEmitter( RNReactNativeGutenbergBridge );

// Send messages

export function sendNativeEditorDidLayout() {
// For now, this is only needed on iOS to solve layout issues with the toolbar.
// If this become necessary on Android in the future, we can try to build a registration API from Native
// to register messages it wants to receive, similar to the Native -> JS messages listener system.
if ( isIOS ) {
RNReactNativeGutenbergBridge.editorDidLayout();
}
}

// Register listeners

export function subscribeParentGetHtml( callback ) {
return gutenbergBridgeEvents.addListener( 'requestGetHtml', callback );
}
Expand Down
14 changes: 13 additions & 1 deletion react-native-gutenberg-bridge/ios/GutenbergBridgeDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,19 @@ public protocol GutenbergBridgeDelegate: class {
/// image Url or nil to signal that the action was canceled.
func gutenbergDidRequestMediaPicker(with callback: @escaping MediaPickerDidPickMediaCallback)

/// Informs the delegate that the Gutenberg module has finished loading.
/// Tells the delegate that the Gutenberg module has finished loading.
///
func gutenbergDidLoad()


/// Tells the delegate every time the editor has finished layout.
///
func gutenbergDidLayout()
}

// MARK: - Optional GutenbergBridgeDelegate methods

public extension GutenbergBridgeDelegate {
func gutenbergDidLoad() { }
func gutenbergDidLayout() { }
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ @interface RCT_EXTERN_MODULE(RNReactNativeGutenbergBridge, NSObject)

RCT_EXTERN_METHOD(provideToNative_Html:(NSString *)html changed:(BOOL)changed)
RCT_EXTERN_METHOD(onMediaLibraryPress:(RCTResponseSenderBlock)callback)
RCT_EXTERN_METHOD(moduleDidMount)
RCT_EXTERN_METHOD(editorDidLayout)

@end
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@objc (RNReactNativeGutenbergBridge)
public class RNReactNativeGutenbergBridge: RCTEventEmitter {
weak var delegate: GutenbergBridgeDelegate?
private var isJSLoading = true

// MARK: - Messaging methods

Expand All @@ -21,9 +22,9 @@ public class RNReactNativeGutenbergBridge: RCTEventEmitter {
}

@objc
func moduleDidMount() {
func editorDidLayout() {
DispatchQueue.main.async {
self.delegate?.gutenbergDidLoad()
self.delegate?.gutenbergDidLayout()
}
}
}
Expand All @@ -42,6 +43,15 @@ extension RNReactNativeGutenbergBridge {
public override static func requiresMainQueueSetup() -> Bool {
return true
}

public override func batchDidComplete() {
if isJSLoading {
isJSLoading = false
DispatchQueue.main.async {
self.delegate?.gutenbergDidLoad()
}
}
}
}

// MARK: - Helpers
Expand Down
28 changes: 7 additions & 21 deletions src/app/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import React from 'react';
// Gutenberg imports
import { registerCoreBlocks } from '@wordpress/block-library';
import { registerBlockType, setUnregisteredTypeHandlerName } from '@wordpress/blocks';
import RNReactNativeGutenbergBridge from 'react-native-gutenberg-bridge';

import AppContainer from './AppContainer';
import initialHtml from './initial-html';
Expand All @@ -25,26 +24,13 @@ type PropsType = {
initialHtmlModeEnabled: boolean,
};

class AppProvider extends React.Component<PropsType> {
componentDidMount() {
// At this points (apparently) component setup haven't finished yet.
// Giving it one extra milisecond does the trick.
setTimeout( () => {
RNReactNativeGutenbergBridge.moduleDidMount();
}, 1 );
const AppProvider = ( { initialData, initialHtmlModeEnabled }: PropsType ) => {
if ( initialData === undefined ) {
initialData = initialHtml;
}

render() {
let { initialData } = this.props;

if ( initialData === undefined ) {
initialData = initialHtml;
}

return (
<AppContainer initialHtml={ initialData } initialHtmlModeEnabled={ this.props.initialHtmlModeEnabled } />
);
}
}
return (
<AppContainer initialHtml={ initialData } initialHtmlModeEnabled={ initialHtmlModeEnabled } />
);
};

export default AppProvider;
5 changes: 4 additions & 1 deletion src/block-management/block-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { withDispatch, withSelect } from '@wordpress/data';
import { compose } from '@wordpress/compose';
import { createBlock, isUnmodifiedDefaultBlock } from '@wordpress/blocks';
import { DefaultBlockAppender } from '@wordpress/editor';
import { sendNativeEditorDidLayout } from 'react-native-gutenberg-bridge';

import EventEmitter from 'events';

Expand Down Expand Up @@ -149,7 +150,9 @@ export class BlockManager extends React.Component<PropsType, StateType> {

onRootViewLayout = ( event: LayoutChangeEvent ) => {
const { height } = event.nativeEvent.layout;
this.setState( { rootViewHeight: height } );
this.setState( { rootViewHeight: height }, () => {
sendNativeEditorDidLayout();
} );
}

componentDidMount() {
Expand Down
78 changes: 38 additions & 40 deletions src/block-management/block-toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import React, { Component } from 'react';
import { View, ScrollView, SafeAreaView } from 'react-native';
import { View, ScrollView } from 'react-native';
import { withSelect, withDispatch } from '@wordpress/data';
import { compose } from '@wordpress/compose';
import { Toolbar, ToolbarButton } from '@wordpress/components';
Expand Down Expand Up @@ -36,45 +36,43 @@ export class BlockToolbar extends Component<PropsType> {
} = this.props;

return (
<SafeAreaView>
<View style={ styles.container }>
<ScrollView
horizontal={ true }
showsHorizontalScrollIndicator={ false }
keyboardShouldPersistTaps={ 'always' }
alwaysBounceHorizontal={ false }
>
<Toolbar>
<ToolbarButton
label={ __( 'Add block' ) }
icon="insert"
onClick={ onInsertClick }
/>
<ToolbarButton
label={ __( 'Undo' ) }
icon="undo"
isDisabled={ ! hasUndo }
onClick={ undo }
/>
<ToolbarButton
label={ __( 'Redo' ) }
icon="redo"
isDisabled={ ! hasRedo }
onClick={ redo }
/>
</Toolbar>
{ showKeyboardHideButton && ( <Toolbar>
<ToolbarButton
label={ __( 'Keyboard hide' ) }
icon="arrow-down"
onClick={ onKeyboardHide }
/>
</Toolbar> ) }
<BlockControls.Slot />
<BlockFormatControls.Slot />
</ScrollView>
</View>
</SafeAreaView>
<View style={ styles.container }>
<ScrollView
horizontal={ true }
showsHorizontalScrollIndicator={ false }
keyboardShouldPersistTaps={ 'always' }
alwaysBounceHorizontal={ false }
>
<Toolbar>
<ToolbarButton
label={ __( 'Add block' ) }
icon="insert"
onClick={ onInsertClick }
/>
<ToolbarButton
label={ __( 'Undo' ) }
icon="undo"
isDisabled={ ! hasUndo }
onClick={ undo }
/>
<ToolbarButton
label={ __( 'Redo' ) }
icon="redo"
isDisabled={ ! hasRedo }
onClick={ redo }
/>
</Toolbar>
{ showKeyboardHideButton && ( <Toolbar>
<ToolbarButton
label={ __( 'Keyboard hide' ) }
icon="arrow-down"
onClick={ onKeyboardHide }
/>
</Toolbar> ) }
<BlockControls.Slot />
<BlockFormatControls.Slot />
</ScrollView>
</View>
);
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/components/keyboard-aware-flat-list.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
* @format
* @flow
*/
import { FlatList, KeyboardAvoidingView } from 'react-native';
import { FlatList } from 'react-native';
import KeyboardAvoidingView from '../components/keyboard-avoiding-view';

type PropsType = {
...FlatList.propTypes,
Expand Down
17 changes: 13 additions & 4 deletions src/components/keyboard-aware-flat-list.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,19 @@ const KeyboardAwareFlatList = ( props: PropsType ) => {
shouldPreventAutomaticScroll,
...listProps
} = props;
const { height: fullHeight } = Dimensions.get( 'window' );
const keyboardVerticalOffset = fullHeight - parentHeight;
const blockHolderPadding = 8;
const extraScrollHeight = blockToolbarHeight + innerToolbarHeight + blockHolderPadding + keyboardVerticalOffset;

const extraScrollHeight = ( () => {
const { height: fullHeight, width: fullWidth } = Dimensions.get( 'window' );
const keyboardVerticalOffset = fullHeight - parentHeight;
const blockHolderPadding = 8;

if ( fullWidth > fullHeight ) { //landscape mode
//we won't try to make inner block visible in landscape mode because there's not enough room for it
return blockToolbarHeight + keyboardVerticalOffset;
}
//portrait mode
return blockToolbarHeight + keyboardVerticalOffset + blockHolderPadding + innerToolbarHeight;
} )();

return (
<KeyboardAwareScrollView
Expand Down

0 comments on commit d8ac9cf

Please sign in to comment.