Nativescript behavior of the '< Go Back' button - nativescript

I've got the following ActionBar definition
<ActionBar class="action-bar" title="Settings">
<NavigationButton text="Go Back" android.systemIcon="ic_menu_back" tap="onBackTap"/>
</ActionBar>
The Android version does get called.
In the iOS version - the onBackTap method is never called.
Also it seems in iOS version, even if the NavigationButton entry is not there, {N} inserts one automatically.

UPDATE:
Indeed, it appears that the NavigationButton in iOS can only be used to navigate back and can not be overridden with tap action. Reference from the NativeScript documentation
In iOS, the back button is used explicitly for navigation. It
navigates to the previous page and you cannot handle the tap event to
override this behaviour.
As for the appearing NavigationButton for iOS - it is by design just as in native iOS app. If you do not want to have back navigation you can force it with
clearHistory: true
Uncomment this line in the test application and delete the navigationButton from the sub-page and when navigation from main-page to sub-page the NavButton won't appear.

So as #nick verified, on iOS version of {N} one cannot get the tap event of the Navigation button. I understand why {N} has to add the BACK button automatically if the navigation button is not there (because iPhones don't have a physical BACK button), but not calling an existing tap event is, IMHO, adding unnecessary differences in the framework. Here's the proposed logic for iOS.
if NavigationButton present then
if tap event handler set by user then
use it
else
auto-gen a tap event handler
else
auto-gen a back-button and a tap event handler
Anyway here's how I'm getting around this issue for my app.
<NavigationButton visibility="collapse"/>
<ActionItem ios.position="left" text="< Back" tap="onBack"/>
This gets the behavior I expect and is cross-platform compatible with the Android version.

Related

Back Button Pressed is not firing

I'm trying to implement a function that will be called when user press back button.
Working exactly how i expect in UWP, but the issue is with android.
In android I got two back button,
One at top Navigation (Let's call it navbackbutton ), and other we get at bottom, the three android button "background apps,Home and back button(android backbutton),
Android back button is firing onBackpressed override method but navbackbutton is not, it is just taking me to the previous page.
I dont understand why it is happening and how to fix it.
Page.OnBackButtonPressed is only triggered with the hardware back button on Android .
You can override OnOptionsItemSelected within MainActivity to hook the navigation back button event , refer to here .
Another way is that customize NavigationPage.TitleView(a layout with a back button and title label) to replace the default navigation bar and then you can get the back button event .

Nativescript Vue: How to dismiss searchBar keyboard when scrolling ListView?

I have a SearchBar component and a ListView component. When I tap the search bar, the keyboard comes up but it stays up even if the user decides to scroll ListView under it. I can't seem to find either
1) any event on the ListView that I can trigger the search bar to close on when it's scrolling
--or--
2) any event on the search bar that I can check to see if it's not focused , then close it.
Either of those would be sufficient but I can't seem to find any in the documentation.
Both components are independent of each other, you must call dismissSoftInput() on the search bar upon scroll.
Unfortunately the scroll event is not supported out of the box while using ListView. There is an open feature request on Github, which also discusses how you may implement this event with an override & bit of native code in your project. You may also consider using RadListView, supports scroll events out of the box.

Xamarin Forms - Syncfusion SF Schedule swipe Error - iOS only

I have a Syncfusion schedule used in month view, but once I swipe to go to the next month the app crashes and shows me this error:
"Event registration is overwriting existing delegate. Either just use events or your own delegate: Foundation.NSObject UIKit.UIGestureRecognizer+UIGestureRecognizerDelegate"
This only happens on my iOS project and is fine on Android.
I have no custom renderers associated with the feature.
Would anyone know what is causing this?
iOS controls have some gesture events and if you use those gesture events you can't add gesture recognizes or the app will crash. So it is likely that SF control is using those events.

After assigning GetViewForAnnotation, Xamarin.Forms class doesn't receive Click event

I have a Xamarin.Forms page with a map containing numerous pins. I've built a custom iOS renderer to change the image of the displayed pin.
Once I assign the GetViewForAnnotation delegate, my Xamarin.Forms class no longer receives the "Clicked" event. I can access it through the custom renderer, I do believe, but what I want to do when the user taps the title of the pin is push another Xamarin.Forms page to the navigation stack, and I don't know how to give control back to my Xamarin.Forms app from within my Xamarin.iOS app.
I have a feeling I'll need this type of logic in a few other places... where I need to handle a CustomRenderer event but then pass control back to the Xamarin.Forms app for navigation or other purposes.
So I have a couple directions I'd like to go:
1 - More straightforward - get my "Clicked" event to fire in the Xamarin.Forms app when the map's pin is clicked, even though the iOS app is handling the creation of the pin via a CustomRenderer
2 - More advanced and customizable - pass control back to my Xamarin.Forms app (maybe raise an event related to the Renderer level?)
I'd prefer at this time to just get my Clicked event back, but I'm guessing that may not work once I assign the GetViewForAnnotation event in the CustomRenderer.
From what I read, you can detect the annotation click within your renderer.
Within your renderer in the OnElementChanged you can get access to the View in the Xamarin.Forms PCL it relates to.
A few possibilities to consider going forward:-
a) Use MessagingCenter to convey messaging between interests (see
here).
b) Use the standard event raising, i.e. public event
EventHandler<someEventArgs> OnSomeEvent through your View in your
PCL.
c) Use an ICommand approach on your View in your PCL if your
more MVVM orientated, and invoke this way instead.
Once you have your notification back through your View / Page, depending on where your doing things, you can then do a normal navigation based on the information you have been given from your platform-specific renderer in the PCL.

iPhone simulator not responding when using storyboards

I'm quite new to iOS Programming. I've done Objective-C for about a year, and now I want to start making apps for the iPhone. I think I'm missing out on something really simple, though. What I've done is this:
First I created a new Single View Application with TestApp as a product name. I enabled Use Storyboards, Use Automatic Reference Counting and Include Unit Tests. After creating the project, I dragged a UIButton onto the View in the storyboard file.
Note that I didn't write a single line of code. I launched my app in the iPhone Simulator and pressed the button, but it's not responding. I know I didn't assign an action to the press of the button, but the gradient of the button isn't changing, as I know it should. The User Interaction Enabled properties of both my view and my button were enabled.
Recently, I've created a few apps in Xcode that worked just fine, but I didn't use storyboards in those projects. Thus, I'm guessing there's something extra to do when using storyboards of which I'm just unaware. I'm using Xcode 4.5 and the iPhone 6.0 Simulator.
I wrote NSLog(#"View was loaded."); statement in the viewDidLoad method of my ViewController to make sure this view controller was actually loaded. (I know my button wouldn't show up if it was the wrong view controller, but I did this just to make sure.)
I also wrote a changeTitle: method in my ViewController to change the title of my button to New Title after it was pressed, just in case the button worked but its gradient just wouldn't respond to a tap. I linked this IBAction to my button, but it wasn't called.
In my ViewController, I created an IBOutlet of a UIButton which I connected to my button. In the viewDidLoad method of my ViewController, I changed the title of my button to New Title, this actually worked. The title of my button changed to this new title when launching my app in the iOS Simulator. The button itself still wasn't responding, though.
As a last try, I also wrote [button setEnabled:YES]; in my ViewController's viewDidLoad method, but this didn't help. My button still doesn't respond to any tap. What am I missing out on?
This is weird. I had an issue with my printer, so I restarted my computer. After this, this issue was suddenly solved as well (just like my printer issue). I'm not sure how this could have affected anything, but I'm glad it works again!
Ran into the same issue.
Apparently Content Reseting the Simulator worked for me
Very strange this..

Resources