GiampaoloGabba / Xamarin.Plugin.SharedTransitions

Shared Element Transitions between pages in Xamarin.Forms (IOS/Android)
MIT License
414 stars 59 forks source link

Sharedtransitions for app shell causing error for Android. Error is caused whenever I attempt to go back on any page #69

Open brettnguyen opened 2 years ago

brettnguyen commented 2 years ago

Bug Information

I added the shared transition app shell to my app shell code and now whenever I navigate backwards I get

System.NotSupportedException "Unable to activate instance of type Plugin.SharedTransitions.Platforms.Android.SharedTransitionPageRenderer from native handle 0x7fe61ad9b4 (key_handle 0x45d1348)."

System.MissingMethodException " No constructor found for Plugin.SharedTransitions.Platforms.Android.SharedTransitionPageRenderer::.ctor(System.IntPtr, Android.Runtime.JniHandleOwnership)"

Java.Interop.JavaLocationException "Exception of type 'Java.Interop.JavaLocationException' was thrown."

It is on any page I try to navigate backwards my code only has the shared transition shell implemented into it. I haven't even done the shared transitions I wanted to yet because there isn't a point to implement anything if I can't even go backwards.

Version Number of Plugin: 2.4.0

Device Tested On: Pixel3_XL_API_31

Simulator Tested On: Pixel3_XL_API_31

Version of VS: 8.10.12 (build 16)

Version of Xamarin: 5.0.0.2196

Versions of other things you are using: Should be known in another test I striped away all pages except the login and forgotusername page and added the shared transition shell to my app shell and still got the error when going backward from a page. As well as removed all other nuget packages and plugins. I can provide this code if needed.

Steps to reproduce the Behavior

Not sure just added the SharedTransitions shell to the app shell and then that's it. I have tested on other projects though and the app shell shared transition works fine.

For ease of debugging navigate from the login page to forgotusername or forgot password by tapping on the labels on the login page than click the back arrow on those page to get the error

Expected Behavior

Allow shared transition and allow to navigate backwards without crashing

Actual Behavior

Allows shared transition but not allowing me to navigate backwards as well as normal navigation from page to page lost its default page animation.

Code snippet

https://github.com/brettnguyen/CollegeVSDemo/tree/SharedTransitionIssue

Exact error message

System.NotSupportedException: Unable to activate instance of type Plugin.SharedTransitions.Platforms.Android.SharedTransitionPageRenderer from native handle 0x7fe61ad9b4 (key_handle 0x45d1348). ---> System.MissingMethodException: No constructor found for Plugin.SharedTransitions.Platforms.Android.SharedTransitionPageRenderer::.ctor(System.IntPtr, Android.Runtime.JniHandleOwnership) ---> Java.Interop.JavaLocationException: Exception of type 'Java.Interop.JavaLocationException' was thrown. at Java.Lang.Error: Exception of type 'Java.Lang.Error' was thrown. at java.lang.Error: Java callstack: at at crc643f46942d9dd1fff9.PageRenderer.n_onAttachedToWindow(Native Method) at at crc643f46942d9dd1fff9.PageRenderer.onAttachedToWindow(PageRenderer.java:56) at at android.view.View.dispatchAttachedToWindow(View.java:20479) at at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3489) at at android.view.ViewGroup.addViewInner(ViewGroup.java:5278) at at android.view.ViewGroup.addView(ViewGroup.java:5064) at at android.view.ViewGroup.addView(ViewGroup.java:5004) at at android.view.ViewGroup.addView(ViewGroup.java:4976) at at android.view.ViewOverlay$OverlayViewGroup.add(ViewOverlay.java:208) at at android.view.ViewGroupOverlay.add(ViewGroupOverlay.java:72) at at androidx.transition.ViewGroupOverlayApi18.add(ViewGroupOverlayApi18.java:48) at at androidx.transition.Visibility.onDisappear(Visibility.java:431) at at androidx.transition.Visibility.createAnimator(Visibility.java:257) at at androidx.transition.Transition.createAnimators(Transition.java:744) at at androidx.transition.TransitionSet.createAnimators(TransitionSet.java:480) at at androidx.transition.Transition.playTransition(Transition.java:1808) at at androidx.transition.TransitionManager$MultiListener.onPreDraw(TransitionManager.java:300) at at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:1093) at at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:3089) at at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1952) at at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:8171) at at android.view.Choreographer$CallbackRecord.run(Choreographer.java:972) at at android.view.Choreographer.doCallbacks(Choreographer.java:796) at at android.view.Choreographer.doFrame(Choreographer.java:731) at at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:957) at at android.os.Handler.handleCallback(Handler.java:938) at at android.os.Handler.dispatchMessage(Handler.java:99) at at android.os.Looper.loop(Looper.java:223) at at android.app.ActivityThread.main(ActivityThread.java:7656) at at java.lang.reflect.Method.invoke(Native Method) at at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) at at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947) --- End of inner exception stack trace --- at Java.Interop.TypeManager.CreateProxy (System.Type type, System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00096] in /Users/builder/azdo/_work/1/s/xamarin-android/src/Mono.Android/Java.Interop/TypeManager.cs:342 at Java.Interop.TypeManager.CreateInstance (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type targetType) [0x00111] in /Users/builder/azdo/_work/1/s/xamarin-android/src/Mono.Android/Java.Interop/TypeManager.cs:306 --- End of inner exception stack trace --- at Java.Interop.TypeManager.CreateInstance (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type targetType) [0x00154] in /Users/builder/azdo/_work/1/s/xamarin-android/src/Mono.Android/Java.Interop/TypeManager.cs:313 at Java.Lang.Object.GetObject (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type type) [0x00023] in /Users/builder/azdo/_work/1/s/xamarin-android/src/Mono.Android/Java.Lang/Object.cs:304 at Java.Lang.Object._GetObject[T] (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00017] in /Users/builder/azdo/_work/1/s/xamarin-android/src/Mono.Android/Java.Lang/Object.cs:290 at Java.Lang.Object.GetObject[T] (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00000] in /Users/builder/azdo/_work/1/s/xamarin-android/src/Mono.Android/Java.Lang/Object.cs:281 at Java.Lang.Object.GetObject[T] (System.IntPtr jnienv, System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00006] in /Users/builder/azdo/_work/1/s/xamarin-android/src/Mono.Android/Java.Lang/Object.cs:275 at Android.Views.View.n_OnAttachedToWindow (System.IntPtr jnienv, System.IntPtr native__this) [0x00000] in /Users/builder/azdo/_work/1/s/xamarin-android/src/Mono.Android/obj/Release/monoandroid10/android-29/mcw/Android.Views.View.cs:16825 at at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.86(intptr,intptr)

Additional Information

If I add

[Obsolete] public SharedTransitionPageRenderer(IntPtr handle, JniHandleOwnership transfer) : base(Xamarin.Forms.Forms.Context) { }

to the SharedTransitionpagerenderer I get this message

System.NullReferenceException: Object reference not set to an instance of an object. at Xamarin.Forms.Platform.Android.PageRenderer.OnAttachedToWindow () [0x00027] in D:\a\1\s\Xamarin.Forms.Platform.Android\Renderers\PageRenderer.cs:60 at Android.Views.View.n_OnAttachedToWindow (System.IntPtr jnienv, System.IntPtr native__this) [0x00008] in /Users/builder/azdo/_work/1/s/xamarin-android/src/Mono.Android/obj/Release/monoandroid10/android-29/mcw/Android.Views.View.cs:16826 at at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.86(intptr,intptr)

roubachof commented 2 years ago

classic JNI error, the class SharedTransitionPageRenderer is lacking the JNI constructor:

            public SharedTransitionPageRenderer(IntPtr a, JniHandleOwnership b) 
                : base (a, b))
    {

    }
brettnguyen commented 2 years ago

classic JNI error, the class SharedTransitionPageRenderer is lacking the JNI constructor:

            public SharedTransitionPageRenderer(IntPtr a, JniHandleOwnership b) 
                : base (a, b))
  {

  }

I added the source code from the nuget package and am trying to make the changes to the shared transition page but I can't because it says "PageRenderer does not contain a constructor that takes 2 arguments". Did you test this fix on my code? Do you know if it works?

JesusKrists commented 2 years ago

Hi! Are there any updates on this? I would love to use this library however I am also getting the same error, which is really annoying. My knowledge of C# ecosystem is not good enough to fix this myself sadly