Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RNMobile][Monorepo] Make the native app customizable by a parent app #21332

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
2541642
Experiment a new way to setup the native editor that can be customize…
Tug Apr 1, 2020
c252eb3
Add mock for render
Tug Apr 28, 2020
0a61a22
Add other properties to @wordpress/element mock implementation
Tug Apr 29, 2020
b63829e
Merge remote-tracking branch 'origin/feat/import-gutenberg-mobile-no-…
Tug May 15, 2020
318e668
prettier changes
Tug May 15, 2020
3c9d92e
Split block_editor_props action in 2 depending if we're receiving pro…
Tug May 15, 2020
2cfee15
Refactor initializeEditor and init props
Tug May 15, 2020
5c34df8
Do not record screen for Android on non-macos platforms
ceyhun May 19, 2020
ce9e145
Fix building wpandroid
Tug May 19, 2020
da6949a
Update android deviceName for remote e2e tests
ceyhun May 19, 2020
52ef860
Update react-native-get-random-values in bridge build
Tug May 20, 2020
c910d8d
Update formatting
Tug May 20, 2020
67b39a7
Update bridge build config for android
Tug May 20, 2020
688b42e
Revert linking react-native-get-random-values manually for ios
Tug May 20, 2020
e5186c5
Update package-lock.json with changes from running npm install
ceyhun May 22, 2020
0dfffe0
Fix linter error
ceyhun May 22, 2020
75260fc
Remove Podfile change
ceyhun May 22, 2020
16d8a00
Fix android demo app blank screen when building with __DEV__ flag bei…
ceyhun May 22, 2020
14c9a95
Fix native unit tests
ceyhun May 22, 2020
af9a8f4
Remove third-party-podspecs from react-native-bridge
ceyhun May 26, 2020
3e153c2
Commit hermes locally so we can build gutenberg using jitpack without…
Tug May 26, 2020
580130f
Remove hermes headers
Tug May 26, 2020
c5e9385
Update github actions/cache to v2
ceyhun May 27, 2020
3466d25
Only run gallery e2e tests
ceyhun May 27, 2020
0f7f14a
Try different jest config
ceyhun May 27, 2020
ddc7209
Try different jest config
ceyhun May 27, 2020
823d9bd
Add logs
ceyhun May 27, 2020
c724716
Revert "Add logs"
ceyhun May 27, 2020
f684dc3
Add log
ceyhun May 27, 2020
3c8056c
Revert "Add log"
ceyhun May 27, 2020
cc0c972
Add package-lock.json changes after npm install
ceyhun May 27, 2020
85ba21b
Force exit jest after all tests have completed running
ceyhun May 27, 2020
7a96fc7
Update podfile.lock
Tug May 27, 2020
f621b57
Update .gitignore
Tug Jun 1, 2020
37c76c4
Update bridge build
Tug Jun 1, 2020
9fbc93d
Fix link error in react-native-bridge/package.json
Tug Jun 1, 2020
e7961e1
Fix react-native entry in @wordpress/react-native-bridge package.json
Tug Jun 2, 2020
1944d87
Remove unused commands and update clean commands
Tug Jun 2, 2020
9e28af9
Add RNGetRandomValuesPackage to WPAndroid glue code
ceyhun Jun 3, 2020
a530091
Update working directory for npm related bridge commands
ceyhun Jun 3, 2020
6912528
Decrease sleep time for android recording process
ceyhun Jun 3, 2020
cc6d046
Disable npm cache for android and ios runners
ceyhun Jun 3, 2020
1f5c191
Re-enable npm cache but use exact key for restore
ceyhun Jun 3, 2020
1711205
Update package-lock.json by re-adding react-native-editor to bust npm…
ceyhun Jun 3, 2020
dd076a9
Remove nvm step from iOS runner
ceyhun Jun 3, 2020
e5329b4
Decrease sleep time for android recording process
ceyhun Jun 3, 2020
8832f53
Ignore and log android screen recording errors
ceyhun Jun 3, 2020
b46844e
Remove unnecessary patch files
Tug Jun 5, 2020
f71b3ab
Try setting max worker to 2 to avoid error 137 on circle CI
Tug Jun 5, 2020
9113661
Updated commands in README.md
cameronvoell Jun 10, 2020
a79e21a
Use Xcode version 11.4.1 when running e2e tests
ceyhun Jun 12, 2020
66c0dc7
Update package-lock.json
ceyhun Jun 12, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions .github/workflows/rnmobile-android-runner.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,23 @@ jobs:
strategy:
matrix:
native-test-name: [
gutenberg-editor-heading,
gutenberg-editor-image,
gutenberg-editor-gallery
]

steps:
- name: checkout
uses: actions/checkout@v2

- name: Restore npm cache
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.os }}-npm-${{ hashFiles('package-lock.json') }}
restore-keys: |
${{ runner.os }}-npm-

- run: npm ci

- name: Restore Gradle cache
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
Expand Down
20 changes: 8 additions & 12 deletions .github/workflows/rnmobile-ios-runner.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,31 @@ jobs:
strategy:
matrix:
native-test-name: [
gutenberg-editor-heading,
gutenberg-editor-image,
gutenberg-editor-gallery
]

steps:
- uses: actions/checkout@v2

- name: Restore npm cache
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.os }}-npm-${{ hashFiles('package-lock.json') }}
restore-keys: |
${{ runner.os }}-npm-

- name: Install dependencies
run: |
source ~/.nvm/nvm.sh
nvm install
npm ci
- run: npm ci

- name: Prepare build cache key
run: find package-lock.json packages/react-native-editor/ios packages/react-native-aztec/ios packages/react-native-bridge/ios -type f -print0 | sort -z | xargs -0 shasum | tee ios-checksums.txt

- name: Restore build cache
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: packages/react-native-editor/ios/build/gutenberg/Build/Products/Release-iphonesimulator/GutenbergDemo.app
key: ${{ runner.os }}-ios-build-${{ hashFiles('ios-checksums.txt') }}

- name: Restore pods cache
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: |
packages/react-native-editor/ios/Pods
Expand All @@ -55,6 +48,9 @@ jobs:
- name: Bundle iOS
run: npm run native test:e2e:bundle:ios

- name: Switch Xcode Version
run: sudo xcode-select --switch /Applications/Xcode_11.4.1.app

- name: Build (if needed)
run: test -e packages/react-native-editor/ios/build/gutenberg/Build/Products/Release-iphonesimulator/GutenbergDemo.app/GutenbergDemo || SKIP_BUNDLING=true npm run native test:e2e:build-app:ios

Expand Down
38 changes: 25 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions packages/edit-post/src/editor.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ class Editor extends Component {
hiddenBlockTypes,
blockTypes,
post,
postId,
postType,
...props
} = this.props;
Expand All @@ -112,9 +113,9 @@ class Editor extends Component {
);

const normalizedPost = post || {
id: 1,
id: postId,
title: {
raw: props.initialTitle,
raw: props.initialTitle || '',
},
content: {
// make sure the post content is in sync with gutenberg store
Expand Down
16 changes: 11 additions & 5 deletions packages/edit-post/src/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,36 @@
*/
import '@wordpress/core-data';
import '@wordpress/block-editor';
import '@wordpress/editor';
import '@wordpress/viewport';
import '@wordpress/notices';
import { registerCoreBlocks } from '@wordpress/block-library';
import '@wordpress/format-library';
import { render } from '@wordpress/element';

/**
* Internal dependencies
*/
import './store';
import Editor from './editor';

let blocksRegistered = false;

/**
* Initializes the Editor.
* Initializes the Editor and returns a componentProvider
* that can be registered with `AppRegistry.registerComponent`
*
* @param {string} id Unique identifier for editor instance.
* @param {Object} postType Post type of the post to edit.
* @param {Object} postId ID of the post to edit (unused right now)
*/
export function initializeEditor() {
export function initializeEditor( id, postType, postId ) {
if ( blocksRegistered ) {
return;
}

// register and setup blocks
registerCoreBlocks();
blocksRegistered = true;
}

export { default as Editor } from './editor';
render( <Editor postId={ postId } postType={ postType } />, id );
}
1 change: 1 addition & 0 deletions packages/edit-post/src/test/editor.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ const renderEditorWith = ( content ) => {
initialHtmlModeEnabled={ false }
initialTitle={ '' }
postType="post"
postId="1"
/>
);
};
39 changes: 39 additions & 0 deletions packages/element/src/react-platform.native.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* External dependencies
*/
import { AppRegistry } from 'react-native';
import { omit } from 'lodash';

/**
* WordPress dependencies
*/
import { applyFilters, doAction } from '@wordpress/hooks';

/**
* Internal dependencies
*/
import { cloneElement } from './react';

const render = ( element, id ) =>
AppRegistry.registerComponent( id, () => ( propsFromParent ) => {
Copy link
Member

@gziolo gziolo Jun 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity, why not to execute all this logic inside initializeEditor in the @wordpress/edit-post package?

Overriding React methods and adding WP hooks might have some performance implications but I guess it’s called only once.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's to be able to customize the editor from an outside package. In this case a repo that's importing Gutenberg as a submodule. Correct me if I'm wrong @Tug?

Copy link
Contributor Author

@Tug Tug Jun 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No we could totally have this logic in @wordpress/edit-post (or in @wordpress/react-native-editor as it was the case in the monorepo branch before this PR).

The idea here is simply to get closer to having @wordpress/edit-post work as cross-platform package. If you look at edit-post/src/index.native.js
you'll see that the init code is much closer to the web one now.

Overriding React methods and adding WP hooks might have some performance implications but I guess it’s called only once.

We're not overriding anything though, the render function wasn't defined for native prior to this. And yes it's only rendered once on load.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It probably doesn't matter as much then now, but I guess initializeEditor would be the best place to run all those side effects.

const parentProps = omit( propsFromParent || {}, [ 'rootTag' ] );

doAction( 'native.pre-render', parentProps );

const filteredProps = applyFilters(
'native.block_editor_props',
parentProps
);

doAction( 'native.render', filteredProps );

return cloneElement( element, filteredProps );
} );

/**
* Render a given element on Native.
* This actually returns a componentProvider that can be registered with `AppRegistry.registerComponent`
*
* @param {WPElement} element Element to render.
*/
export { render };
6 changes: 3 additions & 3 deletions packages/react-native-bridge/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
node_modules/
npm-debug.log
yarn-error.log


# Xcode
#
Expand All @@ -29,7 +29,7 @@ DerivedData
*.ipa
*.xcuserstate
project.xcworkspace


# Android/IntelliJ
#
Expand All @@ -38,9 +38,9 @@ build/
.gradle
local.properties
*.iml
android/src/main/assets/

# BUCK
buck-out/
\.buckd/
*.keystore

Loading