Skip to content

Add React Native Support #45

@jho406

Description

@jho406

Today, Rails has Strada, a cordova-ish solution that brings the web to mobile by using web views and a JS bridge to native functionality. Superglue can offer a better alternative. Imagine being able to use standard Rails helpers (the flash, form helpers) and your boring Rails workflow to build React Native applications, all while having 100% Native UI controls and access to react-native libraries.

In other words, while Strada tries to bring the Web to native, Superglue tries to bring just Rails to native.

Thoughts

The movement towards "pages"

expo and other JS frameworks are making their way towards page based development. Since Superglue is about page state over the wire. Is there some compatibility here that is worth investigating?

Known quirks of React Native

ReactNative is not the web. Specifically

  1. ReactNative fetch is NOT the web fetch, and there are known issues with redirects losing cookies
  2. Cookies have more known issues. There is a react-native-cookies package that might help this issue.

Possible solutions:

  1. Polyfill to the webview’s fetch. Its possible to create an instance of the Webview, and using injected javascript, create a polyfill fetch (fork something like https://github.com/developit/unfetch ) that proxys to the Webview.
  2. Embrace the known Quirks. React native isn’t quite the web, so create helpers in superglue_rails that give Rails more superpowers. For example, we can embrace that React has an issue with redirect by never redirecting, instead we can render a payload for the app to navigate to somewhere else.
class PostsController < ApplicationController
  def create
    ... do stuff
    navigate_to_screen :home_screen
  end
end

There might be new helpers to think about, for example: navigate_back. link helpersURL helpers.

Embracing React Native also means that some features of superglue would need to be disabled while on native. For example, UJS helpers. We may also need to reshape the redux state shape to accommodate the new navigation helpers.

Next Steps

Of the solutions, I am leaning towards embracing React Native’s quirks. While I don’t have a thought out comparison, I think that because React Native isn’t quite web, its simpler to embrace to quirkiness then to add a layered solution. I believe that Rails itself can be a “Be productive anywhere” solution, even without the web.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    Needs planning

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions