I'm trying to display how many items are there in cart. on top of the cart symbol. but I'm facing an issue using grid layout. since, nativescript wont support superscript. is there any better way to design.
i tried something like below. but the number of items is not properly displaying on top right of the cart symbol.
<GridLayout col="2" rows="auto" columns="*,*">
<Label col="0" text="" fontSize="28" class="fas" textWrap="true" />
<Label col="1" text="{{ line_item_no }}" fontSize="10" textWrap="true" margin="0 5 0 5" class="fcw" />
</GridLayout>
i need a cart symbol of 25 font size. on top right i need a 10 font size number surrounded by a round background. kindly give me some ideas.
you can use text-decoration: line-through; property, see the references below:
https://docs.nativescript.org/api-reference/modules/ui_enums.textdecoration
https://docs.nativescript.org/ui/styling
Related
I'm loading a list of items, each with an URL reference for a thumbnail foreach item. When rendering the list using RadListView, I notice that each image is being loaded several times from the server. This only happens in iOS, in Android each thumbnail only loads once. The view however, is correct (no duplicates).
NativeScript version is 5.1.1
<StackLayout>
<SearchBar id="searchBar" hint="{{sbHint}}" text="{{sbText}}" clear="onClear" submit="onSubmit" />
<GridLayout rows="auto, *" class="list-group">
<lv:RadListView class="listview" items="{{itemList}}" pullToRefresh="true" pullToRefreshInitiated="onPullToRefreshInitiated" loaded="onListLoaded" itemTemplateSelector="selectItemTemplate" row="1">
<lv:RadListView.itemTemplates>
<template key="hasimg">
<GridLayout rows="auto" columns="70,*,auto" class="list-group-item" tap="select">
<Image row="0" col="0" src="{{imgurl}}" width="60" height="50" stretch="aspectFill"/>
<Label row="0" col="1" class="p-l-15 text" text="{{ name }}"/>
<Label class="p-l-15 fa" text="" row="0" col="2"/>
</GridLayout>
</template>
<template key="noimg">
<GridLayout rows="auto" columns="70,*,auto" class="list-group-item" tap="select">
<Label class="fa imgicon" text="" row="0" col="0"/>
<Label row="0" col="1" class="p-l-15 text" text="{{ name }}"/>
<Label class="p-l-15 fa" text="" row="0" col="2"/>
</GridLayout>
</template>
</lv:RadListView.itemTemplates>
</lv:RadListView>
<ActivityIndicator busy="{{ isLoading }}" row="1" horizontalAlignment="center" verticalAlignment="center"/>
</GridLayout>
</StackLayout>
Output from the API server on the same list load, using iOS and Android.
Using iOS (wrong):
GET /v4/item/file/display/1/ 404 Not Found
GET /v4/item/file/display/1/ 404 Not Found
GET /v4/item/file/display/2/ 404 Not Found
GET /v4/item/file/display/2/ 404 Not Found
GET /v4/item/file/display/1/ 404 Not Found
GET /v4/item/file/display/2/ 404 Not Found
GET /v4/item/file/display/1/ 404 Not Found
GET /v4/item/file/display/2/ 404 Not Found
POST /v4/item/list/ 200 OK
Using Android (correct):
GET /v4/item/file/display/1/ 404 Not Found
GET /v4/item/file/display/2/ 404 Not Found
POST /v4/item/list/ 200 OK
(in reversed order, please ignore the 404, I changed the path better to diff each call)
When using ListView, it reuses the item template as you scroll down / up. Let's say if you have 100 data items loaded on ListView, it would not create 100 View / Image components. It will probably create a few depending on the visible area of your screen, when you scroll up / down the same views will be reused for other data items to keep the performance up. This is the advantage of using ListView or RadListView.
Coming to why the Image was loaded multiple times, by default Android caches the image and uses it on subsequent requests. With iOS, it doesn't. So it hits the URL every time whenever it has to render the image while you scroll up / down.
The solution is to cache your images in temp storage. You could simply do it with http module and a bit of logical statements Or there are even several plugins you could find in the market place for this purpose, nativescript-web-image-cache or nativescript-image-cache-it are couple to name.
I am creating an Arabic app with NativeScript. I want each row inside list view to be viewed in rtl direction so the text in the row is aligned to the right.
I tired using text-align:right and horizontal-align:right but didn't worked.
How can I do this?
Thank you.
As there is no code snippet of what you have tried so far we can only speculate what is your code structure.(see here)
However here is a very basic example on how to align all list-view cell templates to the right by default.
<ListView.itemTemplate>
<GridLayout rows="*" columns="*">
<Label row="0" col="0" text="right aligned text" textAlignment="right" textWrap="true" />
</GridLayout>
</ListView.itemTemplate>
I have this code in main-page.xml:
<GridLayout rows="auto, *">
<Label text="Title" class="title" row="0" />
<ListView id="listView" items="{{ listItems }}" row="1">
<ListView.itemTemplate>
<StackLayout>
<Button text="{{ name }}" tap="dd" />
</StackLayout>
</ListView.itemTemplate>
</ListView>
</GridLayout>
When I scroll the title stick to the top (stay and don't move), is there is a way to make it behave normally ?
I found a cleaner solution using : https://docs.nativescript.org/cookbook/ui/repeater
<ScrollView>
<StackLayout>
<Label text="Title" class="title" />
<Repeater id="listItems" items="{{ listItems }}">
<Repeater.itemTemplate>
<StackLayout>
<Button text="{{ name }}" tap="loadGuide" />
</StackLayout>
</Repeater.itemTemplate>
</Repeater>
</StackLayout>
This is definitely the expected behavior when placing a Label at a row of a GridLayout which is set to auto. What you want to achieve can be done but will require additional implementations for example like this (No boring ActionBar) third party Android library. What you can do is either implement the same using pure JavaScript/TypeScript directly in your app (by managing the size of the ActionBar) or create a custom NativeScript plugin that uses the mentioned android library.
One of the many beauties of NativeScript is that 100% of the native iOS and Android APIs are accessible meaning anything that is achievable in an native iOS or Android app is achievable in {N}.
I just recently started with NativeScript and ran into a roadblock.
I have a AppBuilder/NativeScript project (iOS only for now) in which I want to implement a floating action button. I have seen plenty of examples where the FAB is positioned above a ListView however my scenario is different:
I have 3 repeaters (displaying unrelated data).
each repeater may or may not be visible on the page (if there is no data to display, I am hiding it)
I would like to place the FAB on the bottom right regardless of what the content is
The whole page is wrapped in a ScrollView
I tried using nativescript-floatingactionbutton, but I cannot compile with this module installed. I keep getting "Cannot build project because module nativescript-floatingactionbutton contains insecure code. Remove the module and try again."
I also tried an AbsoluteLayout on the page level, but it seems that the layout overlays the rest of the page and I cannot even see the content, just the FAB.
Here is the markup
<Page id="MainPage" xmlns="http://schema.nativescript.org/tns.xsd" actionBarHidden="true" loaded="pageLoaded" xmlns:drawer="nativescript-telerik-ui/sidedrawer" xmlns:sharedDrawers="widgets/drawers">
<drawer:RadSideDrawer id="mainDrawer">
<drawer:RadSideDrawer.mainContent>
<ScrollView id="wrapper" opacity="0">
<DockLayout stretchLastChild="false">
<GridLayout id="mainHeader" cssClass="header" dock="top" columns="50, *, 50">
<Label class="icomoon-icon" text="" row="0" col="0" horizontalAlignment="center" tap="openDrawer" fontSize="18" />
<Label horizontalAlignment="center" text="{{ pageTitle }}" row="0" col="1" />
<Label class="icomoon-icon" text="" row="0" col="2" horizontalAlignment="center" tap="notifications" fontSize="18" />
</GridLayout>
<GridLayout cssClass="main" rows="auto, *" >
<StackLayout row="0">
<StackLayout cssClass="{{arr.length ? '' : 'hidden' }}">
<label cssClass="section-title" text="{{strings.activeLoans}}"></label>
<Repeater items="{{ arr }}" >
<Repeater.itemTemplate cssClass="item">
...
</Repeater.itemTemplate>
</Repeater>
</StackLayout>
<StackLayout cssClass="{{arr2.length ? '' : 'hidden' }}">
<label cssClass="section-title" text="{{strings.history}}" marginTop="20" />
<Repeater items="{{ arr2 }}">
<Repeater.itemTemplate>
...
</Repeater.itemTemplate>
</Repeater>
</StackLayout>
<StackLayout cssClass="{{arr3.length ? '' : 'hidden' }}">
<label cssClass="section-title" text="{{strings.data}}" marginTop="20" />
<Image src="~/images/pic.jpg" />
<Repeater items="{{ arr3 }}">
<Repeater.itemTemplate>
...
</Repeater.itemTemplate>
</Repeater>
</StackLayout>
</StackLayout>
</GridLayout>
</DockLayout>
</ScrollView>
</drawer:RadSideDrawer.mainContent>
<drawer:SideDrawer.drawerContent>
<sharedDrawers:mainDrawer />
</drawer:SideDrawer.drawerContent>
</drawer:RadSideDrawer>
<!--<AbsoluteLayout cssClass="fabContainer">
<Image src="res://fab_add" tap="newLoan" cssClass="fab" />
</AbsoluteLayout>-->
</Page>
I have truncated and changed some of the non-relevant code.
Any help is greatly appreciated.
Thank you.
Аs Brad Martin says, the plugin cannot be built inside Telerik Platform as not all of its maintainers are white listed. To be more precise, when an iOS build of a plugin containing a pod file is initiated in Telerik Platform, the service checks its maintainers. As a pod file can contain post build scripts, Telerik Platform is currently flagging plugins as safe by keeping a list of white listed maintainers.
This plugin has 5 maintainers - Brad Martin being only one of them. Brad’s email is white listed but ‘gabrielbiga’ and ‘lazaromenezes’ are not yet whitelisted. #Brad Martin- can you please let us know whether we should whitelist these users emails as well?
The other approach would be to replace the pod file with frameworks instead.
One last thing, moving forward with Telerik Platform releases Telerik Platform team will be working on improving the support for plugins containing pods. They will probably remove the "whitelisting” approach with sandboxing instead but we couldn’t yet comment on any specifics.
When I render a ListView in NativeScript, I get more rows than I have data. Is there a way to control this? I would like to see the minimum number of rows required to display my data.
<Page xmlns="http://www.nativescript.org/tns.xsd"
loaded="load">
<ListView items="{{ data }}">
<ListView.itemTemplate>
<Button text="{{ name }}" tap="{{ action }}"/>
</ListView.itemTemplate>
</ListView>
</Page>
For short lists, use a Repeater. For the separators, just use a StackLayout with a height of 1 and set the background-color to some grey. It will look just like a ListView. ListViews are meant to be used with large datasets that require virtualization of the rows.