question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

React Native support

See original GitHub issue

It looks like there are just a couple little missing pieces to work with react native. I’m not sure exactly how to integrate them properly into the codebase so I will put the snippets here. We just need a NetworkStatus implementation and to pass AsyncStorage for the storage engine when creating the client. IMO these should just be defaults when react native is the environment.

Detecting react-native

if (typeof navigator != 'undefined' && navigator.product == 'ReactNative') {
  // I'm in react-native, use the ReactNativeNetworkStatus and AsyncStorage
}

React native network status implementation

import {  NetInfo } from "react-native"
import { NetworkStatus, NetworkStatusChangeCallback } from "apollo-offline-client"

class ReactNativeNetworkStatus implements NetworkStatus {
  public onStatusChangeListener(callback: NetworkStatusChangeCallback): void {
    const listener = (connected: boolean) => {
      callback.onStatusChange({online: connected})
    };
    NetInfo.isConnected.addEventListener('connectionChange', listener)
  }

  public async isOffline(): Promise<boolean> {
    const isConnected = await NetInfo.isConnected.fetch()
    return !isConnected
  }
}

Config for react native

import { AsyncStorage } from "react-native"
import ReactNativeNetworkStatus from "./react-native-network-status.ts"

let config = {
  httpUrl: "http://localhost:4000/graphql",
  wsUrl: "ws://localhost:4000/graphql",
  storage: AsyncStorage,
  networkStatus: new ReactNativeNetworkStatus()
} 

edit: oops it looks like AsyncStorage might not be just drop in. Types don’t line up but I think it will work regardless.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:32 (19 by maintainers)

github_iconTop GitHub Comments

2reactions
wtrockicommented, Apr 22, 2019

Additionally, I will refactor current config to decouple cordova integration and provide a similar package for cordova. After this is done documentation will have separate chapters for each platform and we will avoid having if inside the package.

We do not have any example application now for the React Native so looking for a community for input and end to end testing the package.

1reaction
wtrockicommented, Dec 4, 2019

Docs: https://offix.dev/docs/next/react-native

This is pointing to master. We going to land it in 0.12.0 release

Read more comments on GitHub >

github_iconTop Results From Across the Web

Where to get help - React Native
If you need help with your React Native app, the right place to ...
Read more >
Where To Get Support - React
Where To Get Support. React has a community of millions of developers. On this page we've listed some React-related communities that you can...
Read more >
React Native - Wikipedia
React Native is an open-source UI software framework created by Meta Platforms, Inc. It is used to develop applications for Android, Android TV,...
Read more >
React Native Support - Flipper
React Native Support ... Meta's React Native and Developer Tooling teams work in close collaboration to ensure Flipper offers top-notch out-of-the-box value for ......
Read more >
Support Policy · React Native for Windows + macOS
The React Native for Windows (RNW) Team strives to provide full support for the latest stable version of RNW, with progressively reduced support...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found