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] Add capability to bridge to show/hide audio block #28952

Merged
merged 1 commit into from
Feb 15, 2021
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 @@ -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?,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public enum Capabilities: String {
case xposts
case unsupportedBlockEditor
case canEnableUnsupportedBlockEditor
case audioBlock
}

/// Wrapper for single block data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ extension GutenbergViewController: GutenbergBridgeDataSource {
.unsupportedBlockEditor: unsupportedBlockEnabled,
.canEnableUnsupportedBlockEditor: unsupportedBlockCanBeActivated,
.mediaFilesCollectionBlock: true,
.audioBlock: true
]
}

Expand Down
16 changes: 16 additions & 0 deletions packages/react-native-editor/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down