File tree Expand file tree Collapse file tree
packages/react-native/ReactCommon/react/nativemodule/samples/platform/android Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -361,7 +361,23 @@ public class SampleTurboModule(private val context: ReactApplicationContext) :
361361 toast?.show()
362362 }
363363
364- override fun invalidate (): Unit = Unit
364+ override fun invalidate () {
365+ // Reject anything still in flight: the JS context that made these calls is going away, so the
366+ // results can never be delivered. Clearing the fields also lets the callbacks (which stay
367+ // registered until the launchers are unregistered) tolerate a late result harmlessly.
368+ pendingPermissionPromise?.reject(
369+ " E_MODULE_INVALIDATED" , " Permission request cancelled: SampleTurboModule was invalidated" )
370+ pendingPermissionPromise = null
371+
372+ pendingPickMediaPromise?.reject(
373+ " E_MODULE_INVALIDATED" , " Media pick cancelled: SampleTurboModule was invalidated" )
374+ pendingPickMediaPromise = null
375+
376+ pendingPickMultipleMediaPromise?.reject(
377+ " E_MODULE_INVALIDATED" , " Multiple media pick cancelled: SampleTurboModule was invalidated" )
378+ pendingPickMultipleMediaPromise = null
379+ super .invalidate()
380+ }
365381
366382 override fun getName (): String {
367383 return NAME
You can’t perform that action at this time.
0 commit comments