How to use react-native-offline - 8 common examples

To help you get started, we’ve selected a few react-native-offline examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github developmentseed / observe / app / services / auth.js View on Github external
export async function preAuth () {
  if (!await checkInternetConnection()) {
    // return early if not connected
    return false
  }

  if (preAuthorizing) {
    try {
      // allow 5 seconds for active preauthorization to complete (after which
      // whatever is waiting will be able to continue)
      await pTimeout(waitForPreauthorization(), 5000)

      console.log('alternate preAuthorization succeeded')

      return true
    } catch (err) {
      console.log('alternative preAuthorization timed out or failed', err)
github Osedea / react-native-offline-first-example / js / store.js View on Github external
// @flow
import { Platform } from 'react-native';
import { composeWithDevTools } from 'remote-redux-devtools';
import { applyMiddleware, createStore } from 'redux';
import Thunk from 'redux-thunk';
import { createNetworkMiddleware } from 'react-native-offline';
import { persistStore, autoRehydrate } from 'redux-persist';
import realmPersist from 'redux-persist-realm';

import reducer from './reducer';

const preloadedState = {};
const networkMiddleware = createNetworkMiddleware();
const composeEnhancers = composeWithDevTools({
    name: Platform.OS,
    hostname: '127.0.0.1',
    port: 8888,
    realtime: true,
});

const store = createStore(
    reducer,
    preloadedState,
    composeEnhancers(
        applyMiddleware(...[
            networkMiddleware,
            Thunk,
        ]),
        autoRehydrate()
github Osedea / react-native-offline-first-example / js / api.js View on Github external
// @flow

import { create } from 'apisauce';
import { withNetworkConnectivity } from 'react-native-offline';

export const API_URL = __DEV__
    ? 'http://localhost:3030'
    : 'http://138.197.149.40';
export const withCheckInternet = withNetworkConnectivity({
    pingServerUrl: API_URL,
});

const api = create({
    baseURL: API_URL,
});

api.addResponseTransform((response) => {
    if (response.status >= 400 || !response.ok) {
        const error = new Error(response.status || response.problem);

        error.status = response.status;
        error.response = response;

        throw error;
    }
github iamrommel / offline-demo / mobile / onConnectionChange.js View on Github external
(isConnected) => {
      if (isConnected) {

        //check if there is internet connection
        checkInternetConnection().then((hasInternet) => {
          if (hasInternet)
            onConnect && onConnect()
          else
            onDisconnect && onDisconnect()
        })
      }
      else {
        onDisconnect && onDisconnect()
      }
    }
  )
github anchetaWern / RNOffline / Root.js View on Github external
createNetworkMiddleware
} from "react-native-offline";

import LoginScreen from "./src/screens/LoginScreen";
import UsersScreen from "./src/screens/UsersScreen";
import ChatScreen from "./src/screens/ChatScreen";

import { Provider } from "react-redux";
import { createStore, combineReducers, applyMiddleware } from "redux";

import ChatReducer from "./src/reducers/ChatReducer";

import { watcherSaga } from "./src/sagas";

const sagaMiddleware = createSagaMiddleware();
const networkMiddleware = createNetworkMiddleware();

const persistConfig = {
  key: "root",
  storage,
  blacklist: ["network", "chat"]
};

const chatPersistConfig = {
  key: "chat",
  storage: storage,
  blacklist: ["isNetworkBannerVisible"]
};

const rootReducer = combineReducers({
  chat: persistReducer(chatPersistConfig, ChatReducer),
  network
github rgommezz / react-native-offline / example / redux / createStore.js View on Github external
export default function createReduxStore({
  withSaga = false,
  queueReleaseThrottle = 1000,
} = {}) {
  const networkMiddleware = createNetworkMiddleware({
    regexActionType: /^OTHER/,
    actionTypes: ['ADD_ONE', 'SUB_ONE'],
    queueReleaseThrottle,
  });

  const sagaMiddleware = createSagaMiddleware();

  const rootReducer = combineReducers({
    counter,
    network,
  });

  const middlewares = [networkMiddleware];
  if (withSaga === true) {
    middlewares.push(sagaMiddleware);
  }
github anchetaWern / RNOffline / src / reducers / ChatReducer.js View on Github external
export default (state = INITIAL_STATE, action) => {
  switch (action.type) {
    case offlineActionTypes.CONNECTION_CHANGE:
      if (network.isConnected != action.payload && !action.payload) {
        return { ...state, isNetworkBannerVisible: true };
      } else {
        return { ...state, isNetworkBannerVisible: false };
      }

    case SET_CURRENT_USER:
      return { ...state, user: action.user };

    case SET_CURRENT_ROOM:
      return { ...state, room: action.room };

    case PUT_USER:
      const current_users = [...state.users];
      const users = current_users.concat(action.user);
      return { ...state, users };
github anchetaWern / RNOffline / src / reducers / ChatReducer.js View on Github external
export default (state = INITIAL_STATE, action) => {
  switch (action.type) {
    case offlineActionTypes.CONNECTION_CHANGE:
      if (network.isConnected != action.payload && !action.payload) {
        return { ...state, isNetworkBannerVisible: true };
      } else {
        return { ...state, isNetworkBannerVisible: false };
      }

    case SET_CURRENT_USER:
      return { ...state, user: action.user };

    case SET_CURRENT_ROOM:
      return { ...state, room: action.room };

    case PUT_USER:
      const current_users = [...state.users];
      const users = current_users.concat(action.user);
      return { ...state, users };

react-native-offline

Handy toolbelt to deal with offline mode in React Native applications. Cross-platform, provides a smooth redux integration.

MIT
Latest version published 2 years ago

Package Health Score

56 / 100
Full package analysis