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

Dynamic scenes? #2911

Closed
compojoom opened this issue Feb 28, 2018 · 4 comments
Closed

Dynamic scenes? #2911

compojoom opened this issue Feb 28, 2018 · 4 comments

Comments

@compojoom
Copy link
Contributor

I think that this is impossible, but nevertheless wanted to ask if one can define dynamic scenes?

I have a list with companies & once the user clicks on one of them - he is presented with the data for this company. We have a tab scene here. Unfortunately for me - some of the users on this screen need to see 3 or 2 tabs.
I don't know in advance if the user is able to see 2 or 3 tabs. I need to open the company - read the configuration for the user and present him with the correct UI. (this is different for every company)

Ideal would be to have a HOC that reads the necessary data (does a network request) and either renders 2 or 3 tabs. Since this doesn't seem to be possible and I'm dealing with a Tab component I decided to try a workaround.

For tabs we can pass a tabBarComponent. I wanted to reuse the one from react-navigation, but before rendering it remove the unnecessary tab. This unfortunately didn't work. Is there a way to modify the routes without breaking everything?

Since I was not able to modify the routes - I just recreated the react-navigation TabBarBottom and just added this line in the render function:

if(myCompanyProfile && myCompanyProfile.role === 'standard' && index === 1) {
              return null
            }

This is obviously the most stupid way to do this and I wonder if someone else faced the same issue and what did you do?

@asciifaceman
Copy link
Contributor

Could you do an iter where you are defining your routing stack JSX and render them dynamically at app-load?

Something like

RenderTabsDynamic() {
    return somedata.map(function(tab, i) {
        <Scene
                key="tab_{i}"
                title="Tab #{i}"
        >
    });
}

render() {
  return(
    <Tabs>
      {this.RenderTabsDynamic()}
    </Tabs>
  )
}

I know this is light on details, just to demonstrate the concept.

@compojoom
Copy link
Contributor Author

@asciifaceman - have you tried this yourself? It doesn't work - you cannot have dynamic scene render unless I'm missing something. All your scenes need to be defined in advance.

@asciifaceman
Copy link
Contributor

Hmm, I had never tried it in the router stack but obviously it is a pattern for rendering other objects in Views so assumed it might work.

I mean a kind of junk way you could handle it would be to have two sets of identically functioning tabs, one with 3 and one with 2, and you only push one or the other depending on the state. But thats a lot of copied code and is not elegant in any way. It might get you to point B for now.

@aksonov
Copy link
Owner

aksonov commented Aug 8, 2018

Dynamic scenes are not supported.

@aksonov aksonov closed this as completed Aug 8, 2018
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

3 participants