Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

Issue with Navigation when Using Xamarin.Auth and Renders

$
0
0

I have A PCL project and developing for iOS and Android. ALL my pages are in the PCL project and navigation in there works like a charm, but currently I am stuck at the point when I have to consume the Xamarin.Auth for facebook via Renderers and Dependency Services.

[assembly: ExportRenderer (typeof (LoginPage), typeof (LoginPageRenderer))]
namespace OSYS.Droid
{
    public class LoginPageRenderer : PageRenderer
    {
        protected override void OnElementChanged (ElementChangedEventArgs<Page> e)
        {
            base.OnElementChanged (e);
            var activity = this.Context as Activity;
            var auth = new OAuth2Authenticator (
                clientId: App.Instance.OAuthSettings.ClientId, // your OAuth2 client id
                scope: App.Instance.OAuthSettings.Scope, // The scopes for the particular API you're accessing. The format for this will vary by API.
                authorizeUrl: App.Instance.OAuthSettings.AuthorizeUrl, // the auth URL for the service
                redirectUrl:  App.Instance.OAuthSettings.RedirectUrl); // the redirect URL for the service

            auth.AllowCancel = true;
            auth.Completed += (sender, eventArgs) => 
            {
                if (eventArgs.IsAuthenticated) 
                {
                //  App.Instance.SuccessfulLoginAction.Invoke();
                    App.Instance.SaveToken(eventArgs.Account.Properties["access_token"]);
                    //Use eventArgs.Account to do wonderful things
                } 
                else 
                {
                    var builder = new AlertDialog.Builder (this.Context);
                    builder.SetMessage ("Not Authenticated");
                    builder.SetPositiveButton ("Ok", (o, k) => { });
                    builder.Create().Show();
                //  App.Instance.UnSuccessfulLoginAction.Invoke();
                }
            };
            activity.StartActivity (auth.GetUI(activity));
        }

    }
}

There are 2 problems:
When I am on the login screen of Facebook and press the back button first the facebook UI closes and an empty screen appears afterwards when I press back again i return to my main screen. While debugging on the second key press of the back button my debugger stops on the break point OnDisappearing() which is a protected method of the LoginPage.cs

When I log successfully I want to navigate to a page of my own desire but again the black screen and nothing happens.
With App.Instance.SuccessfulLoginAction.Invoke I call an Action method to perform a Navigation but seems not to work they I want.

How Can I navigate properly when using Renderers?


Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>