Publicado em 4. outubro 2025 por Jan Bunk
Pra alguns sites pode ser útil modificar dinamicamente os botões na barra do app. Tu pode fazer isso com essas funções JavaScript.
executeWhenAppReady() do nosso script auxiliar de aplicação. Ele garante que seu site não tente interagir com o aplicativo antes que ele esteja pronto ou quando o site for carregado usando um navegador comum (ReferenceError, a função não está definida). getAppBarItemsUsa essa função pra pegar uma lista de objetos representando todos os itens da barra do app que estão sendo exibidos no momento.
<script>
try {
// returns a list of objects representing the app bar items
let appBarItems = (await getAppBarItems())["appBarItems"];
}
catch (e) {
// Can occur if:
// - the app couldn't connect to the native code. Should be very unlikely.
console.log(e);
}
</script>
setAppBarItemsUsa essa função pra modificar os itens da barra do app que devem ser exibidos.
<script>
try {
// example for an app bar item object
let newAppBarItem = {
action: {
urlToRedirectTo: "https://webtoapp.design/contact",
javascriptToExecute: null,
elementToClickSelector: null,
isFavoriteAction: false,
isShareAction: false,
isOpenExternallyAction: false,
isSettingsAction: false,
isRateAction: false,
isPastNotificationsAction: false,
},
icon: {
name: "list"
}
};
// get the currently displayed app bar items
let allAppBarItems = (await getAppBarItems())["appBarItems"];
// add the new app bar item to the list of app bar items
allAppBarItems.push(newAppBarItem);
// display the list of app bar items, including the new app bar item
await setAppBarItems(allAppBarItems);
}
catch (e) {
// Can occur if:
// - the app couldn't connect to the native code. Should be very unlikely.
console.log(e);
}
</script>
Aqui está uma lista de documentação de desenvolvedores relacionada a como mudar dinamicamente o menu do app. Certifique-se de que está vendo a documentação aplicável ao layout do seu app.