Skip to content

Commit b616eb2

Browse files
authored
fix: simplify coroutine cancelation to avoid hanging promises (#912)
* fix: simplify coroutine cancelation to avoid hanging promises * Create tasty-seas-hope.md
1 parent 04a2395 commit b616eb2

File tree

2 files changed

+7
-13
lines changed

2 files changed

+7
-13
lines changed

.changeset/tasty-seas-hope.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@react-native-documents/picker": patch
3+
---
4+
5+
fix: simplify coroutine cancelation to avoid hanging promises on Android

packages/document-picker/android/src/main/java/com/reactnativedocumentpicker/RNDocumentPickerModule.kt

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import kotlinx.coroutines.cancel
2525
import kotlinx.coroutines.launch
2626

2727
class RNDocumentPickerModule(reactContext: ReactApplicationContext) :
28-
NativeDocumentPickerSpec(reactContext), LifecycleEventListener {
28+
NativeDocumentPickerSpec(reactContext) {
2929
private var currentPickOptions: PickOptions? = null
3030
private var currentUriOfFileBeingExported: Uri? = null
3131
private val promiseWrapper = PromiseWrapper(NAME)
@@ -70,15 +70,12 @@ class RNDocumentPickerModule(reactContext: ReactApplicationContext) :
7070
}
7171

7272
init {
73-
reactContext.addActivityEventListener(activityEventListener)
74-
reactContext.addLifecycleEventListener(this)
73+
reactApplicationContext.addActivityEventListener(activityEventListener)
7574
}
7675

7776
override fun invalidate() {
7877
fileCopyingCoroutine.cancel("module invalidated")
7978
reactApplicationContext.removeActivityEventListener(activityEventListener)
80-
// TODO verify this should be done (and order)
81-
// reactApplicationContext.removeLifecycleEventListener(this)
8279
super.invalidate()
8380
}
8481

@@ -330,12 +327,4 @@ class RNDocumentPickerModule(reactContext: ReactApplicationContext) :
330327
private const val E_OTHER_PRESENTING_ERROR = "OTHER_PRESENTING_ERROR"
331328
private const val E_INVALID_DATA_RETURNED = "INVALID_DATA_RETURNED"
332329
}
333-
334-
override fun onHostResume() {}
335-
336-
override fun onHostPause() {}
337-
338-
override fun onHostDestroy() {
339-
fileCopyingCoroutine.cancel("host destroyed")
340-
}
341330
}

0 commit comments

Comments
 (0)