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

[RN Mobile][Global Styles] Adds new Prop for Global Styles Settings #30544

Merged
merged 24 commits into from
Jun 29, 2021
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
7102a51
Adds new Prop for Global Styles Settings
antonis Apr 6, 2021
906a9f6
Rename updateTheme to be more generic for update settings include GSS…
chipsnyder May 6, 2021
226780b
Fix wrong naming of subscribeUpdateEditorSettings
May 7, 2021
8ad3a37
Update Gutenberg demo
May 7, 2021
0132134
Updates new props to rawStyles and rawFeatures
antonis May 13, 2021
0f4fffc
Merge branch 'trunk' into rnmobile/3163-GSS
chipsnyder May 14, 2021
bf75be1
Update iOS Bridge for new values
chipsnyder May 14, 2021
aeaf65f
Mobile - Global styles: Pass settings and set color palette and gradi…
May 18, 2021
ee936cb
Merge branch 'trunk' into rnmobile/3163-GSS
May 21, 2021
4058908
Merge branch 'trunk' into rnmobile/3163-GSS
antonis May 26, 2021
32a2b3a
Removes Android rawFeatures prop
antonis May 27, 2021
9741f39
Mobile - Remove usage of rawFeatures
May 27, 2021
9a404b4
Remove rawFeatures
chipsnyder May 27, 2021
792ab77
Adds raw Styles in React Native Bridge
antonis May 28, 2021
954d337
Mobile - Pass rawStyles on initial props and fix colors and gradients
May 28, 2021
eae36b0
Merge branch 'rnmobile/3163-GSS' of github.com:WordPress/gutenberg in…
May 28, 2021
d2ba74f
Merge remote-tracking branch 'origin/trunk' into rnmobile/3163-GSS
chipsnyder Jun 16, 2021
2e12d2c
Add Raw Features back
chipsnyder Jun 16, 2021
1bbda52
Revert "Removes Android rawFeatures prop"
antonis Jun 17, 2021
1f34a27
Add rawFeatures in the mobile editor
Jun 17, 2021
3d780d3
Mobile - Global styles: Set theme's background and text color (#30810)
Jun 18, 2021
f8e2fa7
Merge branch 'trunk' into rnmobile/3163-GSS
Jun 22, 2021
a0e9a1d
Merge branch 'trunk' into rnmobile/3163-GSS
antonis Jun 23, 2021
aee06f1
Merge branch 'trunk' into rnmobile/3163-GSS
antonis Jun 29, 2021
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
24 changes: 13 additions & 11 deletions packages/editor/src/components/provider/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import RNReactNativeGutenbergBridge, {
subscribeSetTitle,
subscribeMediaAppend,
subscribeReplaceBlock,
subscribeUpdateTheme,
subscribeUpdateEditorSettings,
subscribeUpdateCapabilities,
subscribeShowNotice,
} from '@wordpress/react-native-bridge';
Expand Down Expand Up @@ -126,15 +126,17 @@ class NativeEditorProvider extends Component {
}
);

this.subscriptionParentUpdateTheme = subscribeUpdateTheme(
( theme ) => {
this.subscriptionParentUpdateEditorSettings = subscribeUpdateEditorSettings(
( editorSettings ) => {
// Reset the colors and gradients in case one theme was set with custom items and then updated to a theme without custom elements.

theme.colors = validateThemeColors( theme.colors );

theme.gradients = validateThemeGradients( theme.gradients );

this.props.updateSettings( theme );
editorSettings.colors = validateThemeColors(
editorSettings.colors
);
editorSettings.gradients = validateThemeGradients(
editorSettings.gradients
);

this.props.updateSettings( editorSettings );
}
);

Expand Down Expand Up @@ -176,8 +178,8 @@ class NativeEditorProvider extends Component {
this.subscriptionParentMediaAppend.remove();
}

if ( this.subscriptionParentUpdateTheme ) {
this.subscriptionParentUpdateTheme.remove();
if ( this.subscriptionParentUpdateEditorSettings ) {
this.subscriptionParentUpdateEditorSettings.remove();
}

if ( this.subscriptionParentUpdateCapabilities ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class RNReactNativeGutenbergBridgeModule extends ReactContextBaseJavaModu
private static final String EVENT_NAME_NOTIFY_MODAL_CLOSED = "notifyModalClosed";
private static final String EVENT_NAME_PREFERRED_COLOR_SCHEME = "preferredColorScheme";
private static final String EVENT_NAME_MEDIA_REPLACE_BLOCK = "replaceBlock";
private static final String EVENT_NAME_UPDATE_THEME = "updateTheme";
private static final String EVENT_NAME_UPDATE_EDITOR_SETTINGS = "updateEditorSettings";
private static final String EVENT_NAME_SHOW_NOTICE = "showNotice";

private static final String MAP_KEY_UPDATE_HTML = "html";
Expand Down Expand Up @@ -153,7 +153,7 @@ public void updateTheme(@Nullable Bundle editorTheme) {
writableMap.putArray(MAP_KEY_THEME_UPDATE_GRADIENTS, Arguments.fromList((ArrayList)gradients));
}

emitToJS(EVENT_NAME_UPDATE_THEME, writableMap);
emitToJS(EVENT_NAME_UPDATE_EDITOR_SETTINGS, writableMap);
}

@ReactMethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ data class GutenbergProps @JvmOverloads constructor(
editorTheme?.also { theme ->
theme.getSerializable(PROP_COLORS)?.let { putSerializable(PROP_COLORS, it) }
theme.getSerializable(PROP_GRADIENTS)?.let { putSerializable(PROP_GRADIENTS, it) }
theme.getSerializable(PROP_STYLES)
?.let { putSerializable(PROP_STYLES, it) }
theme.getSerializable(PROP_FEATURES)
?.let { putSerializable(PROP_FEATURES, it) }
}
}

Expand Down Expand Up @@ -65,6 +69,8 @@ data class GutenbergProps @JvmOverloads constructor(
private const val PROP_TRANSLATIONS = "translations"
private const val PROP_COLORS = "colors"
private const val PROP_GRADIENTS = "gradients"
private const val PROP_STYLES = "rawStyles"
private const val PROP_FEATURES = "rawFeatures"

const val PROP_CAPABILITIES = "capabilities"
const val PROP_CAPABILITIES_CONTACT_INFO_BLOCK = "contactInfoBlock"
Expand Down
7 changes: 5 additions & 2 deletions packages/react-native-bridge/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,11 @@ export function subscribeAndroidModalClosed( callback ) {
: undefined;
}

export function subscribeUpdateTheme( callback ) {
return gutenbergBridgeEvents.addListener( 'updateTheme', callback );
export function subscribeUpdateEditorSettings( callback ) {
return gutenbergBridgeEvents.addListener(
'updateEditorSettings',
callback
);
}

export function subscribePreferredColorScheme( callback ) {
Expand Down
38 changes: 24 additions & 14 deletions packages/react-native-bridge/ios/Gutenberg.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,10 @@ public class Gutenberg: NSObject {
initialProps["capabilities"] = capabilities.toJSPayload()
}

let editorTheme = dataSource.gutenbergEditorTheme()
if let colors = editorTheme?.colors {
initialProps["colors"] = colors
}

if let gradients = editorTheme?.gradients {
initialProps["gradients"] = gradients
let editorSettings = dataSource.gutenbergEditorSettings()
let settingsUpdates = properties(from: editorSettings)
initialProps.merge(properties(from: editorSettings)) { (intialProp, settingsUpdates) -> Any in
settingsUpdates
}

return initialProps
Expand Down Expand Up @@ -184,19 +181,32 @@ public class Gutenberg: NSObject {
bridgeModule.sendEventIfNeeded(.setFocusOnTitle, body: nil)
}

public func updateTheme(_ editorTheme: GutenbergEditorTheme?) {
public func updateEditorSettings(_ editorSettings: GutenbergEditorSettings?) {
let settingsUpdates = properties(from: editorSettings)
sendEvent(.updateEditorSettings, body: settingsUpdates)
}

private func properties(from editorSettings: GutenbergEditorSettings?) -> [String : Any] {
var settingsUpdates = [String : Any]()
settingsUpdates["isFSETheme"] = editorSettings?.isFSETheme ?? false
Copy link
Contributor

Choose a reason for hiding this comment

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

@antonis @geriux I pushed the iOS Changes in bf75be1. As part of that, I included isFSETheme which maps to __unstableEnableFullSiteEditingBlocks which may not be critical yet but I included it in case it helps identify if colors and gradients are blank because the theme wants the default values or if it's blank because we're using an FSE theme.


var themeUpdates = [String : Any]()
if let rawStyles = editorSettings?.rawStyles {
settingsUpdates["rawStyles"] = rawStyles
}

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

if let colors = editorTheme?.colors {
themeUpdates["colors"] = colors
if let colors = editorSettings?.colors {
settingsUpdates["colors"] = colors
}

if let gradients = editorTheme?.gradients {
themeUpdates["gradients"] = gradients
if let gradients = editorSettings?.gradients {
settingsUpdates["gradients"] = gradients
}

sendEvent(.updateTheme, body:themeUpdates)
return settingsUpdates
}

public func showNotice(_ message: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public protocol GutenbergBridgeDataSource: class {
func gutenbergCapabilities() -> [Capabilities: Bool]

/// Asks the data source for a list of theme colors.
func gutenbergEditorTheme() -> GutenbergEditorTheme?
func gutenbergEditorSettings() -> GutenbergEditorSettings?

/// Asks the data source for a view to show while the Editor is loading.
var loadingView: UIView? { get }
Expand All @@ -70,7 +70,10 @@ public extension GutenbergBridgeDataSource {
}
}

public protocol GutenbergEditorTheme {
public protocol GutenbergEditorSettings {
var isFSETheme: Bool { get }
var rawStyles: String? { get }
var rawFeatures: String? { get }
var colors: [[String: String]]? { get }
var gradients: [[String: String]]? { get }
}
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ extension RNReactNativeGutenbergBridge {
case mediaUpload
case setFocusOnTitle
case mediaAppend
case updateTheme
case updateEditorSettings
case replaceBlock
case updateCapabilities
case showNotice
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ extension GutenbergViewController: GutenbergBridgeDataSource {
return ExampleAttachmentDelegate()
}

func gutenbergEditorTheme() -> GutenbergEditorTheme? {
func gutenbergEditorSettings() -> GutenbergEditorSettings? {
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion test/native/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jest.mock( '@wordpress/react-native-bridge', () => {
subscribeFeaturedImageIdNativeUpdated: jest.fn(),
subscribeMediaAppend: jest.fn(),
subscribeAndroidModalClosed: jest.fn(),
subscribeUpdateTheme: jest.fn(),
subscribeUpdateEditorSettings: jest.fn(),
subscribePreferredColorScheme: () => 'light',
subscribeUpdateCapabilities: jest.fn(),
subscribeShowNotice: jest.fn(),
Expand Down