Custom Navigation with Xamarin.Forms - xamarin

I’m working on an application for Android and iOS, which requires a certain flexibility for one or two views. That’s why we created & implemented a service that translated a basic list of objects into a user interface for both iOS & Android. But now that Xamarin.Forms is released, we decided to replace our service by the one Xamarin provides. I did succeed in creating the views with Xamarin.Forms, resulting in better looking & smoother running pages. But my problem lies in the navigation of it. Here is a little drawing on what I would like to achieve:
I would like my app to start an activity that starts with a custom fragment. After clicking a button on this fragment, I would like the page I created with the Xamarin.Forms api to be added to my current navigation stack! Once the user is finished with the Xamarin.Forms page, it navigates to a second custom fragment, all that without breaking the navigation cycle. Does anybody have an idea on how I can achieve this?
For the iOS developpers: replace Activity with NavigationController & Fragment with ViewController

Take a look at CarouselPage for Xamarin.Forms' own approach. It doesn't look like that's what you need but you can also look at its source code and maybe make a custom renderer yourself.
You may also want to take a look at MVVM
As for the easier/hackier way you'd want to make a button on each page and when the button is tapped execute Navigation.PushModalAsync(nextPage) - there won't be a "< Back" button any more, you may need to implement that yourself if you need it.

If by your meaning of 'current navigation stack' is for using the native Navigation of each platform, then remember that you don't have to use Xamarin.Forms' Navigation Model and functions such like PushAsync.
If you prefer to do Navigation with code specific to each platform then you can do this the same as normal. Just create your stub pages in each platform specific project and set the Xamarin.Forms content for each page from the shared project.
From each platform specific stub page (Activity / UIView / PhoneApplicationPage) you could then execute an Action<> call setting on the shared Xamarin.Forms page to help with the navigation, or alternatively, hook into a custom-event that is raised from the Xamarin.Forms** page back to the platform specific stub page to allow you to do navigation from there.
Like Sten mentioned there won't be any 'Back' button so you will most likely have to do that yourself.

Related

Difference between Prism Dialogs vs Popup

I am implementing Prism in a new Xamarin Forms App. I have been using Rg.Plugins.Popup in the app before converting to Prism.
What are the limitation on the Prism Dialogs vs Prism.Plugin.Popups?
What are some examples when you would use one over the other?
Thank you!
Rg.Plugins.Popup is a popular plugin for Xamarin.Forms which accesses the native functionality to provide a "Modal Popup" which traditionally has not been achievable with Xamarin.Forms.
Dialogs in Prism 7.2
If you're using Prism 7.2 you'll find that the DialogService locates the currently displayed page and then "reparent's the content". Or in other words it takes the content of the active Content Page and places it as the root child of an AbsoluteLayout, placing a mask layer and finally your dialog on top. As a result of this approach you'll notice that any navigation bars for instance on the NavigationPage or TabbedPage, or a MasterDetailPage's menu will remain accessible to the user.
While in some regard both the PopupPage and Dialog may look very similar as you can probably tell there is some significant divergence there.
Dialogs in Prism 8
If you're using Prism 8.0 you'll see that we have updated to the latest Xamarin.Forms and as a result we are able to take advantage of a new feature in Xamarin.Forms which allows you to present a Modal Page with a Transparent background. This in effect allows you to replicate the effect of a PopupPage with either some benefits or drawbacks depending on how you look at it.
With Rg.Plugins.Popups you have the ability to push a PopupPage on top of whatever page is currently displayed from anywhere in the app
With Xamarin.Forms page's that have been pushed Modally they are part of your active Navigation Stack
Using the a traditional page with a transparent background and Modal Navigation you in effect have replicated the appearance of what you get with a PopupPage
Limitations
Prism.Plugin.Popups has the benefit of being integrated into the Navigation Service. As such you can inject the Navigation Service into the ViewModel of a PopupPage, and the PopupPage will be dismissed when you navigate away from it to another non PopupPage.
Dialogs are not part of the Navigation Stack tracked by Prism's Navigation Service. Navigation in Xamarin.Forms is dependent on navigating FROM a specific page. Since Prism's NavigationService doesn't know about the Dialog you will need to dismiss the dialog before navigating.
Other Key Differences
Besides what I've mentioned so far the only real difference is that Rg.Plugins.Popup gives you some added animations which honestly I've seen very few people using.

Xamarin Forms MVVM Pattern best place to put repeated UI Code

We have a xamarin forms app using the MVVM pattern. We have repeated UI logic that gets run whenever any contentView is loaded in the application and just wondering where the best place for this will go. Currently in our legacy application it is written in every control which is incredibly frustrating since if it needs fixing then it needs to be fixed in every separate location. What is the best approach for this type of code.
An example of what I mean is that on initialise of every contentView it runs through security privileges of the current user and hides or shows UI controls on that ContentView depending on what the user is allowed to see. This occurs on every form in the system. This is a simple example but there is plenty.
Any ideas?
Why not put it in a parent class? Derive from ContentView, then have all your relevant controls derive from that. You can do this with pages too. All pages in my latest Xamarin Forms app derive from this:
public abstract class BaseContentPage<T> : ContentPage, IViewFor<T> where T : class, IViewModel

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.

JavaFX View Navigation

I'm working on a Desktop JavaFX 2 application. We're using FXML, an MVC architecture to build a tabbed UI. Now I'm struggling to find an elegant way for this scenario:
User clicks button on View 1, which is in a tab on the Main View.
Controller creates a new model object.
New model object is shown through View 2, which is opened in another tab on the Main View.
Would it be suitable to implement a class similar to GWT's com.google.gwt.user.client.History, handling all navigation request. First I'd have to register the main view. Or am I overseeing a JavaFX mechanism?
I implemented a tabbed web browser with history management which sounds a bit similar to your situation. The code is a bit of a mess, but you could look through it if you like to see if there is anything worthwhile there which is applicable to your situation.
For the next release (2.2) of JavaFX there will be a generic pagination control (anybody can register at that link to view the issue) which will probably help encapsulate some of the functionality you require as it mentions TabPane like functionality.
There has also been some discussion of JavaFX history functionality on the open-jfx development mailing list.
The jfx-flow project was created to enable weblike interfaces (e.g. views with history navigation) on JavaFX. Not sure if it's completely developed for your use case, but you could take a look at that too.

Drop down menu like the default iPad application menus

I'm currently working on my first iOS application to run on the iPad, and I've come across a problem. I have been asked to implement menu's similar to the ones in the default applications such as when you click on the "Calendars" button in the top left of the calendars app.
Only issue is, I cant seem to find a standard UI object that looks like these, with the arrow connecting the menu to the button etc. Is this a standard UI component that I should be able to use, or will I have to imitate them by creating a custom object?
Thanks for any help.
That is a UIPopoverController. There isn't an Interface Builder control for this. You need to create one programmatically:
UIPopoverController *popover = [[UIPopoverController alloc]initWithContentViewController:someTableViewController];
See the documentation for more information and sample projects, specifically ToolbarSearch:

Resources