Nativescript Collapsed GridLayout Row still take place in the UI - nativescript

Using this Layout:
<GridLayout columns="70, *" rows="auto, auto, auto">
<Label row="0" col="0" rowSpan="3" text="A" style="background-color: red;"></Label>
<Label row="0" col="1" text="B" style="background-color: green;"></Label>
<Label row="1" col="1" text="C" visibility="collapse" style="background-color: blue;"></Label>
<Label row="2" col="1" text="D" style="background-color: orange"></Label>
</GridLayout>
Is there a reason I can see a white space between row B and D ? I expected row D to go up and take the place of row C.
I'm testing on a physical device so here's a quick paint of the result:
I expected the result to behave like this html table:
<table>
<tbody>
<tr>
<td rowspan="3" style="width: 70px; background-color: red;">A</td>
<td style="width: 500px; background-color: green;">B</td>
</tr>
<tr>
<td style="display: none; background-color: blue;">C</td>
</tr>
<tr>
<td style="background-color: orange;">D</td>
</tr>
</tbody>
</table>
Here's a snip of the html result:

That is because you have defined a GridLayout with 3 rows and you set the label D to the third row. Even when the label C is collapsed, its place won't be taken up.
If you would like to have a layout exactly as the second picture, then I suggest this:
<GridLayout columns="70, *" rows="auto">
<Label row="0" col="0" text="A" style="background-color: red;"></Label>
<StackLayout row="0" col="1">
<Label text="B" style="background-color: green;"></Label>
<Label text="C" visibility="collapse" style="background-color: blue;"></Label>
<Label text="D" style="background-color: orange"></Label>
</StackLayout>
</GridLayout>
P/s: if you put the label C back to visible, the layout will resize itself also

Related

RadListView with tkGroupTemplate with inner content scroll horizontal

Tell us about the problem
I am trying to horizontally set the content that is grouped with the function of but is not possible, because all content is horizontal.
Which platform(s) does your issue occur on?
Both
Please tell us how to recreate the issue in as much detail as possible.
<RadListView
[items]="dataItems"
#productsListView
[groupingFunction]="grouping"
>
<ng-template tkListItemTemplate let-item="item">
<StackLayout orientation="horizontal" width="100%">
<MDCardView width="100" height="100">
<Image stretch="aspectFill" [src]="item.image"></Image>
</MDCardView>
</StackLayout>
</ng-template>
<ng-template tkGroupTemplate let-category="category">
<GridLayout columns="*, auto" ios:height="50">
<Label
col="0"
style="font-weight: bold; font-size: 24"
[text]="category"
></Label>
<Label
col="1"
style="font-size: 12; color: gray;"
text="Ver más"
></Label>
</GridLayout>
</ng-template>
<ListViewGridLayout
tkListViewLayout
itemHeight="100"
scrollDirection="Horizontal"
></ListViewGridLayout>
</RadListView>
Try ScrollView within tkGroupTemplate
<ng-template tkGroupTemplate let-category="category">
<GridLayout>
<ScrollView orientation="horizontal" scrollBarIndicatorVisible="false">
<Label class="m-5 h2" [text]="category"></Label>
</ScrollView>
</GridLayout>
</ng-template>
Playground Sample

Background Image Not Showing On NativeScript Page

I am trying to display a background image on my login page, it is not showing.
I have tried adding the class to the page and my layout. Neither is working.
Is there something in my code that is preventing this for some reason?
<Page loaded="pageLoaded" class="page bgImage" actionBarHidden="true" xmlns="http://www.nativescript.org/tns.xsd">
<FlexboxLayout class="page">
<GridLayout rows="auto, auto, auto">
<StackLayout class="form ">
<Image class="logo" src="~/images/johnevolve.png" />
<Label class="header" text="Health Conscious" />
<StackLayout class="input-field">
<Label text="Username" />
<TextField class="input" text="{{ email }}" hint="Email"
keyboardType="email" autocorrect="false"
autocapitalizationType="none" returnKeyType="next" />
<Label class="hr-light" />
</StackLayout>
<StackLayout class="input-field">
<Label text="Password" />
<TextField id="password" class="input" text="{{ password }}"
hint="Password" secure="true" returnKeyType="{{ isLoggingIn ? 'done' : 'next' }}" />
<Label class="hr-light" />
</StackLayout>
<StackLayout class="input-field" visibility="{{ !isLoggingIn ? 'visible' : 'collapse' }}">
<TextField id="confirmPassword" class="input" text="{{ confirmPassword }}"
hint="Confirm password" secure="true" returnKeyType="done" />
<Label class="hr-light" />
</StackLayout>
<Button text="{{ isLoggingIn ? 'Log In' : 'Sign Up' }}" tap="{{ submit }}"
class="btn btn-primary m-t-20" />
<Label visibility="{{ isLoggingIn ? 'visible' : 'collapse' }}"
text="Forgot your password?" class="login-label" tap="{{ forgotPassword }}" />
</StackLayout>
</GridLayout>
<Label class="login-label sign-up-label" tap="{{ toggleForm }}">
<FormattedString>
<Span text="{{ isLoggingIn ? 'Don’t have an account? ' : 'Back to Login' }}" />
<Span text="{{ isLoggingIn ? 'Sign up' : '' }}" class="bold" />
</FormattedString>
</Label>
</FlexboxLayout>
</Page>
and my css:
.bgImage {
background-image: url("~/images/1-login.png");
}
Edit: Here is the page css rule in case you need that:
.page {
align-items: center;
flex-direction: column;
}
Does anyone know what's going wrong here?
Thank you.
Image In Question:
If this is NativeScript 5.x and you are using HMR/Webpack; the issue is most likely WebPack caused. I have a blog article about this on how to disable HMR mode and re-use Legacy mode.
In a nutshell you need to re-enable Legacy mode.
http://fluentreports.com/blog/?p=935
Please note; this is only relevent to NativeScript 5.x; NativeScript 6 (coming out shortly) will probably not let you re-enable legacy mode.
If you find legacy mode does actually fix your issue; please report this issue to the https://github.com/nativescript/NativeScript-Dev-Webpack repo so it can be looked at.
There was the problem with your FlexboxLayout . It was taking the 100% height and overlapping the background image with it's content.
You can also try with giving background Image to your FlexboxLayout.
<FlexboxLayout class="page bgImage">
and in app.css
.bgImage{
/* background-color: green; */
background-image: url("~/images/1-login.png");
background-repeat: no-repeat;
background-size: cover
}
I have created a playground for you here.

How to add new line to Button from XML

In my NativeScript project, I'm trying to make a bottom bar with an icon and then the word that resembles it underneath it. Like this
Here's the html of what I tried to do:
<GridLayout rows="*,60">
<ScrollView row="0">
<WrapLayout orientation="horizontal">
<Label text="There are no leagues currently." style="color: black; text-align: center; font-weight: bold"></Label>
<Label text="Contact your commissioner" style="color: black; text-align: center; font-weight: bold"></Label>
<Label text="to create one." style="color: black; text-align: center; font-weight: bold"></Label>
</WrapLayout>
</ScrollView>
<StackLayout row="1" orientation="horizontal">
<Button textWrap="true" width="25%">
<FormattedString>
<Span text="\n" class="fa"></Span>
<Span text="Home"></Span>
</FormattedString>
</Button>
<Button textWrap="true" width="25%">
<FormattedString>
<Span text="\n" class="fa"></Span>
<Span text="All Cocktails"></Span>
</FormattedString>
</Button>
<Button textWrap="true" width="25%">
<FormattedString>
<Span text="\n" class="fa"></Span>
<Span text="Favorite"></Span>
</FormattedString>
</Button>
<Button textWrap="true" width="25%">
<FormattedString>
<Span text="\n" class="fa"></Span>
<Span text="Profile"></Span>
</FormattedString>
</Button>
</StackLayout>
</GridLayout>
and here's my css:
.fa {
font-family: 'Font Awesome 5 Free';
}
However, whenever I try to do this, it comes out like this
I'm not quite sure where to go so any help would be great. Thanks!
Here's a working example of my code: https://play.nativescript.org/?template=play-ng&id=r8Jodt&v=19
Use the GridLayout for BottomBar, you can look for the playground sample here
<GridLayout columns="*,*,*,*" rows="*,*" width="100%" row="1" backgroundColor="lightgray">
<Label text="" row="0" col="0" class="fa" width="100%" textAlignment="center"></Label>
<Label text="Home" row="1" col="0" width="100%" textAlignment="center"></Label>
<Label text="" row="0" col="1" class="fa" width="100%" textAlignment="center"></Label>
<Label text="All Cocktails" row="1" col="1" width="100%" textAlignment="center"></Label>
<Label text="" row="0" col="2" class="fa" width="100%" textAlignment="center"></Label>
<Label text="Favorite" row="1" col="2" width="100%" textAlignment="center"></Label>
<Label text="" row="0" col="3" class="fa" width="100%" textAlignment="center"></Label>
<Label text="Profile" row="1" col="3" width="100%" textAlignment="center"></Label>
</GridLayout>
The actual problem here is that \n works only with JavaScript, while using it in HTML (XML) file you should use the encode version of the character that is
, that should give you a new line.
Are you trying to have a custom TabBar for your TabView? If Yes, you may try the nativescript-vector-icons which allows you to use font icons on TabBar.
Make their position as display:absolute and within the class it should be inline-block. With some margins it should be easy to adjust
I would contain all the buttons in a div, and then each button and label group in it's own div.
<div id='button-row'>
<div class='bottom-button>
<button></button>
<p class='label>Label</p>
</div>
<div class='bottom-button>
<button></button>
<p class='label>Label</p>
</div>
// repeat for your buttons
</div>
Your css:
.button-row {
display: flex;
flex-direction: row;
justify-content: space-between;
}
.bottom-button {
display: flex;
flex-direction: column;
justify-content: center;
// the font awesome icons are considered text I believe, so
text-align: center;
// would also work
}
This will make all your buttons in the row evenly spaced, and place your button on top of the label. I like using flexbox because its quick and easy, and mobile responsive. I'm not a CSS pro by any means but it works for me.
Edit: just saw your markup. Try giving formatted string the css of .bottom-button and see if that works.
For \n just worked for android.
using hex code
also not worked for both ios and android.
the final solution I find is as below:
(for nativescript-vue)
<Label textWrap="true" col="0" row="0">
<FormattedString>
<Span class="number" :text="days" />
<Span class="format" :text="'\n' + 'Gün'" />
</FormattedString>
</Label>

In Nativescript how can I achieve a vertically aligned label text using StackLayout

I need something like this:
But this is what I have at the moment:
.rotate {
transform: rotate(-90deg);
font-size: 16px;
color: #FFFFFF;
}
This is my code:
<StackLayout backgroundColor="#3C414B" width="12%" height="100%" horizontalAlignment="center" verticalAlignment="center" (tap)="openDrawer('Right')">
<StackLayout class="rotate" orientation="horizontal">
<Label class="fa" style="margin-right: 10px" text=""></Label>
<Label width="100%" class="" text="New Category" textwrap="false"></Label>
</StackLayout>
</StackLayout>
You will have to set the height explicitly to the width of the element, transform doesn't take care of that by default.
Or you may even consider using an image, here is a related thread from Forums.
It looks like you rotate inner <StackLayout class="rotate" ...>, but it still get width limit of outer <StackLayout width="12%" ...>
Try so:
<StackLayout class="rotate" backgroundColor="#3C414B" width="100%" height="12%" horizontalAlignment="center" verticalAlignment="center">
<StackLayout orientation="horizontal">
<Label class="fa" style="margin-right: 10px" text=""></Label>
<Label text="New Category" textwrap="false" backgroundColor="yellow"></Label>
</StackLayout>
</StackLayout>
Or try to find solution with other layout type. For example, AbsoluteLayout

NativeScript display images in dynamic grid

I'm trying to find a way to display 6 images in two columns and 3 rows.
With for columns and images should be 50%. Here is my code and it does not "overflow" second and third row.
<Repeater items="{{ sviKatalozi }}">
<Repeater.itemsLayout>
<StackLayout orientation="horizontal" width="500" height="1000" />
</Repeater.itemsLayout>
<Repeater.itemTemplate>
<Image width="180" margin="10" src="{{ 'http://imageurl' + katalog_image }}" />
</Repeater.itemTemplate>
</Repeater>
I have found perfect solution <FlexboxLayout> to arrange things in way I want, but could not find a way to use observables and data binding. It does not work if put items="{{ sviKatalozi }}" inside.
<FlexboxLayout flexWrap="wrap" height="50%" width="100%" backgroundColor="lightgray">
<Label text="Label 1" width="50%" height="50" backgroundColor="red"/>
<Label text="Label 2" width="50%" height="50" backgroundColor="green"/>
<Label text="Label 3" width="50%" height="50" backgroundColor="blue"/>
<Label text="Label 4" width="100" height="50" backgroundColor="yellow"/>
</FlexboxLayout>
Is there any way to make this work? Thanks
use ngFor like this
<GridLayout *ngFor="let item of placesArray" width="50%" class="placeBox">
instead of Repeater

Resources