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

New FormsAppCompatActivity is raising an exception in NavigationRenderer custom renderer

$
0
0

I'm upgrading my app to use FormsAppCompatActivity.

Now in my custom renderer that's inheriting NavigationRenderer, I'm getting an exception when calling base.OnElementChanged:

[MonoDroid] UNHANDLED EXCEPTION:
[MonoDroid] System.InvalidCastException: Cannot cast from source type to destination type.
[MonoDroid] at Xamarin.Forms.Platform.Android.NavigationRenderer.SwitchContentAsync (Xamarin.Forms.Page,bool,bool) <IL 0x000bd, 0x003fe>
[MonoDroid] at Xamarin.Forms.Platform.Android.NavigationRenderer.OnPushAsync (Xamarin.Forms.Page,bool) <IL 0x00004, 0x0003f>
[MonoDroid] at Xamarin.Forms.Platform.Android.NavigationRenderer.PushViewAsync (Xamarin.Forms.Page,bool) <IL 0x00003, 0x00036>
[MonoDroid] at Xamarin.Forms.Platform.Android.NavigationRenderer.<OnElementChanged>b__4_0 (Xamarin.Forms.Page) <IL 0x00003, 0x00033>
[MonoDroid] at Xamarin.Forms.EnumerableExtensions.ForEach<Xamarin.Forms.Page> (System.Collections.Generic.IEnumerable`1<Xamarin.Forms.Page>,System.Action`1<Xamarin.Forms.Page>) <0x000bf>
[MonoDroid] at Xamarin.Forms.Platform.Android.NavigationRenderer.OnElementChanged (Xamarin.Forms.Platform.Android.ElementChangedEventArgs`1<Xamarin.Forms.NavigationPage>) <IL 0x000ea, 0x006ff>
[MonoDroid] at Boats.Droid.PageFancyRenderer.OnElementChanged (Xamarin.Forms.Platform.Android.ElementChangedEventArgs`1<Xamarin.Forms.NavigationPage>) [0x00001] in d:\Code\Boats\Droid\Renderers\NavigationPageFancy.cs:33

It's occurring in Xamarin.Forms.Platform.Android.NavigationRenderer.SwitchContentAsync.

I don't exactly what's failing there because I can't step into the source.

The decompiled code for that method is:

using Android.Animation;
using Android.Views;
using System;
using System.Threading.Tasks;

private Task<bool> SwitchContentAsync (Page view, bool animated, bool removed = false)
{
    NavigationRenderer.<>c__DisplayClass13_0 <>c__DisplayClass13_ = new NavigationRenderer.<>c__DisplayClass13_0 ();
    <>c__DisplayClass13_.<>4__this = this;
    base.Context.HideKeyboard (this);
    IVisualElementRenderer renderer = Platform.GetRenderer (view);
    bool flag = renderer != null;
    if (!flag) {
        Platform.SetRenderer (view, renderer = RendererFactory.GetRenderer (view));
    }
    <>c__DisplayClass13_.pageToRemove = this.current;
    NavigationRenderer.<>c__DisplayClass13_0 expr_43 = <>c__DisplayClass13_;
    expr_43.rendererToRemove = ((expr_43.pageToRemove == null) ? null : Platform.GetRenderer (<>c__DisplayClass13_.pageToRemove));
    NavigationRenderer.<>c__DisplayClass13_0 expr_5F = <>c__DisplayClass13_;
    expr_5F.containerToRemove = ((expr_5F.rendererToRemove == null) ? null : ((PageContainer)<>c__DisplayClass13_.rendererToRemove.ViewGroup.Parent));
    PageContainer pageContainer = ((PageContainer)renderer.ViewGroup.Parent) ?? new PageContainer (base.Context, renderer);
    pageContainer.SetWindowBackground ();
    this.current = view;
    ((Platform)base.Element.Platform).NavAnimationInProgress = true;
    <>c__DisplayClass13_.tcs = new TaskCompletionSource<bool> ();
    if (animated) {
        if (NavigationRenderer.currentAnimation != null) {
            NavigationRenderer.currentAnimation.Cancel ();
        }
        if (removed) {
            if (pageContainer.Parent != this) {
                this.AddView (pageContainer, base.Element.LogicalChildren.IndexOf (renderer.Element));
            }
            else {
                ((Page)renderer.Element).SendAppearing ();
            }
            pageContainer.Visibility = ViewStates.Visible;
            if (<>c__DisplayClass13_.containerToRemove != null) {
                Action<Animator> done = delegate (Animator a) {
                    <>c__DisplayClass13_.containerToRemove.Visibility = ViewStates.Gone;
                    <>c__DisplayClass13_.containerToRemove.set_Alpha (1);
                    <>c__DisplayClass13_.containerToRemove.set_ScaleX (1);
                    <>c__DisplayClass13_.containerToRemove.set_ScaleY (1);
                    <>c__DisplayClass13_.<>4__this.RemoveView (<>c__DisplayClass13_.containerToRemove);
                    <>c__DisplayClass13_.tcs.TrySetResult (true);
                    ((Platform)<>c__DisplayClass13_.<>4__this.Element.Platform).NavAnimationInProgress = false;
                    VisualElement element = <>c__DisplayClass13_.rendererToRemove.Element;
                    <>c__DisplayClass13_.rendererToRemove.Dispose ();
                    if (element != null) {
                        Platform.SetRenderer (element, null);
                    }
                };
                NavigationRenderer.currentAnimation = <>c__DisplayClass13_.containerToRemove.Animate ().Alpha (0).ScaleX (0.8).ScaleY (0.8).SetDuration (250).SetListener (new GenericAnimatorListener {
                    OnEnd = delegate (Animator a) {
                        NavigationRenderer.currentAnimation = null;
                        done (a);
                    },
                    OnCancel = done
                });
            }
        }
        else {
            if (pageContainer.Parent != this) {
                this.AddView (pageContainer);
            }
            else {
                ((Page)renderer.Element).SendAppearing ();
            }
            if (flag) {
                base.Element.ForceLayout ();
            }
            pageContainer.set_Alpha (0);
            PageContainer expr_1FA = pageContainer;
            float scaleX;
            expr_1FA.set_ScaleY (scaleX = 0.8);
            expr_1FA.set_ScaleX (scaleX);
            pageContainer.Visibility = ViewStates.Visible;
            NavigationRenderer.currentAnimation = pageContainer.Animate ().Alpha (1).ScaleX (1).ScaleY (1).SetDuration (250).SetListener (new GenericAnimatorListener {
                OnEnd = delegate (Animator a) {
                    if (<>c__DisplayClass13_.containerToRemove != null && <>c__DisplayClass13_.containerToRemove.Handle != IntPtr.Zero) {
                        <>c__DisplayClass13_.containerToRemove.Visibility = ViewStates.Gone;
                        if (<>c__DisplayClass13_.pageToRemove != null) {
                            <>c__DisplayClass13_.pageToRemove.SendDisappearing ();
                        }
                    }
                    NavigationRenderer.currentAnimation = null;
                    <>c__DisplayClass13_.tcs.TrySetResult (true);
                    ((Platform)<>c__DisplayClass13_.<>4__this.Element.Platform).NavAnimationInProgress = false;
                }
            });
        }
    }
    else {
        if (<>c__DisplayClass13_.containerToRemove != null) {
            if (removed) {
                this.RemoveView (<>c__DisplayClass13_.containerToRemove);
            }
            else {
                <>c__DisplayClass13_.containerToRemove.Visibility = ViewStates.Gone;
            }
        }
        if (pageContainer.Parent != this) {
            this.AddView (pageContainer);
        }
        else {
            ((Page)renderer.Element).SendAppearing ();
        }
        if (<>c__DisplayClass13_.containerToRemove != null && !removed) {
            <>c__DisplayClass13_.pageToRemove.SendDisappearing ();
        }
        if (flag) {
            base.Element.ForceLayout ();
        }
        pageContainer.Visibility = ViewStates.Visible;
        <>c__DisplayClass13_.tcs.SetResult (true);
        ((Platform)base.Element.Platform).NavAnimationInProgress = false;
    }
    return <>c__DisplayClass13_.tcs.get_Task ();
}

Viewing all articles
Browse latest Browse all 75885

Trending Articles



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