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

Experimental: Migrate to PSPDFKit 5.4.0 and Android X #168

Closed
wants to merge 8 commits into from
Closed
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
74 changes: 66 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## React Native wrapper for PSPDFKit for iOS, Android & Windows UWP. (PDF SDK for React Native)
## React Native wrapper for PSPDFKit for iOS, Android (Experimental Android X Version) & Windows UWP. (PDF SDK for React Native)

![PDF SDK for React Native](https://github.com/PSPDFKit/react-native/blob/master/article-header.png?raw=true)

Expand Down Expand Up @@ -267,7 +267,7 @@ The PSPDFKit React Native iOS Wrapper allows you to specify a custom grouping fo
- Android Build Tools 23.0.1 (React Native)
- Android Build Tools 28.0.3 (PSPDFKit module)
- Android Gradle plugin >= 3.2.1
- PSPDFKit >= 5.0.1
- PSPDFKit >= 5.4.0
- react-native for example app >= 0.59.2
- react-native for Catalog app >= 0.57.8

Expand All @@ -278,7 +278,7 @@ Let's create a simple app that integrates PSPDFKit and uses the react-native-psp
1. Make sure `react-native-cli` is installed: `yarn global add react-native-cli`
2. Create the app with `react-native init YourApp`.
3. Step into your newly created app folder: `cd YourApp`.
4. Add `react-native-pspdfkit` module from GitHub: `yarn add github:PSPDFKit/react-native`.
4. Add `react-native-pspdfkit` module from GitHub: `yarn add github:PSPDFKit/react-native#reinhard/android-x-support`.
5. Install all the dependencies for the project: `yarn install`. (Because of a [bug](https://github.com/yarnpkg/yarn/issues/2165) you may need to clean `yarn`'s cache with `yarn cache clean` before.)
6. Link module `react-native-pspdfkit`: `react-native link react-native-pspdfkit`.
7. <a id="step-7"></a>Add PSPDFKit repository to `YourApp/android/build.gradle` so PSPDFKit library can be downloaded:
Expand Down Expand Up @@ -333,7 +333,65 @@ Let's create a simple app that integrates PSPDFKit and uses the react-native-psp
...
```

10. <a id="step-10"></a>Enter your PSPDFKit license key into `YourApp/android/app/src/main/AndroidManifest.xml` file:
10. PSPDFKit also uses AndroidX so you need to enable this as well in your `gradle.properties`:

```diff
+ android.useAndroidX=true
+ android.enableJetifier=true
```

Since react-native doesn't have support for AndroidX yet we provide a small gradle script you need to add to the end of your top-level `build.gradle`:

```groovy
// This will create the mapping from the old support library classes to their AndroidX equivalents.
def androidXMapping = [:]
new File("$projectDir/androidx-class-mapping.csv").splitEachLine(",") { fields ->
androidXMapping[fields[0]] = fields[1]
}

allprojects {

// This task copies all sources of the project to a temporary folder and replaces all mentions
// of support library classes with their AndroidX equivalents using our mapping.
task updateImports(type: Copy) {
from "$buildDir/../src/main/java"
into "$buildDir/generated/source/updatedImports"
filter { line ->
androidXMapping.each { support, androidX ->
line = line.replaceAll(support, androidX)
}
return line
}
}

tasks.all { task ->
// We wanna modify all compile tasks.
if (task.name.endsWith("JavaWithJavac")) {

// We need to generate the updated sources first.
task.dependsOn updateImports

// Before the task is executed change the source set it operates on.
task.doFirst {
def newSource = task.getSource().matching {
// We remove the original Java sources folder.
exclude {
return it.file.path.contains('src/main/java')
}
// Then add our modified sources instead.
}.plus(fileTree("$buildDir/generated/source/updatedImports"))

// Finally actually update the task to use our new sources.
task.source = newSource
}
}
}
}
```

You also need to add the [androidx-class-mapping.csv](https://raw.githubusercontent.com/PSPDFKit/react-native/a2a8720fadeef0da8ea8f26722df7cb070420773/samples/Catalog/android/androidx-class-mapping.csv) to the root of you project. With these things in place all support library imports will automatically replaced by their AndroidX counterparts.

11. <a id="step-11"></a>Enter your PSPDFKit license key into `YourApp/android/app/src/main/AndroidManifest.xml` file:

```diff
<application>
Expand All @@ -346,7 +404,7 @@ Let's create a simple app that integrates PSPDFKit and uses the react-native-psp
</application>
```

11. Set primary color. In `YourApp/android/app/src/main/res/values/styles.xml` replace
12. Set primary color. In `YourApp/android/app/src/main/res/values/styles.xml` replace

```xml
<!-- Customize your theme here. -->
Expand All @@ -358,7 +416,7 @@ with
<item name="colorPrimary">#3C97C9</item>
```

12. <a id="step-12"></a>Replace the default component from `YourApp/App.js` with a simple touch area to present a PDF document from the local device filesystem:
13. <a id="step-13"></a>Replace the default component from `YourApp/App.js` with a simple touch area to present a PDF document from the local device filesystem:

```javascript
import React, { Component } from "react";
Expand Down Expand Up @@ -430,13 +488,13 @@ const styles = StyleSheet.create({
});
```

13. Before launching the app you need to copy a PDF document onto your development device or emulator.
14. Before launching the app you need to copy a PDF document onto your development device or emulator.

```bash
adb push /path/to/your/document.pdf /sdcard/document.pdf
```

14. Your app is now ready to launch. From `YourApp` directory run `react-native run-android`.
15. Your app is now ready to launch. From `YourApp` directory run `react-native run-android`.

```bash
react-native run-android
Expand Down
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Contains gradle configuration constants
*/
ext {
PSPDFKIT_VERSION = '5.0.1'
PSPDFKIT_VERSION = '5.4.0'
}

buildscript {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
package com.pspdfkit.react;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.ReadableMapKeySetIterator;
Expand Down
9 changes: 5 additions & 4 deletions android/src/main/java/com/pspdfkit/react/PSPDFKitModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;

import com.facebook.react.bridge.ActivityEventListener;
import com.facebook.react.bridge.ReactApplicationContext;
Expand All @@ -42,6 +38,11 @@
import java.util.HashMap;
import java.util.Map;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;

public class PSPDFKitModule extends ReactContextBaseJavaModule implements Application.ActivityLifecycleCallbacks, ActivityEventListener {

private static final String VERSION_KEY = "versionString";
Expand Down
4 changes: 0 additions & 4 deletions android/src/main/java/com/pspdfkit/react/PSPDFKitPackage.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,12 @@

package com.pspdfkit.react;

import android.app.Application;

import com.facebook.react.ReactPackage;
import com.facebook.react.bridge.JavaScriptModule;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.uimanager.ViewManager;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class PSPDFKitPackage implements ReactPackage {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.pspdfkit.react;

import android.app.Activity;
import android.support.annotation.NonNull;
import android.support.v4.app.FragmentActivity;

import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.ReadableMap;
Expand All @@ -29,6 +27,8 @@

import javax.annotation.Nullable;

import androidx.annotation.NonNull;
import androidx.fragment.app.FragmentActivity;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.disposables.Disposable;
Expand Down
3 changes: 2 additions & 1 deletion android/src/main/java/com/pspdfkit/react/TestingModule.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package com.pspdfkit.react;

import android.support.annotation.NonNull;

import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;

import java.util.HashMap;

import androidx.annotation.NonNull;

public class TestingModule extends ReactContextBaseJavaModule {

private static final HashMap<String, String> values = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.pspdfkit.react.events;

import android.support.annotation.IdRes;
import android.support.annotation.NonNull;

import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.WritableMap;
Expand All @@ -18,6 +16,9 @@
import java.util.List;
import java.util.Map;

import androidx.annotation.IdRes;
import androidx.annotation.NonNull;

/**
* Event sent by the {@link com.pspdfkit.views.PdfView} when an annotation was selected.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.pspdfkit.react.events;

import android.support.annotation.IdRes;
import android.support.annotation.NonNull;

import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.WritableMap;
Expand All @@ -15,6 +13,9 @@

import java.util.Map;

import androidx.annotation.IdRes;
import androidx.annotation.NonNull;

/**
* Event sent by the {@link com.pspdfkit.views.PdfView} when an annotation was selected.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.pspdfkit.react.events;

import android.support.annotation.IdRes;
import android.support.annotation.NonNull;

import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.WritableMap;
Expand All @@ -18,6 +16,9 @@
import java.util.List;
import java.util.Map;

import androidx.annotation.IdRes;
import androidx.annotation.NonNull;

public class PdfViewDataReturnedEvent extends Event<PdfViewDataReturnedEvent> {

public static final String EVENT_NAME = "pdfViewDataReturned";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package com.pspdfkit.react.events;

import android.support.annotation.IdRes;
import android.support.annotation.NonNull;

import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.uimanager.events.Event;
import com.facebook.react.uimanager.events.RCTEventEmitter;

import androidx.annotation.IdRes;
import androidx.annotation.NonNull;

/**
* Event sent by the {@link com.pspdfkit.views.PdfView} when the document save failed.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.pspdfkit.react.events;

import android.support.annotation.IdRes;

import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.uimanager.events.Event;
import com.facebook.react.uimanager.events.RCTEventEmitter;

import androidx.annotation.IdRes;

/**
* Event sent by the {@link com.pspdfkit.views.PdfView} when the document was saved.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package com.pspdfkit.react.events;


import android.support.annotation.IdRes;

import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.uimanager.events.Event;
import com.facebook.react.uimanager.events.RCTEventEmitter;

import androidx.annotation.IdRes;

/**
* Event sent by the {@link com.pspdfkit.views.PdfView} containing info about the current state.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package com.pspdfkit.react.helper;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

import com.pspdfkit.document.providers.DataProvider;

import org.json.JSONObject;

import java.nio.charset.Charset;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

/**
* {@link DataProvider} that is used when adding document instant json.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package com.pspdfkit.react.menu;

import android.content.Context;
import android.support.annotation.IdRes;
import android.support.annotation.IntRange;
import android.support.annotation.NonNull;
import android.util.Log;

import com.facebook.react.bridge.Dynamic;
Expand All @@ -18,6 +15,10 @@
import java.util.ArrayList;
import java.util.List;

import androidx.annotation.IdRes;
import androidx.annotation.IntRange;
import androidx.annotation.NonNull;

/**
* A menu item grouping rule that displays only the menu items configured via the menuItemGrouping prop.
*/
Expand Down Expand Up @@ -90,7 +91,11 @@ private int getIdFromName(@NonNull String name) {
case "signature":
return R.id.pspdf__annotation_creation_toolbar_item_signature;
case "ink":
return R.id.pspdf__annotation_creation_toolbar_item_ink;
return R.id.pspdf__annotation_creation_toolbar_item_ink_pen;
case "pen":
return R.id.pspdf__annotation_creation_toolbar_item_ink_pen;
case "highlighter":
return R.id.pspdf__annotation_creation_toolbar_item_ink_highlighter;
case "note":
return R.id.pspdf__annotation_creation_toolbar_item_note;
case "drawing":
Expand Down Expand Up @@ -119,6 +124,8 @@ private int getIdFromName(@NonNull String name) {
return R.id.pspdf__annotation_creation_toolbar_item_redaction;
case "picker":
return R.id.pspdf__annotation_creation_toolbar_item_picker;
case "sound":
return R.id.pspdf__annotation_creation_toolbar_item_sound;
}

Log.i(TAG, String.format("Received unknown menu item %s.", name));
Expand Down
Loading