- FAB
- Nativescript marketplace, hi ha multiples opcions:
- https://market.nativescript.org/plugins/@nstudio%2Fnativescript-floatingactionbutton
Aplicació a moixonet:
- Canviar Splash Screen i Icon amb sidekick o a mà. Esvollir la icona i imatges que es vulgui (cal un png original de 1024x1024pixels)
- Com a: https://www.nativescript.org/blog/building-responsive-apps-with-nativescript
- Pantalla de Login adaptada per a tablets
- TODO GridLayout: https://www.nativescript.org/blog/building-responsive-apps-with-nativescript
- MASTER/DETAIL LAYOUT
- Veure gràfica: https://docs.nativescript.org/core-concepts/technical-overview
- Conceptes:
- Codi aplicació
- Framework Javascript (opcional)
- Mòduls
- Plugins
- Codi natius i apis natives
- Requeriment: Android Development Kit
- tns: CLI commands
- Playground web i companion Android apps
- Nativescript sidekick: https://www.nativescript.org/nativescript-sidekick
Sol ser app.js però es pot modificar al fitxer app/package.json
- TLTR
- El nostre aplicatiu utilitza SideDrawer per a navegació principal:
Exemple app.js:
new Vue({
render (h) {
return h(
App,
[
h(DrawerContent, { slot: 'drawerContent' }),
h(Home, { slot: 'mainContent' })
]
)
}
}).$start();
Aquí s'indica Home com la pàgina inicial de navegació. A drawerContent hi ha la resta opcions del menú de navegació i s'utiltiza @tap="onNavigationItemTap(PAGENAME)
- Documentació general Nativescript:
- https://docs.nativescript.org/core-concepts/navigation
- UTILITZEM manual routing: https://nativescript-vue.org/en/docs/routing/manual-routing/
- Encara no es suporta vue-router.
- https://nativescript-vue.org/en/docs/routing/manual-routing/#navigatetocomponent-options
Exemple:
<Button text="To Details directly" @tap="$navigateTo(detailPage)" />
Alguns components ja impliquen una navegació en si mateixos:
- Modal View
- BottomNavigation & Tabs
- SideDrawer
Components implicats en la navegació:
- Frame: The logical View unit that is responsible for navigation within an application.
- The Frame component has no visible representation
- It simply provides a container for transitions between pages. It also provides a navigation API which includes history manipulation and setting custom navigation transitions.
- Proporcionen el mètode navigate per navegar/canviar a un altre pàgina
- https://docs.nativescript.org/core-concepts/navigation#frame
- https://docs.nativescript.org/api-reference/modules/_ui_frame_
- Page: concepte principal de navegació a Nativescript
- definició: represents a logical unit for navigation inside a Frame.
- docs: https://docs.nativescript.org/ui/components/page
- API: https://docs.nativescript.org/api-reference/modules/_ui_page_
- És el component XML arrel/root de la plantilla
- Tipus de navegació:
- Forward/downward navigation (https://docs.nativescript.org/core-concepts/navigation#forward-navigation)
- refers to navigating to a screen on the next level in the hierarchy.
- Backward
- refers to navigating back to a screen either on the previous level in the hierarchy or chronologically.
- Mètode: navigateBack
- https://nativescript-vue.org/en/docs/routing/manual-routing/#navigatebackoptions-backstackentry--null
- Lateral
- refers to navigating between screens on the same level in the hierarchy.
- Forward/downward navigation (https://docs.nativescript.org/core-concepts/navigation#forward-navigation)
- Recomanació:
- Posar tots els components que representen pàgines a una carpeta anomenada
pages
per seguir la estructura que fem a Nuxt.
- Posar tots els components que representen pàgines a una carpeta anomenada
Exemple:
<Frame id="root-frame" defaultPage="main-page"/>
- defaultPage: indica la pàgina inicial que s'ha de mostrar
- Sidekick hi ha un assitent per generar automàticament les icones i splash screen
- Concepte Device Fragmentations
- Exemples metricas dispositius: https://material.io/resources/devices/
- Qüestions a tenir en compte: https://www.nativescript.org/blog/supporting-multiple-screen-resolutions-in-your-nativescript-app
- Screen size - The amount of physical space for displaying your application.
- Density - The number of pixels in any given area on the screen. The typical unit of measure is dots per inch (dpi).
- Density-independent pixels (dp) - This is a virtual unit of measure to allow layouts to be designed independent of density. There’s a neat formula for converting dp into screen pixels: px = dp * (dpi / 160)
- Orientation - The screen’s orientation is considered to be landscape when it is wider than it is tall. In contrast, portrait orientation is when the screen is taller than it is wide. The orientation can change during the lifetime of an application as the user rotates the device.
- Resource files - anything from layout files (.xml) to style sheets (.css) and images.
- IMPORTANT: Els qualifiers no estan suportat a Angular ni a Vue
- S'utilitzen qualifiers per indicar diferents fitxers per a diferents plataformes, midas de pantalla, desitats, etc
- TLTR: a diferencia de la web les apps no es pot fer resize sinó que ocupen pantalla sencera. Però si que es diferencia entre:
- screen sizes: mòbil i tablet
- La diferència de mida entre tablets i mobils no es molta (hi ha mobils de la mida tablets i tablets petites). El que si és rellevant és que els mòbils se solen usar en portrait i les tablets en landscape
- ratios
- Qualifiers: https://docs.nativescript.org/ui/supporting-multiple-screens#orientation-qualifiers
- https://www.nativescript.org/blog/building-responsive-apps-with-nativescript
- https://docs.nativescript.org/ui/supporting-multiple-screens
Just in case someone would only need tablet-specific CSS (like myself) and can't wait for an official solution (like myself), you can do:
const isTablet: boolean = device.deviceType == DeviceType.Tablet;
@Component({
styleUrls: ['default.css', (isTablet ? 'tablet.css' : 'phone.css')]
})
OPCIÓ: Plugin: nativescript-orientation
Sembla que només estan disponibles pel flavor vanilla javascript (ni angular ni vue)
- NativeScript/nativescript-angular#404
- https://stackoverflow.com/questions/33822830/am-i-able-to-change-templateurl-in-angular-2-dynamically
Article: https://www.nativescript.org/blog/building-responsive-apps-with-nativescript
Dona error deprecated al instal·lar (no testejat a NativeScript 6):
tns plugin add nativescript-platform-css
Repositori npm privat!:
Abans instal·lar plugin assegureu-vos git està net (git status). Així podrem comprovar quines modificaciones realitza al projecte el fet d'instal·lar un plugin.
Cal instal·lar com a plugin a dins del projecte nativescript:
tns plugin add @nstudio/nativescript-floatingactionbutton
Quines modificacions s'han realitzat al vostre projecte?
Per utilitzar el Plugin:
A fitxers app.js registreu el nou element:
Vue.registerElement(
'Fab',
() => require('@nstudio/nativescript-floatingactionbutton').Fab
);
en el nostre cas volem posar un FAB a la pàgina principal que permeti subscriure's/afegir nous canals als que estem subscrits a la app. La pàgina principal és Home.vue:
<fab
@tap="fabTap"
row="1"
icon="res://ic_add_white"
rippleColor="#f1f1f1"
class="fab-button"
></fab>
- https://nativescript-vue.org/en/docs/elements/components/search-bar/
- https://docs.nativescript.org/api-reference/classes/_ui_search_bar_.searchbar
- https://docs.nativescript.org/angular/ui/ng-components/search-bar
tns plugin add nativescript-ui-autocomplete
A app.js:
import Vue from 'nativescript-vue';
import RadAutoComplete from 'nativescript-ui-autocomplete/vue';
Vue.use(RadAutoComplete);
- https://www.nativescript.org/ui-for-nativescript
- https://docs.nativescript.org/vuejs/ns-ui/AutoCompleteTextView/getting-started
tns plugin add nativescript-ui-listview
A app.js:
import Vue from 'nativescript-vue';
import RadListView from 'nativescript-ui-listview/vue';
Vue.use(RadListView);
Al component:
<RadListView ref="listView"
for="item in itemList"
@itemTap="onItemTap">
<v-template>
<StackLayout class="item" orientation="vertical">
<Label :text="item.name" class="nameLabel"></Label>
<Label :text="item.description" class="descriptionLabel"></Label>
</StackLayout>
</v-template>
</RadListView>
Docs:
- https://docs.nativescript.org/vuejs/ns-ui/ListView/getting-started
- https://docs.nativescript.org/ui/components/RadListView/overview
- LOAD ON DEMAND https://docs.nativescript.org/ui/components/RadListView/load-on-demand
- Gestures (swipe) i Pull to Refresh i altres
- https://docs.nativescript.org/ui/components/RadListView/data-operations