JavaFX View Navigation - model-view-controller

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.

Related

Is something like Prism INavigationAware Interface for ViewModels in Xamarin.Forms 4 AppShell Navigation?

In Prism for Xamarin.Forms there is an interface INavigationAware. You implement it in the ViewModels (if you want to). There are three methods, OnNavigatedFrom, OnNavigatedTo and OnNavigatingTo. These methods are called by the Prism navigation framework. You can load data, do some logging or cancel the navigation operation.
Now I am using the new Shell Navigation (AppShell) in Xamarin.Forms 4.1 without Prism. Is there something equivalent or similar available with Shell Navigation? Is there an adviced pattern to, for example, load some data from a database when the user navigates to the page or to cancel Navigation Operation?
Edit: I understand Prism does not support Shell Navigation at the moment. What I ask, is to do something similar without Prism.
As was provided above. This question has previously been answered. https://stackoverflow.com/a/56793314/4984832
Xamarin.Forms Shell is not currently supported. It is a planned feature in Prism 7.3 and won't start until sometime after some changes from the Xamarin.Forms team are available in an official build. The issue can be tracked here: https://github.com/PrismLibrary/Prism/issues/1809

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

Custom Navigation with Xamarin.Forms

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.

Backbone Marionette iOS style page transitions

I'm making a single page mobile app with Backbone.Marionette and would like to implement page slide transitions. I know how to achieve this via adding and removing the proper css classes for the animation but I'm having trouble with Marionette regions and managing when these classes are being added. I would like the current view in the region to slide out and the next view slide in. how can I accomplish this with regions or layouts in marionette? P.S i'm a newbie with marionette.
You'll need to write a custom Region implementation to facilitate the transition. There's an open ticket on Marionette that has the core code for making this work: https://github.com/marionettejs/backbone.marionette/issues/320#issuecomment-9746319
But you'll need to adjust this code for your specific needs. Be sure to read the comments and discussion around it. I've used this core code for similar needs many times, but haven't found the optimal way of integrating it in to marionette, yet.
Here is a custom region demonstrating view transitions: http://codepen.io/somethingkindawierd/pen/cpiEw

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