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 use modal #2173

Closed
danieljvdm opened this issue Aug 2, 2017 · 16 comments
Closed

How to use modal #2173

danieljvdm opened this issue Aug 2, 2017 · 16 comments

Comments

@danieljvdm
Copy link

danieljvdm commented Aug 2, 2017

Version

  • react-native-router-flux v4b15
  • react-native v46

I'm really struggling with modals as there is no documentation on them and the example has no comments or indication as to how certain scenes are displayed modally and others aren't. Here is my code.

<Router>
  <Scene key="root" hideNavBar hideTabBar>
    <Scene key="tabBar" tabs>
      <Scene key="listings" component={Listings} title="Listings" initial right={MapButton} />
      <Scene key="favorites" component={Favorites} title="Favorites" />
      <Scene key="messages" component={Messages} title="Messages" />
      <Scene key="profile" component={Profile} title="Profile" />
    </Scene>
    <Scene key="modal" modal>
      <Scene key="map" component={Map} title="Map" hideNavBar />
    </Scene>
    <Scene key="listingDetail" component={ListingDetail} title="Listing Detail" clone />
  </Scene>
</Router>;

I'm trying to get the Map component to display modally.

MapButton is the following:

const MapButton = () =>
  <TouchableWithoutFeedback onPress={Actions.map}>
    <Text>Map</Text>
  </TouchableWithoutFeedback>;

I have to use this because rightText is extremely buggy and won't render half the time.

@luco
Copy link
Contributor

luco commented Aug 3, 2017

Try put your root scene inside modal.
Like this:

<Router>
    <Scene key="modal" modal>
       <Scene key="root" hideNavBar hideTabBar>
		    <Scene key="tabBar" tabs>
		      <Scene key="listings" component={Listings} title="Listings" initial right={MapButton} />
		      <Scene key="favorites" component={Favorites} title="Favorites" />
		      <Scene key="messages" component={Messages} title="Messages" />
		      <Scene key="profile" component={Profile} title="Profile" />
		    </Scene>
		</Scene>
        <Scene key="map" component={Map} title="Map" hideNavBar />

@aksonov
Copy link
Owner

aksonov commented Aug 3, 2017

You should make root scene as modal like @luco suggested. Please check Example project, Login is implemented as modal

@aksonov aksonov closed this as completed Aug 3, 2017
@danieljvdm
Copy link
Author

This still doesn't work.

<Router>
    <Scene key="modal" modal>
      <Scene key="root" hideNavBar hideTabBar>
        <Scene key="tabBar" tabs>
          <Scene key="listings" component={Listings} title="Listings" initial right={MapButton} />
          <Scene key="favorites" component={Favorites} title="Favorites" />
          <Scene key="messages" component={Messages} title="Messages" />
          <Scene key="profile" component={Profile} title="Profile" />
        </Scene>
        <Scene key="map" component={Map} title="Map" hideNavBar />
        <Scene key="listingDetail" component={ListingDetail} title="Listing Detail" clone />
      </Scene>
    </Scene>
  </Router>

It doesn't make any sense to me that wrapping everything in the modal scene would make one specific scene modal when I don't want the rest (like ListingDetail) to be modal. Is there a specific parameter in Actions.map that I need to use?

@aksonov
Copy link
Owner

aksonov commented Aug 3, 2017

Unfortunately it is problem of react-navigation - it doesn't support different animations for stack children. I can't reproduce your problem (code looks fine), that is why I ask everybody to fork & modify this repo Example if they want their issues be resolved. Login modal from Example works fine as you can see

@aksonov aksonov reopened this Aug 3, 2017
@danieljvdm
Copy link
Author

So are you saying that there is no way to support a modal iOS transition? I.e. one that slides from the bottom?

@aksonov
Copy link
Owner

aksonov commented Aug 3, 2017

What do you mean? I said you twice that Example has modal Login screen (that slides from the bottom)

@danieljvdm
Copy link
Author

Ok but you also said my code looks fine....

@danieljvdm
Copy link
Author

I've tried my best to follow the Example but because there's no documentation I can't tell what the reason for everything being there is. I can't just copy and paste that code since obviously my routes are different.

@aksonov
Copy link
Owner

aksonov commented Aug 3, 2017

The same I could tell you about your code - I don't see whole project and all details. For example you may use Actions.map and it could be even not generated (and be null) during compilation.

@danieljvdm
Copy link
Author

I'm happy to provide more code samples if you let me know what you need. Actions.map works, it just transitions in from the side inside of what I expect to be from the bottom.

Are you saying that you can't have both push and modal transitions in the same app?

@aksonov
Copy link
Owner

aksonov commented Aug 3, 2017

OMG. Not in app, but in one container. After more deep look your code has error - 'map' still child of 'normal' container (key=root), not modal (key='modal'). Looks like you don't understand what you are doing. Maybe this component is too complex for you...

Try this:

<Router>
    <Scene key="modal" modal>
      <Scene key="root" hideNavBar hideTabBar>
        <Scene key="tabBar" tabs>
          <Scene key="listings" component={Listings} title="Listings" initial right={MapButton} />
          <Scene key="favorites" component={Favorites} title="Favorites" />
          <Scene key="messages" component={Messages} title="Messages" />
          <Scene key="profile" component={Profile} title="Profile" />
        </Scene>
      </Scene>
        <Scene key="map" component={Map} title="Map" hideNavBar />
        <Scene key="listingDetail" component={ListingDetail} title="Listing Detail" clone />
    </Scene>
  </Router>

@danieljvdm
Copy link
Author

Thanks, this fixes the issue. How do you expect me to understand something when there isn't a line of documentation about it? There have been many people opening issues about this modal feature, maybe that is indicative of the need for docs...

@aksonov
Copy link
Owner

aksonov commented Aug 3, 2017

Few recent posts here are about JSX syntax and understanding of navigation containers, not about documentation.
I added more information about modal.

@pedrogoiania
Copy link

pedrogoiania commented Sep 13, 2017

Hi,

worked for me

<Router navigationBarStyle={{backgroundColor: '#FF5722'}} titleStyle={{color: '#fff'}}>
        <Modal>
            <Stack key="root">
                <Scene key='login_screen' component={LoginScreen} title='login' hideNavBar={true} />
            </Stack>
            <Scene key='cadastro_screen' component={CadastroScreen} title='Cadastro' hideNavBar={false} />
        </Modal>
</Router>

@hugoh59
Copy link

hugoh59 commented Jan 25, 2018

When I add the modal wrapper I then get 2 navbar on the top of my view, when I add hideNavBar both of them disappear. How can I solve this issue I want one tab bar only not two obviously... ?

@tquiroga
Copy link

tquiroga commented Mar 5, 2018

Use <Modal hideNavBar> because <Modal> is gonna add its own navbar so you end up having two with the one from your root scene.

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

6 participants