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] Capabilities type safety #23956

Merged
merged 2 commits into from
Jul 16, 2020
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
7 changes: 5 additions & 2 deletions packages/react-native-bridge/ios/Gutenberg.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,11 @@ public class Gutenberg: NSObject {
initialProps["translations"] = translations
}

if let capabilities = dataSource.gutenbergCapabilities() {
initialProps["capabilities"] = capabilities
let capabilities = dataSource.gutenbergCapabilities()
if capabilities.isEmpty == false {
initialProps["capabilities"] = Dictionary<String, Bool>(uniqueKeysWithValues: capabilities.map { key, value in
(key.rawValue, value)
})
}

let editorTheme = dataSource.gutenbergEditorTheme()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ public protocol GutenbergBridgeDataSource: class {
/// Asks the data source for a list of Media Sources to show on the Media Source Picker.
func gutenbergMediaSources() -> [Gutenberg.MediaSource]

func gutenbergCapabilities() -> [String: Bool]?
/// Ask the data source what capabilities should be enabled.
/// Implement this method to enable one or more capabilities.
/// Defaults are not enabled.
func gutenbergCapabilities() -> [Capabilities: Bool]

/// Asks the data source for a list of theme colors.
func gutenbergEditorTheme() -> GutenbergEditorTheme?
Expand All @@ -61,6 +64,10 @@ public extension GutenbergBridgeDataSource {
var loadingView: UIView? {
return nil
}

func gutenbergCapabilities() -> [Capabilities: Bool] {
return [:]
}
}

public protocol GutenbergEditorTheme {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ public struct MediaInfo {
}
}

/// Definition of capabilities to enable in the Block Editor
public enum Capabilities: String {
case mentions
case unsupportedBlockEditor
}

/// Wrapper for single block data
public struct Block {
/// Gutenberg internal block ID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,10 +259,10 @@ extension GutenbergViewController: GutenbergBridgeDataSource {
return nil
}

func gutenbergCapabilities() -> [String : Bool]? {
func gutenbergCapabilities() -> [Capabilities : Bool] {
return [
"mentions": true,
"unsupportedBlockEditor": true,
.mentions: true,
.unsupportedBlockEditor: true,
]
}

Expand Down