Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to wrap my topmost component (App) in a Native Base Root component with v1 RNN ? #4640

Closed
msqar opened this issue Jan 25, 2019 · 5 comments

Comments

@msqar
Copy link

msqar commented Jan 25, 2019

I'm using React-Native-Navigation v1 with Native Base. Wanted to add their ActionSheet component but as a requirement, it says i need to wrap the topmost component inside their Root component.
But i can't seem to find a way to do it, any suggestion?

The way i'm initializing the app is first registering every screen like this:

Navigation.registerComponent('app.ChatScreen', () => ChatScreen, store, Provider);

Then calling for the login:

// Start App
Navigation.startSingleScreenApp({
    screen: {
        screen: 'app.AuthView',
        title: 'Login',
        navigatorStyle: {
          navBarHidden: true
        }
    }
});

I read there was an issue kinda related to this one, where someone suggested creating a wrap function:

function wrap(Component) {
    return function () {
        return (
            <RootComponent>
                <Component />
            </RootComponent>
        );
    };
}

And then wrapping it inside the same register:
Navigation.registerComponent('app.ChatScreen', () => wrap(ChatScreen), store, Provider);

But it doesn't work, it throws: "Can't find variable React" whenever the tabBasedApp starts.

Any ideas? Thanks.

Environment

  • React-Native version: 0.57.8
  • Native-Base version: ^2.10.0
  • Wix React-Native-Navigation: ^1.1.493 (v1)
  • Platform(s) (iOS, Android, or both?): iOS
  • Device info (Simulator/Device? OS version? Debug/Release?): Simulator iPhone X 12.1
@rawrmaan
Copy link
Contributor

rawrmaan commented Feb 4, 2019

Hi @msqar, this simply isn't possible with react-native-navigation, as the native code controls the React root(s). I'd recommend using react-native-actionsheet, which has perfect compatibility with this library. Have a nice day!

@guyca guyca closed this as completed Feb 5, 2019
@msqar
Copy link
Author

msqar commented Feb 6, 2019

@rawrmaan Yes, you're right. I ended up using react-native-actionsheet which works perfectly fine without having to wrap it up. But it was indeed possible to use <Root> from Native-Base with RNN v1 after all.

If anyone is under the same situation, here's the solution.

When in the spec says it requires to wrap the topmost component, is not necessarily the <App>, but inside the render function where you want to make use of this Toast or ActionSheet.

So, if in the render function of a component you have something like this, you can still add the Root on top of eeeevery component there and it will work like a charm :) this solution was brought by someone on Native-Base github. Kudos to him.

render () {
    return (
         <Root>
         <Container>
                // some other inner stuff
         </Container
         </Root>
    );
}

@JonathanRufino
Copy link

@msqar You just saved my day.
I was using NativeBase ActionSheet and was having problem when pushing and poping screen because the context was missing.
But adding to my render instead of my top component fixed the problem

@msqar
Copy link
Author

msqar commented Mar 9, 2019

@msqar You just saved my day.
I was using NativeBase ActionSheet and was having problem when pushing and poping screen because the context was missing.
But adding to my render instead of my top component fixed the problem

Glad it worked for you man :) that was the intention, to help others, although i ended up using a different library. I found that too late. But i'm happy it helped you at least!

@usmaniqbal998
Copy link

Hi just to confirm @msqar , do i have to import Root from native base like this
import {Toast, Root} from 'native-base';and than cover my Render view inside this Root element ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants