Skip to content

Commit 09cde52

Browse files
authored
Merge pull request #65 from PSPDFKit/simone/issue/fix-android-project
Android module enhancements
2 parents 8460b5a + 3f3d7fd commit 09cde52

File tree

8 files changed

+22
-160
lines changed

8 files changed

+22
-160
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ const CONFIGURATION = {
465465

466466
Just like on iOS we also support integrating PSPDFKit directly into the react-native view hierarchy. There are a few thing you need to consider when using this approach:
467467

468-
- Your activity hosting the react component needs to extend from `FragmentActivity`. The default `ReactActivity` doesn't so you will need to update your java code to either manually use a `FragmentActivity` our use our drop-in replacement the `ReactFragmentActivity`.
468+
- Your activity hosting the react component needs to extend from `ReactFragmentActivity`.
469469
- Because of [issues](https://github.com/facebook/react-native/issues/17968) in react-native our `PdfView` needs to call `layout` and `dispatchOnGlobalLayout` on every frame, this might negatively affect your apps performance or even cause it to misbehave.
470470
- `PSPDFKitView` doesn't yet support all the features (outline, bookmarks, thubmnail grid, view settings) using `PSPDFKit.present` provides.
471471

android/src/main/java/com/facebook/react/ReactFragmentActivity.java

Lines changed: 0 additions & 132 deletions
This file was deleted.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public boolean getUseDeveloperSupport() {
3636
protected List<ReactPackage> getPackages() {
3737
return Arrays.<ReactPackage>asList(
3838
new MainReactPackage(),
39-
new PSPDFKitPackage(MainApplication.this)
39+
new PSPDFKitPackage()
4040
);
4141
}
4242
};

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,8 @@ public class PSPDFKitModule extends ReactContextBaseJavaModule implements Applic
4242
@Nullable
4343
private Runnable onPdfActivityOpenedTask;
4444

45-
public PSPDFKitModule(ReactApplicationContext reactContext, Application application) {
45+
public PSPDFKitModule(ReactApplicationContext reactContext) {
4646
super(reactContext);
47-
// We register an activity lifecycle callback so we can get notified of the current activity.
48-
application.registerActivityLifecycleCallbacks(this);
4947
}
5048

5149
@Override
@@ -56,6 +54,10 @@ public String getName() {
5654
@ReactMethod
5755
public void present(@NonNull String document, @NonNull ReadableMap configuration) {
5856
if (getCurrentActivity() != null) {
57+
if (resumedActivity == null) {
58+
// We register an activity lifecycle callback so we can get notified of the current activity.
59+
getCurrentActivity().getApplication().registerActivityLifecycleCallbacks(this);
60+
}
5961
ConfigurationAdapter configurationAdapter = new ConfigurationAdapter(getCurrentActivity(), configuration);
6062
// This is an edge case where file scheme is missing.
6163
if (Uri.parse(document).getScheme() == null) {

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

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,10 @@
2727

2828
public class PSPDFKitPackage implements ReactPackage {
2929

30-
private final Application application;
31-
32-
public PSPDFKitPackage(Application application) {
33-
super();
34-
this.application = application;
35-
}
36-
3730
@Override
3831
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
3932
List<NativeModule> modules = new ArrayList<>();
40-
modules.add(new PSPDFKitModule(reactContext, application));
33+
modules.add(new PSPDFKitModule(reactContext));
4134
return modules;
4235
}
4336

samples/Catalog/Catalog.android.js

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright © 2017 PSPDFKit GmbH. All rights reserved.
1+
// Copyright © 2018 PSPDFKit GmbH. All rights reserved.
22
//
33
// THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
44
// AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE PSPDFKIT LICENSE AGREEMENT.
@@ -178,7 +178,7 @@ class PdfViewScreen extends Component<{}> {
178178
return {
179179
title: "PDF",
180180
headerRight: (
181-
<Button onPress={params.enterAnnotationCreation} title="Annotations" />
181+
<Button onPress={() => params.handleAnnotationButtonPress()} title="Annotations" />
182182
)
183183
};
184184
};
@@ -195,21 +195,19 @@ class PdfViewScreen extends Component<{}> {
195195

196196
componentWillMount() {
197197
this.props.navigation.setParams({
198-
enterAnnotationCreation: this._enterAnnotationCreation
198+
handleAnnotationButtonPress: () => {
199+
if (
200+
this.state.annotationCreationActive ||
201+
this.state.annotationEditingActive
202+
) {
203+
this.refs.pdfView.exitCurrentlyActiveMode();
204+
} else {
205+
this.refs.pdfView.enterAnnotationCreationMode();
206+
}
207+
}
199208
});
200209
}
201210

202-
_enterAnnotationCreation = () => {
203-
if (
204-
this.state.annotationCreationActive ||
205-
this.state.annotationEditingActive
206-
) {
207-
this.refs.pdfView.exitCurrentlyActiveMode();
208-
} else {
209-
this.refs.pdfView.enterAnnotationCreationMode();
210-
}
211-
};
212-
213211
render() {
214212
let buttonTitle = "";
215213
if (this.state.annotationCreationActive) {

samples/Catalog/android/app/src/main/java/com/pspdfkit/react/catalog/MainApplication.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public boolean getUseDeveloperSupport() {
3737
protected List<ReactPackage> getPackages() {
3838
return Arrays.<ReactPackage>asList(
3939
new MainReactPackage(),
40-
new PSPDFKitPackage(MainApplication.this)
40+
new PSPDFKitPackage()
4141
);
4242
}
4343

samples/Catalog/android/gradle.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@
1818
# org.gradle.parallel=true
1919

2020
android.useDeprecatedNdk=true
21+
org.gradle.jvmargs=-Xmx2G -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

0 commit comments

Comments
 (0)