vue.jsnativescriptnativescript-vue

Positioning actionbar items on android


I have this code

<template>
    <Page>
        <ActionBar title="Action Items">
            <StackLayout orientation="horizontal">
                <Image src="res://icon" width="40" height="40"
                    verticalAlignment="center" />
                <Label text="NativeScript" fontSize="24"
                    verticalAlignment="center" />
            </StackLayout>

            <NavigationButton text="Go Back" android.systemIcon="ic_menu_back"
                (tap)="onNavBtnTap()">
            </NavigationButton>

            <ActionItem (tap)="onShare()" ios.systemIcon="9"
                ios.position="left" android.systemIcon="ic_menu_share"
                android.position="actionBar">
            </ActionItem>

            <ActionItem (tap)="onDelete()" ios.systemIcon="16"
                ios.position="right" text="delete" android.position="popup">
            </ActionItem>

        </ActionBar>
        <ScrollView>
            <StackLayout class="home-panel">
                <!--Add your page content here-->
                <Label textWrap="true" text="Play with NativeScript!"
                    class="h2 description-label">
                    {{first}}
                </Label>
                <Label textWrap="true"
                    text=" Write code in the editor or drag and drop components to build a NativeScript mobile application."
                    class="h2 description-label" />
                <Label textWrap="true"
                    text="Scan the QR code with your mobile device and watch the changes sync live while you play with the code."
                    class="h2 description-label" />
            </StackLayout>
        </ScrollView>
    </Page>
</template>

<script>
    export default {
        data() {
            return {
                first: "Once"
            };
        }
    };
</script>

<style scoped>
    .home-panel {
        vertical-align: center;
        font-size: 20;
        margin: 15;
    }

    .description-label {
        margin-bottom: 15;
    }
</style>

which produces enter image description here

My question is how come the back button aligned itself left and the others right without explicitly coding left or right?

<NavigationButton text="Go Back" android.systemIcon="ic_menu_back"
                (tap)="onNavBtnTap()">
</NavigationButton>

and the other buttons are aligning to the right

<ActionItem (tap)="onShare()" ios.systemIcon="9"
                ios.position="left" android.systemIcon="ic_menu_share"
                android.position="actionBar">
            </ActionItem>

<ActionItem (tap)="onDelete()" ios.systemIcon="16"
                ios.position="right" text="delete" android.position="popup">
</ActionItem>

Solution

  • <NavigationButton/> is by default on the left, as it's just calls into the native setNavigationIcon api:

    https://developer.android.com/reference/android/widget/Toolbar#setNavigationIcon(android.graphics.drawable.Drawable)

    While the other <ActionItem> elements are added with the Menu api:

    https://developer.android.com/reference/android/widget/Toolbar#getMenu()


    For your other question, you can do the following:

    <Label :text="`${first} Play with NativeScript!`" textWrap="true" class="h2 description-label" />
    

    :text makes it a binding, the then you pass in a regular JavaScript string literal.

    An alternative would be:

    :text="first + ' Play with NativeScript!'"
    

    Both ways should work fine.