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

Add post type to editor #1606

Merged
merged 5 commits into from
Nov 29, 2019
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion gutenberg
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public class WPAndroidGlueCode {
private static final String PROP_NAME_INITIAL_DATA = "initialData";
private static final String PROP_NAME_INITIAL_TITLE = "initialTitle";
private static final String PROP_NAME_INITIAL_HTML_MODE_ENABLED = "initialHtmlModeEnabled";
private static final String PROP_NAME_POST_TYPE = "postType";
private static final String PROP_NAME_LOCALE = "locale";
private static final String PROP_NAME_TRANSLATIONS = "translations";

Expand Down Expand Up @@ -310,9 +311,17 @@ private ImagePipelineConfig getImagePipelineConfig(OkHttpClient client) {
.newBuilder(mReactRootView.getContext(), client).build();
}

@Deprecated
public void onCreateView(Context initContext, boolean htmlModeEnabled,
Application application, boolean isDebug, boolean buildGutenbergFromSource,
boolean isNewPost, String localeString, Bundle translations) {
onCreateView(initContext, htmlModeEnabled, application, isDebug, buildGutenbergFromSource, "post", isNewPost
, localeString, translations);
}

public void onCreateView(Context initContext, boolean htmlModeEnabled,
Application application, boolean isDebug, boolean buildGutenbergFromSource,
String postType, boolean isNewPost, String localeString, Bundle translations) {
mReactRootView = new ReactRootView(new MutableContextWrapper(initContext));

ReactInstanceManagerBuilder builder =
Expand All @@ -339,6 +348,7 @@ public void onReactContextInitialized(ReactContext context) {
initialProps.putString(PROP_NAME_INITIAL_DATA, "");
initialProps.putString(PROP_NAME_INITIAL_TITLE, "");
initialProps.putBoolean(PROP_NAME_INITIAL_HTML_MODE_ENABLED, htmlModeEnabled);
initialProps.putString(PROP_NAME_POST_TYPE, postType);
initialProps.putString(PROP_NAME_LOCALE, localeString);
initialProps.putBundle(PROP_NAME_TRANSLATIONS, translations);

Expand Down
2 changes: 2 additions & 0 deletions react-native-gutenberg-bridge/ios/Gutenberg.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ public class Gutenberg: NSObject {
initialProps["initialTitle"] = initialTitle
}

initialProps["postType"] = dataSource.gutenbergPostType()

if let locale = dataSource.gutenbergLocale() {
initialProps["locale"] = locale
}
Expand Down
10 changes: 10 additions & 0 deletions react-native-gutenberg-bridge/ios/GutenbergBridgeDataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ public protocol GutenbergBridgeDataSource: class {
/// - Returns: The HTML initial title or nil.
func gutenbergInitialTitle() -> String?

/// Asks the data source for the post type to be presented by the editor.
/// Return `nil` to assume a `post` type.
///
/// - Returns: The post type or nil.
func gutenbergPostType() -> String

/// Asks the data source for an object conforming to `TextViewAttachmentDelegate`
/// to handle media loading.
///
Expand All @@ -39,4 +45,8 @@ public extension GutenbergBridgeDataSource {
func gutenbergMediaSources() -> [Gutenberg.MediaSource] {
return []
}

func gutenbergPostType() -> String {
return "post"
}
}
6 changes: 6 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,24 @@ export class RootComponent extends React.Component {
const { initialHtmlModeEnabled } = this.props;
let initialData = this.props.initialData;
let initialTitle = this.props.initialTitle;
let postType = this.props.postType;

if ( initialData === undefined && __DEV__ ) {
initialData = initialHtml;
}
if ( initialTitle === undefined ) {
initialTitle = 'Welcome to Gutenberg!';
}
if ( postType === undefined ) {
postType = 'post';
}
const Editor = require( '@wordpress/edit-post' ).Editor;
return (
<Editor
initialHtml={ initialData }
initialHtmlModeEnabled={ initialHtmlModeEnabled }
initialTitle={ initialTitle }
postType={ postType }
/>
);
}
Expand Down