Instruction to apply the patch for the missing onActivityResult #30277 on the package react-native-image-crop-picker
This is a first patch version, only for the camera, and has not been yet tested in production (it will be soon within Pl@ntNet). Use it at your own risk. Multiple images has not been tested at all.
-
Copy the patch file to your project
/patch
directory -
Apply the patch:
- if you already have
patch-package
setup:npm i
- for new
patch-package
users, follow those instructions and thennpm i
- if you already have
-
Update/patch your
MainActivity.java
:import com.facebook.react.ReactActivity; import android.content.Intent; import com.reactnative.ivpusic.imagepicker.patch30277.PickerModule30277Workaround; public class MainActivity extends ReactActivity { private final PickerModule30277Workaround mPickerModule30277Workaround = new PickerModule30277Workaround(); @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); mPickerModule30277Workaround.onActivityResultTriggered(getReactInstanceManager(), requestCode, resultCode, data); } @Override protected void onResume() { super.onResume(); mPickerModule30277Workaround.onActivityResume(this, getReactInstanceManager()); } @Override protected void onStop() { super.onStop(); mPickerModule30277Workaround.onActivityStop(getReactInstanceManager()); } }
Unfortunately, as the app is restarted, the native to js link no longer exist (the Promise in this case), it's gone 💫.
So the patch only works with additional code.
When the app is started, a method from the module is exposed and will return a Promise with the image or undefined if no data to recover:
useEffect(() => {
if (Platform.OS !== 'android') {
return
}
ImagePicker.recoverLastImageUri().then(image => {
if(image){
console.log("Image recovered", image);
setPhoto(image);
}
})
}, [])
For Class Components, a suitable method could be componentDidMount
Note: the method should return the same information as the original broken Promise, and it's behavior should be identical for a single. The image should still respect the options sent to the module. In case of multiple images at once, it is most likely different though (check ResultCollector.java
)