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
5 changes: 5 additions & 0 deletions .changeset/tasty-seas-hope.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@react-native-documents/picker": patch
---

fix: simplify coroutine cancelation to avoid hanging promises on Android
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import kotlinx.coroutines.cancel
import kotlinx.coroutines.launch

class RNDocumentPickerModule(reactContext: ReactApplicationContext) :
NativeDocumentPickerSpec(reactContext), LifecycleEventListener {
NativeDocumentPickerSpec(reactContext) {
private var currentPickOptions: PickOptions? = null
private var currentUriOfFileBeingExported: Uri? = null
private val promiseWrapper = PromiseWrapper(NAME)
Expand Down Expand Up @@ -70,15 +70,12 @@ class RNDocumentPickerModule(reactContext: ReactApplicationContext) :
}

init {
reactContext.addActivityEventListener(activityEventListener)
reactContext.addLifecycleEventListener(this)
reactApplicationContext.addActivityEventListener(activityEventListener)
}

override fun invalidate() {
fileCopyingCoroutine.cancel("module invalidated")
reactApplicationContext.removeActivityEventListener(activityEventListener)
// TODO verify this should be done (and order)
// reactApplicationContext.removeLifecycleEventListener(this)
super.invalidate()
}

Expand Down Expand Up @@ -330,12 +327,4 @@ class RNDocumentPickerModule(reactContext: ReactApplicationContext) :
private const val E_OTHER_PRESENTING_ERROR = "OTHER_PRESENTING_ERROR"
private const val E_INVALID_DATA_RETURNED = "INVALID_DATA_RETURNED"
}

override fun onHostResume() {}

override fun onHostPause() {}

override fun onHostDestroy() {
fileCopyingCoroutine.cancel("host destroyed")
}
}
Loading