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
router.getScreenConfig is broken #48
Comments
Have we end up discussing something yesterday? From Slack discussion it's unclear to me whether this is still a bug and will get re-implemented. |
@grabbou we didn't reach any conclusion. there's a small document which you should read and comment your opinion. |
I'm a fan of #1 but happy to discuss. I like that option because there are no options to the screen config, just defaults. This is a simpler approach IMO |
I am leaning towards the last approach which seems to be a natural progression of approach 2. Wiith a signature like this:
Personally I think it might be easier for user to have an explicit access to defaults that are loaded from parent source and params (options) that were explicitly passed to the function, when e.g. accessing an Not really sure if merging these two kinds of objects is a good idea since at some point, e.g. one might want to pass an option that is not part of The biggest problem that I see with merging these two objects is that there's that assumption (at least I have it, I might be wrong) that |
In your example 2 the user would expect the options to be:
Correct? |
Only if the user returns a merged object, |
I think I don't understand very well the problem described in this issue. I think the code example 2 at the beginning illustrates what's wrong currently but I don't understand it very well. From the description:
How can the second argument be two things at once: (the previous config returned from a parent navigation options) and (the options passed to getScreenConfig)?
OK this I understand. Yes that's true. But maybe it doesn't matter we merge those two things into a single
Do you mean learning curve for contributors or for users of the library? There are many more users of the library so if the high-level API is simpler but as a tradeoff the implementation / Flow types are more complex that's an OK tradeoff. Ideally both API and implementation should be simple of course when possible. The issue title says it's broken. What's the bug? Is there a bug in the Example 2 that the In Proposal 1:
Proposal 2: I don't understand from the code examples how it's different from 1? Proposal 3:
What is
And the React Navigation library would do the merging of screen-navigationOptions and navigator-navigatorOptions for me. Basically it would work correctly without any API change. |
It can be used for back button, or any button that changes navigation state such as updating params etc.
We had a discussion on slack regarding this https://reactnativecore.slack.com/archives/navigation/p1485457433002182
It has different config options, for example instead of a
previous result is type HeaderOptionItemConfig = {
title: string;
icon: IconOptions => React.Element<*>; options is type IconOptions = {
focused: boolean;
tintColor: boolean;
} options in proposal 1 is HeaderOptionItemConfig & ?IconOptions
Because they are merged together HeaderOptionItemConfig & ?IconOptions
This will work as long as the user returns a merged object. Also if the library merges them automatically, it doesn't need to be passed in the arguments. And merging these 2 and passing in argument means what I wrote in #1 which is confusing behaviour, merging options passed from the library with the header config defined in |
I'm not worried about flow types being complex or API implementation. I'm more opposed to the confusing behaviour. It allows users to do strange things which don't make sense, e.g.- tabBar: (navigation, options) => ({
focused: true,
}) Can you guess what this does? I think what @ericvicenti wants is to treat options passed to |
Closing since we decided not to change any current behaviour. |
Reopening as #984 will close it in a bit. |
…4/fix-build chore: use tsc only for decalartions
Currently the second argument received by a navigation options item is the previous config returned from a parent navigation options, and the options passed to
getScreenConfig
.IMO it's a confusing behaviour, because fundamentally they are different types of objects, one is the configuration for navigator, other is arbitrary options the navigator can pass to the configuration function. For example, the tab navigator can provide a
focused
argument for the icon, which doesn't make sense in a config.The way this works is, only the global navigator config receives the options passed to the
getScreenConfig
, and it has to explicitly merge it with, say, header config and return it. Which means if you have a static header configuration for screens, and then add a header configuration at the global level to be used as default, it breaks the screen configuration because it doesn't receive the options anymore and you've to explicitly merge the options in the global navigator config. Same for the route navigation config, which will break if you add a screen config.Personally I think the confusing behaviour and the learning curve associated with it is not worth getting rid of one extra function.
global config - the
navigationOptions
passed in the second argument to the navigatorscreen config - the static
navigationOptions
in the screensroute config - the
navigationOptions
specified for individual routes in the first argument to the navigatorFlow types for both,
These are the current api and the proposals we discussed:
Current API
Options is the result of previous header function/previous header object
Flow type,
How it is used,
Pros
router.getScreenConfig
doesn't deal with options passed to icon, so it's pretty generic, navigators can do whatever they wantCons
Proposed API #1
Options is the result of previous header function/previous header object merged with params passed to
getScreenConfig
Flow type,
How it is used,
Pros
Cons
focused
doesn't make sense insidenavigationOptions.header
. For some things liketintColor
, it could be irrelevant iftintColor
might make sense in the config, but see next one for thatgetScreenConfig
has to handle the options, limited to objects onlynavigationOptions
or the params passed togetScreenConfig
? Can I override the other?Proposed API #2
Options is the result of previous header function/previous header object
Flow type,
How it is used,
Pros
router.getScreenConfig
doesn't deal with options passed to iconCons
activeTintColor
, but for the icon, I have to type it again, and I made a typoProposed API #3
Previous result is the result of previous header function/previous header object
Flow type,
How it is used,
Pros
Cons
getScreenConfig
has to handle the options, limited to objects only, e.g. -getScreenConfig(..., () => {})
is not possible (likely not a significant issue)cc @skevy @mkonicek
The text was updated successfully, but these errors were encountered: