title: How to handle UI based Navigation in Cross Platform Apps?
body: <p>Assume that you have a cross platform application. The application runs on Android and on iOS. Your shared language across both platforms is Java. Typically you would write your business logic in Java and all you UI specific part in Java (for Android) and Objective-C (for iOS). </p>
  
  <p>Typically when you implement the <a href="http://de.wikipedia.org/wiki/Model_View_Presenter" rel="noreferrer">MVP pattern</a> in a cross platform, cross language application you would have the Model and the Presenter in Java and provide a Java interface for your Views which is known to your presenters. This way your shared Java presenters can communicate with whatever view implementation you use on the platform specific part. </p>
  
  <p>Lets assume we want to write a iOS app with a Java part which could be shared later on with the same Android app. Here is a graphical representation of the design: </p>
  
  <p><img src="https://i.stack.imgur.com/h5r6L.png" alt="enter image description here"></p>
  
  <p>On the left side there is the Java part. In Java you write your models, controllers as well as your view interfaces. You make all the wiring using dependency injection. Then the Java code can be translated to Objective-C using <a href="https://github.com/google/j2objc" rel="noreferrer">J2objc</a>. </p>
  
  <p>On the right side you have the Objective-C part. Here your <code>UIViewController</code>'s can implement the Java interfaces which where translated into ObjectiveC protocols. </p>
  
  <p><strong>Problem:</strong> </p>
  
  <p>What I am struggling about is how navigation between views takes place. Assume you are on UIViewControllerA and you tap a button which should bring you to  UIViewControllerB. What would you do?</p>
  
  <p><strong>Case 1:</strong> </p>
  
  <p><img src="https://i.stack.imgur.com/zNH9x.png" alt="enter image description here"></p>
  
  <p>You report the button tap to the Java ControllerA (1) of UIViewControllerA and the Java ControllerA calls Java ControllerB (2) which is linked to UIViewControllerB (3). Then you have the problem that you do not know from the Java Controller side how to insert the UIViewControllerB in the Objective-C View hierarchy. You cannot handle that from the Java side because you have only access to the View interfaces. </p>
  
  <p><strong>Case 2:</strong> </p>
  
  <p><img src="https://i.stack.imgur.com/JwUCT.png" alt="enter image description here"></p>
  
  <p>You can make the transition to UIViewControllerB whether it is modal or with a UINavigationController or whatever (1). Then, first you need the correct instance of UIViewControllerB which is bind to the Java ControllerB (2). Otherwise the UIViewControllerB could not interact which the Java ControllerB (2,3). When you have the correct instance you need to tell Java ControllerB that the View (UIViewControllerB) has been revealed.</p>
  
  <p>I am still struggling with this problem of how to handle the navigation between different controllers.</p>
  
  <p><strong>How can I model the navigation between different Controllers and handle the cross platform View changes appropriately?</strong></p>