Skip to content

Instantly share code, notes, and snippets.

@vladdancer
Last active January 18, 2021 17:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vladdancer/d9fe6e4103dde8276bd9af8d0c5f0ff9 to your computer and use it in GitHub Desktop.
Save vladdancer/d9fe6e4103dde8276bd9af8d0c5f0ff9 to your computer and use it in GitHub Desktop.
workaround for a bug with hiding view toolbar on specific page on #framework7 #v5
<script>
import {
App,
View,
Toolbar,
Views,
Link, f7ready
} from 'framework7-svelte';
import {states} from "./services/store";
import routes from './routes';
import {onMount} from "svelte";
let activeRoute = 'home';
onMount(() => {
f7ready(instance => {
const tabbar = instance.$('.tabbar-app');
instance.on('routeChange', (page) => {
activeRoute = page.route.component.prototype.constructor.name.toLowerCase();
activeRoute !== 'thread'
? tabbar.show()
: tabbar.hide();
});
});
});
</script>
<App params={ f7params }>
<Views>
<View>
<Toolbar class="tabbar-app" tabbar position={'bottom'}>
<Link href="/">Home</Link>
<Link href="/threads">Chats</Link>
<Link href="/apartments">Props</Link>
</Toolbar>
</View>
</Views>
</App>
<script>
import {
App,
View,
Views,
f7ready
} from 'framework7-svelte';
import {states} from "./services/store";
import routes from './routes';
import {onMount} from "svelte";
import MainToolbar from './components/MainToolbarSolution2.svelte'
let activeRoute = 'home';
function getComponentNameFromPage(page) {
return page.route.component.prototype.constructor.name.toLowerCase();
}
onMount(() => {
f7ready(instance => {
appInstance = instance;
instance.on('routeChange', (to, from,router) => {
try {
activeRoute = getComponentNameFromPage(to)
}
catch (e) { console.log(e); }
if ($states.loggedIn && activeRoute === 'thread') {
$states.showMainToolbar = false;
}
});
});
});
</script>
<App params={ f7params }>
<View>
<MainToolbar activeRoute={activeRoute}/>
</View>
</App>
<script>
import {
Toolbar,
Icon,
Link,
} from 'framework7-svelte';
import {states} from "../services/store";
export let activeRoute;
let user;
$: user = $states.user || false;
</script>
{#if $states.showMainToolbar}
{#if user && user.role === 'client'}
<Toolbar class="tabbar-app" tabbar position={'bottom'}>
<Link href="/">Home</Link>
<Link href="/chats">Chats</Link>
</Toolbar>
{:else if user && user.role === 'consultant'}
<Toolbar class="tabbar-app" tabbar position={'bottom'}>
<Link href="/">Home</Link>
<Link href="/threads">Chats</Link>
<Link href="/apartments">Props</Link>
</Toolbar>
{/if}
{/if}
@thebestgin
Copy link

I think you mean: let activeRoute = page.route.component.prototype.constructor.name.toLowerCase();

@vladdancer
Copy link
Author

@thebestgin, thank you. Yeah, it was mistake. I've updated the gist.
BTW: now I'm using a different approach to show/hide tabbar.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment