NativeScript Side Drawer unhooked page - nativescript

I'm new to NativeScript and I've been following the instructions here to create my app.
However I find out that all pages are hooked to the drawer, how do I unhook some pages, such as Login, Create ...?

You can get a reference to the sidedrawer and disable the interaction.
import { getRootView } from "tns-core-modules/application";
this.drawer = <RadSideDrawer>getRootView();
this.drawer.gesturesEnabled = false;
The above is implemented in the login page of this POC application.

Related

Nativescript Vue: How to create a basic layout

How can I create a basic template for all my pages?
I try to make a RadSideDrawer on all pages available. (With exception for some specific pages like login / registration etc.).
Currently I copy and past my Menu on all pages. What is the correct way handling this?
You haven't shown any code... So not sure how are you even including it. In app-root?
But you can set menu to false to disable it on some pages:
Example:
import { RadSideDrawer } from 'nativescript-ui-sidedrawer'
let sideDrawer = Application.getRootView()
sideDrawer.getViewById('sideDrawer')
sideDrawer.gesturesEnabled = false
And enable it programmatically this way.

Xamarin Forms WebView open external link

I have a webview inside my application and when an external link is clicked (that in normal browser is open in a new tab), I can't then go back to my website.
It is possible when a new tab is open to have the menu closed that tab like Gmail do ?
The objective is that, whenever a link is clicked, the user would have the choice to choose which option to view the content with, e.g. Clicking a link would suggest open youtube app or google chrome. The purpose is to appear the google chrome option
Or what suggestions do you have to handle this situation ?
If I understood you correctly, you want to have the option to select how to open the web link - inside your app, or within another app's (browser) context.
If this is correct, then you can use Xamarin.Essentials: Browser functionality.
public async Task OpenBrowser(Uri uri)
{
await Browser.OpenAsync(uri, BrowserLaunchMode.SystemPreferred);
}
Here the important property is the BrowserLaunchMode flag, which you can learn more about here
Basically, you have 2 options - External & SystemPreferred.
The first one is clear, I think - it will open the link in an external browser.
The second options takes advantage of Android's Chrome Custom Tabs & for iOS - SFSafariViewController
P.S. You can also customise the PreferredToolbarColor, TitleMode, etc.
Edit: Based from your feedback in the comments, you want to control how to open href links from your website.
If I understood correctly, you want the first time that you open your site, to not have the nav bar at the top, and after that to have it. Unfortunately, this is not possible.
You can have the opposite behaviour achieved - the first time that you open a website, to have the nav bar and if the user clicks on any link, to open it externally (inside a browser). You have 2 options for this:
To do it from your website - change the a tag's target to be _blank like this;
To do it from your mobile app - create a Custom renderer for the WebView. In the Android project's renderer implementation, change the Control's WebViewClient like so:
public class CustomWebViewClient : WebViewClient
{
public override bool ShouldOverrideUrlLoading(Android.Webkit.WebView view, IWebResourceRequest request)
{
Intent intent = new Intent(Intent.ActionView, request.Url);
CrossCurrentActivity.Current.StartActivity(intent);
return true;
}
}

How to hide TimePicker and DatePicker on lifecycle events in Xamarin Forms

I'm running into an issue on android where our TimePicker and DatePicker stay visible when we navigate OnPause(). We need to redirect our users back to the login screen when they background the application, but if the TimePicker or DatePicker is active when they do this it stays on the screen. It appears above the login screen and pressing cancel or ok crashes the app.
We are hooking into the native android lifecycle events (not just using Xamarins built in hooks) and we redirect OnResume(). I've tested this in a barebones app though and it still happens OnPause().
Here is our TimePicker causing us the issue:
<TimePicker x:Name="VitalTimePicker" HorizontalOptions="Fill" VerticalOptions="Fill" IsVisible="false" PropertyChanged="OnTimePickerPropertyChanged"/>
And here is an example of changing screens on a lifecycle event:
protected override void OnSleep()
{
App.Current.MainPage = new NavigationPage(new NotesPage());
}
Any ideas? I was thinking of clearing the Pickers but I can't seem to find how to do that
Edit
Just to add a little more context
The Application class (app.xaml.cs) has lifecycle hooks that we use to catch when our users background the app. In here we call MainPage = new NavigationPage(new LoginPage()); which takes the app back to the login page.
I've added
protected override void OnDisappearing()
{
VitalTimePicker.Unfocus();
VitalDatePicker.Unfocus();
}
to the view i'm working from and it seems to be called when we background the application, but for some reason the TimePicker is staying on the screen when our login page pops up again.
You can programmatically close DatePickers and TimePickers using the method Unfocus(). I'd recommend closing them before you call the next page, as I don't know if they will be able to be referenced and closed after the other screen has been initialized.
Create a method that calls VitalTimePicker.Unfocus() and the same for any other picker you have, and call this method before changing to login screen and you should be good to go.

How to control webapp accessing between webview and web browser?

What I have
A webapp with Laravel 5.6.
A webview with React Native.
What I want to do
Only allow users to access to webapp via Webview.
Allow all users to access to home page of webapp via web browsers.
Allow web administrators to access to admin pages of webapp via both
of webview and web browsers.
My questions
Can I control these golds only with Laravel?
If yes, how to do it?
Should I separate homepage of webapp and content page of webapp into
2 difference domain (or sub domain)?
Or is therer any other suggestion?
Thank you.
Okay here is what i got after extracting android from react, we need to do following changes in android
MainActivity.java
// REMOTE RESOURCE
mWebView.loadUrl("YOUR_URL_HERE");
And
MyWebViewClient.java : just return false
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// if (Uri.parse(url).getHost().endsWith("YOUR_URL_HERE")) {
// return false;
// }
//
// Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
// view.getContext().startActivity(intent);
// return true;
return (false);
}
Hope it helps
Here's is my webview screenshot

Closing Android Activity opened from Forms.Context.StartActivity

I am working on facebook authentication in a Xamarin forms app and want to use "native" login on each device.
The Facebook SDK (by Xamarin) is not designed for forms since it requires passing in an Android activity that implements some specific interfaces.
However; I was able to get the UI to display using a custom page renderer and then in that renderer calling StartActitivty with an activity that uses the exact implementation described in the Facebook SDK getting started. https://components.xamarin.com/view/facebookandroid
So far everything works perfect. The android app starts, xamarin forms kicks in, the custom page renderer is loaded the login android activity starts and the user logs in with facebook and we get to the console.writeline below.
So, how do I dismiss this intent or otherwise get back to xamarin forms?
Do I:
Dismiss this intent? - if so then what?
Inject something to "reset" the main page?
Other?
public void OnCompleted (Xamarin.Facebook.Model.IGraphUser user, Response response)
{
//TODO: show user details with welcome and button that takes them to main app.
//TODO: switch back to xam forms from here on out.
//TODO: figure out how to change the `main` activity to xam forms.
// 'Me' request callback
if (user != null) {
//How do I get back to Xamarin forms from here?
Console.WriteLine ("GOT USER: " + user.Name);
} else {
Console.WriteLine ("Failed to get 'me'!");
}
}
You should call Finish();
Anyway, if you want to see exactly how I did it, you can check it here:
https://github.com/IdoTene/XamarinFormsNativeFacebook

Resources