Skip to content

Improve react-navigation CustomAction#6581

Merged
marcaaron merged 5 commits into
mainfrom
marcaaron-improveCustomAction
Dec 9, 2021
Merged

Improve react-navigation CustomAction#6581
marcaaron merged 5 commits into
mainfrom
marcaaron-improveCustomAction

Conversation

@marcaaron

@marcaaron marcaaron commented Dec 3, 2021

Copy link
Copy Markdown
Contributor

Details

cc @parasharrajat - trying to document better the logic in our CustomAction and make it more generic

Fixed Issues

None

Tests / QA Steps

Same as #6207

Tested On

  • Web
  • Mobile Web
  • Desktop
  • iOS
  • Android

@marcaaron marcaaron self-assigned this Dec 3, 2021
Comment thread src/libs/Navigation/CustomActions.js Outdated
* @returns {Object}
*/
function getParamsFromState(state) {
return lodashGet(state, 'routes[0].state.routes[0].params', {});

@parasharrajat parasharrajat Dec 3, 2021

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be wrong. As the active route is decided via the index property on the state. I think it should be recursive until we get the final Active state. there could be multiple nested states.

In our case, there are only two level.
Stack
=> Drawer || Stack

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you saying it could be wrong when we use the state returned from getStateFromPath()?
Or are you saying the existing logic had some problem and could be wrong?

What should I do to observe this?

@parasharrajat parasharrajat Dec 3, 2021

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I observed from this code is that you are trying to get the params of the active route.
If you are meant to do that then

So this statement routes[0].state.routes[0].params is not necessarily giving us params of active route. Under the state object, any route could be active from all items in the routes array. The state has an index property that tells which one is the active one.
state.routes[state.index ?? 0] I saw similar code in the react-navigation codebase.

Now the route you get from the above step can have a nested state which will follow on. So I am suggesting getting it via recursion.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I understand... but there are only two cases where we try to use the state currently:

  1. active route which is the just using the root state (logic should be the same as before - was it wrong?)
  2. current route which we were previously getting the params and screen name from the custom navigate(), but it seemed better to extract that out of getStateFromPath() (which I don't think returns any nested state for the report case)

So which case do we need to use recursion for? Is there something I can do in the app to break the current logic and see that what we have isn't working correctly?

@parasharrajat parasharrajat Dec 3, 2021

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that it just works for our cases. Probably we don't need to get that deeper into it. I can't think of any cases in our App where this logic won't work as this is extracted from the previous code.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok gonna leave a note somewhere about this - but maybe not worry about a solution. The custom action will probably need to evolve as time goes on and navigators get more complex.

Comment thread src/libs/Navigation/CustomActions.js Outdated
* @returns {String}
*/
function getScreenNameFromState(state) {
return lodashGet(state, 'routes[0].state.routes[0].name', '');

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for this.

@parasharrajat

Copy link
Copy Markdown
Member

BTW, loved the clean-up here and it started to sound meaningful now.

@marcaaron marcaaron requested a review from a team December 7, 2021 18:15
@MelvinBot MelvinBot requested review from alex-mechler and removed request for a team December 7, 2021 18:16
@marcaaron marcaaron marked this pull request as ready for review December 7, 2021 18:16
@marcaaron marcaaron requested a review from a team as a code owner December 7, 2021 18:16
@marcaaron marcaaron removed the request for review from a team December 7, 2021 18:16
@MelvinBot MelvinBot requested a review from Luke9389 December 7, 2021 18:17
@marcaaron marcaaron removed the request for review from Luke9389 December 7, 2021 18:17

@Luke9389 Luke9389 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Big fan of these changes. Thanks @marcaaron

@alex-mechler alex-mechler left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A lot cleaner. Thanks for leaving good comments throughout

@parasharrajat did you want to review again?

@parasharrajat parasharrajat left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

const history = _.map(state.history ? [...state.history] : [screenRoute], () => screenRoute);

// Force drawer to close and show the report screen
// Force drawer to close and show

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NAB: I think this is removed mistakenly or and show can be removed as well.

Suggested change
// Force drawer to close and show
// Force drawer to close

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yea, not a mistake because I didn't want to have the "report page" referenced here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see what you mean actually. It does kind of seem like an unfinished thought... "and show... what?"

@marcaaron marcaaron merged commit 9efb4d5 into main Dec 9, 2021
@marcaaron marcaaron deleted the marcaaron-improveCustomAction branch December 9, 2021 18:19
@OSBotify

OSBotify commented Dec 9, 2021

Copy link
Copy Markdown
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by @marcaaron in version: 1.1.19-5 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by @Julesssss in version: 1.1.21-1 🚀

platform result
🤖 android 🤖 failure ❌
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

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

Successfully merging this pull request may close these issues.

5 participants