Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue where adding images in PdfViewComponent didn't work #375

Merged
merged 2 commits into from
Aug 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 25 additions & 16 deletions android/src/main/java/com/pspdfkit/react/PSPDFKitModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -300,25 +300,34 @@ public void onActivityResult(Activity activity, final int requestCode, final int
// Forward the result to all our fragments.
FragmentActivity fragmentActivity = (FragmentActivity) activity;
for (final Fragment fragment : fragmentActivity.getSupportFragmentManager().getFragments()) {
if (fragment instanceof PdfFragment ||
fragment instanceof GalleryImagePickerFragment ||
fragment instanceof CameraImagePickerFragment) {
// When starting an intent from a fragment its request code is shifted to make it unique,
// we undo it here manually since react by default eats all activity results.
int requestIndex = requestCode >> REQUEST_CODE_TO_INDEX;
if (requestIndex != 0) {
// We need to wait until the next frame with delivering the result to the fragment,
// otherwise the app will crash since the fragment won't be ready.
activityResultHandler.post(new Runnable() {
@Override
public void run() {
fragment.onActivityResult(requestCode & MASKED_REQUEST_CODE_TO_REAL_CODE, resultCode, data);
}
});
handleFragment(fragment, requestCode, resultCode, data);
}
}
}

private void handleFragment(@NonNull final Fragment fragment, final int requestCode, final int resultCode, @NonNull final Intent data) {
if (fragment instanceof PdfFragment ||
fragment instanceof GalleryImagePickerFragment ||
fragment instanceof CameraImagePickerFragment) {
// When starting an intent from a fragment its request code is shifted to make it unique,
// we undo it here manually since react by default eats all activity results.
int requestIndex = requestCode >> REQUEST_CODE_TO_INDEX;
if (requestIndex != 0) {
// We need to wait until the next frame with delivering the result to the fragment,
// otherwise the app will crash since the fragment won't be ready.
activityResultHandler.post(new Runnable() {
@Override
public void run() {
fragment.onActivityResult(requestCode & MASKED_REQUEST_CODE_TO_REAL_CODE, resultCode, data);
}
}
});
}
}

// Also send this to all child fragments so we ensure the result is handled.
for (final Fragment childFragment : fragment.getChildFragmentManager().getFragments()) {
handleFragment(childFragment, requestCode, resultCode, data);
}
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-pspdfkit",
"version": "1.29.7",
"version": "1.29.8",
"description": "A React Native module for the PSPDFKit library.",
"keywords": [
"react native",
Expand Down
2 changes: 1 addition & 1 deletion samples/Catalog/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Catalog",
"version": "1.29.7",
"version": "1.29.8",
"private": true,
"scripts": {
"start": "react-native start",
Expand Down
2 changes: 1 addition & 1 deletion samples/NativeCatalog/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "NativeCatalog",
"version": "1.29.7",
"version": "1.29.8",
"private": true,
"scripts": {
"android": "react-native run-android",
Expand Down