chore: make ContextWrapper implement LifecycleOwner
This commit is contained in:
1 parent
e42441c234
commit
2d3753a887
8 files changed
+56
-40
No files matched your search
@@ -88,7 +88,16 @@ class UsbCameraView(context: Context, appContext: AppContext) : ExpoView(context
|
||||
// Create a ContextWrapper that automatically injects RECEIVER_EXPORTED
|
||||
// This is required to fix the crash on Android 14+ when the 3rd party ausbc library
|
||||
// calls registerReceiver without the required flag.
|
||||
val wrappedContext = object : android.content.ContextWrapper(activityContext) {
|
||||
val wrappedContext = object : android.content.ContextWrapper(activityContext), androidx.lifecycle.LifecycleOwner {
|
||||
override val lifecycle: androidx.lifecycle.Lifecycle
|
||||
get() {
|
||||
if (activityContext is androidx.lifecycle.LifecycleOwner) {
|
||||
return (activityContext as androidx.lifecycle.LifecycleOwner).lifecycle
|
||||
}
|
||||
// Fallback to avoid crash, though CameraX needs a real lifecycle
|
||||
throw IllegalStateException("activityContext is not a LifecycleOwner!")
|
||||
}
|
||||
|
||||
override fun getApplicationContext(): android.content.Context {
|
||||
return this
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user