React Native support
See original GitHub issueIt 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:
- Created 4 years ago
- Reactions:2
- Comments:32 (19 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

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.
Docs: https://offix.dev/docs/next/react-native
This is pointing to master. We going to land it in 0.12.0 release