I have a simple TabView like this using NativeScript w/angular:
<TabView [(ngModel)]="tabSelectedIndex" height="300px" (selectedIndexChanged)="onSelectedIndexChanged($event)">
<StackLayout *tabItem="{title: 'Tab 1'}">
<Label text="Content in Tab 1"></Label>
</StackLayout>
<StackLayout *tabItem="{title: 'Button 1'}">
<!-- these won't be content here because clicking this should not change to a another tab, but instead should do something else. -->
</StackLayout>
<StackLayout *tabItem="{title: 'Tab 2'}">
<Label text="Content in Tab 2"></Label>
</StackLayout>
</TabView>
I want a button in the tab bar that doesn't change the view, but instead does something else (such as open a modal dialog).
I tried a new <StackLayout> both inside and outside of <TabView>.
I also tried using an <AbsoluteLayout>. All methods caused the app to crash.
Is it possible to capture the tab view change using selectedIndexChanged and prevent the change?
I tried stopPropagation() on the event but got error:
Property 'stopPropagation' does not exist on type 'SelectedIndexChangedEventData'.
I tried changing the view back to the view that existed when the middle button was clicked, but there is a noticeable flicker because the view has to change before this event is even fired. What would have been acceptable is something like onSelectedIndexWill Change but that method does not exist.
onSelectedIndexChanged(args: SelectedIndexChangedEventData) {
if (args.newIndex === 1) { //the middle button
setTimeout(() => {
tabView.selectedIndex = args.oldIndex; //go back to the previous view (causes flicker)
//do stuff for the button click.
});
}
}
Or is there another way to incorporate a button in the tab bar that doesn't link to a new view?
Or should I not implement a native tab bar and instead just create a navigation bar from scratch?
Here's how it can be done for ios.
Here is a sample app in NativeScript playground showing the issue. Click center link to see the flicker.
Do to the fact that the NativeScript team has refused to export the delegates this is not something you can monkey patch in at this point. The only way to do this is to fork the TabView code and create your own plugin using it.
However, making this change should be fairly simple once you have your forked copy. You just need to on around line 64 public tabBarControllerShouldSelectViewController(tabBarController: UITabBarController, viewController: UIViewController): boolean {
You just need to detect which viewController it is trying to load; and then return false in the case where you don't want to actually change the view. ;-)
Two possible ways;
check the owner.selectedIndex; I believe it should be pointing to the proper new index at this point;
however if it is not then the second possible method would be to check the viewController against the owners viewcontroller list (i.e. const selectedIndex = owner._ios.viewControllers.indexOfObject(viewController); )
Related
Antd Button
The following code comes from the antd document
import { Button } from 'antd';
ReactDOM.render(
<div>
<Button>Default</Button>
<Button type="dashed">Dashed</Button>
<Button type="danger">Danger</Button>
</div>,
mountNode,
);
Like the default Button, Dashed Button, when you click, you'll have a highlight and border shadow effect.But I want Button to revert to the default state after clicking, rather than clicking elsewhere before it becomes the default state.
This is what happens when I set up the Uploade's click button, which keeps me clicking (highlighted and bordered) when I upload the file successfully or fails, which makes people look a little unusual.Although this detail is acceptable to most people, it still feels a little strange.
I have thought about using the Dragger component of Upload, which can meet my needs on the display. But I want to automatically hide the upload button when the upload content meets the requirements, and Dragger seems to be unsatisfied. So I chose to use the Upload component. After the condition is met, the content in the Upload is made blank, and the hidden effect is achieved. The above situation will occur in the middle of the Button.
I looked at Button's API
and didn't find an action like reset.
Here is my example code. When you click on the Button component, the highlight will not disappear. When you click on the Button upload component, the highlight will not disappear after uploading the file. After clicking on the Dragger component and uploading the file, the highlighting disappears automatically.
Whether there is a good action to reset the Button style.
If you know thank you for answering.Thank you.
You need to customise ant-btn class like so:
.ant-btn:focus {
color: inherit !important;
border: 1px solid rgb(217, 217, 217);
}
Here is the codepen
I have a toolbar item implemented in Xamarin Forms project in xaml like this.
<ContentPage.ToolbarItems>
<ToolbarItem Name="Create" Command="{Binding AddNewCabin}" Text="Add Cabin" ></ToolbarItem>
</ContentPage.ToolbarItems>
The command AddNewCabin is binded to a navigation method.
When I come back from the next page the text for the tool bar item is paled out like a visited link. I have no idea how to turn off that kind of behavoiur.
I thought that was an issue with a click event however I tried binding the click or the command to an empty method and the text is not paled out. It is only paled out if there is some Push navigation that occurs afterwards using this event.
I have also tried navigating using other events on the same page from listview for example and in that case the toolbar item is also NOT paled out.
So the only occasion when it is paled out (changes color) is when I navigate using the commnd or event binding of the toolbar item. In all other cases this doesn't occur and I have no idea why. Does anybody know? Thanks.
PS. I Aam testing in IOs.
Sadly, I cannot reproduce behavior of your toolbar item. On my machine navigating from toolbar item works perfectly. Check my gif. Colors of button "Add" are switching properly.
You should try removing and adding your button on the OnAppearing event.
But this is very strange behavior. Can you post more code of your implementation?
I am trying to work with the Google Place Picker API
(https://developers.google.com/places/ios-api/placepicker)
I and want to edit a few things when the modal PlacePicker view appears.
For example the 'Title' should be either another language or set by me. Or generally edit navigation bar (left button etc).
I would also like to change the mapStyle ?
I am trying to add an image next to the hamburger menu in my app. I am using a master detail page and it renders fine in ios and android. I tried using setting the icons for the detail pages. but the icons never showed. How do I achive this. I am looking to add an image similar to the amazon app.
I checked out this app on my phone and it uses a lot of custom constructions that aren't supported by out of the box Xamarin Forms controls. Something like the back arrow next to the hamburger menu is not a standard thing (on iOS at least). Also looking at the actual menu that the hamburger button triggers it becomes clear that its not an out of the box hamburger menu. Theirs pops over the content instead of sliding it out of view as the built-in one does.
More than likely they implemented their own hamburger menu and navigation structure which gave them the freedom to add buttons next to it. If you want to achieve this with out of the box controls you will most likely need custom renderers for each platform to create a replica of this navigation structure.
What is built-in in Xamarin Forms is that you can set the page title to an image instead of text by using the NavigationPage.SetTitleIcon method, which could be used to achieve what you want:
public class MyPage : NavigationPage
{
public MyPage ()
{
var myContentPage = new MyContentPage (Color.White);
this.Push (myContentPage);
var s = "icon.png";
NavigationPage.SetTitleIcon (myContentPage, s);
}
}
Even then, this is limited in functionality. If you want to fiddle with the alignment of the image e.g. you would also need to resort to a custom renderer.
I have a navigation controller stack where one of the views has a dynamic title.
The view controllers and their titles go like this:
Main --> ItemsTableView --> ItemDetails
Title:Main Title: NN Items Title: Details
Because the iOS UINavigationController sets the text of the "Back" button to be the title of the previous screen, the "Back" button on the details screen says "< NN Items" where NN is a dynamically changing number.
I'm trying to do some iOS UI automation, but the accessibility Label / ID of the back button is set by the system to it's button text. This means that the accessibility label of the back button on the details screen will change dynamically, and I can't find it from my scripts!
If I could get a reference to the UIBarButtonItem then I could easily set it's accessibilityLabel or accessibilityIdentifier from code to be a fixed string, however I can't figure out how to do this?
All of the stuff I've been able to find references setting the back button to a custom button via self.navigationItem.backBarButtonItem or similar, but when I read this property it's nil. I haven't been able to find out how to get access to the standard item without replacing it. I'd prefer not to replace the button if possible
This was bugging me as well. I've been writing Xcode 7 UI Tests and was trying to come up with a generic way of tapping on the back button without having to replace it with a custom button.
The following is how I solved this for Xcode 7 UI Tests - but you may also be able to apply this to UI Automation as well.
I discovered that (in terms of Xcode 7 UI Tests at least) the back bar button item that is created by the system consists of two buttons the entire thing is a button with an accessibility label of whatever the title of the button is, and then the arrow is also a button with an accessibility label of "Back".
Thus, as long as there aren't any other buttons on the screen that are identified as "Back", the back button can be accessed via the accessibility label of "Back". Like so in the case of UI Tests:
[[app.buttons matchingIdentifier:#"Back"] elementBoundByIndex:0]
Here I'm getting the first button that can be identified by "Back". I my case there could only ever be two such buttons - the arrow, or the whole back button itself (in the case where the back button's title is also "Back"). Since both of these buttons are essentially the same, just getting the first one it finds is sufficient.