Skip to content

Commit

Permalink
Update iOS Bridge for new values
Browse files Browse the repository at this point in the history
  • Loading branch information
chipsnyder committed May 14, 2021
1 parent 0f4fffc commit bf75be1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 24 deletions.
48 changes: 25 additions & 23 deletions packages/react-native-bridge/ios/Gutenberg.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,9 @@ public class Gutenberg: NSObject {
}

let editorSettings = dataSource.gutenbergEditorSettings()
if let rawGlobalStylesBaseStyles = editorSettings?.rawGlobalStylesBaseStyles {
initialProps["rawGlobalStylesBaseStyles"] = rawGlobalStylesBaseStyles
} else {
// We only need to include Colors and Gradients here if the Global Styles data wasn't provided
if let colors = editorSettings?.colors {
initialProps["colors"] = colors
}

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

return initialProps
Expand Down Expand Up @@ -190,21 +182,31 @@ public class Gutenberg: NSObject {
}

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]()
if let rawGlobalStylesBaseStyles = editorSettings?.rawGlobalStylesBaseStyles {
settingsUpdates["rawGlobalStylesBaseStyles"] = rawGlobalStylesBaseStyles
} else {
// We only need to include Colors and Gradients here if the Global Styles data wasn't provided
if let colors = editorSettings?.colors {
settingsUpdates["colors"] = colors
}

if let gradients = editorSettings?.gradients {
settingsUpdates["gradients"] = gradients
}
settingsUpdates["isFSETheme"] = editorSettings?.isFSETheme ?? false

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

sendEvent(.updateEditorSettings, body: settingsUpdates)
if let rawFeatures = editorSettings?.rawFeatures {
settingsUpdates["rawFeatures"] = rawFeatures
}

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

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

return settingsUpdates
}

public func showNotice(_ message: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ public extension GutenbergBridgeDataSource {
}

public protocol GutenbergEditorSettings {
var rawGlobalStylesBaseStyles: String? { get }
var isFSETheme: Bool { get }
var rawStyles: String? { get }
var rawFeatures: String? { get }
var colors: [[String: String]]? { get }
var gradients: [[String: String]]? { get }
}

0 comments on commit bf75be1

Please sign in to comment.