react-native-pdf-renderer 1.5.1 → 2.0.0
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 +32 -17
- package/ReactNativePdfRenderer.podspec +9 -2
- package/android/build.gradle +121 -39
- package/android/gradle/wrapper/gradle-wrapper.properties +3 -1
- package/android/src/main/AndroidManifest.xml +1 -2
- package/android/src/main/java/com/github/douglasjunior/reactNativePdfRenderer/PdfRendererPackage.java +32 -9
- package/android/src/main/java/com/github/douglasjunior/reactNativePdfRenderer/PdfRendererViewManagerImpl.java +94 -0
- package/android/src/main/java/com/github/douglasjunior/reactNativePdfRenderer/modules/ObservableZoom.java +63 -63
- package/android/src/main/java/com/github/douglasjunior/reactNativePdfRenderer/modules/PdfRendererRecyclerView.java +30 -33
- package/android/src/newarch/com/github/douglasjunior/reactNativePdfRenderer/modules/PdfRendererViewManager.java +102 -0
- package/android/src/oldarch/com/github/douglasjunior/reactNativePdfRenderer/modules/PdfRendererViewManager.java +92 -0
- package/dist/PdfRendererView.d.ts +4 -4
- package/dist/PdfRendererView.js +3 -3
- package/dist/PdfRendererView.js.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/mock.js +17 -0
- package/dist/mock.js.map +1 -1
- package/dist/specs/RNPdfRendererViewNativeComponent.d.ts +19 -0
- package/dist/specs/RNPdfRendererViewNativeComponent.js +4 -0
- package/dist/specs/RNPdfRendererViewNativeComponent.js.map +1 -0
- package/ios/ReactNativePdfRenderer.xcodeproj/project.pbxproj +10 -4
- package/ios/ReactNativePdfRendererLibrary/RNPDFView.h +9 -3
- package/ios/ReactNativePdfRendererLibrary/{RNPDFView.m → RNPDFView.mm} +9 -10
- package/ios/ReactNativePdfRendererLibrary/RNPdfRendererComponentView.h +44 -0
- package/ios/ReactNativePdfRendererLibrary/RNPdfRendererComponentView.mm +134 -0
- package/ios/ReactNativePdfRendererLibrary/RNPdfRendererModule.h +7 -0
- package/ios/ReactNativePdfRendererLibrary/RNPdfRendererModule.m +13 -0
- package/package.json +35 -16
- package/src/PdfRendererView.tsx +147 -0
- package/src/index.ts +24 -0
- package/src/mock.tsx +32 -0
- package/src/specs/RNPdfRendererViewNativeComponent.ts +51 -0
- package/android/src/main/java/com/github/douglasjunior/reactNativePdfRenderer/modules/PdfRendererViewManager.java +0 -118
package/README.md
CHANGED
|
@@ -39,6 +39,21 @@ npm i -S react-native-pdf-renderer
|
|
|
39
39
|
|
|
40
40
|
Go to the folder **your-project/ios** and run `pod install`, and you're done.
|
|
41
41
|
|
|
42
|
+
### Android specific (optional)
|
|
43
|
+
|
|
44
|
+
Customize the [`androidx.recyclerview:recyclerview`](https://developer.android.com/jetpack/androidx/releases/recyclerview) version by setting `ext` in your `android/build.gradle` file.
|
|
45
|
+
|
|
46
|
+
Example:
|
|
47
|
+
|
|
48
|
+
```gradle
|
|
49
|
+
buildscript {
|
|
50
|
+
ext {
|
|
51
|
+
recyclerviewVersion = "1.2.1"
|
|
52
|
+
}
|
|
53
|
+
...
|
|
54
|
+
}
|
|
55
|
+
```
|
|
56
|
+
|
|
42
57
|
## Basic usage
|
|
43
58
|
|
|
44
59
|
There is only one component that you need to use to render the PDF file.
|
|
@@ -47,19 +62,19 @@ There is only one component that you need to use to render the PDF file.
|
|
|
47
62
|
import PdfRendererView from 'react-native-pdf-renderer';
|
|
48
63
|
|
|
49
64
|
const App = () => {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
65
|
+
return (
|
|
66
|
+
<SafeAreaView style={{flex: 1}}>
|
|
67
|
+
<PdfRendererView
|
|
68
|
+
style={{backgroundColor: 'red'}}
|
|
69
|
+
source="file:///path/to/local/file.pdf"
|
|
70
|
+
distanceBetweenPages={16}
|
|
71
|
+
maxZoom={5}
|
|
72
|
+
onPageChange={(current, total) => {
|
|
73
|
+
console.log(current, total);
|
|
74
|
+
}}
|
|
75
|
+
/>
|
|
76
|
+
</SafeAreaView>
|
|
77
|
+
);
|
|
63
78
|
}
|
|
64
79
|
|
|
65
80
|
export default App;
|
|
@@ -79,7 +94,7 @@ For more details, see the [Sample Project](https://github.com/douglasjunior/reac
|
|
|
79
94
|
|distanceBetweenPages|`number`|`16`|Distance in `DPI` between pages.|
|
|
80
95
|
|maxZoom|`number`|`5`|Max zoom scale.|
|
|
81
96
|
|maxPageResolution|`number`|`2048`|(Android only) Max page resolution (width/height) in pixels when zooming. Defined to prevent Android crash when zooming too much: https://github.com/douglasjunior/react-native-pdf-renderer/issues/26 . |
|
|
82
|
-
|singlePage|`boolean`|`false`|
|
|
97
|
+
|singlePage|`boolean`|`false`|Renders only the first page without scroll. (useful for display thumbnail)|
|
|
83
98
|
|onPageChange|`(current: number, total: number) => void`||Invoked on pages scroll.|
|
|
84
99
|
|style|`StyleProp<ViewStyle>`||Styles to be applied to the native [view](https://reactnative.dev/docs/view-style-props).|
|
|
85
100
|
|
|
@@ -103,9 +118,9 @@ If you need `borderRadius`, the best option is to wrap the `PdfRendererView` in
|
|
|
103
118
|
|
|
104
119
|
```jsx
|
|
105
120
|
<View style={{ flex: 1, borderRadius: 24, overflow: 'hidden' }}>
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
121
|
+
<PdfRendererView
|
|
122
|
+
// ...
|
|
123
|
+
/>
|
|
109
124
|
</View>
|
|
110
125
|
```
|
|
111
126
|
|
|
@@ -3,6 +3,7 @@ require 'json'
|
|
|
3
3
|
packageJson = JSON.parse(File.read('package.json'))
|
|
4
4
|
version = packageJson["version"]
|
|
5
5
|
repository = packageJson["repository"]["url"]
|
|
6
|
+
fabric_enabled = ENV['RCT_NEW_ARCH_ENABLED'] == '1'
|
|
6
7
|
|
|
7
8
|
Pod::Spec.new do |s|
|
|
8
9
|
s.name = "ReactNativePdfRenderer"
|
|
@@ -15,7 +16,13 @@ Pod::Spec.new do |s|
|
|
|
15
16
|
s.source = { :git => repository, :tag => version }
|
|
16
17
|
s.platform = :ios, "11.0"
|
|
17
18
|
s.preserve_paths = 'README.md', 'package.json', '*.js'
|
|
18
|
-
s.source_files = 'ios/ReactNativePdfRendererLibrary/**/*.{h,m}'
|
|
19
|
+
s.source_files = 'ios/ReactNativePdfRendererLibrary/**/*.{h,m,mm,swift}'
|
|
19
20
|
|
|
20
|
-
s.
|
|
21
|
+
s.frameworks = 'PDFKit'
|
|
22
|
+
|
|
23
|
+
if fabric_enabled
|
|
24
|
+
install_modules_dependencies(s)
|
|
25
|
+
else
|
|
26
|
+
s.dependency "React-Core"
|
|
27
|
+
end
|
|
21
28
|
end
|
package/android/build.gradle
CHANGED
|
@@ -1,62 +1,144 @@
|
|
|
1
1
|
buildscript {
|
|
2
|
-
ext.
|
|
3
|
-
|
|
2
|
+
ext.IS_ROOT = project == rootProject
|
|
3
|
+
|
|
4
|
+
repositories {
|
|
5
|
+
mavenCentral()
|
|
6
|
+
google()
|
|
4
7
|
}
|
|
5
8
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
repositories {
|
|
11
|
-
google()
|
|
12
|
-
mavenCentral()
|
|
13
|
-
}
|
|
9
|
+
dependencies {
|
|
10
|
+
classpath("com.android.tools.build:gradle:8.10.1")
|
|
11
|
+
}
|
|
12
|
+
}
|
|
14
13
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
def isNewArchitectureEnabled() {
|
|
15
|
+
// To opt-in for the New Architecture, you can either:
|
|
16
|
+
// - Set `newArchEnabled` to true inside the `gradle.properties` file
|
|
17
|
+
// - Invoke gradle with `-newArchEnabled=true`
|
|
18
|
+
// - Set an environment variable `ORG_GRADLE_PROJECT_newArchEnabled=true`
|
|
19
|
+
return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true"
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
def safeExtGet(prop, fallback) {
|
|
23
|
+
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
def resolveReactNativeDirectory() {
|
|
27
|
+
def reactNativeLocation = safeExtGet("REACT_NATIVE_NODE_MODULES_DIR", null)
|
|
28
|
+
if (reactNativeLocation != null) {
|
|
29
|
+
return file(reactNativeLocation)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Fallback to node resolver for custom directory structures like monorepos.
|
|
33
|
+
def reactNativePackage = file(
|
|
34
|
+
providers.exec {
|
|
35
|
+
workingDir(rootDir)
|
|
36
|
+
commandLine("node", "--print", "require.resolve('react-native/package.json')")
|
|
37
|
+
}.standardOutput.asText.get().trim()
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
if (reactNativePackage.exists()) {
|
|
41
|
+
return reactNativePackage.parentFile
|
|
19
42
|
}
|
|
43
|
+
|
|
44
|
+
throw new Exception(
|
|
45
|
+
"[react-native-pdf-renderer] Unable to resolve react-native location in " +
|
|
46
|
+
"node_modules. You should add project extension property (in app/build.gradle) " +
|
|
47
|
+
"`REACT_NATIVE_NODE_MODULES_DIR` with path to react-native."
|
|
48
|
+
)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (isNewArchitectureEnabled()) {
|
|
52
|
+
apply plugin: 'com.facebook.react'
|
|
20
53
|
}
|
|
21
54
|
|
|
22
55
|
apply plugin: 'com.android.library'
|
|
56
|
+
apply plugin: 'kotlin-android'
|
|
57
|
+
|
|
58
|
+
def reactNativeArchitectures() {
|
|
59
|
+
def value = project.getProperties().get("reactNativeArchitectures")
|
|
60
|
+
return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
def REACT_NATIVE_DIR = resolveReactNativeDirectory()
|
|
64
|
+
|
|
65
|
+
def reactProperties = new Properties()
|
|
66
|
+
file("$REACT_NATIVE_DIR/ReactAndroid/gradle.properties").withInputStream { reactProperties.load(it) }
|
|
67
|
+
|
|
68
|
+
def REACT_NATIVE_VERSION = reactProperties.getProperty("VERSION_NAME")
|
|
69
|
+
def REACT_NATIVE_MINOR_VERSION = REACT_NATIVE_VERSION.split("\\.")[1].toInteger()
|
|
70
|
+
|
|
71
|
+
repositories {
|
|
72
|
+
mavenCentral()
|
|
73
|
+
}
|
|
23
74
|
|
|
24
75
|
android {
|
|
25
|
-
|
|
26
|
-
//noinspection GradleDependency
|
|
27
|
-
buildToolsVersion safeExtGet('buildToolsVersion', '30.0.2')
|
|
76
|
+
compileSdk safeExtGet('compileSdkVersion', 35)
|
|
28
77
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
78
|
+
namespace = "com.github.douglasjunior.reactNativePdfRenderer"
|
|
79
|
+
buildFeatures {
|
|
80
|
+
buildConfig = true
|
|
81
|
+
prefab = true
|
|
33
82
|
}
|
|
34
|
-
|
|
35
|
-
|
|
83
|
+
|
|
84
|
+
// Used to override the NDK path/version on internal CI or by allowing
|
|
85
|
+
// users to customize the NDK path/version from their root project (e.g. for M1 support)
|
|
86
|
+
if (rootProject.hasProperty("ndkPath")) {
|
|
87
|
+
ndkPath rootProject.ext.ndkPath
|
|
88
|
+
}
|
|
89
|
+
if (rootProject.hasProperty("ndkVersion")) {
|
|
90
|
+
ndkVersion rootProject.ext.ndkVersion
|
|
36
91
|
}
|
|
37
|
-
}
|
|
38
92
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
93
|
+
defaultConfig {
|
|
94
|
+
minSdkVersion safeExtGet('minSdkVersion', 24)
|
|
95
|
+
targetSdkVersion safeExtGet('targetSdkVersion', 35)
|
|
96
|
+
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
|
|
97
|
+
buildConfigField "int", "REACT_NATIVE_MINOR_VERSION", REACT_NATIVE_MINOR_VERSION.toString()
|
|
98
|
+
|
|
99
|
+
if (isNewArchitectureEnabled()) {
|
|
100
|
+
var appProject = rootProject.allprojects.find { it.plugins.hasPlugin('com.android.application') }
|
|
101
|
+
externalNativeBuild {
|
|
102
|
+
cmake {
|
|
103
|
+
cppFlags "-O2", "-frtti", "-fexceptions", "-Wall", "-Werror", "-std=c++20", "-DANDROID"
|
|
104
|
+
arguments "-DREACT_NATIVE_DIR=${REACT_NATIVE_DIR}",
|
|
105
|
+
"-DREACT_NATIVE_MINOR_VERSION=${REACT_NATIVE_MINOR_VERSION}",
|
|
106
|
+
"-DANDROID_STL=c++_shared",
|
|
107
|
+
"-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON"
|
|
108
|
+
abiFilters(*reactNativeArchitectures())
|
|
109
|
+
}
|
|
110
|
+
}
|
|
46
111
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
112
|
+
|
|
113
|
+
compileOptions {
|
|
114
|
+
sourceCompatibility JavaVersion.VERSION_1_8
|
|
115
|
+
targetCompatibility JavaVersion.VERSION_1_8
|
|
50
116
|
}
|
|
51
117
|
|
|
52
|
-
|
|
53
|
-
|
|
118
|
+
packagingOptions {
|
|
119
|
+
// For some reason gradle only complains about the duplicated version of libreact_render libraries
|
|
120
|
+
// while there are more libraries copied in intermediates folder of the lib build directory, we exclude
|
|
121
|
+
// only the ones that make the build fail
|
|
122
|
+
exclude "**/libreact_render*.so"
|
|
123
|
+
exclude "**/libreactnative.so"
|
|
124
|
+
exclude "**/libjsi.so"
|
|
125
|
+
exclude "**/libc++_shared.so"
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
sourceSets {
|
|
129
|
+
main {
|
|
130
|
+
if (isNewArchitectureEnabled()) {
|
|
131
|
+
java.srcDirs += ['src/newarch']
|
|
132
|
+
} else {
|
|
133
|
+
java.srcDirs += ['src/oldarch']
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
54
137
|
}
|
|
55
138
|
}
|
|
56
139
|
|
|
57
140
|
dependencies {
|
|
58
|
-
//
|
|
59
|
-
implementation "com.facebook.react:react-native:${safeExtGet('reactNativeVersion', '+')}"
|
|
141
|
+
implementation 'com.facebook.react:react-native:+' // from node_modules
|
|
60
142
|
|
|
61
|
-
implementation "androidx.recyclerview:recyclerview:${safeExtGet('recyclerViewVersion', '1.
|
|
143
|
+
implementation "androidx.recyclerview:recyclerview:${safeExtGet('recyclerViewVersion', '1.4.0')}"
|
|
62
144
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
distributionBase=GRADLE_USER_HOME
|
|
2
2
|
distributionPath=wrapper/dists
|
|
3
|
-
distributionUrl=https\://services.gradle.org/distributions/gradle-
|
|
3
|
+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip
|
|
4
|
+
networkTimeout=10000
|
|
5
|
+
validateDistributionUrl=true
|
|
4
6
|
zipStoreBase=GRADLE_USER_HOME
|
|
5
7
|
zipStorePath=wrapper/dists
|
|
@@ -23,28 +23,51 @@
|
|
|
23
23
|
package com.github.douglasjunior.reactNativePdfRenderer;
|
|
24
24
|
|
|
25
25
|
import androidx.annotation.NonNull;
|
|
26
|
+
import androidx.annotation.Nullable;
|
|
26
27
|
|
|
27
|
-
import com.facebook.react.
|
|
28
|
+
import com.facebook.react.BaseReactPackage;
|
|
28
29
|
import com.facebook.react.bridge.NativeModule;
|
|
29
30
|
import com.facebook.react.bridge.ReactApplicationContext;
|
|
31
|
+
import com.facebook.react.module.model.ReactModuleInfo;
|
|
32
|
+
import com.facebook.react.module.model.ReactModuleInfoProvider;
|
|
30
33
|
import com.facebook.react.uimanager.ViewManager;
|
|
31
34
|
import com.github.douglasjunior.reactNativePdfRenderer.modules.PdfRendererViewManager;
|
|
32
35
|
|
|
33
36
|
import java.util.Collections;
|
|
37
|
+
import java.util.HashMap;
|
|
34
38
|
import java.util.List;
|
|
39
|
+
import java.util.Map;
|
|
40
|
+
|
|
41
|
+
public class PdfRendererPackage extends BaseReactPackage {
|
|
42
|
+
|
|
43
|
+
@Nullable
|
|
44
|
+
@Override
|
|
45
|
+
public NativeModule getModule(@NonNull String s, @NonNull ReactApplicationContext reactApplicationContext) {
|
|
46
|
+
if (PdfRendererViewManagerImpl.REACT_CLASS.equals(s)) {
|
|
47
|
+
return new PdfRendererViewManager(reactApplicationContext);
|
|
48
|
+
}
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
35
51
|
|
|
36
|
-
public class PdfRendererPackage implements ReactPackage {
|
|
37
|
-
@NonNull
|
|
38
52
|
@Override
|
|
39
|
-
public List<
|
|
40
|
-
return Collections.
|
|
53
|
+
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
|
|
54
|
+
return Collections.singletonList(new PdfRendererViewManager(reactContext));
|
|
41
55
|
}
|
|
42
56
|
|
|
43
57
|
@NonNull
|
|
44
58
|
@Override
|
|
45
|
-
public
|
|
46
|
-
return
|
|
47
|
-
|
|
48
|
-
|
|
59
|
+
public ReactModuleInfoProvider getReactModuleInfoProvider() {
|
|
60
|
+
return () -> {
|
|
61
|
+
Map<String, ReactModuleInfo> map = new HashMap<>();
|
|
62
|
+
map.put(PdfRendererViewManagerImpl.REACT_CLASS, new ReactModuleInfo(
|
|
63
|
+
PdfRendererViewManagerImpl.REACT_CLASS, // name
|
|
64
|
+
PdfRendererViewManagerImpl.REACT_CLASS, // className
|
|
65
|
+
false, // canOverrideExistingModule
|
|
66
|
+
false, // needsEagerInit
|
|
67
|
+
false, // isCxxModule
|
|
68
|
+
false // isTurboModule
|
|
69
|
+
));
|
|
70
|
+
return map;
|
|
71
|
+
};
|
|
49
72
|
}
|
|
50
73
|
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
// MIT License
|
|
2
|
+
|
|
3
|
+
// Copyright (c) 2025 Douglas Nassif Roma Junior
|
|
4
|
+
|
|
5
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
// of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
// in the Software without restriction, including without limitation the rights
|
|
8
|
+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
// copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
// furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
// The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
// copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
// SOFTWARE.
|
|
22
|
+
|
|
23
|
+
package com.github.douglasjunior.reactNativePdfRenderer;
|
|
24
|
+
|
|
25
|
+
import android.view.View;
|
|
26
|
+
|
|
27
|
+
import androidx.annotation.NonNull;
|
|
28
|
+
|
|
29
|
+
import com.facebook.react.bridge.Arguments;
|
|
30
|
+
import com.facebook.react.bridge.ReadableMap;
|
|
31
|
+
import com.facebook.react.bridge.WritableMap;
|
|
32
|
+
import com.facebook.react.uimanager.events.Event;
|
|
33
|
+
import com.github.douglasjunior.reactNativePdfRenderer.modules.PdfRendererRecyclerView;
|
|
34
|
+
|
|
35
|
+
import java.io.IOException;
|
|
36
|
+
import java.util.HashMap;
|
|
37
|
+
import java.util.Map;
|
|
38
|
+
|
|
39
|
+
public class PdfRendererViewManagerImpl {
|
|
40
|
+
public static final String REACT_CLASS = "RNPdfRendererView";
|
|
41
|
+
public static final String ON_PAGE_CHANGE_EVENT = "onPageChange";
|
|
42
|
+
|
|
43
|
+
public static Map<String, Object> getExportedCustomBubblingEventTypeConstants() {
|
|
44
|
+
Map<String, Object> map = new HashMap<>();
|
|
45
|
+
Map<String, Object> bubblingMap = new HashMap<>();
|
|
46
|
+
bubblingMap.put("phasedRegistrationNames", new HashMap<String, String>() {{
|
|
47
|
+
put("bubbled", ON_PAGE_CHANGE_EVENT);
|
|
48
|
+
}});
|
|
49
|
+
map.put("pageChange", bubblingMap);
|
|
50
|
+
return map;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
public static void setParams(PdfRendererRecyclerView view, ReadableMap params) {
|
|
54
|
+
if (params == null) return;
|
|
55
|
+
|
|
56
|
+
var source = params.getString("source");
|
|
57
|
+
var singlePage = params.hasKey("singlePage") && params.getBoolean("singlePage");
|
|
58
|
+
var maxZoom = params.hasKey("maxZoom") ? Double.valueOf(params.getDouble("maxZoom")).floatValue() : 5;
|
|
59
|
+
|
|
60
|
+
try {
|
|
61
|
+
if (source != null) {
|
|
62
|
+
view.updateSource(source);
|
|
63
|
+
} else {
|
|
64
|
+
view.closeAdapter();
|
|
65
|
+
}
|
|
66
|
+
} catch (IOException e) {
|
|
67
|
+
throw new RuntimeException("Error setting PDF source: " + e.getMessage(), e);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
view.setSinglePage(singlePage);
|
|
71
|
+
view.setMaxZoom(maxZoom);
|
|
72
|
+
view.setOverScrollMode(singlePage ? View.OVER_SCROLL_NEVER : View.OVER_SCROLL_IF_CONTENT_SCROLLS);
|
|
73
|
+
|
|
74
|
+
view.forceRequestLayout();
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
public static Event<?> createOnPageChangeEvent(int surfaceId, int targetId, int position, int total) {
|
|
78
|
+
return new Event<>(surfaceId, targetId) {
|
|
79
|
+
@NonNull
|
|
80
|
+
@Override
|
|
81
|
+
public String getEventName() {
|
|
82
|
+
return "pageChange";
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
@Override
|
|
86
|
+
protected WritableMap getEventData() {
|
|
87
|
+
var data = Arguments.createMap();
|
|
88
|
+
data.putInt("position", position);
|
|
89
|
+
data.putInt("total", total);
|
|
90
|
+
return data;
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
}
|
|
@@ -1,63 +1,63 @@
|
|
|
1
|
-
// MIT License
|
|
2
|
-
|
|
3
|
-
// Copyright (c) 2023 Douglas Nassif Roma Junior
|
|
4
|
-
|
|
5
|
-
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
// of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
// in the Software without restriction, including without limitation the rights
|
|
8
|
-
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
// copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
// furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
// The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
// copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
// SOFTWARE.
|
|
22
|
-
|
|
23
|
-
package com.github.douglasjunior.reactNativePdfRenderer.modules;
|
|
24
|
-
|
|
25
|
-
import java.util.HashSet;
|
|
26
|
-
import java.util.Set;
|
|
27
|
-
|
|
28
|
-
public class ObservableZoom {
|
|
29
|
-
private final Set<ZoomChangeListener> listeners = new HashSet<>();
|
|
30
|
-
private float zoom;
|
|
31
|
-
|
|
32
|
-
public ObservableZoom(int initialZoom) {
|
|
33
|
-
this.zoom = initialZoom;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
public void addListener(ZoomChangeListener listener) {
|
|
37
|
-
this.listeners.add(listener);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
public void removeListener(ZoomChangeListener zoomListener) {
|
|
41
|
-
this.listeners.remove(zoomListener);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
private void notifyListeners() {
|
|
45
|
-
for (ZoomChangeListener listener : listeners) {
|
|
46
|
-
listener.onZoomChange(this.zoom);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
public float getZoom() {
|
|
51
|
-
return zoom;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
public void setZoom(float newZoom) {
|
|
55
|
-
if (newZoom == this.zoom) return;
|
|
56
|
-
this.zoom = newZoom;
|
|
57
|
-
notifyListeners();
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
public interface ZoomChangeListener {
|
|
61
|
-
void onZoomChange(float newZoom);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
1
|
+
// MIT License
|
|
2
|
+
|
|
3
|
+
// Copyright (c) 2023 Douglas Nassif Roma Junior
|
|
4
|
+
|
|
5
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
// of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
// in the Software without restriction, including without limitation the rights
|
|
8
|
+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
// copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
// furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
// The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
// copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
// SOFTWARE.
|
|
22
|
+
|
|
23
|
+
package com.github.douglasjunior.reactNativePdfRenderer.modules;
|
|
24
|
+
|
|
25
|
+
import java.util.HashSet;
|
|
26
|
+
import java.util.Set;
|
|
27
|
+
|
|
28
|
+
public class ObservableZoom {
|
|
29
|
+
private final Set<ZoomChangeListener> listeners = new HashSet<>();
|
|
30
|
+
private float zoom;
|
|
31
|
+
|
|
32
|
+
public ObservableZoom(int initialZoom) {
|
|
33
|
+
this.zoom = initialZoom;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
public void addListener(ZoomChangeListener listener) {
|
|
37
|
+
this.listeners.add(listener);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
public void removeListener(ZoomChangeListener zoomListener) {
|
|
41
|
+
this.listeners.remove(zoomListener);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
private void notifyListeners() {
|
|
45
|
+
for (ZoomChangeListener listener : listeners) {
|
|
46
|
+
listener.onZoomChange(this.zoom);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
public float getZoom() {
|
|
51
|
+
return zoom;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
public void setZoom(float newZoom) {
|
|
55
|
+
if (newZoom == this.zoom) return;
|
|
56
|
+
this.zoom = newZoom;
|
|
57
|
+
notifyListeners();
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
public interface ZoomChangeListener {
|
|
61
|
+
void onZoomChange(float newZoom);
|
|
62
|
+
}
|
|
63
|
+
}
|