[Android] ImagePickerModule.onActivityResult not called when using library from Android Fragment
See original GitHub issueImagePickerModule.onActivityResult is not being called, even after adding super.onActivityResult(requestCode, resultCode, data)
to my MainActivity.
I think the problem has something to do with placing my React component inside of a Fragment in my Android app. I’m guessing I need to pass my MainActivity.onActivityResult (which does get called) data into my fragment manually somehow.
Also, I tried setting a breakpoint in my fragment’s onActivityResult, and it is not called. I don’t know what that means exactly, but it seems relevant.
I managed to call my fragment’s onActivityResult when the result comes in to my MainActivity.onActivityResult, but ImagePickerModule.onActivityResult is still not being called.
Here is the code for my fragment that’s displaying the React Component.
package com.sterling.vims.shopqueue
import android.content.Context
import android.support.v4.app.Fragment
import android.os.Bundle
import android.preference.PreferenceManager
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.facebook.react.BuildConfig
import com.facebook.react.LifecycleState
import com.facebook.react.ReactInstanceManager
import com.facebook.react.ReactRootView
import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler
import com.facebook.react.shell.MainReactPackage
import com.imagepicker.ImagePickerPackage
import com.oblador.vectoricons.VectorIconsPackage
import com.sterling.vims.user.User
import com.sterling.vims.inventory.Lot
import fr.bamlab.rnimageresizer.ImageResizerPackage
class ShopQueueFragment : Fragment(), DefaultHardwareBackBtnHandler {
private var mReactRootView: ReactRootView? = null
private var mReactInstanceManager: ReactInstanceManager? = null
override fun onAttach(context: Context?) {
super.onAttach(context)
mReactRootView = ReactRootView(context)
mReactInstanceManager = ReactInstanceManager.builder()
.setApplication(activity.application)
.setBundleAssetName("shopqueue.bundle")
.setJSMainModuleName("index.android")
.addPackage(MainReactPackage())
.setUseDeveloperSupport(BuildConfig.DEBUG)
.setInitialLifecycleState(LifecycleState.RESUMED)
.addPackage(ImagePickerPackage())
.addPackage(ImageResizerPackage())
.addPackage(VectorIconsPackage())
.build()
}
override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
super.onCreateView(inflater, container, savedInstanceState)
return mReactRootView
}
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
val storage = PreferenceManager.getDefaultSharedPreferences(context)
val user = User.current(context)
val lotId = Lot.getCurrentLot(context)?.id ?: 0
val token = user.accessToken
val initialProperties = Bundle()
initialProperties.putInt("lotId", lotId)
initialProperties.putString("token", token)
initialProperties.putString("apiEndpoint",
storage.getString("api_endpoint", null))
mReactRootView?.startReactApplication(
mReactInstanceManager, "ShopQueue", initialProperties)
}
override fun invokeDefaultOnBackPressed() {
activity.onBackPressed()
}
override fun onPause() {
super.onPause()
mReactInstanceManager?.onHostPause(activity)
}
override fun onResume() {
super.onResume()
mReactInstanceManager?.onHostResume(activity, this)
}
}
Issue Analytics
- State:
- Created 7 years ago
- Comments:7
Top GitHub Comments
Solved!
I had to put this
mReactInstanceManager?.onActivityResult(this, requestCode, resultCode, data)
into my activity/fragment’s onActivityResult.@Gagege thanks!