ianstormtaylor / slate

A completely customizable framework for building rich text editors. (Currently in beta.)
http://slatejs.org
MIT License
29.7k stars 3.24k forks source link

Slate For React Native #1374

Open realbisoye opened 6 years ago

realbisoye commented 6 years ago

Do you want to request a feature or report a bug?

Feature

What's the current behavior?

React Native Version for Slate

Scenario

We are currently working on some improvements to our platform at my company and one of the feature we are rebuilding is our data creation page (a rich text editor). We have decided to use slate for this after considering other alternatives and found slate to be the best for our use case and most importantly, Slate's structured data is very similar to how we want our data to look.

Considering the fact that a good percentage of our users uses our mobile apps (android and iOS, both built with React Native), we have need to make the editor work on React Native to enable our users load and edit information on their mobile devices. I guess a number of slate users who may have similar needs as us or has existing or planning to build react-native apps will love to have a react-native slate version.

Internally, we have been looking into how we can build a slate-react-native and after trying a number of ideas, we were able to make it work by using webview.

The webview implementation is not optimal and is just currently being used as a stop-gap solution and my team members ( @vshia and @UrosZivaljevic) and I, with the support of the SlateJs community would love to create a proper react-native version, hence the reason for creating this issue. Ideally, interested contributor can indicate interest here and we can brainstorm on the best way to do this.

realbisoye commented 6 years ago

For Context, we have tried the following ideas;

Also mentioned in the original issue, kindly lets discuss how we can solve this, it can be based on any of the ideas we have tried (we are probably doing one or two things wrong) or a fresh method.

Nantris commented 6 years ago

@andela-batolagbe Thanks for what you're doing. I think this is awesome and important.

Instinctively Webview doesn't seem like a great solution due to it's hacky nature, but factually speaking, what significant problems are you having with this solution?

Nantris commented 6 years ago

Anyone have an update on this? Has any more work been done on this either officially or by the community? Can anyone give me some feedback on how the Webview solution works in the field?

vshia commented 6 years ago

@Slapbox We put a hold on this for now since it seemed like too much work to get working and we were able to get a webview working in our mobile app for iOS. For iOS, we used WKWebView to load Slate (as opposed to UIWebView) and used ideas from https://blog.bigbinary.com/2016/05/25/send-receive-data-between-react-native-and-webview.html to pass data between React Native and our Slate webview.

juangl commented 6 years ago

I'd say that one of the downsides of the webView approach is the deprecated native webView component on iOS. the React Native WebView relies on UIWebView, which is deprecated and brings lots of pitfalls, such as the click delay. I'd suggest implementing it on a WKWebView.

You have to bundle React in your webView asset as well (and other libraries you may use) and this increases your app size. You can't use the same library on React Native and WebView (you may want to use Preact instead).

But there are also lots of advantage. I believe that this is a solid approach.

oyeanuj commented 6 years ago

@vshia @realbisoye Is there an example implementation or gist of your setup today?

Nantris commented 6 years ago

@vshia and @juangl thank you very much for reports. They are tremendously helpful.

@juangl can you clarify this for me? I'm a bit confused by it.

You can't use the same library on React Native and WebView (you may want to use Preact instead).

If anyone has any implementation code they'd be willing to share, I would be extremely appreciative. I've loved Slate so far, but I'm worried about getting it working on React-Native.

realbisoye commented 6 years ago

@oyeanuj, @Slapbox, There is a simple demo/test of idea app here. Although its slightly different from our actual implementation as this uses React Native UI Webview (our current app uses WK Webview), the basic idea is the same with what we have (A mini react/slate app running in a webview).

In case you want to try it out, there is WKWebview component for react native you can consider.

juangl commented 6 years ago

@Slapbox Sorry for the confusion. I mean, you would have two bundles, one for your app and one for the WebView. Each containing the React library separately.

Nantris commented 6 years ago

@realbisoye thank you so much for making that code public! I'm sure that will be a huge help to myself and many others. Have you had any issues with performance? Has there been a substantial difference between the speed of the React Native Webview and the WKWebview?

@juangl I see what you mean now. Thanks very much for taking the time to clarify.

vshia commented 6 years ago

@Slapbox I'm pretty sure that RN Webview library is a wrapper for WKWebView so there wouldn't be a difference in speed.

Nantris commented 6 years ago

@realbisoye is your company using Slate on mobile at this point?

vshia commented 6 years ago

@Slapbox , @realbisoye, Nathan (@nathanfu88) and I were working on this and ended up using Slate in a webview on an Android/iOS app. On iOS, Slate in a webview worked as-expected. On Android, we ran into the known issues and our findings are posted here which was posted in https://github.com/ianstormtaylor/slate/issues/725#issuecomment-398152295.

Nantris commented 6 years ago

@mattkrick is working on some improvements to his already outstanding work seen in this PR: https://github.com/ianstormtaylor/slate/pull/1935

I'm very excited!

Edit: Holy crap those are some lengthy and formal findings!

Francesco-Lanciana commented 4 years ago

Out of interest (I know next to nothing about native apps and react-native), what does using Slate for this get you over using a plain UITextView that's editable in something like Swift for iOS (I'm guessing react-native has a component to create something like this)?

DaniAkash commented 4 years ago

Hi, I created React Native Draftjs using a create react app project that runs inside a webview of react native. So far it has been working great. If anyone's interested you can follow the pattern in my project to implement a react native version of slate.js

devanflores commented 3 years ago

how does this work? I'm struggling to inject the slate react component into the webview component in react native. How do you put the slate component within the webview react native? Pinging @DaniAkash @realbisoye because you seem to know how to get slate working inside the source of the webview

linuxhackr commented 2 years ago

@devanflores did you find solution? I'm facing same issue.

davevilela commented 1 year ago

Any Followups on this ?

CanRau commented 1 year ago

Still in early development but Lexical looks great and might bring RN support at some point

https://github.com/facebook/lexical/discussions/2410

Nantris commented 1 year ago

They're only planning an iOS native version currently, as far as I'm aware.