rgommezz / react-native-offline

Handy toolbelt to deal nicely with offline/online connectivity in a React Native app. Smooth redux integration ✈️
MIT License
2.34k stars 271 forks source link

Example app included in the repository #21

Closed dustinromey closed 5 years ago

dustinromey commented 7 years ago

This is an issue I'm struggling with on my current project. What would be very very useful is an example project to show typical usage.

So sort of something like this repository: https://github.com/spencercarli/offline-redux-actions, for this article: https://medium.com/differential/handling-offline-actions-in-react-native-74949cbfabf2

rgommezz commented 7 years ago

I wrote a medium article to showcase some real life examples. Please check https://blog.callstack.io/your-react-native-offline-tool-belt-795abd5f0183

dustinromey commented 7 years ago

Yep, saw the article linked from the readme. And to be clear, thanks! Its a great explanation of your library's value and intro to its usage.

Just think a full cycle of the library's usage would be helpful in mentally following it, and assumed this was the correct way to say so.

rgommezz commented 7 years ago

Agree that an example app would be helpful. In the meantime, maybe you could tell me what you are struggling with in particular and I can try to help you out.

engmsaleh commented 7 years ago

@rauliyohmc I have integrated the lib in Redux Middleware way, I want to know where and how to use. I'm using an ignite-based project

engmsaleh commented 7 years ago

Also, state.network.isConnected is always true even if there is no internet connection

rgommezz commented 6 years ago

@engmsaleh, I believe https://github.com/rauliyohmc/react-native-offline#how-to-orchestrate-redux-to-dispatch-connection_change-as-the-first-action-when-the-app-starts-up should resolve that problem.

vshy108 commented 6 years ago

Platform: macOS High Sierra v10.13.1 Android Emulator: Nexus 6 API 23

Refer to https://github.com/rauliyohmc/react-native-offline#how-to-orchestrate-redux-to-dispatch-connection_change-as-the-first-action-when-the-app-starts-up and setup

App = withNetworkConnectivity({
  withRedux: true // It won't inject isConnected as a prop in this case
})(App);

After I switched the data status from Home to Denied in Android Emulator, Redux-logger shows the actions dispatched is image

{type: "@@network-connectivity/CONNECTION_CHANGE", payload: false} and the next state of network.isConnected remains true

Should we handle the action in the network reducer manually?

function reducer(state: NetworkState = initialState, action: Action): NetworkState {
  switch (action.type) {
    // handle the action manually
    case '@@network-connectivity/CONNECTION_CHANGE':
      return {
        ...state,
        isConnected: action.payload,
      };
    default:
      return state;
  }
}
rgommezz commented 6 years ago

@vshy108, are you setting up network reducer as per the docs? You may be missing step 1: https://github.com/rauliyohmc/react-native-offline#1--give-the-network-reducer-to-redux

stephane-r commented 6 years ago

Same problem with me, state.network.isConnected is always true even if there is no internet connection :

const reducers = combineReducers({
  nav: navReducer,
  i18n: i18nReducer,
  app: appReducer,
  storage: storageReducer,
  network
});

And my container :

const SyncButtonContainer = withNetworkConnectivity({
  withRedux: true,
  checkConnectionInterval: 1000
})(connect(
  mapStateToProps,
  mapDispatchToProps
)(SyncButton));

Anyone have idea ?

johhansantana commented 6 years ago

I tried following https://github.com/rauliyohmc/react-native-offline#how-to-orchestrate-redux-to-dispatch-connection_change-as-the-first-action-when-the-app-starts-up but ended up with the following error:

TypeError: (0, _reduxPersist.autoRehydrate) is not a function. (In '(0, _reduxPersist.autoRehydrate)()', '(0, _reduxPersist.autoRehydrate)' is undefined)
johhansantana commented 6 years ago

After a bit of research, I notice a few issues in their end stating to use v4 of redux-persist. I downgraded to v4 and now it works.

The issue now is that after going into airplane mode, the isConnected changes to false like it's suppose to but now it doesn't change back to true after the connection is restored.

Any ideas?

leonardo2204 commented 6 years ago

@johhansantana I'm having the very same problem, once I get isConnected to false, even after connection is restored it never returns true. I'll try debugging some more to find out. I'm not even using redux, just ConnectivityRenderer out of the box.

Thanks

leonardo2204 commented 6 years ago

Just found out, by default the lib pings google using http, and ios blocks it. Changing to https should work. BTW @rgommezz I really think that the default url should use https, what do you think?

Thanks

IssueHuntBot commented 6 years ago

@boostio funded this issue with $20. Visit this issue on Issuehunt

IssueHuntBot commented 5 years ago

@issuehuntfest has funded $300.00 to this issue. See it on IssueHunt

IssueHuntBot commented 5 years ago

@norris1z has submitted a pull request. See it on IssueHunt

IssueHuntBot commented 5 years ago

@rgommezz has cancelled their pull request. See it on IssueHunt

IssueHuntBot commented 5 years ago

@rgommezz has rewarded $224.00 to @rgommezz. See it on IssueHunt