Nativescript-vue: How to build a chat template - nativescript

I want to build a small chat as we all know from WhatsApp.
Currently I am able to display messages within a ListView.
<template>
<Page>
<ListView separatorColor="transparent" for="item in messages">
<v-template>
<GridLayout>
<TextView
height="auto"
editable="false"
:text="item.message"
/>
</GridLayout>
</v-template>
</ListView>
</Page>
</template>
My next step is to add a TextView with a Button at the end of the page. But here are coming my problems:
Which Layout component should I choose to position a TextView at the bottom of the page.
If I tab into my editable TextView the virtual keyboard overlaps my current page. Instead it should resize the whole page. How can I do this?
This is my current playground project: https://play.nativescript.org/?template=play-vue&id=F8lXkO
EDIT:
I found a way which works on Android using DockLayout:
https://play.nativescript.org/?template=play-vue&id=F8lXkO&v=3
Unfortunately this works only in the playground. Using the latest nativescript version on android is not working. If I tab on the TextView the layout breaks => https://github.com/sowinski/nativescript-vue-chat

Use GridLayout for the entire view. You can use this as a guide - https://github.com/Especializa/nativescript-whatsapp-template
Use this to better understand Nativescript layouts - https://www.nslayouts.com/

Related

iOS Xamarin Forms - Toolbar and Navigation items not showing

I am adding iOS support for my already existing Xamarin Forms android app.
The toolbar items, navigational back arrow and the hamburger menu do not show on iOS:
While they work perfectly on Android:
The Application.MainPage is set to a Shell:
<Shell xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="app.MainPage"
FlyoutBackgroundColor="{StaticResource cBackgroundColorDark}"
Shell.TabBarTitleColor="{StaticResource cBackgroundColor}"
Shell.BackgroundColor="{StaticResource cBackgroundColor}">
<Shell.Resources>
<ResourceDictionary>
<vm:FlyoutVM x:Key="vm" x:Name="vm"/>
</ResourceDictionary>
</Shell.Resources>
<Shell.FlyoutHeader>
</Shell.FlyoutHeader>
<ShellContent Title="page1"
IsTabStop="True"
ContentTemplate="{DataTemplate views:Page1Page}"/>
...
<Shell.FlyoutContent>
</Shell.FlyoutContent>
<Shell.FlyoutFooter>
</Shell.FlyoutFooter>
</Shell>
The page with the toolbar items is simply:
<ContentPage>
<ContentPage.ToolbarItems>
<ToolbarItem Text="Example"
IconImageSource="Example.png"
Clicked="ExampleToolbarItem_Clicked"
/>
</ContentPage.ToolbarItems>
</ContentPage>
All navigation (hamburger menu, back button ect) and toolbar items can be tapped on iOS and work as intended - they just are not visible.
I do not understand why this does not work on iOS, any suggestions why this might be the case?
(I cannot find any styling that might be making it act differently. I have also tried displaying a toolbar with just text (no icons) and the problem persists)
I can provide more code if needed.
EDIT
I ended up creating a new Xamarin shell template project and moving everything over. That fixed the issue...
Most likely the image size for ios is incorrect. I use this https://appicon.co/#image-sets to create image set for ios.

Labels are not visible in Xamarin.iOS

I just recently started Xamarin.Forms. I run the following code by deploying it to my own IPhone device. The code is the default code that is added whenever a new page is added.
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="TestReal.MainPage">
<ContentPage.Content>
<StackLayout>
<Label Text="Welcome to Xamarin.Forms!"
VerticalOptions="CenterAndExpand"
HorizontalOptions="CenterAndExpand" />
</StackLayout>
</ContentPage.Content>
</ContentPage>
The problem is that the label that is supposed to say "Welcome to Xamarin Forms!" doesn't appear. I tried rotating the screen, giving it a bigger padding and margin. Giving it a different background color, foreground color and etc. However a slider or a button is displayed correctly. Just the label is not visible.
I found the solution to the issue. Since the dark mode was on on my IPhone device the text was looking white. When dark mode is turned off I am able to see the label and it works as expected.
Try this: Why won't text on a label show up on an actual device but will in the simulator? (Xcode)

Controls are disabled in MenuItems used in Shell in Xamarin Forms

The code below when entered in AppShell for Xamarin Forms only works in Android. In iOS the Switch is rendered but can't be toggled (as if it is disabled). Are there any tricks to making this work in iOS as well or is this a bug?
I tried placing the the Switch in a completely different ContentView and loading it in the Shell with local: and also tried including the Switch in the DataTemplate directly. All of them work in Android, just not iOS.
Thanks for your help
<MenuItem>
<Shell.MenuItemTemplate>
<DataTemplate>
<ContentView>
<Switch IsToggled="True" />
</ContentView>
</DataTemplate>
</Shell.MenuItemTemplate>
</MenuItem>

Xamarin Forms: How to give exact circle background for icons?

I have some icons on my xamarin forms project. I need a circle background for my icon. See the screenshot below:
I tried Xam.Plugins.Forms.ImageCircle plugin and tried Framelayout. Imagecircle plugin only cropping the icon and Framelayout gives a rounded corner layout. Nothing gives me a perfect circle background. I go through the FFImageloading documentation, but which is also the same as Imagecircle plugin.
Image code
<Image
Source="ic_group_fill_xx.png"
WidthRequest="25"
HeightRequest="25"/>
Is there any way to achieve this feature?
I usually prefer to make an icon that by default has a circle in it, doesn't make sense to add extra code for something that can be done for free.
There is great document by Android on working with Images for Android applications which can be found here, you can also use Android Asset Studio for creating awesome images.
I normally use an ImageButton for this (and because of the clicked property you don't need to use Gesture Recognizers for detecting taps)
The code below gives me a perfect circle on Android & iOS
<ImageButton Source="icon_name"
BackgroundColor="Blue"
HeightRequest="60"
WidthRequest="60"
CornerRadius="30"
Padding="15"
Clicked="Btn_Clicked" />
The image below is from my app, the image button is inside AbsoluteLayout and the icon is 64x64
Use the ImageCircle.Forms.Plugn plugin which I am already using it,
Import namespace like below,
xmlns:controls="clr-namespace:ImageCircle.Forms.Plugin.Abstractions;assembly=ImageCircle.Forms.Plugin"
And use the image control like below sample,
<controls:CircleImage
Source="{Binding ProfileImage}"
HorizontalOptions="Start"
VerticalOptions="Center"
WidthRequest="40"
Aspect="AspectFill"
BorderColor="#B8BCC9"
BorderThickness="1"
HeightRequest="40" />

Image Button in Xamarin forms

I am very new to Xamarin. I need to add a image button that display Facebook icon on my Xamarin app and when the user clicks on that icon, I need to be redirected to http://www.facebook.com. How can I accomplish this. Here is what I have so far
<StackLayout Padding="50">
<Image Source="facebook.png" HeightRequest="80" WidthRequest="80" >
<Button Text="Mission" Clicked="Mission_Clicked"></Button>
<Button Text="Continue" Clicked="Continue_Clicked"></Button>
</StackLayout>
On the click of Facebook, I just want the Facebook page to be displayed on the phones.
Any help will be appreciated.
Button already has an Image property
<Button Clicked="FacebookClicked" Image="facebook.png" HeightRequest="80" WidthRequest="80" />
UPDATE Xamarin.Forms 3.4.0
ImageButton:
The ImageButton view combines the Button view and Image view to create a button whose content is an image.
<ImageButton Source="xamagon.png"
BackgroundColor="Transparent"
WidthRequest="300"
HeightRequest="300"
FlexLayout.AlignSelf="Center"
FlexLayout.Grow="1"
Clicked="ImageButton_Clicked"
Aspect="AspectFit">
</ImageButton>
Try to place an image instead of button.
You can make use of Tap Gesture Gesture Recognizer to take click events.
Try something like this :

Resources