Nativescript 6 external image parent does not respect height - nativescript

I have an NS 6 app and testing on an iPhone 6+ with iOS 13.
In this app I have a ListView and in the ListView I have a nativescript-carousel.
In the carousel I have an image component that loads an external image. The issue is that when I load the page, the image is loaded, but the parent does not expand vertically to accommodate the full height of the image. I can only see a small portion of it.
I tried refreshing the ListView and calling page.requestLayout(), but that did not help. If I set the image height, everything works, but the issue is that some of the carousel items may not have an image, so I cannot commit to a set height.
Here is my code (truncated for brevity):
<ListView id="lst" items="{{ asks }}">
<ListView.itemTemplate>
<StackLayout class="ask-item">
…
<GridLayout rows="*" columns="*" marginTop="10">
<ns:Carousel items="{{ recs }}" color="white" pageChanged="myChangeEvent" android:indicatorAnimation="slide" indicatorColor="#999999" indicatorColorUnselected="#dddddd" indicatorOffset="0,15" showIndicator="true">
<ns:Carousel.itemTemplate>
<ns:CarouselItem backgroundColor="#f9f9f9" verticalAlignment="middle">
<StackLayout class="rec-item">
…
<Image src="{{ image }}" stretch="aspectFit" horizontalAlignment="center" />
…
</StackLayout>
</ns:CarouselItem>
</ns:Carousel.itemTemplate>
</ns:Carousel>
</GridLayout>
</StackLayout>
</ListView.itemTemplate>
</ListView>
What is the best way to handle this issue?
Thank you.

By nature iOS ListView height can not be changed once rendered, you will have to update the specific list item.
Try downloading the image upfront or listen to isLoading property change, once then capture the height of the raw image and bind the height to the layout. The images height could be in raw pixel, you might want to convert that into density independent pixel for better display on high resolution devices.

Related

How to show a video in each row in a stacklayout / listview [Xamarin.Forms]?

I am using the plugin https://github.com/Baseflow/XamarinMediaManager where they have video support.
I successfully use it and am able to play a video, but now that i try to display multiple videos in a stacklayout list (similiar to a instagram or twitter feed), then we are running into issues.
So i bind each item in the list to a unique video URL, but once i scroll through the list, then the video appears 1st on top of eachother/the same video is reused on all rows, even though it should only be in 1.
<StackLayout BindableLayout.ItemsSource="{Binding FlowList}">
<BindableLayout.ItemTemplate>
<DataTemplate>
<StackLayout>
<Label Text="{Binding Title}"/>
<mm:VideoView VerticalOptions="FillAndExpand"
AutoPlay="True"
Source="{Binding Video}"
VideoAspect="AspectFill"/>
</StackLayout>
</DataTemplate>
</BindableLayout.ItemTemplate>
</StackLayout>
So the Title for each row loads well, indicating that there is nothing wrong going on with the binding etc. The issue as explained above is that the same 1 video appears on all rows, even though it should only be on one and each row has a unique video attached to it, same as the "Title" for the label.
Anyone know if there is a limitation/bug with the MediaManager plugin and if there is any other suggestion/route to go here?
You have to give proper HeightRequest to your VideoView otherwise it create problem if you did't set it.
You need to add height request for video viewer that will resolve your issue.
By adding from Xaml or xaml.cs

NativeScript GridLayout Alignment Problem - iOS

I am trying to make it so I have the MENU label on the far left of the ActionBar and the logo in the center, for iOS.
<template>
<ActionBar>
<GridLayout backgroundColor="green" columns="*, *" rows="*, *">
<Label v-if="isIos" row="0" col="0" text="MENU" #tap="openDrawer()" class="c-actionbar_label_ios"/>
<Image v-if="isIos" row="0" col="1" #tap="goToHome()" src="~/assets/images/sklar-logo.png" class="c-actionbar_logo"/>
</GridLayout>
</ActionBar>
</template>
The problem is that GridLayout stays right in the center and doesn't stretch the full width. I was thinking *,* meant two columns 50% width each, but that must not be the case. I put a green background on it so you can see the current width.
Is there some way to do accomplish this layout with GridLayout or any other layout? I've messed with FlexBoxLayout also, but can't get that to do what I want because you cant use % widths.

How to overlap images in Xamarin forms

I want to design as attached screenshot
I tried using RelativeLayount and AbsoluteLayout but Still not successful to have the required result. Can you help
<RelativeLayout HorizontalOptions="Center">
<Image Source="XX.png" />
<Image Source="YY.png"/>
<Image Source="WW.png"/>
</RelativeLayout>
These are the three images
You can use AbsoluteLayout and specify image positions to make them overlap:
<AbsoluteLayout>
<Image Source="aa.png" Aspect="Fill" AbsoluteLayout.LayoutFlags="All" AbsoluteLayout.LayoutBounds=".5,.5,1,1"/>
<Image Source="bb.png" Aspect="Fill" AbsoluteLayout.LayoutFlags="All" AbsoluteLayout.LayoutBounds=".5,.5,1,1"/>
</AbsoluteLayout>
But in your case, it will be difficult to adjust the positions since your images are of different scale, and are not symmetrical, it's recommended that you make some adjustment on your images first so that it will be easier for you to put them into the screen.
For more information about AbsoluteLayout, see Xamarin.Forms AbsoluteLayout
Option 1 - Use grid with same Row and Column
Option 2 - Use AbsoluteLayout

Nativescript Angular ScrollView tether item to top of page

I have a scrollview with an image at the top, then a searchbar and a list. I'm trying to make it so that the searchbar doesn't leave the top of the page when scrolling up so that the list keeps scrolling underneath it.
Format:
<ScrollView>
<Image src="testimage.png"></Image>
<Searchbar></Searchbar>
<ListView items></ListView>
</ScrollView>
Is there a way to do this in NativeScript?
Use GridLayout, ListView itself has built-in scrollbar.
<GridLayout rows="auto,auto,*">
<!-- you might want to set a height for image, depends on your image source -->
<Image row="0" src="testimage.png"></Image>
<Searchbar row="1"></Searchbar>
<ListView row="2" ...></ListView>
</GridLayout>

Why won't controls stretch in WP7?

Here is a simple XAML snippet:
<Grid x:Name="ContentGrid">
<ContentControl Background="Yellow" VerticalAlignment="Stretch"></ContentControl>
</Grid>
In WPF, the content control stretches the entire height of the grid.
In WP7 however, the content control does not stretch.
Why?
Avoid using ContentControl directly.
If you use something which inherits from it, such as a button, then, in a grid, as per your example, you'll automatically get horizontal and vertical stretching.
This will creat a button with a yellow background which fills the screen:
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<Button Background="Yellow" />
</Grid>
However, if you just wanted a yellow background to your grid - which is all your sample would do - you could just set the background property on the grid itself.
I fixed this by defining my own template:
<ContentControl><ContentControl.Template><ControlTemplate><ContentPresenter/> ...
Not sure why it fixes it but it works....

Resources