Coder Social home page Coder Social logo

Comments (3)

smaris avatar smaris commented on June 30, 2024

Got it working by moving the screen options to the wrapping component:

const LoginComponent = withNetworkConnectivity()(Login)
LoginComponent.navigatorStyle = { tabBarHidden: true, navBarHidden: true }

Navigation.registerComponent('Login', () => connect(mapStateToProps, mapDispatchToProps)(LoginComponent), store, Provider)

But I should still have a root component, because now i'm setting listeners on all screens. State will be updated on connection change, so it will try to set state on screens that are unmounted. Any idea how to accomplish this with react-native-navigation?

from react-native-offline.

rgommezz avatar rgommezz commented on June 30, 2024

Hi, thanks for submitting your issue.

I am actively working on a branch to release a new version of the library this week.

First of all, if you wanna integrate the library with redux you need to pass false to withNetworkConnectivity, so it should be:

export const registerScreens = () => {
  Navigation.registerComponent('Login', () => connect(mapStateToProps, mapDispatchToProps)(withNetworkConnectivity(false)(Login)), store, Provider)
  Navigation.registerComponent('Home', () => connect(mapStateToProps, mapDispatchToProps)(withNetworkConnectivity(false)(Home)), store, Provider)
}

That way, the state is kept in the store and not passed down as a prop to your wrapped component.

In terms of statics hoisting, that will be fixed with the upcoming release, so you won't have to move the screen options to the wrapping component.

I haven't used react-native-navigation in any project so far, but based on the API it seems to me (at least for Android where I have some knowledge) every time you use Navigation.registerComponent, the library is creating a new Android activity underneath the hood, so you will have different root components depending on your active screen.

That being said, you don't have to worry about listeners. There will be only one active at a time.

I don't know the implementation details on iOS but I guess they should follow a similar approach where the React context is scoped to the active screen.

Apart from statics hoisting, the new version will include Flow support and the possibility of cancelling enqueued actions with another redux action, like NAVIGATE_TO_ANOTHER_SCREEN from navigation-alike libraries, where it may makes sense to discard the fetching action since it won't be relevant any longer, so stay tuned!

Also, if you have suggestions about new features for the library, feel free to open another issue with your ideas :)

from react-native-offline.

felipemartim avatar felipemartim commented on June 30, 2024

@rauliyohmc By wrapping up every screen, you end up doing HEAD requests on each navigation transition. Maybe the connectivity change logic could be managed by an event channel in redux-saga, so it could work without having a root component.

from react-native-offline.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.