diff --git a/.gitignore b/.gitignore index b5cd0124e5d4b..48cd7580beed1 100644 --- a/.gitignore +++ b/.gitignore @@ -48,3 +48,4 @@ test/storybook-playwright/specs/__snapshots__ test/storybook-playwright/specs/*-snapshots/** test/gutenberg-test-themes/twentytwentyone test/gutenberg-test-themes/twentytwentythree +packages/react-native-editor/src/setup-local.js diff --git a/docs/contributors/code/react-native/getting-started-react-native.md b/docs/contributors/code/react-native/getting-started-react-native.md index e13ac748aaf29..53d5f7eee5a12 100644 --- a/docs/contributors/code/react-native/getting-started-react-native.md +++ b/docs/contributors/code/react-native/getting-started-react-native.md @@ -71,6 +71,40 @@ npm run native ios -- -- --simulator="iPhone Xs Max" To see a list of all of your available iOS devices, use `xcrun simctl list devices`. +### Customizing the Demo Editor + +By default, the Demo editor renders most of the supported core blocks. This is helpful to showcase the editor's capabilities, but can be distracting when focusing on a specific block or feature. One can customize the editor's intial state by leveraging the `native.block_editor_props` hook in a `packages/react-native-editor/src/setup-local.js` file. + +
Example setup-local.js + +```js +/** + * WordPress dependencies + */ +import { addFilter } from '@wordpress/hooks'; + +export default () => { + addFilter( + 'native.block_editor_props', + 'core/react-native-editor', + ( props ) => { + return { + ...props, + initialHtml, + }; + } + ); +}; + +const initialHtml = ` + +

Just a Heading

+ +`; +``` + +
+ ### Troubleshooting If the Android emulator doesn't start correctly, or compiling fails with `Could not initialize class org.codehaus.groovy.runtime.InvokerHelper` or similar, it may help to double check the set up of your development environment against the latest requirements in [React Native's documentation](https://reactnative.dev/docs/environment-setup). With Android Studio, for example, you will need to configure the `ANDROID_HOME` environment variable and ensure that your version of JDK matches the latest requirements. diff --git a/packages/react-native-editor/metro.config.js b/packages/react-native-editor/metro.config.js index 05e57e3cfbcab..307853a612c8c 100644 --- a/packages/react-native-editor/metro.config.js +++ b/packages/react-native-editor/metro.config.js @@ -27,6 +27,7 @@ module.exports = { inlineRequires: false, }, } ), + unstable_allowRequireContext: true, // Used for optional setup configuration. }, server: { enhanceMiddleware: ( middleware ) => ( req, res, next ) => { diff --git a/packages/react-native-editor/src/index.js b/packages/react-native-editor/src/index.js index a4ca31e3e9488..32ba1c6f3441d 100644 --- a/packages/react-native-editor/src/index.js +++ b/packages/react-native-editor/src/index.js @@ -51,6 +51,12 @@ const registerGutenberg = ( { // Initialize editor this.editorComponent = setup(); + // Apply optional setup configuration, enabling modification via hooks. + if ( typeof require.context === 'function' ) { + const req = require.context( './', false, /setup-local\.js$/ ); + req.keys().forEach( ( key ) => req( key ).default() ); + } + // Dispatch pre-render hooks. doAction( 'native.pre-render', parentProps );