react-native-pdf-renderer 1.6.0 → 2.0.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.
Files changed (31) hide show
  1. package/README.md +4 -4
  2. package/ReactNativePdfRenderer.podspec +9 -2
  3. package/android/build.gradle +111 -66
  4. package/android/gradle/wrapper/gradle-wrapper.properties +3 -1
  5. package/android/src/main/java/com/github/douglasjunior/reactNativePdfRenderer/PdfRendererPackage.java +32 -9
  6. package/android/src/main/java/com/github/douglasjunior/reactNativePdfRenderer/PdfRendererViewManagerImpl.java +94 -0
  7. package/android/src/main/java/com/github/douglasjunior/reactNativePdfRenderer/modules/PdfRendererRecyclerView.java +26 -32
  8. package/android/src/newarch/com/github/douglasjunior/reactNativePdfRenderer/modules/PdfRendererViewManager.java +102 -0
  9. package/android/src/oldarch/com/github/douglasjunior/reactNativePdfRenderer/modules/PdfRendererViewManager.java +92 -0
  10. package/dist/PdfRendererView.d.ts +4 -4
  11. package/dist/PdfRendererView.js +3 -3
  12. package/dist/PdfRendererView.js.map +1 -1
  13. package/dist/index.js.map +1 -1
  14. package/dist/mock.js +17 -0
  15. package/dist/mock.js.map +1 -1
  16. package/dist/specs/RNPdfRendererViewNativeComponent.d.ts +19 -0
  17. package/dist/specs/RNPdfRendererViewNativeComponent.js +4 -0
  18. package/dist/specs/RNPdfRendererViewNativeComponent.js.map +1 -0
  19. package/ios/ReactNativePdfRenderer.xcodeproj/project.pbxproj +10 -4
  20. package/ios/ReactNativePdfRendererLibrary/RNPDFView.h +9 -3
  21. package/ios/ReactNativePdfRendererLibrary/{RNPDFView.m → RNPDFView.mm} +9 -10
  22. package/ios/ReactNativePdfRendererLibrary/RNPdfRendererComponentView.h +44 -0
  23. package/ios/ReactNativePdfRendererLibrary/RNPdfRendererComponentView.mm +134 -0
  24. package/ios/ReactNativePdfRendererLibrary/RNPdfRendererModule.h +7 -0
  25. package/ios/ReactNativePdfRendererLibrary/RNPdfRendererModule.m +13 -0
  26. package/package.json +36 -16
  27. package/src/PdfRendererView.tsx +147 -0
  28. package/src/index.ts +24 -0
  29. package/src/mock.tsx +32 -0
  30. package/src/specs/RNPdfRendererViewNativeComponent.ts +51 -0
  31. package/android/src/main/java/com/github/douglasjunior/reactNativePdfRenderer/modules/PdfRendererViewManager.java +0 -118
package/README.md CHANGED
@@ -22,9 +22,9 @@ Every React Native developer knows (or will discover soon) [the pain of updating
22
22
 
23
23
  ## Requirements
24
24
 
25
- - React Native >= 0.60.0
26
- - iOS >= 11.0
27
- - Android >= API 19
25
+ - React Native >= 0.71.0
26
+ - iOS >= 12.0
27
+ - Android >= API 21
28
28
 
29
29
  ## Install
30
30
 
@@ -94,7 +94,7 @@ For more details, see the [Sample Project](https://github.com/douglasjunior/reac
94
94
  |distanceBetweenPages|`number`|`16`|Distance in `DPI` between pages.|
95
95
  |maxZoom|`number`|`5`|Max zoom scale.|
96
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 . |
97
- |singlePage|`boolean`|`false`|(Experimental) Renders only the first page without scroll. (useful for display thumbnail)|
97
+ |singlePage|`boolean`|`false`|Renders only the first page without scroll. (useful for display thumbnail)|
98
98
  |onPageChange|`(current: number, total: number) => void`||Invoked on pages scroll.|
99
99
  |style|`StyleProp<ViewStyle>`||Styles to be applied to the native [view](https://reactnative.dev/docs/view-style-props).|
100
100
 
@@ -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.dependency 'React-Core'
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
@@ -1,99 +1,144 @@
1
- def safeAppExtGet(prop, fallback) {
2
- def appProject = rootProject.allprojects.find { it.plugins.hasPlugin('com.android.application') }
3
- appProject?.ext?.has(prop) ? appProject.ext.get(prop) : fallback
1
+ buildscript {
2
+ ext.IS_ROOT = project == rootProject
3
+
4
+ repositories {
5
+ mavenCentral()
6
+ google()
7
+ }
8
+
9
+ dependencies {
10
+ classpath("com.android.tools.build:gradle:8.10.1")
11
+ }
12
+ }
13
+
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
4
24
  }
5
25
 
6
26
  def resolveReactNativeDirectory() {
7
- def reactNativeLocation = safeAppExtGet("REACT_NATIVE_NODE_MODULES_DIR", null)
27
+ def reactNativeLocation = safeExtGet("REACT_NATIVE_NODE_MODULES_DIR", null)
8
28
  if (reactNativeLocation != null) {
9
29
  return file(reactNativeLocation)
10
30
  }
11
31
 
12
- // monorepo workaround
13
- // react-native can be hoisted or in project's own node_modules
14
- def reactNativeFromProjectNodeModules = file("${rootProject.projectDir}/../node_modules/react-native")
15
- if (reactNativeFromProjectNodeModules.exists()) {
16
- return reactNativeFromProjectNodeModules
17
- }
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
+ )
18
39
 
19
- def reactNativeFromNodeModulesWithReanimated = file("${projectDir}/../../react-native")
20
- if (reactNativeFromNodeModulesWithReanimated.exists()) {
21
- return reactNativeFromNodeModulesWithReanimated
40
+ if (reactNativePackage.exists()) {
41
+ return reactNativePackage.parentFile
22
42
  }
23
43
 
24
- throw new GradleException(
25
- "Unable to resolve react-native location in node_modules. You should project extension property (in `app/build.gradle`) `REACT_NATIVE_NODE_MODULES_DIR` with path to react-native."
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."
26
48
  )
27
49
  }
28
50
 
29
- def reactNativeRootDir = resolveReactNativeDirectory()
51
+ if (isNewArchitectureEnabled()) {
52
+ apply plugin: 'com.facebook.react'
53
+ }
54
+
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()
30
64
 
31
65
  def reactProperties = new Properties()
32
- file("$reactNativeRootDir/ReactAndroid/gradle.properties").withInputStream { reactProperties.load(it) }
66
+ file("$REACT_NATIVE_DIR/ReactAndroid/gradle.properties").withInputStream { reactProperties.load(it) }
33
67
 
34
68
  def REACT_NATIVE_VERSION = reactProperties.getProperty("VERSION_NAME")
35
- def REACT_NATIVE_MINOR_VERSION = REACT_NATIVE_VERSION.startsWith("0.0.0-") ? 1000 : REACT_NATIVE_VERSION.split("\\.")[1].toInteger()
69
+ def REACT_NATIVE_MINOR_VERSION = REACT_NATIVE_VERSION.split("\\.")[1].toInteger()
36
70
 
37
- buildscript {
38
- ext.safeExtGet = { prop, fallback ->
39
- rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
40
- }
41
- ext.IS_ROOT = project == rootProject
71
+ repositories {
72
+ mavenCentral()
73
+ }
42
74
 
43
- // The Android Gradle plugin is only required when opening the android folder stand-alone.
44
- // This avoids unnecessary downloads and potential conflicts when the library is included as a
45
- // module dependency in an application project.
75
+ android {
76
+ compileSdk safeExtGet('compileSdkVersion', 35)
46
77
 
47
- if (IS_ROOT) {
48
- repositories {
49
- google()
50
- mavenCentral()
51
- }
52
- dependencies {
53
- classpath "com.android.tools.build:gradle:7.3.1"
54
- }
78
+ namespace = "com.github.douglasjunior.reactNativePdfRenderer"
79
+ buildFeatures {
80
+ buildConfig = true
81
+ prefab = true
55
82
  }
56
- }
57
83
 
58
- apply plugin: 'com.android.library'
59
-
60
- android {
61
- namespace "com.github.douglasjunior.reactNativePdfRenderer"
62
- compileSdkVersion safeExtGet("compileSdkVersion", 33)
63
- defaultConfig {
64
- minSdkVersion safeExtGet('minSdkVersion', 21)
65
- //noinspection OldTargetApi
66
- targetSdkVersion safeExtGet('targetSdkVersion', 33)
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
67
88
  }
68
- lintOptions {
69
- abortOnError false
89
+ if (rootProject.hasProperty("ndkVersion")) {
90
+ ndkVersion rootProject.ext.ndkVersion
70
91
  }
71
- }
72
92
 
73
- repositories {
74
- mavenCentral()
75
- mavenLocal()
76
- if (REACT_NATIVE_MINOR_VERSION < 71) {
77
- maven {
78
- // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
79
- url "$reactNativeRootDir/android"
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
+ }
111
+ }
112
+
113
+ compileOptions {
114
+ sourceCompatibility JavaVersion.VERSION_1_8
115
+ targetCompatibility JavaVersion.VERSION_1_8
80
116
  }
81
- maven {
82
- // Android JSC is installed from npm
83
- url "$reactNativeRootDir/../jsc-android/dist"
117
+
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
+ }
84
136
  }
85
137
  }
86
- google()
87
138
  }
88
139
 
89
140
  dependencies {
90
- if (REACT_NATIVE_MINOR_VERSION >= 71) {
91
- implementation "com.facebook.react:react-android${IS_ROOT ? ':+' : ''}"
92
- // version substituted by RNGP
93
- } else {
94
- // noinspection GradleDynamicVersion
95
- implementation "com.facebook.react:react-native:+" // From node_modules
96
- }
141
+ implementation 'com.facebook.react:react-native:+' // from node_modules
97
142
 
98
- implementation "androidx.recyclerview:recyclerview:${safeExtGet('recyclerViewVersion', '1.2.1')}"
143
+ implementation "androidx.recyclerview:recyclerview:${safeExtGet('recyclerViewVersion', '1.4.0')}"
99
144
  }
@@ -1,5 +1,7 @@
1
1
  distributionBase=GRADLE_USER_HOME
2
2
  distributionPath=wrapper/dists
3
- distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
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.ReactPackage;
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<NativeModule> createNativeModules(@NonNull ReactApplicationContext reactApplicationContext) {
40
- return Collections.emptyList();
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 List<ViewManager> createViewManagers(@NonNull ReactApplicationContext reactApplicationContext) {
46
- return Collections.singletonList(
47
- new PdfRendererViewManager(reactApplicationContext)
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
+ }
@@ -41,27 +41,21 @@ import android.view.ViewGroup;
41
41
  import android.widget.ImageView;
42
42
 
43
43
  import androidx.annotation.NonNull;
44
- import androidx.core.view.ViewCompat;
45
44
  import androidx.recyclerview.widget.LinearLayoutManager;
46
45
  import androidx.recyclerview.widget.RecyclerView;
47
46
 
48
- import com.facebook.react.bridge.Arguments;
49
- import com.facebook.react.bridge.ReactApplicationContext;
50
- import com.facebook.react.uimanager.events.RCTEventEmitter;
51
-
52
47
  import java.io.File;
53
48
  import java.io.IOException;
54
49
 
55
50
  @SuppressLint({"ViewConstructor", "NotifyDataSetChanged"})
56
51
  public class PdfRendererRecyclerView extends RecyclerView {
57
- private final ViewGroup mParent;
58
52
  private final GestureDetector mGestureDetector;
59
53
  private final int mMinZoom = 1;
60
- private final ReactApplicationContext mReactApplicationContext;
61
54
  private final ScaleGestureDetector mScaleDetector;
62
55
  private final Matrix mMatrix;
63
56
  private final ObservableZoom mZoomObserver;
64
57
  private final LayoutManager mLayoutManager;
58
+ private final PdfRendererRecyclerViewListener mListener;
65
59
  private boolean mRequestedLayout = false;
66
60
  private float mMaxZoom = 5;
67
61
  private float mMaxPageResolution;
@@ -71,7 +65,7 @@ public class PdfRendererRecyclerView extends RecyclerView {
71
65
  private int mCurrentItemPosition = -1;
72
66
  private boolean mSinglePage;
73
67
 
74
- public PdfRendererRecyclerView(@NonNull ReactApplicationContext context, ViewGroup parent) {
68
+ public PdfRendererRecyclerView(@NonNull Context context, PdfRendererRecyclerViewListener listener) {
75
69
  super(context);
76
70
 
77
71
  mZoomObserver = new ObservableZoom(mMinZoom);
@@ -90,11 +84,13 @@ public class PdfRendererRecyclerView extends RecyclerView {
90
84
  }
91
85
  });
92
86
 
93
- mReactApplicationContext = context;
94
- mParent = parent;
87
+ mListener = listener;
95
88
  mMatrix = new Matrix();
96
89
  mScaleDetector = new ScaleGestureDetector(getContext(), new ScaleListener());
97
90
  mGestureDetector = new GestureDetector(context, new GestureListener());
91
+
92
+ this.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
93
+ this.setClipToOutline(true);
98
94
  }
99
95
 
100
96
  public void setDistanceBetweenPages(float distanceBetweenPages) {
@@ -124,16 +120,6 @@ public class PdfRendererRecyclerView extends RecyclerView {
124
120
  }
125
121
  }
126
122
 
127
- public void updateSource(String source) throws IOException {
128
- mCurrentItemPosition = -1;
129
- var adapter = (PdfRendererAdapter) getAdapter();
130
- if (adapter == null) return;
131
- adapter.close();
132
- adapter.updateSource(source);
133
- adapter.notifyDataSetChanged();
134
- post(this::dispatchPageChangeEvent);
135
- }
136
-
137
123
  private void dispatchPageChangeEvent() {
138
124
  var newPosition = mLayoutManager.findLastCompletelyVisibleItemPosition();
139
125
  if (newPosition < 0) newPosition = mLayoutManager.findLastVisibleItemPosition();
@@ -144,16 +130,20 @@ public class PdfRendererRecyclerView extends RecyclerView {
144
130
  var adapter = (PdfRendererAdapter) getAdapter();
145
131
  if (adapter == null) return;
146
132
 
147
- var event = Arguments.createMap();
148
- event.putInt("position", newPosition);
149
- event.putInt("total", adapter.getPageCount());
150
-
151
- mReactApplicationContext
152
- .getJSModule(RCTEventEmitter.class)
153
- .receiveEvent(mParent.getId(), "pageChange", event);
133
+ mListener.onPageChange(this, newPosition, adapter.getPageCount());
154
134
  }
155
135
  }
156
136
 
137
+ public void updateSource(String source) throws IOException {
138
+ mCurrentItemPosition = -1;
139
+ var adapter = (PdfRendererAdapter) getAdapter();
140
+ if (adapter == null) return;
141
+ adapter.close();
142
+ adapter.updateSource(source);
143
+ adapter.notifyDataSetChanged();
144
+ post(this::dispatchPageChangeEvent);
145
+ }
146
+
157
147
  @Override
158
148
  protected void dispatchDraw(@NonNull Canvas canvas) {
159
149
  canvas.save();
@@ -260,7 +250,7 @@ public class PdfRendererRecyclerView extends RecyclerView {
260
250
 
261
251
  /**
262
252
  * Fix a problem with React Native layout
263
- * https://stackoverflow.com/a/49381907/2826279
253
+ * <a href="https://stackoverflow.com/a/49381907/2826279">Read more</a>
264
254
  */
265
255
  @SuppressLint("WrongCall")
266
256
  @Override
@@ -278,6 +268,10 @@ public class PdfRendererRecyclerView extends RecyclerView {
278
268
  this.mSinglePage = singlePage;
279
269
  }
280
270
 
271
+ public interface PdfRendererRecyclerViewListener {
272
+ void onPageChange(PdfRendererRecyclerView target, int position, int total);
273
+ }
274
+
281
275
  private class ScaleListener extends ScaleGestureDetector.SimpleOnScaleGestureListener {
282
276
  @Override
283
277
  public boolean onScale(ScaleGestureDetector detector) {
@@ -293,7 +287,7 @@ public class PdfRendererRecyclerView extends RecyclerView {
293
287
 
294
288
  mMatrix.postScale(factor, factor, getWidth() / 2f, getHeight() / 2f);
295
289
  validateMatrixLimits();
296
- ViewCompat.postInvalidateOnAnimation(PdfRendererRecyclerView.this);
290
+ postInvalidateOnAnimation();
297
291
 
298
292
  return true;
299
293
  }
@@ -312,10 +306,10 @@ public class PdfRendererRecyclerView extends RecyclerView {
312
306
 
313
307
  private class GestureListener extends GestureDetector.SimpleOnGestureListener {
314
308
  @Override
315
- public boolean onScroll(MotionEvent e1, MotionEvent e2, float dX, float dY) {
309
+ public boolean onScroll(MotionEvent e1, @NonNull MotionEvent e2, float dX, float dY) {
316
310
  mMatrix.postTranslate(-dX, -dY);
317
311
  validateMatrixLimits();
318
- ViewCompat.postInvalidateOnAnimation(PdfRendererRecyclerView.this);
312
+ postInvalidateOnAnimation();
319
313
  return true;
320
314
  }
321
315
 
@@ -338,7 +332,7 @@ public class PdfRendererRecyclerView extends RecyclerView {
338
332
 
339
333
  validateMatrixLimits();
340
334
 
341
- ViewCompat.postInvalidateOnAnimation(PdfRendererRecyclerView.this);
335
+ postInvalidateOnAnimation();
342
336
 
343
337
  mZoomObserver.setZoom(newZoom);
344
338
  return true;
@@ -0,0 +1,102 @@
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.modules;
24
+
25
+ import static com.github.douglasjunior.reactNativePdfRenderer.PdfRendererViewManagerImpl.REACT_CLASS;
26
+
27
+ import androidx.annotation.NonNull;
28
+ import androidx.annotation.Nullable;
29
+
30
+ import com.facebook.react.bridge.ReactApplicationContext;
31
+ import com.facebook.react.bridge.ReadableMap;
32
+ import com.facebook.react.module.annotations.ReactModule;
33
+ import com.facebook.react.uimanager.SimpleViewManager;
34
+ import com.facebook.react.uimanager.ThemedReactContext;
35
+ import com.facebook.react.uimanager.UIManagerHelper;
36
+ import com.facebook.react.uimanager.annotations.ReactProp;
37
+ import com.facebook.react.uimanager.events.EventDispatcher;
38
+ import com.facebook.react.viewmanagers.RNPdfRendererViewManagerInterface;
39
+ import com.github.douglasjunior.reactNativePdfRenderer.PdfRendererViewManagerImpl;
40
+
41
+ import java.util.Map;
42
+
43
+ @ReactModule(name = REACT_CLASS)
44
+ public class PdfRendererViewManager extends SimpleViewManager<PdfRendererRecyclerView> implements RNPdfRendererViewManagerInterface<PdfRendererRecyclerView>, PdfRendererRecyclerView.PdfRendererRecyclerViewListener {
45
+
46
+ private final ReactApplicationContext mReactApplicationContext;
47
+
48
+ public PdfRendererViewManager(ReactApplicationContext reactApplicationContext) {
49
+ this.mReactApplicationContext = reactApplicationContext;
50
+ }
51
+
52
+ @NonNull
53
+ @Override
54
+ public String getName() {
55
+ return REACT_CLASS;
56
+ }
57
+
58
+ @NonNull
59
+ @Override
60
+ protected PdfRendererRecyclerView createViewInstance(@NonNull ThemedReactContext themedReactContext) {
61
+ return new PdfRendererRecyclerView(mReactApplicationContext, this);
62
+ }
63
+
64
+ @Nullable
65
+ @Override
66
+ public Map<String, Object> getExportedCustomBubblingEventTypeConstants() {
67
+ return PdfRendererViewManagerImpl.getExportedCustomBubblingEventTypeConstants();
68
+ }
69
+
70
+ @Override
71
+ public void onPageChange(PdfRendererRecyclerView target, int position, int total) {
72
+ EventDispatcher eventDispatcher = UIManagerHelper.getEventDispatcherForReactTag(
73
+ mReactApplicationContext,
74
+ target.getId()
75
+ );
76
+
77
+ if (eventDispatcher != null) {
78
+ int surfaceId = UIManagerHelper.getSurfaceId(mReactApplicationContext);
79
+ eventDispatcher.dispatchEvent(
80
+ PdfRendererViewManagerImpl.createOnPageChangeEvent(surfaceId, target.getId(), position, total)
81
+ );
82
+ }
83
+ }
84
+
85
+ @ReactProp(name = "maxPageResolution")
86
+ @Override
87
+ public void setMaxPageResolution(PdfRendererRecyclerView view, float value) {
88
+ view.setMaxPageResolution(value);
89
+ }
90
+
91
+ @ReactProp(name = "distanceBetweenPages")
92
+ @Override
93
+ public void setDistanceBetweenPages(PdfRendererRecyclerView view, float value) {
94
+ view.setDistanceBetweenPages(value);
95
+ }
96
+
97
+ @ReactProp(name = "params")
98
+ @Override
99
+ public void setParams(PdfRendererRecyclerView view, @Nullable ReadableMap params) {
100
+ PdfRendererViewManagerImpl.setParams(view, params);
101
+ }
102
+ }