draft-js icon indicating copy to clipboard operation
draft-js copied to clipboard

Add React Native support

Open tuckerconnelly opened this issue 10 years ago • 31 comments

tuckerconnelly avatar Mar 02 '16 11:03 tuckerconnelly

It would be awesome to see a React Native version. I don't have the bandwidth to build it, but I'd be happy to support anyone interested in creating one.

I would not recommend trying to port the existing Editor and its handlers directly. Rather, it probably makes sense to build a separate editor component that uses the Draft model.

hellendag avatar Mar 02 '16 15:03 hellendag

Is there any updates to this?

johnpaulmanoza avatar Jul 28 '16 02:07 johnpaulmanoza

No, we're not planning to work on this for the time being.

sophiebits avatar Jul 28 '16 03:07 sophiebits

Consider Using Draft.js for rich text editing on the web app, then convert the output to a json object with Draft.js convertToRaw function and store it in the database.

if the consumer of the rich text is a react-native mobile application, what is the best approach to represent the rich text?

thanks in advanced.

navidmesbah avatar Nov 10 '16 05:11 navidmesbah

if the consumer of the rich text is a react-native mobile application, what is the best approach to represent the rich text?

I've just done something very similar. I went with rendering the rich text using a read-only Draft component that lives inside a WebView.

hadynz avatar Nov 10 '16 06:11 hadynz

@hadynz

I think this is the best approach at the time...

navidmesbah avatar Nov 10 '16 06:11 navidmesbah

@hadynz can you give a simple example how you implemented it.

hbarve1 avatar Nov 17 '16 05:11 hbarve1

I've been working with RN+Draft on iOS for some time. It's fairly pleasant, however the WebView wrapper would need events/modifications that aren't currently supported in RN or the react-native-webview project, afaik. Having DraftJS support from RN would be awesome, although seems rife with challenges:

iOS

Draft+iOS works fairly well after establishing events. A major pain point is the editor toolbar, as I've yet to see a mobile editing toolbar work well inside a UIWebView. Plus, native toolbar would certainly require events between JS<->Native.

A custom keyboard toolbar is a fairly consistent alternative to a browser toolbar on iOS. The ZSS editor is a known-good implementation reference for this. Alternatively, swizzling a custom tooltip would save some screen space, although a nightmare to implement. The nightmare is in maintaining text selection with the tooltip while formatting, updating custom blocks, and whatnot. Perhaps I just haven't seen a proper implementation of a swizzled tooltip yet, but that's what been seen so far. Another issue with tooltips is that certain selectors are off-limits:

- (BOOL)canPerformAction:(SEL)action withSender:(id)sender {
  BOOL canPerform = NO;
  // ...
  if (action == @selector(format:) || action == @selector(cut:) || action == @selector(copy:) || action == @selector(paste:) || action == @selector(_promptForReplace:) || action == @selector(replace:) || action == @selector(_define:) || action == @selector(_share:)) {
    canPerform = YES;
  }
  return canPerform;
}

_define:, _promptForReplace:, _share:, and replacementText selectors above will build and run in development, only to be rejected on submission to iTunes Connect. Custom selectors, etc would be needed, if you wanted to provide the defaults like "Replace..." in the tooltip menu. Maybe not that bad to implement, just haven't been too far down that rabbit hole.

The app references non-public selectors in Frameworks/RNEditorWebViewBridge.framework/RNEditorWebViewBridge: _define:, _promptForReplace:, _share:, replacementText

@hbarve1 This comment doesn't cover the entire process, however it might provide a reference point, on iOS.

Android

The primary extent of my testing was to realize the issues already present for Android, here. I haven't seen many examples of a working contenteditable editor on Android, yet. AFAIK, Chrome and Gecko both had poor editor support, until recently. Also, until recently, Chrome wasn't supported on Android (consistently/sanely). I seem to recall reading that Gecko's contenteditable support works on Android, but I can't speak from experience.

It seems that if Android were to get some real love, time/effort would get focused into better supporting contenteditable in either Chrome, Gecko, both, or some other unknown engine. At least then support could be potentially provided to any common device, although perhaps unlikely for some models/API versions. It appears that there has been momentum with Gecko to support a standalone GeckoView, which if it does have working contenteditable support, etc., then that might the best candidate for best supporting an editor on Android. Seems like Android is quite a mountain, at least for now.

TheTekton avatar Nov 17 '16 08:11 TheTekton

If anyone is still interested, we've developed a Draft.js render for React Native here: https://github.com/globocom/react-native-draftjs-render

darlenedms avatar Mar 23 '17 18:03 darlenedms

@darlenedms I am gonna use it! Thanks !

Liqiankun avatar Aug 03 '17 03:08 Liqiankun

I'm currently trying to implement an editor for ReactNative compatible with draft-js.

shqld avatar Oct 18 '17 10:10 shqld

Which will be made public soon, though it's still early alpha.

shqld avatar Oct 18 '17 11:10 shqld

@shqld please let us know.

zjaml avatar Dec 25 '17 08:12 zjaml

@shqld Would be happy to join in on this

lucidlive avatar Dec 29 '17 14:12 lucidlive

Hi folks! Is there any news around this? Or maybe DraftJS's RawDraftContentState compatible editor for RN?

I have a big DB with existing comments which saved in DraftJS's RawDraftContentState serialized format and now I need to implement comments in RN app.

hosembafer avatar Jan 23 '18 17:01 hosembafer

I'm currently trying to implement an editor for ReactNative compatible with draft-js.

@shqld Are you working on it now & when it will be available to us? Are there no other solutions for react native editor?

For now:

  • I am planning to use React draftjs editor for web app & also need the same editor for a mobile app. I need both the data structure same.
  • Can I use https://github.com/wix/react-native-zss-rich-text-editor library as a mobile editor with the same data structure which actually draftjs saves in the database?
  • Can we also save data from the react-native-zss-rich-text-editor editor to database and retrieve it back for web app(ex-using draft editor) & mobile(ex-react-native-zss-rich-text-editor editor).

I just want my data structure same for both the web and mobile app, that they can help me to edit and view the same data without any worry. Is it possible to do that for now without any react native draft editor (which is not available right now)?

How is Facebook using their post editor for mobile and web? Are they using react native for facebook app? I also have seen Dropbox paper app using an editor which works awesome both in the web app as well as mobile. Are facebook & dropbox paper using native android or ios apps for their mobile app's editor?

Msspl-PrashenjeetRoy avatar Jan 29 '18 09:01 Msspl-PrashenjeetRoy

https://github.com/rehashstudio/react-native-draft-js this project support React Native

Leadrive avatar Mar 29 '18 14:03 Leadrive

I am adding a text-editor feature in my react-native app and https://github.com/rehashstudio/react-native-draft-js only support rendering but I want to add "draft js editor". Alternative https://github.com/wix/react-native-zss-rich-text-editor is available but it don't support #tags or @user like autocomplete like feature can. can any one help me with this and how to achieve this.

suryakant-t-yadav avatar Sep 26 '18 05:09 suryakant-t-yadav

some progress?

martin-badin avatar Jan 06 '19 09:01 martin-badin

https://github.com/globocom/react-native-draftjs-render

Does this help with having a text editor or does it only render?

adamsythe avatar Jan 22 '19 09:01 adamsythe