Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
}
```

Expand Down
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/Versions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -17,11 +18,22 @@ actual class ExceptionHandlerBinderImpl<T : Any> actual constructor(
private val errorPresenter: ErrorPresenter<T>,
private val eventsDispatcher: EventsDispatcher<ErrorEventListener<T>>
) : ExceptionHandlerBinder {

private var eventsListener: ErrorEventListener<T>? = null

override fun bind(viewController: UIViewController) {
eventsDispatcher.listener = object : ErrorEventListener<T> {
eventsListener = createEventsListener(viewController)
eventsDispatcher.listener = eventsListener
}

private fun createEventsListener(viewController: UIViewController) =
object : ErrorEventListener<T> {
val viewControllerRef = WeakReference(viewController)

override fun showError(throwable: Throwable, data: T) {
errorPresenter.show(throwable, viewController, data)
viewControllerRef.get()?.let {
errorPresenter.show(throwable, it, data)
}
}
}
}
}