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

[Mobile] Set the Gutenberg version from the host apps #54219

Draft
wants to merge 3 commits into
base: trunk
Choose a base branch
from
Draft
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
15 changes: 11 additions & 4 deletions packages/editor/src/components/provider/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ class NativeEditorProvider extends Component {
componentDidMount() {
const {
capabilities,
gutenbergVersion,
locale,
hostAppNamespace,
updateEditorSettings,
Expand All @@ -105,6 +106,7 @@ class NativeEditorProvider extends Component {
...this.getThemeColors( this.props ),
locale,
hostAppNamespace,
gutenbergVersion,
} );

this.subscriptionParentGetHtml = subscribeParentGetHtml( () => {
Expand Down Expand Up @@ -152,14 +154,19 @@ class NativeEditorProvider extends Component {

this.subscriptionParentUpdateEditorSettings =
subscribeUpdateEditorSettings(
( { galleryWithImageBlocks, ...editorSettings } ) => {
( {
galleryWithImageBlocks,
gutenbergVersion: updatedGutenbergVersion,
...editorSettings
} ) => {
if ( typeof galleryWithImageBlocks === 'boolean' ) {
window.wp.galleryBlockV2Enabled =
galleryWithImageBlocks;
}
updateEditorSettings(
this.getThemeColors( editorSettings )
);
updateEditorSettings( {
gutenbergVersion: updatedGutenbergVersion,
...this.getThemeColors( editorSettings ),
} );
}
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public class RNReactNativeGutenbergBridgeModule extends ReactContextBaseJavaModu
private static final String MAP_KEY_THEME_UPDATE_RAW_STYLES = "rawStyles";
private static final String MAP_KEY_THEME_UPDATE_RAW_FEATURES = "rawFeatures";
private static final String MAP_KEY_GALLERY_WITH_IMAGE_BLOCKS = "galleryWithImageBlocks";
private static final String MAP_KEY_GUTENBERG_VERSION = "gutenbergVersion";
public static final String MAP_KEY_MEDIA_FINAL_SAVE_RESULT_SUCCESS_VALUE = "success";

private static final String MAP_KEY_IS_PREFERRED_COLOR_SCHEME_DARK = "isPreferredColorSchemeDark";
Expand Down Expand Up @@ -161,6 +162,7 @@ public void updateTheme(@Nullable Bundle editorTheme) {
Serializable gradients = editorTheme.getSerializable(MAP_KEY_THEME_UPDATE_GRADIENTS);
Serializable rawStyles = editorTheme.getSerializable(MAP_KEY_THEME_UPDATE_RAW_STYLES);
Serializable rawFeatures = editorTheme.getSerializable(MAP_KEY_THEME_UPDATE_RAW_FEATURES);
Serializable gutenbergVersion = editorTheme.getSerializable(MAP_KEY_GUTENBERG_VERSION);

// We must assign null here to distinguish between a missing value and false
Boolean galleryWithImageBlocks = null;
Expand Down Expand Up @@ -189,6 +191,10 @@ public void updateTheme(@Nullable Bundle editorTheme) {
writableMap.putBoolean(MAP_KEY_GALLERY_WITH_IMAGE_BLOCKS, galleryWithImageBlocks);
}

if (gutenbergVersion != null) {
writableMap.putString(MAP_KEY_GUTENBERG_VERSION, gutenbergVersion.toString());
}

emitToJS(EVENT_NAME_UPDATE_EDITOR_SETTINGS, writableMap);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ data class GutenbergProps @JvmOverloads constructor(
?.let { putSerializable(PROP_QUOTE_BLOCK_V2, it) }
theme.getSerializable(PROP_LIST_BLOCK_V2)
?.let { putSerializable(PROP_LIST_BLOCK_V2, it) }
theme.getSerializable(PROP_GUTENBERG_VERSION)
?.let { putSerializable(PROP_GUTENBERG_VERSION, it) }
}
}

Expand Down Expand Up @@ -106,6 +108,7 @@ data class GutenbergProps @JvmOverloads constructor(
private const val PROP_GALLERY_WITH_IMAGE_BLOCKS = "galleryWithImageBlocks"
private const val PROP_QUOTE_BLOCK_V2 = "quoteBlockV2"
private const val PROP_LIST_BLOCK_V2 = "listBlockV2"
private const val PROP_GUTENBERG_VERSION = "gutenbergVersion"

const val PROP_INITIAL_DATA = "initialData"
const val PROP_LOCALE = "locale"
Expand Down
4 changes: 4 additions & 0 deletions packages/react-native-bridge/ios/Gutenberg.swift
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,10 @@ public class Gutenberg: UIResponder {
if let gradients = editorSettings?.gradients {
settingsUpdates["gradients"] = gradients
}

if let gutenbergVersion = editorSettings?.gutenbergVersion {
settingsUpdates["gutenbergVersion"] = gutenbergVersion
}

return settingsUpdates
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,5 @@ public protocol GutenbergEditorSettings {
var rawFeatures: String? { get }
var colors: [[String: String]]? { get }
var gradients: [[String: String]]? { get }
var gutenbergVersion: String? { get }
}
2 changes: 2 additions & 0 deletions packages/react-native-editor/src/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ const setupInitHooks = () => {
rawStyles,
rawFeatures,
galleryWithImageBlocks,
gutenbergVersion,
locale,
} = props;

Expand All @@ -95,6 +96,7 @@ const setupInitHooks = () => {
rawStyles,
rawFeatures,
galleryWithImageBlocks,
gutenbergVersion,
locale,
};
}
Expand Down