Getting all nested route names and screens

72 Views Asked by At

normally i would get all routes using useNavigation getState or navigationRef the problem is that we use nested navigation, so the return of getstate for example has the following format

{
     "stale": false,
     "type": "stack",
     "key": "stack-DiGJro88IUoMOLo87v41B",
     "index": 0,
     "routeNames": [
         "x1",
         "x2",
         "x3",
         "x4",
         "x5",
         "x6",
         "x7",
         "x8",
         "x9",
         "x10",
         "x11",
         "x12/y1",
         "x13/y2"
     ],
     "routes": [
         {
             "key": "x1-A5vscVNkU6JjW-EXmkoL7",
             "name": "x1",
             "state": {
                 "stale": false,
                 "type": "drawer",
                 "key": "drawer-JEWHrXqwLa1IuBLc-tjSN",
                 "index": 0,
                 "routeNames": [
                     "BottomTabStack"
                 ],
                 "history": [
                     {
                         "type": "route",
                         "key": "BottomTabStack-zQj6uthKqSWhzQi1Ix4D_"
                     }
                 ],
                 "routes": [
                     {
                         "name": "BottomTabStack",
                         "key": "BottomTabStack-zQj6uthKqSWhzQi1Ix4D_",
                         "state": {
                             "stale": false,
                             "type": "tab",
                             "key": "tab-0d5oXxhjNhFMUBt3wmQJ_",
                             "index": 0,
                             "routeNames": [
                                 "BottomTab/y3",
                                 "BottomTab/y1",
                                 "BottomTab/y2",
                                 "BottomTab/y4"
                             ],
                             "history": [
                                 {
                                     "type": "route",
                                     "key": "BottomTab/y3-H-v1eQ-VUkwFwt1H95bN1"
                                 }
                             ],
                             "routes": [
                                 {
                                     "name": "BottomTab/y3",
                                     "key": "BottomTab/y3-H-v1eQ-VUkwFwt1H95bN1",
                                     "state": {
                                         "stale": false,
                                         "type": "stack",
                                         "key": "stack-X2D6PLuliM9DGipdLuIq3",
                                         "index": 0,
                                         "routeNames": [
                                             "Home"
                                         ],
                                         "routes": [
                                             {
                                                 "key": "Home-SR0TiqYwLA6Gqkq2PN6x8",
                                                 "name": "Home"
                                             }
                                         ]
                                     }
                                 },
                                 {
                                     "name": "BottomTab/y1",
                                     "key": "BottomTab/y1-pvw-79D1D8_7LD4aKFj8N"
                                 },
                                 {
                                     "name": "BottomTab/y2",
                                     "key": "BottomTab/y2-mzVPXwMwscI4tJnF0YGGA"
                                 },
                                 {
                                     "name": "BottomTab/y4",
                                     "key": "BottomTab/y4-NA11rHHu6P8JTlpjZGvNi"
                                 }
                             ]
                         }
                     }
                 ],
                 "default": "closed"
             }
         }
     ]
}

i have a feature flag that returns to me a routename plus screen that is going to be on a banner. in case of a invalid route i should not render that banner. using the useNavigation and navigationRef i wasn't able to get nested screens under the "routeNames": ["Home"], more screens(routeNames) are added to the array when i navigate on the app.

example BottomTab/y1 has no routeNames, but if i go to the tab and open this route will be added a "routeNames": ["Home"] under his "umbrela".

tried to make a list of all route names and screen names using useNavigation getState or navigationRef, cant get the nested information.

0

There are 0 best solutions below