lilcodelab / Xamarin.Plugin.Calendar

Calendar plugin for Xamarin.Forms
MIT License
260 stars 60 forks source link

Ensure that the GestureDetector is disposed #128

Open kvpt opened 2 years ago

kvpt commented 2 years ago

I received a log from a crash of my app that is related to the SwipeAwareContainerRenderer class used by the calendar. From the stacktrace the crash seem to be caused by a press that try to access the renderer, but it has already been disposed so it crash the application. This PR make two things :

  1. Ensure that the the gesture detector is disposed correctly like in #115
  2. Decouple the renderer from the gesture listener because the two have not the same lifecycle, by doing this we ensure that the gesture listener is disposed before the renderer which is not garanted when the renderer is itself the gesture listener

FYI, the stacktrace of the crash

System.NotSupportedException: Unable to activate instance of type Xamarin.Plugin.Calendar.Android.SwipeAwareContainerRenderer from native handle 0xffc46fdc (key_handle 0xe4b6c0a).
  at IJavaPeerable Java.Interop.TypeManager.CreateInstance(IntPtr handle, JniHandleOwnership transfer, Type targetType)
  at IJavaPeerable Java.Lang.Object.GetObject(IntPtr handle, JniHandleOwnership transfer, Type type)
  at IOnGestureListener Java.Lang.Object._GetObject<IOnGestureListener>(IntPtr handle, JniHandleOwnership transfer)
  at IOnGestureListener Java.Lang.Object.GetObject<IOnGestureListener>(IntPtr handle, JniHandleOwnership transfer) x 2
  at void Android.Views.GestureDetector+IOnGestureListenerInvoker.n_OnLongPress_Landroid_view_MotionEvent_(IntPtr jnienv, IntPtr native__this, IntPtr native_e)
--- End of inner exception stack trace ---
  System.MissingMethodException: No constructor found for Xamarin.Plugin.Calendar.Android.SwipeAwareContainerRenderer::.ctor(System.IntPtr, Android.Runtime.JniHandleOwnership)
    at object Java.Interop.TypeManager.CreateProxy(Type type, IntPtr handle, JniHandleOwnership transfer)
    at IJavaPeerable Java.Interop.TypeManager.CreateInstance(IntPtr handle, JniHandleOwnership transfer, Type targetType)