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

React Native support #38

Closed
dynamichny opened this issue Dec 3, 2021 · 4 comments
Closed

React Native support #38

dynamichny opened this issue Dec 3, 2021 · 4 comments
Labels
feature request Feature requested by the community

Comments

@dynamichny
Copy link

Cant find anything about this topic in documentation, but im wondering if the library supports React Native?
If not, do you plan to support this platform as well in future?

@GuillaumeSalles
Copy link
Contributor

Hi @dynamichny,

To be completely transparent with you, we didn't try @liveblocks/client and @livebocks/react with react native, but my understanding is that it should work since we only depend on fetch and WebSocket. If it does not work for some reason, we will make sure to fix the issues to make it work!

@GuillaumeSalles
Copy link
Contributor

GuillaumeSalles commented Feb 20, 2022

Based on @vinodsantharam feedback and some investigation, it's possible to use @liveblocks/client and @liveblocks/react with React native, but it requires some work. I'm reopening this issue to keep track of what could be improved to officially support React native.

Here are the necessary work around as of v0.14.1:

  • use a polyfill for atob (used to parse jwt token)
import {decode, encode} from 'base-64';

if (!global.btoa) {
  global.btoa = encode;
}

if (!global.atob) {
  global.atob = decode;
}
  • Patch window.addEventListener to not crash on window.addEventListener("online").
window.addEventListener = () => {};

To officially support it, we need to:

  • Not crash on window.addEventListener.
  • Give a clear error message when atob is not defined.
  • Optional but it would great to use @react-native-community/netinfo to reconnect faster instead of waiting for the heartbeat.
  • And of course, official documentation

@GuillaumeSalles GuillaumeSalles mentioned this issue Mar 11, 2022
Closed
@nandorojo
Copy link

for the online listener, maybe you could do what react-query does, and let people register their own listener.

@GuillaumeSalles GuillaumeSalles added the feature request Feature requested by the community label Jun 25, 2022
@GuillaumeSalles
Copy link
Contributor

We now have an official example: https://github.com/liveblocks/liveblocks/tree/main/examples/react-native-todo-list

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Feature requested by the community
Projects
None yet
Development

No branches or pull requests

3 participants