react-native-pdf 6.6.2 → 6.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -41
- package/android/build.gradle +71 -13
- package/android/src/main/java/org/wonday/pdf/{RCTPdfManager.java → PdfManager.java} +57 -21
- package/android/src/main/java/org/wonday/pdf/PdfView.java +25 -0
- package/android/src/main/java/org/wonday/pdf/{RCTPdfView.java → RNPDFPackage.java} +2 -3
- package/android/src/paper/java/com/facebook/react/viewmanagers/RNPDFPdfViewManagerDelegate.java +86 -0
- package/android/src/paper/java/com/facebook/react/viewmanagers/RNPDFPdfViewManagerInterface.java +33 -0
- package/fabric/RNPDFPdfNativeComponent.js +46 -0
- package/index.d.ts +2 -0
- package/index.js +25 -27
- package/index.js.flow +2 -0
- package/ios/{RCTPdf/PdfManager.m → RNPDFPdf/PdfManager.mm} +1 -1
- package/ios/{RCTPdf/RCTPdfPageView.h → RNPDFPdf/RNPDFPdfPageView.h} +1 -1
- package/ios/{RCTPdf/RCTPdfPageView.m → RNPDFPdf/RNPDFPdfPageView.mm} +5 -5
- package/ios/{RCTPdf/RCTPdfPageViewManager.h → RNPDFPdf/RNPDFPdfPageViewManager.h} +1 -1
- package/ios/{RCTPdf/RCTPdfPageViewManager.m → RNPDFPdf/RNPDFPdfPageViewManager.mm} +4 -4
- package/ios/{RCTPdf/RCTPdfView.h → RNPDFPdf/RNPDFPdfView.h} +15 -5
- package/ios/{RCTPdf/RCTPdfView.m → RNPDFPdf/RNPDFPdfView.mm} +321 -54
- package/ios/{RCTPdf/RCTPdfViewManager.h → RNPDFPdf/RNPDFPdfViewManager.h} +1 -1
- package/ios/{RCTPdf/RCTPdfViewManager.m → RNPDFPdf/RNPDFPdfViewManager.mm} +7 -5
- package/ios/{RCTPdf.xcodeproj → RNPDFPdf.xcodeproj}/project.pbxproj +42 -42
- package/package.json +19 -3
- package/react-native-pdf.podspec +28 -3
- package/windows/RCTPdf/pch.h +2 -0
- package/ios/RCTPdf.xcodeproj/xcuserdata/wonday.xcuserdatad/xcschemes/xcschememanagement.plist +0 -14
- /package/ios/{RCTPdf → RNPDFPdf}/PdfManager.h +0 -0
package/README.md
CHANGED
|
@@ -114,14 +114,14 @@ in the app `.vcxproj` file, before `<None Include="packages.config" />`.
|
|
|
114
114
|
<details>
|
|
115
115
|
<summary>FAQ details</summary>
|
|
116
116
|
|
|
117
|
-
Q1. After installation and running, I can not see the pdf file.
|
|
117
|
+
Q1. After installation and running, I can not see the pdf file.
|
|
118
118
|
A1: maybe you forgot to excute ```react-native link``` or it does not run correctly.
|
|
119
119
|
You can add it manually. For detail you can see the issue [`#24`](https://github.com/wonday/react-native-pdf/issues/24) and [`#2`](https://github.com/wonday/react-native-pdf/issues/2)
|
|
120
120
|
|
|
121
|
-
Q2. When running, it shows ```'Pdf' has no propType for native prop RCTPdf.acessibilityLabel of native type 'String'```
|
|
121
|
+
Q2. When running, it shows ```'Pdf' has no propType for native prop RCTPdf.acessibilityLabel of native type 'String'```
|
|
122
122
|
A2. Your react-native version is too old, please upgrade it to 0.47.0+ see also [`#39`](https://github.com/wonday/react-native-pdf/issues/39)
|
|
123
123
|
|
|
124
|
-
Q3. When I run the example app I get a white/gray screen / the loading bar isn't progressing .
|
|
124
|
+
Q3. When I run the example app I get a white/gray screen / the loading bar isn't progressing .
|
|
125
125
|
A3. Check your uri, if you hit a pdf that is hosted on a `http` you will need to do the following:
|
|
126
126
|
|
|
127
127
|
**iOS:**
|
|
@@ -151,10 +151,10 @@ add an exception for the server hosting the pdf in the ios `info.plist`. Here is
|
|
|
151
151
|
**Android:**
|
|
152
152
|
[`see here`](https://stackoverflow.com/questions/54818098/cleartext-http-traffic-not-permitted)
|
|
153
153
|
|
|
154
|
-
Q4. why doesn't it work with react native expo?.
|
|
154
|
+
Q4. why doesn't it work with react native expo?.
|
|
155
155
|
A4. Expo does not support native module. you can read more expo caveats [`here`](https://facebook.github.io/react-native/docs/getting-started.html#caveats)
|
|
156
156
|
|
|
157
|
-
Q5. Why can't I run the iOS example? `'Failed to build iOS project. We ran "xcodebuild" command but it exited with error code 65.'`
|
|
157
|
+
Q5. Why can't I run the iOS example? `'Failed to build iOS project. We ran "xcodebuild" command but it exited with error code 65.'`
|
|
158
158
|
A5. Run the following commands in the project folder (e.g. `react-native-pdf/example`) to ensure that all dependencies are available:
|
|
159
159
|
```
|
|
160
160
|
yarn install (or npm install)
|
|
@@ -169,6 +169,16 @@ react-native run-ios
|
|
|
169
169
|
<details>
|
|
170
170
|
<summary>ChangeLog details</summary>
|
|
171
171
|
|
|
172
|
+
v6.7.1
|
|
173
|
+
1. Fixed: fix ios project setting
|
|
174
|
+
2. Fixed: fix typo in RNPDFPdfViewManagerInterface interface causing android build error
|
|
175
|
+
|
|
176
|
+
v6.7.0
|
|
177
|
+
1. Fixed: fix(iOS): center page at tap point after double tap to zoom
|
|
178
|
+
2. Fixed: add PDFKit to podspec to make ios compile
|
|
179
|
+
3. Improved: Update build.gradle to support RN 0.71 on new arch
|
|
180
|
+
4. Fixed: fix some small bugs and documents.
|
|
181
|
+
|
|
172
182
|
v6.6.2
|
|
173
183
|
1. Fixed: Migrate to ViewPropTypes exported from 'deprecated-react-native-prop-types'
|
|
174
184
|
2. Added: Decode File Path for iOS
|
|
@@ -200,42 +210,6 @@ v6.3.0
|
|
|
200
210
|
1. Add windows support
|
|
201
211
|
2. Fixed some bugs
|
|
202
212
|
|
|
203
|
-
v6.2.2
|
|
204
|
-
1. Fixed incorrect type of onPageSingleTap and onScaleChanged argument
|
|
205
|
-
2. Fixed included missing setPage method in TypeScript and Flow types
|
|
206
|
-
3. fixed Xcode 12 compatibility
|
|
207
|
-
|
|
208
|
-
v6.2.1
|
|
209
|
-
1. Fixed typescript `onLoadComplete()` definition
|
|
210
|
-
2. Switched the AndroidPdfViewer dependency from Barteksc repo to TalbotGooday
|
|
211
|
-
3. Add singlePage property
|
|
212
|
-
|
|
213
|
-
v6.2.0
|
|
214
|
-
1. Fixed ReferenceError, url should be source.uri
|
|
215
|
-
2. Dependency bump to support React-Native >= 0.62
|
|
216
|
-
|
|
217
|
-
v6.1.2
|
|
218
|
-
1. Fixed wrong scale returned from onScaleChanged()
|
|
219
|
-
2. Fixed iOS Double Tap zoom
|
|
220
|
-
3. Fixed Some critical typo fixes
|
|
221
|
-
|
|
222
|
-
v6.1.1
|
|
223
|
-
1. Fixed undefined is not an object, crashing on ios
|
|
224
|
-
|
|
225
|
-
v6.1.0
|
|
226
|
-
1. Fixed react-native warning on `componentWill*`
|
|
227
|
-
2. Fixed onPageSingleTap
|
|
228
|
-
3. Set the PDF View background color to be transparent On iOS
|
|
229
|
-
|
|
230
|
-
v6.0.1
|
|
231
|
-
1. Expose prop to trust self-signed SSL certs
|
|
232
|
-
2. Use ViewStyleProp in index.js.flow, not deprecated StyleSheet.Styles
|
|
233
|
-
|
|
234
|
-
v6.0.0
|
|
235
|
-
1. Add JS callback onPressLink for pdf link press listener
|
|
236
|
-
2. Fix calling setState while unmounted
|
|
237
|
-
|
|
238
|
-
|
|
239
213
|
[[more]](https://github.com/wonday/react-native-pdf/releases)
|
|
240
214
|
|
|
241
215
|
</details>
|
|
@@ -314,6 +288,8 @@ const styles = StyleSheet.create({
|
|
|
314
288
|
| minScale | number | 1.0 | min scale| ✔ | ✔ | ✔ | 5.0.5 |
|
|
315
289
|
| maxScale | number | 3.0 | max scale| ✔ | ✔ | ✔ | 5.0.5 |
|
|
316
290
|
| horizontal | bool | false | draw page direction, if you want to listen the orientation change, you can use [[react-native-orientation-locker]](https://github.com/wonday/react-native-orientation-locker)| ✔ | ✔ | ✔ | <3.0 |
|
|
291
|
+
| showsHorizontalScrollIndicator | bool | true | shows or hides the horizontal scroll bar indicator on iOS| ✔ | | | 6.6 |
|
|
292
|
+
| showsVerticalScrollIndicator | bool | true | shows or hides the vertical scroll bar indicator on iOS| ✔ | | | 6.6 |
|
|
317
293
|
| fitWidth | bool | false | if true fit the width of view, can not use fitWidth=true together with scale| ✔ | ✔ | ✔ | <3.0, abandoned from 3.0 |
|
|
318
294
|
| fitPolicy | number | 2 | 0:fit width, 1:fit height, 2:fit both(default)| ✔ | ✔ | ✔ | 3.0 |
|
|
319
295
|
| spacing | number | 10 | the breaker size between pages| ✔ | ✔ | ✔ | <3.0 |
|
package/android/build.gradle
CHANGED
|
@@ -1,46 +1,100 @@
|
|
|
1
1
|
description = 'react-native-pdf'
|
|
2
2
|
|
|
3
3
|
buildscript {
|
|
4
|
+
ext.safeExtGet = {prop, fallback ->
|
|
5
|
+
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
|
|
6
|
+
}
|
|
4
7
|
repositories {
|
|
5
8
|
mavenCentral()
|
|
6
9
|
google()
|
|
7
10
|
}
|
|
8
11
|
|
|
9
12
|
dependencies {
|
|
10
|
-
classpath
|
|
13
|
+
classpath("com.android.tools.build:gradle:7.2.0")
|
|
11
14
|
}
|
|
12
15
|
}
|
|
13
16
|
|
|
14
17
|
repositories {
|
|
15
18
|
mavenCentral()
|
|
16
19
|
maven {
|
|
17
|
-
|
|
20
|
+
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
|
|
21
|
+
url "$projectDir/../node_modules/react-native/android"
|
|
18
22
|
content {
|
|
19
23
|
// Use Jitpack only for AndroidPdfViewer; the rest is hosted at mavenCentral.
|
|
20
24
|
includeGroup "com.github.TalbotGooday"
|
|
21
25
|
}
|
|
22
26
|
}
|
|
27
|
+
maven { url 'https://jitpack.io' }
|
|
23
28
|
}
|
|
24
29
|
|
|
25
30
|
apply plugin: 'com.android.library'
|
|
26
31
|
|
|
27
|
-
def
|
|
32
|
+
def resolveReactNativeDirectory() {
|
|
33
|
+
def reactNativeLocation = safeExtGet("REACT_NATIVE_NODE_MODULES_DIR", null)
|
|
34
|
+
if (reactNativeLocation != null) {
|
|
35
|
+
return file(reactNativeLocation)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// monorepo workaround
|
|
39
|
+
// react-native can be hoisted or in project's own node_modules
|
|
40
|
+
def reactNativeFromProjectNodeModules = file("${rootProject.projectDir}/../node_modules/react-native")
|
|
41
|
+
if (reactNativeFromProjectNodeModules.exists()) {
|
|
42
|
+
return reactNativeFromProjectNodeModules
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
def reactNativeFromNodeModulesWithPDF = file("${projectDir}/../../react-native")
|
|
46
|
+
if (reactNativeFromNodeModulesWithPDF.exists()) {
|
|
47
|
+
return reactNativeFromNodeModulesWithPDF
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
throw new Exception(
|
|
51
|
+
"[react-native-pdf] Unable to resolve react-native location in " +
|
|
52
|
+
"node_modules. You should add project extension property (in app/build.gradle) " +
|
|
53
|
+
"`REACT_NATIVE_NODE_MODULES_DIR` with path to react-native."
|
|
54
|
+
)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
def getReactNativeMinorVersion() {
|
|
58
|
+
def REACT_NATIVE_DIR = resolveReactNativeDirectory()
|
|
28
59
|
|
|
29
|
-
def
|
|
30
|
-
|
|
31
|
-
def _buildToolsVersion = _ext.has('buildToolsVersion') ? _ext.buildToolsVersion : '28.0.3'
|
|
32
|
-
def _minSdkVersion = _ext.has('minSdkVersion') ? _ext.minSdkVersion : 16
|
|
33
|
-
def _targetSdkVersion = _ext.has('targetSdkVersion') ? _ext.targetSdkVersion : 28
|
|
60
|
+
def reactProperties = new Properties()
|
|
61
|
+
file("$REACT_NATIVE_DIR/ReactAndroid/gradle.properties").withInputStream { reactProperties.load(it) }
|
|
34
62
|
|
|
63
|
+
def REACT_NATIVE_VERSION = reactProperties.getProperty("VERSION_NAME")
|
|
64
|
+
def REACT_NATIVE_MINOR_VERSION = REACT_NATIVE_VERSION.startsWith("0.0.0-") ? 1000 : REACT_NATIVE_VERSION.split("\\.")[1].toInteger()
|
|
35
65
|
|
|
66
|
+
return REACT_NATIVE_MINOR_VERSION
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
def isNewArchitectureEnabled() {
|
|
70
|
+
// To opt-in for the New Architecture, you can either:
|
|
71
|
+
// - Set `newArchEnabled` to true inside the `gradle.properties` file
|
|
72
|
+
// - Invoke gradle with `-newArchEnabled=true`
|
|
73
|
+
// - Set an environment variable `ORG_GRADLE_PROJECT_newArchEnabled=true`
|
|
74
|
+
return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true"
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (isNewArchitectureEnabled()) {
|
|
78
|
+
apply plugin: "com.facebook.react"
|
|
79
|
+
}
|
|
36
80
|
|
|
37
81
|
android {
|
|
38
|
-
compileSdkVersion
|
|
39
|
-
buildToolsVersion _buildToolsVersion
|
|
82
|
+
compileSdkVersion safeExtGet('compileSdkVersion', 31)
|
|
40
83
|
|
|
41
84
|
defaultConfig {
|
|
42
|
-
minSdkVersion
|
|
43
|
-
targetSdkVersion
|
|
85
|
+
minSdkVersion safeExtGet('minSdkVersion', 21)
|
|
86
|
+
targetSdkVersion safeExtGet('targetSdkVersion', 31)
|
|
87
|
+
buildConfigField("boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString())
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
sourceSets.main {
|
|
91
|
+
java {
|
|
92
|
+
if (!isNewArchitectureEnabled()) {
|
|
93
|
+
srcDirs += [
|
|
94
|
+
"src/paper/java",
|
|
95
|
+
]
|
|
96
|
+
}
|
|
97
|
+
}
|
|
44
98
|
}
|
|
45
99
|
|
|
46
100
|
lintOptions {
|
|
@@ -58,7 +112,11 @@ android {
|
|
|
58
112
|
}
|
|
59
113
|
|
|
60
114
|
dependencies {
|
|
61
|
-
|
|
115
|
+
if (isNewArchitectureEnabled() && getReactNativeMinorVersion() < 71) {
|
|
116
|
+
implementation project(":ReactAndroid")
|
|
117
|
+
} else {
|
|
118
|
+
implementation 'com.facebook.react:react-native:+'
|
|
119
|
+
}
|
|
62
120
|
// NOTE: The original repo at com.github.barteksc is abandoned by the maintainer; there will be no more updates coming from that repo.
|
|
63
121
|
// It was taken over by com.github.TalbotGooday; from now on please use this repo until (if ever) the Barteksc repo is resumed.
|
|
64
122
|
implementation 'com.github.TalbotGooday:AndroidPdfViewer:3.1.0-beta.3'
|
|
@@ -8,39 +8,43 @@
|
|
|
8
8
|
|
|
9
9
|
package org.wonday.pdf;
|
|
10
10
|
|
|
11
|
-
import java.io.File;
|
|
12
|
-
|
|
13
11
|
import android.content.Context;
|
|
14
|
-
import android.view.ViewGroup;
|
|
15
|
-
import android.util.Log;
|
|
16
|
-
import android.graphics.PointF;
|
|
17
|
-
import android.net.Uri;
|
|
18
12
|
|
|
19
|
-
import
|
|
13
|
+
import androidx.annotation.NonNull;
|
|
14
|
+
import androidx.annotation.Nullable;
|
|
15
|
+
|
|
16
|
+
import com.facebook.infer.annotation.Assertions;
|
|
20
17
|
import com.facebook.react.bridge.ReactApplicationContext;
|
|
21
|
-
import com.facebook.react.bridge.
|
|
22
|
-
import com.facebook.react.
|
|
23
|
-
import com.facebook.react.bridge.WritableMap;
|
|
18
|
+
import com.facebook.react.bridge.ReadableArray;
|
|
19
|
+
import com.facebook.react.module.annotations.ReactModule;
|
|
24
20
|
import com.facebook.react.uimanager.SimpleViewManager;
|
|
25
21
|
import com.facebook.react.uimanager.ThemedReactContext;
|
|
26
22
|
import com.facebook.react.uimanager.annotations.ReactProp;
|
|
27
|
-
import com.facebook.react.uimanager.events.RCTEventEmitter;
|
|
28
|
-
import com.facebook.react.common.MapBuilder;
|
|
29
|
-
import com.facebook.react.modules.core.DeviceEventManagerModule;
|
|
30
|
-
|
|
31
|
-
import static java.lang.String.format;
|
|
32
|
-
import java.lang.ClassCastException;
|
|
33
23
|
|
|
34
|
-
import com.
|
|
24
|
+
import com.facebook.react.uimanager.ViewManagerDelegate;
|
|
25
|
+
import com.facebook.react.viewmanagers.RNPDFPdfViewManagerDelegate;
|
|
26
|
+
import com.facebook.react.viewmanagers.RNPDFPdfViewManagerInterface;
|
|
35
27
|
|
|
36
|
-
|
|
37
|
-
|
|
28
|
+
@ReactModule(name = PdfManager.REACT_CLASS)
|
|
29
|
+
public class PdfManager extends SimpleViewManager<PdfView> implements RNPDFPdfViewManagerInterface<PdfView> {
|
|
30
|
+
public static final String REACT_CLASS = "RNPDFPdfView";
|
|
38
31
|
private Context context;
|
|
39
32
|
private PdfView pdfView;
|
|
33
|
+
private final ViewManagerDelegate<PdfView> mDelegate;
|
|
34
|
+
|
|
35
|
+
@Nullable
|
|
36
|
+
@Override
|
|
37
|
+
protected ViewManagerDelegate<PdfView> getDelegate() {
|
|
38
|
+
return mDelegate;
|
|
39
|
+
}
|
|
40
40
|
|
|
41
|
+
public PdfManager() {
|
|
42
|
+
mDelegate = new RNPDFPdfViewManagerDelegate<>(this);
|
|
43
|
+
}
|
|
41
44
|
|
|
42
|
-
public
|
|
45
|
+
public PdfManager(ReactApplicationContext reactContext){
|
|
43
46
|
this.context = reactContext;
|
|
47
|
+
mDelegate = new RNPDFPdfViewManagerDelegate<>(this);
|
|
44
48
|
}
|
|
45
49
|
|
|
46
50
|
@Override
|
|
@@ -90,6 +94,16 @@ public class RCTPdfManager extends SimpleViewManager<PdfView> {
|
|
|
90
94
|
pdfView.setHorizontal(horizontal);
|
|
91
95
|
}
|
|
92
96
|
|
|
97
|
+
@Override
|
|
98
|
+
public void setShowsHorizontalScrollIndicator(PdfView view, boolean value) {
|
|
99
|
+
// NOOP on Android
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
@Override
|
|
103
|
+
public void setShowsVerticalScrollIndicator(PdfView view, boolean value) {
|
|
104
|
+
// NOOP on Android
|
|
105
|
+
}
|
|
106
|
+
|
|
93
107
|
@ReactProp(name = "spacing")
|
|
94
108
|
public void setSpacing(PdfView pdfView, int spacing) {
|
|
95
109
|
pdfView.setSpacing(spacing);
|
|
@@ -115,8 +129,13 @@ public class RCTPdfManager extends SimpleViewManager<PdfView> {
|
|
|
115
129
|
pdfView.setEnablePaging(enablePaging);
|
|
116
130
|
}
|
|
117
131
|
|
|
132
|
+
@Override
|
|
133
|
+
public void setEnableRTL(PdfView view, boolean value) {
|
|
134
|
+
// NOOP on Android
|
|
135
|
+
}
|
|
136
|
+
|
|
118
137
|
@ReactProp(name = "fitPolicy")
|
|
119
|
-
public void
|
|
138
|
+
public void setFitPolicy(PdfView pdfView, int fitPolicy) {
|
|
120
139
|
pdfView.setFitPolicy(fitPolicy);
|
|
121
140
|
}
|
|
122
141
|
|
|
@@ -125,6 +144,23 @@ public class RCTPdfManager extends SimpleViewManager<PdfView> {
|
|
|
125
144
|
pdfView.setSinglePage(singlePage);
|
|
126
145
|
}
|
|
127
146
|
|
|
147
|
+
// It seems funny, but this method is called through delegate on Paper, but on Fabric we need to
|
|
148
|
+
// use `receiveCommand` method and call this one there
|
|
149
|
+
@Override
|
|
150
|
+
public void setNativePage(PdfView view, int page) {
|
|
151
|
+
pdfView.setPage(page);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
@Override
|
|
155
|
+
public void receiveCommand(@NonNull PdfView root, String commandId, @androidx.annotation.Nullable ReadableArray args) {
|
|
156
|
+
Assertions.assertNotNull(root);
|
|
157
|
+
if ("setNativePage".equals(commandId)) {
|
|
158
|
+
Assertions.assertNotNull(args);
|
|
159
|
+
assert args != null;
|
|
160
|
+
setNativePage(root, args.getInt(0));
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
128
164
|
@Override
|
|
129
165
|
public void onAfterUpdateTransaction(PdfView pdfView) {
|
|
130
166
|
super.onAfterUpdateTransaction(pdfView);
|
|
@@ -87,6 +87,10 @@ public class PdfView extends PDFView implements OnPageChangeListener,OnLoadCompl
|
|
|
87
87
|
private float lastPageWidth = 0;
|
|
88
88
|
private float lastPageHeight = 0;
|
|
89
89
|
|
|
90
|
+
// used to store the parameters for `super.onSizeChanged`
|
|
91
|
+
private int oldW = 0;
|
|
92
|
+
private int oldH = 0;
|
|
93
|
+
|
|
90
94
|
public PdfView(ThemedReactContext context, AttributeSet set){
|
|
91
95
|
super(context,set);
|
|
92
96
|
this.context = context;
|
|
@@ -110,6 +114,27 @@ public class PdfView extends PDFView implements OnPageChangeListener,OnLoadCompl
|
|
|
110
114
|
);
|
|
111
115
|
}
|
|
112
116
|
|
|
117
|
+
// In some cases Yoga (I think) will measure the view only along one axis first, resulting in
|
|
118
|
+
// onSizeChanged being called with either w or h set to zero. This in turn starts the rendering
|
|
119
|
+
// of the pdf under the hood with one dimension being set to zero and the follow-up call to
|
|
120
|
+
// onSizeChanged with the correct dimensions doesn't have any effect on the already started process.
|
|
121
|
+
// The offending class is DecodingAsyncTask, which tries to get width and height of the pdfView
|
|
122
|
+
// in the constructor, and is created as soon as the measurement is complete, which in some cases
|
|
123
|
+
// may be incomplete as described above.
|
|
124
|
+
// By delaying calling super.onSizeChanged until the size in both dimensions is correct we are able
|
|
125
|
+
// to prevent this from happening.
|
|
126
|
+
//
|
|
127
|
+
// I'm not sure whether the second condition is necessary, but without it, it would be impossible
|
|
128
|
+
// to set the dimensions to zero after first measurement.
|
|
129
|
+
@Override
|
|
130
|
+
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
|
|
131
|
+
if ((w > 0 && h > 0) || this.oldW > 0 || this.oldH > 0) {
|
|
132
|
+
super.onSizeChanged(w, h, this.oldW, this.oldH);
|
|
133
|
+
this.oldW = w;
|
|
134
|
+
this.oldH = h;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
113
138
|
@Override
|
|
114
139
|
public void loadComplete(int numberOfPages) {
|
|
115
140
|
SizeF pageSize = getPageSize(0);
|
|
@@ -8,7 +8,6 @@
|
|
|
8
8
|
|
|
9
9
|
package org.wonday.pdf;
|
|
10
10
|
|
|
11
|
-
import java.util.Arrays;
|
|
12
11
|
import java.util.Collections;
|
|
13
12
|
import java.util.List;
|
|
14
13
|
import java.util.ArrayList;
|
|
@@ -19,7 +18,7 @@ import com.facebook.react.bridge.NativeModule;
|
|
|
19
18
|
import com.facebook.react.bridge.ReactApplicationContext;
|
|
20
19
|
import com.facebook.react.uimanager.ViewManager;
|
|
21
20
|
|
|
22
|
-
public class
|
|
21
|
+
public class RNPDFPackage implements ReactPackage {
|
|
23
22
|
|
|
24
23
|
@Override
|
|
25
24
|
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
|
|
@@ -34,7 +33,7 @@ public class RCTPdfView implements ReactPackage {
|
|
|
34
33
|
@Override
|
|
35
34
|
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
|
|
36
35
|
List<ViewManager> modules = new ArrayList<>();
|
|
37
|
-
modules.add(new
|
|
36
|
+
modules.add(new PdfManager(reactContext));
|
|
38
37
|
return modules;
|
|
39
38
|
}
|
|
40
39
|
}
|
package/android/src/paper/java/com/facebook/react/viewmanagers/RNPDFPdfViewManagerDelegate.java
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
|
|
3
|
+
*
|
|
4
|
+
* Do not edit this file as changes may cause incorrect behavior and will be lost
|
|
5
|
+
* once the code is regenerated.
|
|
6
|
+
*
|
|
7
|
+
* @generated by codegen project: GeneratePropsJavaDelegate.js
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
package com.facebook.react.viewmanagers;
|
|
11
|
+
|
|
12
|
+
import android.view.View;
|
|
13
|
+
import androidx.annotation.Nullable;
|
|
14
|
+
import com.facebook.react.bridge.ReadableArray;
|
|
15
|
+
import com.facebook.react.uimanager.BaseViewManagerDelegate;
|
|
16
|
+
import com.facebook.react.uimanager.BaseViewManagerInterface;
|
|
17
|
+
|
|
18
|
+
public class RNPDFPdfViewManagerDelegate<T extends View, U extends BaseViewManagerInterface<T> & RNPDFPdfViewManagerInterface<T>> extends BaseViewManagerDelegate<T, U> {
|
|
19
|
+
public RNPDFPdfViewManagerDelegate(U viewManager) {
|
|
20
|
+
super(viewManager);
|
|
21
|
+
}
|
|
22
|
+
@Override
|
|
23
|
+
public void setProperty(T view, String propName, @Nullable Object value) {
|
|
24
|
+
switch (propName) {
|
|
25
|
+
case "path":
|
|
26
|
+
mViewManager.setPath(view, value == null ? null : (String) value);
|
|
27
|
+
break;
|
|
28
|
+
case "page":
|
|
29
|
+
mViewManager.setPage(view, value == null ? 0 : ((Double) value).intValue());
|
|
30
|
+
break;
|
|
31
|
+
case "scale":
|
|
32
|
+
mViewManager.setScale(view, value == null ? 0f : ((Double) value).floatValue());
|
|
33
|
+
break;
|
|
34
|
+
case "minScale":
|
|
35
|
+
mViewManager.setMinScale(view, value == null ? 0f : ((Double) value).floatValue());
|
|
36
|
+
break;
|
|
37
|
+
case "maxScale":
|
|
38
|
+
mViewManager.setMaxScale(view, value == null ? 0f : ((Double) value).floatValue());
|
|
39
|
+
break;
|
|
40
|
+
case "horizontal":
|
|
41
|
+
mViewManager.setHorizontal(view, value == null ? false : (boolean) value);
|
|
42
|
+
break;
|
|
43
|
+
case "showsHorizontalScrollIndicator":
|
|
44
|
+
mViewManager.setShowsHorizontalScrollIndicator(view, value == null ? false : (boolean) value);
|
|
45
|
+
break;
|
|
46
|
+
case "showsVerticalScrollIndicator":
|
|
47
|
+
mViewManager.setShowsVerticalScrollIndicator(view, value == null ? false : (boolean) value);
|
|
48
|
+
break;
|
|
49
|
+
case "enablePaging":
|
|
50
|
+
mViewManager.setEnablePaging(view, value == null ? false : (boolean) value);
|
|
51
|
+
break;
|
|
52
|
+
case "enableRTL":
|
|
53
|
+
mViewManager.setEnableRTL(view, value == null ? false : (boolean) value);
|
|
54
|
+
break;
|
|
55
|
+
case "enableAnnotationRendering":
|
|
56
|
+
mViewManager.setEnableAnnotationRendering(view, value == null ? false : (boolean) value);
|
|
57
|
+
break;
|
|
58
|
+
case "enableAntialiasing":
|
|
59
|
+
mViewManager.setEnableAntialiasing(view, value == null ? false : (boolean) value);
|
|
60
|
+
break;
|
|
61
|
+
case "fitPolicy":
|
|
62
|
+
mViewManager.setFitPolicy(view, value == null ? 0 : ((Double) value).intValue());
|
|
63
|
+
break;
|
|
64
|
+
case "spacing":
|
|
65
|
+
mViewManager.setSpacing(view, value == null ? 0 : ((Double) value).intValue());
|
|
66
|
+
break;
|
|
67
|
+
case "password":
|
|
68
|
+
mViewManager.setPassword(view, value == null ? null : (String) value);
|
|
69
|
+
break;
|
|
70
|
+
case "singlePage":
|
|
71
|
+
mViewManager.setSinglePage(view, value == null ? false : (boolean) value);
|
|
72
|
+
break;
|
|
73
|
+
default:
|
|
74
|
+
super.setProperty(view, propName, value);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
@Override
|
|
79
|
+
public void receiveCommand(T view, String commandName, ReadableArray args) {
|
|
80
|
+
switch (commandName) {
|
|
81
|
+
case "setNativePage":
|
|
82
|
+
mViewManager.setNativePage(view, args.getInt(0));
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
package/android/src/paper/java/com/facebook/react/viewmanagers/RNPDFPdfViewManagerInterface.java
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
|
|
3
|
+
*
|
|
4
|
+
* Do not edit this file as changes may cause incorrect behavior and will be lost
|
|
5
|
+
* once the code is regenerated.
|
|
6
|
+
*
|
|
7
|
+
* @generated by codegen project: GeneratePropsJavaInterface.js
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
package com.facebook.react.viewmanagers;
|
|
11
|
+
|
|
12
|
+
import android.view.View;
|
|
13
|
+
import androidx.annotation.Nullable;
|
|
14
|
+
|
|
15
|
+
public interface RNPDFPdfViewManagerInterface<T extends View> {
|
|
16
|
+
void setPath(T view, @Nullable String value);
|
|
17
|
+
void setPage(T view, int value);
|
|
18
|
+
void setScale(T view, float value);
|
|
19
|
+
void setMinScale(T view, float value);
|
|
20
|
+
void setMaxScale(T view, float value);
|
|
21
|
+
void setHorizontal(T view, boolean value);
|
|
22
|
+
void setShowsHorizontalScrollIndicator(T view, boolean value);
|
|
23
|
+
void setShowsVerticalScrollIndicator(T view, boolean value);
|
|
24
|
+
void setEnablePaging(T view, boolean value);
|
|
25
|
+
void setEnableRTL(T view, boolean value);
|
|
26
|
+
void setEnableAnnotationRendering(T view, boolean value);
|
|
27
|
+
void setEnableAntialiasing(T view, boolean value);
|
|
28
|
+
void setFitPolicy(T view, int value);
|
|
29
|
+
void setSpacing(T view, int value);
|
|
30
|
+
void setPassword(T view, @Nullable String value);
|
|
31
|
+
void setSinglePage(T view, boolean value);
|
|
32
|
+
void setNativePage(T view, int page);
|
|
33
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @flow
|
|
3
|
+
* @format
|
|
4
|
+
*/
|
|
5
|
+
'use strict';
|
|
6
|
+
|
|
7
|
+
import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';
|
|
8
|
+
import codegenNativeCommands from 'react-native/Libraries/Utilities/codegenNativeCommands';
|
|
9
|
+
|
|
10
|
+
type ChangeEvent = $ReadOnly<{|
|
|
11
|
+
message: ?string,
|
|
12
|
+
|}>;
|
|
13
|
+
|
|
14
|
+
export type NativeProps = $ReadOnly<{|
|
|
15
|
+
...ViewProps,
|
|
16
|
+
path: ?string,
|
|
17
|
+
page: ?Int32,
|
|
18
|
+
scale: ?Float,
|
|
19
|
+
minScale: ?Float,
|
|
20
|
+
maxScale: ?Float,
|
|
21
|
+
horizontal: ?boolean,
|
|
22
|
+
enablePaging: ?boolean,
|
|
23
|
+
enableRTL: ?boolean,
|
|
24
|
+
enableAnnotationRendering: ?boolean,
|
|
25
|
+
showsHorizontalScrollIndicator: ?boolean,
|
|
26
|
+
showsVerticalScrollIndicator: ?boolean,
|
|
27
|
+
enableAntialiasing: ?boolean,
|
|
28
|
+
fitPolicy: ?Int32,
|
|
29
|
+
spacing: ?Int32,
|
|
30
|
+
password: ?string,
|
|
31
|
+
onChange: ?BubblingEventHandler<ChangeEvent>,
|
|
32
|
+
singlePage: ?boolean,
|
|
33
|
+
|}>;
|
|
34
|
+
|
|
35
|
+
interface NativeCommands {
|
|
36
|
+
+setNativePage: (
|
|
37
|
+
viewRef: React.ElementRef<ComponentType>,
|
|
38
|
+
page: Int32,
|
|
39
|
+
) => void;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export const Commands: NativeCommands = codegenNativeCommands<NativeCommands>({
|
|
43
|
+
supportedCommands: ['setNativePage'],
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
export default codegenNativeComponent<NativeProps>('RNPDFPdfView');
|
package/index.d.ts
CHANGED
|
@@ -35,6 +35,8 @@ interface Props {
|
|
|
35
35
|
minScale?: number,
|
|
36
36
|
maxScale?: number,
|
|
37
37
|
horizontal?: boolean,
|
|
38
|
+
showsHorizontalScrollIndicator?: boolean,
|
|
39
|
+
showsVerticalScrollIndicator?: boolean,
|
|
38
40
|
spacing?: number,
|
|
39
41
|
password?: string,
|
|
40
42
|
renderActivityIndicator?: (progress: number) => React.ReactElement,
|