From f72daa0764752b8ab69a7a9f4ca82adc5f7afd24 Mon Sep 17 00:00:00 2001 From: Ceyhun Ozugur Date: Thu, 11 Feb 2021 16:25:16 +0100 Subject: [PATCH] Add capability to bridge to show/hide audio block --- .../mobile/WPAndroidGlue/GutenbergProps.kt | 3 +++ .../ios/GutenbergBridgeDelegate.swift | 1 + .../main/java/com/gutenberg/MainActivity.java | 1 + .../GutenbergDemo/GutenbergViewController.swift | 1 + packages/react-native-editor/src/index.js | 16 ++++++++++++++++ 5 files changed, 22 insertions(+) diff --git a/packages/react-native-bridge/android/src/main/java/org/wordpress/mobile/WPAndroidGlue/GutenbergProps.kt b/packages/react-native-bridge/android/src/main/java/org/wordpress/mobile/WPAndroidGlue/GutenbergProps.kt index 933288ff19c881..dd33c571acc05c 100644 --- a/packages/react-native-bridge/android/src/main/java/org/wordpress/mobile/WPAndroidGlue/GutenbergProps.kt +++ b/packages/react-native-bridge/android/src/main/java/org/wordpress/mobile/WPAndroidGlue/GutenbergProps.kt @@ -9,6 +9,7 @@ data class GutenbergProps @JvmOverloads constructor( val enableXPosts: Boolean, val enableUnsupportedBlockEditor: Boolean, val canEnableUnsupportedBlockEditor: Boolean, + val enableAudioBlock: Boolean, val localeSlug: String, val postType: String, val editorTheme: Bundle?, @@ -44,6 +45,7 @@ data class GutenbergProps @JvmOverloads constructor( putBoolean(PROP_CAPABILITIES_MEDIAFILES_COLLECTION_BLOCK, enableMediaFilesCollectionBlocks) putBoolean(PROP_CAPABILITIES_UNSUPPORTED_BLOCK_EDITOR, enableUnsupportedBlockEditor) putBoolean(PROP_CAPABILITIES_CAN_ENABLE_UNSUPPORTED_BLOCK_EDITOR, canEnableUnsupportedBlockEditor) + putBoolean(PROP_CAPABILITIES_AUDIO_BLOCK, enableAudioBlock) } companion object { @@ -74,5 +76,6 @@ data class GutenbergProps @JvmOverloads constructor( const val PROP_CAPABILITIES_XPOSTS = "xposts" const val PROP_CAPABILITIES_UNSUPPORTED_BLOCK_EDITOR = "unsupportedBlockEditor" const val PROP_CAPABILITIES_CAN_ENABLE_UNSUPPORTED_BLOCK_EDITOR = "canEnableUnsupportedBlockEditor" + const val PROP_CAPABILITIES_AUDIO_BLOCK = "audioBlock" } } diff --git a/packages/react-native-bridge/ios/GutenbergBridgeDelegate.swift b/packages/react-native-bridge/ios/GutenbergBridgeDelegate.swift index daf77a2c26edc7..7b3122dae97578 100644 --- a/packages/react-native-bridge/ios/GutenbergBridgeDelegate.swift +++ b/packages/react-native-bridge/ios/GutenbergBridgeDelegate.swift @@ -22,6 +22,7 @@ public enum Capabilities: String { case xposts case unsupportedBlockEditor case canEnableUnsupportedBlockEditor + case audioBlock } /// Wrapper for single block data diff --git a/packages/react-native-editor/android/app/src/main/java/com/gutenberg/MainActivity.java b/packages/react-native-editor/android/app/src/main/java/com/gutenberg/MainActivity.java index ed3fdb7616676a..1946c46b517d57 100644 --- a/packages/react-native-editor/android/app/src/main/java/com/gutenberg/MainActivity.java +++ b/packages/react-native-editor/android/app/src/main/java/com/gutenberg/MainActivity.java @@ -31,6 +31,7 @@ protected Bundle getLaunchOptions() { capabilities.putBoolean(GutenbergProps.PROP_CAPABILITIES_MENTIONS, true); capabilities.putBoolean(GutenbergProps.PROP_CAPABILITIES_XPOSTS, true); capabilities.putBoolean(GutenbergProps.PROP_CAPABILITIES_UNSUPPORTED_BLOCK_EDITOR, true); + capabilities.putBoolean(GutenbergProps.PROP_CAPABILITIES_AUDIO_BLOCK, true); bundle.putBundle(GutenbergProps.PROP_CAPABILITIES, capabilities); return bundle; } diff --git a/packages/react-native-editor/ios/GutenbergDemo/GutenbergViewController.swift b/packages/react-native-editor/ios/GutenbergDemo/GutenbergViewController.swift index 175ad6dbebe63c..cd5f8fd4b1afbd 100644 --- a/packages/react-native-editor/ios/GutenbergDemo/GutenbergViewController.swift +++ b/packages/react-native-editor/ios/GutenbergDemo/GutenbergViewController.swift @@ -302,6 +302,7 @@ extension GutenbergViewController: GutenbergBridgeDataSource { .unsupportedBlockEditor: unsupportedBlockEnabled, .canEnableUnsupportedBlockEditor: unsupportedBlockCanBeActivated, .mediaFilesCollectionBlock: true, + .audioBlock: true ] } diff --git a/packages/react-native-editor/src/index.js b/packages/react-native-editor/src/index.js index 1c8ffa445b042b..48f4b827fe9654 100644 --- a/packages/react-native-editor/src/index.js +++ b/packages/react-native-editor/src/index.js @@ -18,6 +18,7 @@ import { validateThemeColors, validateThemeGradients, } from '@wordpress/block-editor'; +import { dispatch } from '@wordpress/data'; const reactNativeSetup = () => { // Disable warnings as they disrupt the user experience in dev mode @@ -99,6 +100,21 @@ const setupInitHooks = () => { }; } ); + + wpHooks.addAction( + 'native.render', + 'core/react-native-editor', + ( props ) => { + const isAudioBlockEnabled = + props.capabilities && props.capabilities.audioBlock; + + if ( isAudioBlockEnabled === true ) { + dispatch( 'core/edit-post' ).showBlockTypes( [ 'core/audio' ] ); + } else { + dispatch( 'core/edit-post' ).hideBlockTypes( [ 'core/audio' ] ); + } + } + ); }; let blocksRegistered = false;