I was trying to access and didn't find the UINavigationBar from an ActionBar, could someone help me there?
TS file
let bar: ActionBar = this.page.getViewById<ActionBar>("bar");
bar.ios.nativeView // undefined
bar.nativeView // undefined
HTML file
<ActionBar id="bar" class="action-bar" title="Recipients"></ActionBar>
Ok I figure out what i've done wrong just putting in Manoj Solution
HTML:
<ActionBar id="bar" class="action-bar" title="Recipients" (loaded)="loadActionBar($event)"></ActionBar>
TS:
loadActionBar($event): void {
let bar: ActionBar = this.page.getViewById<ActionBar>("bar");
bar.nativeView // works
}
Related
In Android, the page loads with the keyboard expanded and the focus is on the search bar.
I am trying to keep the focus from not being there on page load. The relevant code is :
<StackLayout height="100%"
class="main-container"
>
<SearchBar ref="searchBars"
class="search-bar"
#loaded="onSearchLoaded($event)"
#textChange="onTextChanged($event)"/>
I have tried adding:
mounted() {
this.$refs.searchBars.nativeView.dismissSoftInput();
}
but this has not worked. I also tried adding this.$refs.searchBars.nativeView.dismissSoftInput()
to the #loaded event function of the searchBar.
Try this
<SearchBar #loaded="onSearchBarLoaded($event)" />
And add a method:
onSearchBarLoaded: function(event) {
if (event.object.android) {
setTimeout(() => {
event.object.dismissSoftInput();
event.object.android.clearFocus();
}, 0);
}
}
I have also tried the above method and failed. So I've did a small trick to tackle the situation.
I've added a dummy search bar and set the visibility to hidden. So the focus will shift to the dummy search bar! Here is my code.
<SearchBar
v-model="searchPhrase"
#textChange="onSearch"
#submit="onSearch"
backgroundColor="white"
#clear="clearSearch" />
<!--Dummy searchbar -->
<SearchBar v-show="false" />
You can use a method to focus on what ever you want.
searchBars() {
this.$refs.searchBars.nativeView.focus();
},
I have a Xamarin.Forms app and want to set the NavigationBar to be translucent. But when I do, I get a strange behavior with the Xamarin views:
ListViews or TableViews behave correctly. But when I wrap them in a RefreshView, they are overlapped by the UINavigationBar.
-- TRANSLUCENCY WITHOUT REFRESHVIEW: OKAY
<ContentPage>
<ListView>
...
</ListView>
</ContentPage>
-- TRANSLUCENCY WITHOUT REFRESHVIEW: BUGGY
<ContentPage>
<RefreshView> <----
<ListView>
...
</ListView>
</RefreshView>
</ContentPage>
Am I missing something?
Repro on GitHub: https://github.com/awaescher/xamarin-repro
How to make a translucent NavigationBar: https://xamgirl.com/transparent-navigation-bar-in-xamarin-forms/
We can use navigationPage.BarBackgroundColor = Color.Transparent to achieve that .
NavigateFromMenu method modified as follow :
case (int)MenuItemType.TranslucentWithoutRefreshView:
MenuPages.Add(id, CreateTranslucentNavigationPage(new TranslucentWithRefreshPage(),false));
break;
case (int)MenuItemType.TranslucentWithRefreshView:
MenuPages.Add(id, CreateTranslucentNavigationPage(new TranslucentWithRefreshPage(),true));
break;
Then in CreateTranslucentNavigationPage method :
private Xamarin.Forms.NavigationPage CreateTranslucentNavigationPage(Xamarin.Forms.Page page, bool value)
{
var navigationPage = new Xamarin.Forms.NavigationPage(page);
if (value)
{
navigationPage.BarBackgroundColor = Color.Transparent;
navigationPage.BarTextColor = Color.Black;
}
//Xamarin.Forms.PlatformConfiguration.iOSSpecific.NavigationPage.SetIsNavigationBarTranslucent(navigationPage, true);
return navigationPage;
}
The effect :
I'm trying to find a way to remove the tab buttons on a element with an Angular 6 app but with no avail so far. Basically, I only want to keep the Tab contents and their swipe functionality.
Apparently there are specific android and iOS methods you can use but I'm unsure how to do that.
<TabView [(ngModel)]="tabSelectedIndex" (selectedIndexChanged)="onSelectedIndexChanged($event)" (loaded)="tabViewLoaded($event)">
<ng-container *ngFor="let article of articles" #tabView>
<StackLayout *tabItem="{title: article.id}">
<StackLayout>
<NewsDetails></NewsDetails>
</StackLayout>
</StackLayout>
</ng-container>
</TabView>
On my .ts file I can find a reference to the element like this:
#ViewChild("tabView") tabView: ElementRef;
ngAfterViewInit() {
console.dir(this.tabView.nativeElement);
}
But I have no idea what to do from now on. Any ideas? All previous questions regarding this have not worked.
Here is a sample playground link: https://play.nativescript.org/?template=play-ng&id=iK9ZTM
Use the code below with the loaded event of TabView.
onTabViewLoaded(event: EventData) {
const tabView = <TabView>event.object;
if (isIOS) {
tabView.viewController.tabBar.hidden = true;
}
if (isAndroid) {
const tabLayout = tabView.nativeViewProtected.tabLayout;
tabLayout.getLayoutParams().height = 0;
tabLayout.requestLayout();
}
}
I recently did that for a sample work I posted in Uplabs
How to hide a button, a label or a grid cell on iOS and show it on android, I have a xamarin.forms app (portable), I know that I have to use on platform but how to access the visibility of the controls.
Thanks
If you want to do it on XAML, in order to hide a view on a specific platform, you can use this:
<Button>
<Button.IsVisible>
<OnPlatform x:TypeArguments="x:Boolean"
iOS="false"
Android="true"/>
</Button.IsVisible>
</Button>
Hope it helps!
// IOS, Android, WP
SomeButton.IsVisible = Device.OnPlatform<bool>(false, true, true);
Or
if (Device.OS == TargetPlatform.Android)
{
SomeButton.IsVisible = true;
}
else
...
All of these answers seem to involve creating the control whether or not you actually need it and then setting IsVisible to false on the platforms you don't want it on. A better solution IMO is to only create the control in the first place if you do in fact need it. A first step would be to wrap it in a content view:
<ContentView>
<OnPlatform x:TypeArguments="View">
<OnPlatform.Android>
<Button Text="Something" ...etc... />
</OnPlatform.Android>
</OnPlatform>
</ContentView>
That's better, but it still creates a superfluous ContentView. Take it one step further and use OnPlatform to declare a ControlTemplate and you'll achieve the most optimal implementation across all platforms.
Like mindOfAi mentioned you can do this in XAML like this:
<Button>
<Button.IsVisible>
<OnPlatform x:TypeArguments="x:Boolean"
iOS="false"
Android="true"/>
</Button.IsVisible>
</Button>
In code you can use the Device.OnPlatform or check the Device.OS property.
That would look like:
// ... Other code here
Device.OnPlatform(iOS: () => { myButton.IsVisible = false; });
// Or do this:
if (Device.OS == TargetPlatform.iOS)
myButton.IsVisible = false;
// ... Other code here
From Xamarin.Forms version 2.5.x this is done as per code below. Using a basic button as an example.
<Button Text="NFC Pairing" Command="{Binding YourVmCommand}">
<Button.IsVisible>
<OnPlatform x:TypeArguments="x:Boolean">
<On Platform="iOS">true</On>
<On Platform="Android">false</On>
</OnPlatform>
</Button.IsVisible>
</Button>
Nigel
Expanding the solutions, you can also do xaml inline:
IsVisible="{OnPlatform iOS=true, Android=false}"
For anyone that stumbles upon this question seeking for the codebehind solution:
switch (Device.RuntimePlatform)
{
case Device.iOS:
//iOS specific code here
break;
case Device.Android:
//Android specific code here
break;
}
The Device class has the following Device constants:
Constants as shown from VS 2019 Intellisense.
I am creating an Arabic(RTL) app with NativeScript. I want the action bar to be sorted in rtl direction so the title is the right and menu options is to the left.
I tired using css and horizontalAlignment but nothing worked.
How can I achieve this?
Thank you.
Example
<Page xmlns="http://schemas.nativescript.org/tns.xsd">
<Page.ActionBar>
<ActionBar >
<Label text="TITLE"/>
</ActionBar>
</Page.ActionBar>
</Page>
And with css u can set to right side with or other styling of ActionBar
ActionBar Label{
text-align:right;
horizontal-align:right;
}
If you need RTL support due to language vs just "alignment" I would convert the entire app to RTL using android.view .View.LAYOUT_DIRECTION_RTL:
This code will make the ActionBar ( and other components ) across the app to RTL
# app.module.ts
import {
android as Android,
AndroidActivityEventData,
AndroidApplication } from '#nativescript/core/application';
Android.addEventListener(AndroidApplication.activityCreatedEvent, (event: AndroidActivityEventData) => {
event.activity.getWindow().getDecorView().setLayoutDirection(android.view .View.LAYOUT_DIRECTION_RTL);
});