median.navigation methods in the JavaScript Bridge to add a badge to a tab, swap the buttons in the top bar, change the bar color, or replace a whole navigation instance.
Each call applies to the instance that matches the current page, unless you pass instanceId. The change shows again whenever the user returns to a page of that instance.
Developer DemoDisplay our demo page in your app to test during development https://median.dev/navigation-runtime
Prerequisites
Your app must use navigation instances, otherwise themedian.navigation methods fail.
Item fields
setTopItems and setBottomItems take an array of items. Each item can have these fields:
Update an item
updateTopItem and updateBottomItem change one item without replacing the others.
Fields you leave out stay unchanged. Calling
setTopItems or setBottomItems clears earlier item updates for that bar.
Add a badge to a bottom tab
Change a top bar item
This example changes the icon of the first top bar item and the code that runs when the user taps it.Top bar
Set the top bar color
The text color doesn’t change the status bar text, a title image, or the bottom tab bar.
Replace the top bar items
Bottom tab bar
Replace the bottom tabs
Read items
getTopItems and getBottomItems return the items as they’re currently shown, including runtime changes.
index to use as item in updateTopItem and updateBottomItem, and a badge that’s null when none is set. Bottom tab bar items also have selected, which is true for the tab that matches the current page.
Instances
An instance defines which pages it appears on and which navigation components it shows.visibleIn takes one URL pattern or an array of them. See Matching pages for the pattern format.
Replacing an instance removes the runtime changes made to it.
getInstance and getInstances include runtime changes. You can pass their output back to setInstance and setInstances.
Instance fields
JSON
Add an instance
Results and errors
Setters, updaters, and resetters return a promise that resolves with{ success: true }. If a call fails, the promise rejects with an error object:
JSON
callback function instead, it receives { success: false, error: { code, message } } on failure.