diff --git a/README.md b/README.md index d74f015..66c3749 100755 --- a/README.md +++ b/README.md @@ -37,6 +37,7 @@ on the platforms. Converts the exception class to an error object to display. Th - kotlin 1.3.72 - 0.1.0 - 0.2.0 + - 0.2.1 ## Installation root build.gradle @@ -51,7 +52,7 @@ allprojects { project build.gradle ```groovy dependencies { - commonMainApi("dev.icerock.moko:errors:0.2.0") + commonMainApi("dev.icerock.moko:errors:0.2.1") } ``` diff --git a/buildSrc/src/main/kotlin/Versions.kt b/buildSrc/src/main/kotlin/Versions.kt index ac76c0e..c0c3d98 100755 --- a/buildSrc/src/main/kotlin/Versions.kt +++ b/buildSrc/src/main/kotlin/Versions.kt @@ -9,7 +9,7 @@ object Versions { const val minSdk = 16 } - const val mokoErrors = "0.2.0" + const val mokoErrors = "0.2.1" const val kotlin = "1.3.72" private const val androidArch = "2.0.0" diff --git a/errors/src/iosMain/kotlin/dev/icerock/moko/errors/handler/ExceptionHandlerBinder.kt b/errors/src/iosMain/kotlin/dev/icerock/moko/errors/handler/ExceptionHandlerBinder.kt index ed587ea..2eeac2e 100644 --- a/errors/src/iosMain/kotlin/dev/icerock/moko/errors/handler/ExceptionHandlerBinder.kt +++ b/errors/src/iosMain/kotlin/dev/icerock/moko/errors/handler/ExceptionHandlerBinder.kt @@ -8,6 +8,7 @@ import dev.icerock.moko.errors.ErrorEventListener import dev.icerock.moko.errors.presenters.ErrorPresenter import dev.icerock.moko.mvvm.dispatcher.EventsDispatcher import platform.UIKit.UIViewController +import kotlin.native.ref.WeakReference actual interface ExceptionHandlerBinder { fun bind(viewController: UIViewController) @@ -17,11 +18,22 @@ actual class ExceptionHandlerBinderImpl actual constructor( private val errorPresenter: ErrorPresenter, private val eventsDispatcher: EventsDispatcher> ) : ExceptionHandlerBinder { + + private var eventsListener: ErrorEventListener? = null + override fun bind(viewController: UIViewController) { - eventsDispatcher.listener = object : ErrorEventListener { + eventsListener = createEventsListener(viewController) + eventsDispatcher.listener = eventsListener + } + + private fun createEventsListener(viewController: UIViewController) = + object : ErrorEventListener { + val viewControllerRef = WeakReference(viewController) + override fun showError(throwable: Throwable, data: T) { - errorPresenter.show(throwable, viewController, data) + viewControllerRef.get()?.let { + errorPresenter.show(throwable, it, data) + } } } - } }