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] Enable new block in Gutenberg Mobile #47836

Merged
merged 5 commits into from
Feb 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ data class GutenbergProps @JvmOverloads constructor(
val enableContactInfoBlock: Boolean,
val enableLayoutGridBlock: Boolean,
val enableTiledGalleryBlock: Boolean,
val enableVideoPressBlock: Boolean,
val enableFacebookEmbed: Boolean,
val enableInstagramEmbed: Boolean,
val enableLoomEmbed: Boolean,
Expand Down Expand Up @@ -68,6 +69,7 @@ data class GutenbergProps @JvmOverloads constructor(
putBoolean(PROP_CAPABILITIES_CONTACT_INFO_BLOCK, enableContactInfoBlock)
putBoolean(PROP_CAPABILITIES_LAYOUT_GRID_BLOCK, enableLayoutGridBlock)
putBoolean(PROP_CAPABILITIES_TILED_GALLERY_BLOCK, enableTiledGalleryBlock)
putBoolean(PROP_CAPABILITIES_VIDEOPRESS_BLOCK, enableVideoPressBlock)
putBoolean(PROP_CAPABILITIES_MEDIAFILES_COLLECTION_BLOCK, enableMediaFilesCollectionBlocks)
putBoolean(PROP_CAPABILITIES_UNSUPPORTED_BLOCK_EDITOR, enableUnsupportedBlockEditor)
putBoolean(PROP_CAPABILITIES_CAN_ENABLE_UNSUPPORTED_BLOCK_EDITOR, canEnableUnsupportedBlockEditor)
Expand Down Expand Up @@ -111,6 +113,7 @@ data class GutenbergProps @JvmOverloads constructor(
const val PROP_CAPABILITIES_CONTACT_INFO_BLOCK = "contactInfoBlock"
const val PROP_CAPABILITIES_LAYOUT_GRID_BLOCK = "layoutGridBlock"
const val PROP_CAPABILITIES_TILED_GALLERY_BLOCK = "tiledGalleryBlock"
const val PROP_CAPABILITIES_VIDEOPRESS_BLOCK = "videoPressBlock"
const val PROP_CAPABILITIES_FACEBOOK_EMBED_BLOCK = "facebookEmbed"
const val PROP_CAPABILITIES_INSTAGRAM_EMBED_BLOCK = "instagramEmbed"
const val PROP_CAPABILITIES_LOOM_EMBED_BLOCK = "loomEmbed"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public enum Capabilities: String {
case contactInfoBlock
case layoutGridBlock
case tiledGalleryBlock
case videoPressBlock
case mediaFilesCollectionBlock
case mentions
case xposts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ protected Bundle getLaunchOptions() {
capabilities.putBoolean(GutenbergProps.PROP_CAPABILITIES_REUSABLE_BLOCK, false);
capabilities.putBoolean(GutenbergProps.PROP_CAPABILITIES_IS_AUDIO_BLOCK_MEDIA_UPLOAD_ENABLED, true);
capabilities.putBoolean(GutenbergProps.PROP_CAPABILITIES_TILED_GALLERY_BLOCK, true);
capabilities.putBoolean(GutenbergProps.PROP_CAPABILITIES_VIDEOPRESS_BLOCK, true);
capabilities.putBoolean(GutenbergProps.PROP_CAPABILITIES_FACEBOOK_EMBED_BLOCK, true);
capabilities.putBoolean(GutenbergProps.PROP_CAPABILITIES_INSTAGRAM_EMBED_BLOCK, true);
capabilities.putBoolean(GutenbergProps.PROP_CAPABILITIES_LOOM_EMBED_BLOCK, true);
Expand Down
1 change: 1 addition & 0 deletions packages/react-native-editor/babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module.exports = function ( api ) {
'../../node_modules/@babel/plugin-proposal-async-generator-functions'
),
'@babel/plugin-transform-runtime',
'@babel/plugin-transform-named-capturing-groups-regex',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The new block makes use of regex named capture groups, which is only supported in the version of Hermes available in RN 0.71 (see facebook/hermes#696 for more details). This resulted in the following error:

bundle/android/App.text.js:3647:961: error: Invalid regular expression: Quantifier has nothing to repeat
...atch(/^https?:\/\/(?<host>video(?:\.word|s\.files\.word)?press\.com)(?:\/v|\/embed)?\/(?<guid>[a-zA-Z\d]{8})/);ret...

The use of @babel/plugin-transform-named-capturing-groups-regex is a workaround to that error.

Copy link
Contributor

Choose a reason for hiding this comment

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

Good catch! I was wondering if we'd need to add this package as a dependency but noticed in the documentation that is already included when using @babel/preset-env, which is a dependency in Gutenberg (reference).

[
'react-native-platform-specific-extensions',
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ extension GutenbergViewController: GutenbergBridgeDataSource {
.canEnableUnsupportedBlockEditor: unsupportedBlockCanBeActivated,
.mediaFilesCollectionBlock: true,
.tiledGalleryBlock: true,
.videoPressBlock: true,
.isAudioBlockMediaUploadEnabled: true,
.reusableBlock: false,
.facebookEmbed: true,
Expand Down