Skip to content

Commit e84c89e

Browse files
author
irgendeinich
committed
Address review remarks
1 parent bfd363c commit e84c89e

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

android/src/main/java/com/pspdfkit/react/PSPDFKitModule.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ public class PSPDFKitModule extends ReactContextBaseJavaModule implements Applic
4646
private static final String VERSION_KEY = "versionString";
4747
private static final String FILE_SCHEME = "file:///";
4848

49+
private static final int REQUEST_CODE_TO_INDEX = 16;
50+
private static final int MASKED_REQUEST_CODE_TO_REAL_CODE = 0xffff;
51+
4952
@Nullable
5053
private Activity resumedActivity;
5154
@Nullable
@@ -55,7 +58,7 @@ public class PSPDFKitModule extends ReactContextBaseJavaModule implements Applic
5558
* Used to dispatch onActivityResult calls to our fragments.
5659
*/
5760
@NonNull
58-
private Handler handler = new Handler(Looper.getMainLooper());
61+
private Handler activityResultHandler = new Handler(Looper.getMainLooper());
5962

6063
public PSPDFKitModule(ReactApplicationContext reactContext) {
6164
super(reactContext);
@@ -204,14 +207,14 @@ public void onActivityResult(Activity activity, final int requestCode, final int
204207
fragment instanceof CameraImagePickerFragment) {
205208
// When starting an intent from a fragment its request code is shifted to make it unique,
206209
// we undo it here manually since react by default eats all activity results.
207-
int requestIndex = requestCode >> 16;
210+
int requestIndex = requestCode >> REQUEST_CODE_TO_INDEX;
208211
if (requestIndex != 0) {
209212
// We need to wait until the next frame with delivering the result to the fragment,
210213
// otherwise the app will crash since the fragment won't be ready.
211-
handler.post(new Runnable() {
214+
activityResultHandler.post(new Runnable() {
212215
@Override
213216
public void run() {
214-
fragment.onActivityResult(requestCode & 0xffff, resultCode, data);
217+
fragment.onActivityResult(requestCode & MASKED_REQUEST_CODE_TO_REAL_CODE, resultCode, data);
215218
}
216219
});
217220
}

0 commit comments

Comments
 (0)