How to navigate from Content Page to Shell in native forms? - xamarin.forms

In my xamarin forms native 3.x project, currently I am navigating from content page to content page using below code
Android.Support.V4.App.Fragment mainPage = new ContentPage().CreateSupportFragment(this);
SupportFragmentManager
.BeginTransaction()
.Replace(Resource.Id.fragment_frame_layout, mainPage)
.Commit();
Ref:- https://learn.microsoft.com/en-us/xamarin/xamarin-forms/platform/native-forms
But this is not working in case of navigation from content page to Shell (Xamarin Forms 4.0.0).
Any help is appreciated.

Related

Xamarin.Forms navigation stack flow

I'm trying to work out the correct way of structuring the navigation for my Xamarin.Forms application.
Please note the LoginPage is currently set as the application's MainPage.
The intended (visual) structure is as follows:
CheckPermissionsPage ➜ LoginPage ➜ HomePage
I am following a MVVM structure, so my LoginPageViewModel is displaying a modal of CheckPermissionsPage within it's constructor as so:
await Application.Current.MainPage.Navigation.PushModalAsync(new CheckPermissionsPage());
The idea is that the check permissions page validates the application has permissions to specific services and if it does, the page automatically closes. The user must then login to the application, after which the HomePage is displayed.
How would I structure the LoginPage so that the CheckPermissionsPage modal can be displayed/hidden based on permissions state. Consequently, after a successful login, the HomePage is displayed (without an option to return to the LoginPage). Thanks!
I ended up changing the application MainPage to navigate throughout the pages. So my initial application main page is now the CheckPermissionsPage. Should permissions be granted I then run Application.Current.MainPage = new NavigationPage(new LoginPage());. After logging in, the HomePage is displayed with Application.Current.MainPage = new NavigationPage(new HomePage());. This probably isn't the most ideal solution, but it does allow me to prevent back navigation for my LoginPage.

Mobile devices wont get View.Mobile.cshtml views after visiting page with desktop

I created a asp.net mvc app with a Index.cshtml and a Index.Mobile.cshtml. The views are using the same controller and action. In development I get the mobile view on my phone and with desktop the desktop view. Everything works as expected.
After deploying the application to the production server everything works as expected on a smartphone, until I navigate from a desktop browser to the page. After I navigated from a desktop browser to the page I won't get the mobile view anymore on a mobile device.
I disabled and enabled cache settings but get either way i have this strange behavior. Am i missing something?
edited:
I got the following theme structure:
/Themes/DefaultTheme/Views/Cart/Index.Mobile.cshtml
/Themes/OceanasTheme/Views/Cart/Index.cshtml
In my custom razor view engine I modified the ViewLocationFormats, simplified:
var customViewLocationFormats = new List<string>();
customViewLocationFormats.Add("~/Themes/DefaultTheme/Views/{1}/{0}.cshtml");
customViewLocationFormats.Add("~/Themes/OceanasTheme/Views/{1}/{0}.cshtml");
//override default view location
ViewLocationFormats = customViewLocationFormats.ToArray();
When I copy the Index.Mobile.cshtml to the OceanasTheme folder the same problem appears, except I get the Mobile.сshtml from the OceanasTheme each time after I visited with desktop. (the desktop gets the Index.cshtml from the OceanasTheme).
Updated to MVC 5.2.7 and removed Microsoft.AspNet.Mvc.FixedDisplayModes package. But it still doesn't work.
RazorViewEngine is caching views with DefaultViewLocationCache. The .Mobile view location is stored in cache after first request with mobile. When requesting with a desktop browser the desktop variant is not found in the cache, so RazorViewEngine is gonna try to find the view on the disk. It will find the view in the different folder, and will store it in cache, But it also checks if the mobile exists in that folder. Because the .Mobile is not in this folder it will overwrite the cache with an empty path.
I fixed this issue by creating a custom implementation of IViewLocationCache.

Xamarin forms : Issue with Deeplinking

I implement deep linking to android part of my Xamarin forms project. But when I click the URL, initially it loads a black page with app name on the top, after a short period only it opens my app. I need to avoid this black screen. Also, the app opens in the same window, no new window is started for my app, if I click the URL from WhatsApp, the app opens in the WhatsApp window.
I need a solution for these 2 problems.
Thanks in advance.
In android manifest set android:name like below:
android:name=".MainActivity"
And in Mainactivity add Name like below:
[Activity(Name = "packagename.MainActivity")]

Following links in a course on SAP successfactors app

We're developing SCORM content for our client to put on their SuccessFactors LMS, and access through the SuccessFactors app on ipads.
Some of the course pages include links to pages on the internet and the clients intranet, but we're finding that these links will replace the course in the app's web view, and we aren't able to return to the course.
Has anyone found a way around this, so we can open the links in a new window and keep the learner in the course?
The Successfactors iOS app should work similarly to other iOS apps.The following code forces the iOS app to open a URL in the Safari browser. I believe it may also open in the default browser. Please try this code:
<div id="launchInBrowser" data-href="https://stackoverflow.com/posts/37790430">Stack Overflow</div>
and in the page's javascript:
document.getElementById("launchInBrowser").addEventListener("click", function(evt) {
var a = document.createElement('a');
a.setAttribute("href", this.getAttribute("data-href"));
a.setAttribute("target", "_blank");
var dispatch = document.createEvent("HTMLEvents");
dispatch.initEvent("click", true, true);
a.dispatchEvent(dispatch);}, false);
check here for more information:
Force link to open in mobile safari from a web app with javascript

No View Based Application Template XCode

I've just installed the new iOS SDK and the View Based Application template has disappeared. Any ideas as to how to get it back?
Now it's called "Single View Application". Take this template and it should work :-)

Resources