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.
Files changed (33) hide show
  1. package/README.md +32 -17
  2. package/ReactNativePdfRenderer.podspec +9 -2
  3. package/android/build.gradle +121 -39
  4. package/android/gradle/wrapper/gradle-wrapper.properties +3 -1
  5. package/android/src/main/AndroidManifest.xml +1 -2
  6. package/android/src/main/java/com/github/douglasjunior/reactNativePdfRenderer/PdfRendererPackage.java +32 -9
  7. package/android/src/main/java/com/github/douglasjunior/reactNativePdfRenderer/PdfRendererViewManagerImpl.java +94 -0
  8. package/android/src/main/java/com/github/douglasjunior/reactNativePdfRenderer/modules/ObservableZoom.java +63 -63
  9. package/android/src/main/java/com/github/douglasjunior/reactNativePdfRenderer/modules/PdfRendererRecyclerView.java +30 -33
  10. package/android/src/newarch/com/github/douglasjunior/reactNativePdfRenderer/modules/PdfRendererViewManager.java +102 -0
  11. package/android/src/oldarch/com/github/douglasjunior/reactNativePdfRenderer/modules/PdfRendererViewManager.java +92 -0
  12. package/dist/PdfRendererView.d.ts +4 -4
  13. package/dist/PdfRendererView.js +3 -3
  14. package/dist/PdfRendererView.js.map +1 -1
  15. package/dist/index.js.map +1 -1
  16. package/dist/mock.js +17 -0
  17. package/dist/mock.js.map +1 -1
  18. package/dist/specs/RNPdfRendererViewNativeComponent.d.ts +19 -0
  19. package/dist/specs/RNPdfRendererViewNativeComponent.js +4 -0
  20. package/dist/specs/RNPdfRendererViewNativeComponent.js.map +1 -0
  21. package/ios/ReactNativePdfRenderer.xcodeproj/project.pbxproj +10 -4
  22. package/ios/ReactNativePdfRendererLibrary/RNPDFView.h +9 -3
  23. package/ios/ReactNativePdfRendererLibrary/{RNPDFView.m → RNPDFView.mm} +9 -10
  24. package/ios/ReactNativePdfRendererLibrary/RNPdfRendererComponentView.h +44 -0
  25. package/ios/ReactNativePdfRendererLibrary/RNPdfRendererComponentView.mm +134 -0
  26. package/ios/ReactNativePdfRendererLibrary/RNPdfRendererModule.h +7 -0
  27. package/ios/ReactNativePdfRendererLibrary/RNPdfRendererModule.m +13 -0
  28. package/package.json +35 -16
  29. package/src/PdfRendererView.tsx +147 -0
  30. package/src/index.ts +24 -0
  31. package/src/mock.tsx +32 -0
  32. package/src/specs/RNPdfRendererViewNativeComponent.ts +51 -0
  33. package/android/src/main/java/com/github/douglasjunior/reactNativePdfRenderer/modules/PdfRendererViewManager.java +0 -118
@@ -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;
@@ -433,11 +427,14 @@ public class PdfRendererRecyclerView extends RecyclerView {
433
427
 
434
428
  float zoomFactor = Math.min(newZoom, scalingFactor);
435
429
 
436
- return Bitmap.createBitmap(
430
+ var bitmap = Bitmap.createBitmap(
437
431
  Math.round(scaledPageWidth * zoomFactor),
438
432
  Math.round(scaledPageHeight * zoomFactor),
439
433
  Bitmap.Config.ARGB_8888
440
434
  );
435
+ // Fill the bitmap with white color by default to prevent issues with transparent PDFs
436
+ bitmap.eraseColor(Color.WHITE);
437
+ return bitmap;
441
438
  }
442
439
 
443
440
  public void update(int position, float newZoom) {
@@ -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
+ }
@@ -0,0 +1,92 @@
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 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.uimanager.SimpleViewManager;
33
+ import com.facebook.react.uimanager.ThemedReactContext;
34
+ import com.facebook.react.uimanager.UIManagerHelper;
35
+ import com.facebook.react.uimanager.UIManagerModule;
36
+ import com.facebook.react.uimanager.annotations.ReactProp;
37
+ import com.github.douglasjunior.reactNativePdfRenderer.PdfRendererViewManagerImpl;
38
+
39
+ import java.io.IOException;
40
+ import java.util.Map;
41
+
42
+ public class PdfRendererViewManager extends SimpleViewManager<PdfRendererRecyclerView> implements PdfRendererRecyclerView.PdfRendererRecyclerViewListener {
43
+ private final ReactApplicationContext mReactApplicationContext;
44
+
45
+ public PdfRendererViewManager(ReactApplicationContext reactApplicationContext) {
46
+ this.mReactApplicationContext = reactApplicationContext;
47
+ }
48
+
49
+ @NonNull
50
+ @Override
51
+ public String getName() {
52
+ return REACT_CLASS;
53
+ }
54
+
55
+ @NonNull
56
+ @Override
57
+ protected PdfRendererRecyclerView createViewInstance(@NonNull ThemedReactContext themedReactContext) {
58
+ return new PdfRendererRecyclerView(mReactApplicationContext, this);
59
+ }
60
+
61
+ @Nullable
62
+ @Override
63
+ public Map<String, Object> getExportedCustomBubblingEventTypeConstants() {
64
+ return PdfRendererViewManagerImpl.getExportedCustomBubblingEventTypeConstants();
65
+ }
66
+
67
+ @ReactProp(name = "params")
68
+ public void setParams(PdfRendererRecyclerView view, @Nullable ReadableMap params) throws IOException {
69
+ PdfRendererViewManagerImpl.setParams(view, params);
70
+ }
71
+
72
+ @ReactProp(name = "distanceBetweenPages")
73
+ public void setDistanceBetweenPages(PdfRendererRecyclerView view, float distanceBetweenPages) {
74
+ view.setDistanceBetweenPages(distanceBetweenPages);
75
+ }
76
+
77
+ @ReactProp(name = "maxPageResolution")
78
+ public void setMaxPageResolution(PdfRendererRecyclerView view, float maxPageResolution) {
79
+ view.setMaxPageResolution(maxPageResolution);
80
+ }
81
+
82
+ @Override
83
+ public void onPageChange(PdfRendererRecyclerView target, int position, int total) {
84
+ UIManagerModule uiManager = mReactApplicationContext.getNativeModule(UIManagerModule.class);
85
+ if (uiManager != null) {
86
+ int surfaceId = UIManagerHelper.getSurfaceId(mReactApplicationContext);
87
+ uiManager.getEventDispatcher().dispatchEvent(
88
+ PdfRendererViewManagerImpl.createOnPageChangeEvent(surfaceId, target.getId(), position, total)
89
+ );
90
+ }
91
+ }
92
+ }
@@ -1,4 +1,5 @@
1
- import { ViewProps } from 'react-native';
1
+ import React from 'react';
2
+ import { StyleProp, ViewStyle } from 'react-native';
2
3
  export type PdfRendererViewPropsType = {
3
4
  testID?: string;
4
5
  /**
@@ -6,7 +7,7 @@ export type PdfRendererViewPropsType = {
6
7
  *
7
8
  * Note: Border radius is not supported.
8
9
  */
9
- style?: ViewProps['style'];
10
+ style?: StyleProp<ViewStyle>;
10
11
  /**
11
12
  * Path to a file stored on device.
12
13
  *
@@ -36,7 +37,6 @@ export type PdfRendererViewPropsType = {
36
37
  */
37
38
  maxPageResolution?: number;
38
39
  /**
39
- * (Experimental)
40
40
  *
41
41
  * Renders only the first page without scroll. (useful for display thumbnail).
42
42
  *
@@ -51,5 +51,5 @@ export type PdfRendererViewPropsType = {
51
51
  */
52
52
  onPageChange?: (page: number, totalPages: number) => void;
53
53
  };
54
- declare const PdfRendererView: ({ testID, onPageChange, style, source, singlePage, distanceBetweenPages, maxZoom, maxPageResolution, }: PdfRendererViewPropsType) => JSX.Element;
54
+ declare const PdfRendererView: ({ testID, onPageChange, style, source, singlePage, distanceBetweenPages, maxZoom, maxPageResolution, }: PdfRendererViewPropsType) => React.JSX.Element;
55
55
  export default PdfRendererView;
@@ -16,8 +16,8 @@
16
16
  // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17
17
  // SOFTWARE.
18
18
  import React, { useCallback, useMemo } from 'react';
19
- import { requireNativeComponent, StyleSheet, } from 'react-native';
20
- const PdfRendererNative = requireNativeComponent('RNPdfRendererView');
19
+ import { StyleSheet, } from 'react-native';
20
+ import PdfRendererNative from './specs/RNPdfRendererViewNativeComponent';
21
21
  const styles = StyleSheet.create({
22
22
  default: {
23
23
  backgroundColor: 'gray',
@@ -30,7 +30,7 @@ const PdfRendererView = ({ testID = undefined, onPageChange, style, source, sing
30
30
  style,
31
31
  {
32
32
  // See https://github.com/douglasjunior/react-native-pdf-renderer#limitations
33
- borderRadius: null,
33
+ borderRadius: undefined,
34
34
  },
35
35
  ], [style]);
36
36
  const handlePageChange = useCallback((event) => {
@@ -1 +1 @@
1
- {"version":3,"file":"PdfRendererView.js","sourceRoot":"","sources":["../src/PdfRendererView.tsx"],"names":[],"mappings":"AAAA,cAAc;AAEd,gDAAgD;AAEhD,+EAA+E;AAC/E,gFAAgF;AAChF,+EAA+E;AAC/E,4EAA4E;AAC5E,wEAAwE;AACxE,2DAA2D;AAE3D,iFAAiF;AACjF,kDAAkD;AAElD,6EAA6E;AAC7E,2EAA2E;AAC3E,8EAA8E;AAC9E,yEAAyE;AACzE,gFAAgF;AAChF,gFAAgF;AAChF,YAAY;AAEZ,OAAO,KAAK,EAAE,EAAC,WAAW,EAAE,OAAO,EAAC,MAAM,OAAO,CAAC;AAClD,OAAO,EAEL,sBAAsB,EACtB,UAAU,GAEX,MAAM,cAAc,CAAC;AA4DtB,MAAM,iBAAiB,GAAG,sBAAsB,CAAC,mBAAmB,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UAAU;QACV,OAAO;KACR,CAAC,EACF,CAAC,MAAM,EAAE,UAAU,EAAE,OAAO,CAAC,CAC9B,CAAC;IAEF,OAAO,CACL,oBAAC,iBAAiB,IAChB,MAAM,EAAE,MAAM,EACd,iBAAiB,EAAE,iBAAiB,EACpC,oBAAoB,EAAE,oBAAoB,EAC1C,KAAK,EAAE,UAAU,EACjB,MAAM,EAAE,MAAM,EACd,YAAY,EAAE,gBAAgB,GAC9B,CACH,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,eAAe,CAAC"}
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc;AAEd,gDAAgD;AAEhD,+EAA+E;AAC/E,gFAAgF;AAChF,+EAA+E;AAC/E,4EAA4E;AAC5E,wEAAwE;AACxE,2DAA2D;AAE3D,iFAAiF;AACjF,kDAAkD;AAElD,6EAA6E;AAC7E,2EAA2E;AAC3E,8EAA8E;AAC9E,yEAAyE;AACzE,gFAAgF;AAChF,gFAAgF;AAChF,YAAY;AAEZ,OAAO,EAAC,OAAO,EAAC,MAAM,mBAAmB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc;AAEd,gDAAgD;AAEhD,+EAA+E;AAC/E,gFAAgF;AAChF,+EAA+E;AAC/E,4EAA4E;AAC5E,wEAAwE;AACxE,2DAA2D;AAE3D,iFAAiF;AACjF,kDAAkD;AAElD,6EAA6E;AAC7E,2EAA2E;AAC3E,8EAA8E;AAC9E,yEAAyE;AACzE,gFAAgF;AAChF,gFAAgF;AAChF,YAAY;AAEZ,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC"}
package/dist/mock.js CHANGED
@@ -1,3 +1,20 @@
1
+ // MIT License
2
+ // Copyright (c) 2024 Douglas Nassif Roma Junior
3
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ // of this software and associated documentation files (the "Software"), to deal
5
+ // in the Software without restriction, including without limitation the rights
6
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ // copies of the Software, and to permit persons to whom the Software is
8
+ // furnished to do so, subject to the following conditions:
9
+ // The above copyright notice and this permission notice shall be included in all
10
+ // copies or substantial portions of the Software.
11
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17
+ // SOFTWARE.
1
18
  import React from 'react';
2
19
  import { View } from 'react-native';
3
20
  const PdfRendererViewMock = (props) => {
package/dist/mock.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"mock.js","sourceRoot":"","sources":["../src/mock.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAC,IAAI,EAAC,MAAM,cAAc,CAAC;AAGlC,MAAM,mBAAmB,GAAG,CAAC,KAA+B,EAAE,EAAE;IAC9D,OAAO,oBAAC,IAAI,IAAC,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,GAAI,CAAC;AAC5D,CAAC,CAAC;AAEF,eAAe,mBAAmB,CAAC"}
1
+ {"version":3,"file":"mock.js","sourceRoot":"","sources":["../src/mock.tsx"],"names":[],"mappings":"AAAA,cAAc;AAEd,gDAAgD;AAEhD,+EAA+E;AAC/E,gFAAgF;AAChF,+EAA+E;AAC/E,4EAA4E;AAC5E,wEAAwE;AACxE,2DAA2D;AAE3D,iFAAiF;AACjF,kDAAkD;AAElD,6EAA6E;AAC7E,2EAA2E;AAC3E,8EAA8E;AAC9E,yEAAyE;AACzE,gFAAgF;AAChF,gFAAgF;AAChF,YAAY;AAEZ,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAGpC,MAAM,mBAAmB,GAAG,CAAC,KAA+B,EAAE,EAAE;IAC9D,OAAO,oBAAC,IAAI,IAAC,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,GAAI,CAAC;AAC5D,CAAC,CAAC;AAEF,eAAe,mBAAmB,CAAC"}
@@ -0,0 +1,19 @@
1
+ import type { HostComponent, ViewProps } from 'react-native';
2
+ import { BubblingEventHandler, Float, Int32 } from 'react-native/Libraries/Types/CodegenTypes';
3
+ export type NativeParams = {
4
+ source?: string;
5
+ singlePage: boolean;
6
+ maxZoom: Float;
7
+ };
8
+ type PageChangeEventPayload = {
9
+ position: Int32;
10
+ total: Int32;
11
+ };
12
+ export interface NativeProps extends ViewProps {
13
+ maxPageResolution: Float;
14
+ distanceBetweenPages: Float;
15
+ params: NativeParams;
16
+ onPageChange: BubblingEventHandler<PageChangeEventPayload>;
17
+ }
18
+ declare const _default: HostComponent<NativeProps>;
19
+ export default _default;
@@ -0,0 +1,4 @@
1
+ // MIT License
2
+ import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';
3
+ export default codegenNativeComponent('RNPdfRendererView');
4
+ //# sourceMappingURL=RNPdfRendererViewNativeComponent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RNPdfRendererViewNativeComponent.js","sourceRoot":"","sources":["../../src/specs/RNPdfRendererViewNativeComponent.ts"],"names":[],"mappings":"AAAA,cAAc;AA4Bd,OAAO,sBAAsB,MAAM,yDAAyD,CAAC;AAoB7F,eAAe,sBAAsB,CACnC,mBAAmB,CACU,CAAC"}
@@ -7,8 +7,9 @@
7
7
  objects = {
8
8
 
9
9
  /* Begin PBXBuildFile section */
10
- 241DF20429B9FD8B003ED990 /* RNPDFView.m in Sources */ = {isa = PBXBuildFile; fileRef = 241DF20129B9FD8B003ED990 /* RNPDFView.m */; };
10
+ 241DF20429B9FD8B003ED990 /* RNPDFView.mm in Sources */ = {isa = PBXBuildFile; fileRef = 241DF20129B9FD8B003ED990 /* RNPDFView.mm */; };
11
11
  241DF20529B9FD8B003ED990 /* RNPdfRendererModule.m in Sources */ = {isa = PBXBuildFile; fileRef = 241DF20329B9FD8B003ED990 /* RNPdfRendererModule.m */; };
12
+ 248B169F2E10C36D00F84136 /* RNPdfRendererComponentView.mm in Sources */ = {isa = PBXBuildFile; fileRef = 248B169E2E10C36D00F84136 /* RNPdfRendererComponentView.mm */; };
12
13
  /* End PBXBuildFile section */
13
14
 
14
15
  /* Begin PBXCopyFilesBuildPhase section */
@@ -25,9 +26,11 @@
25
26
 
26
27
  /* Begin PBXFileReference section */
27
28
  241DF20029B9FD8A003ED990 /* RNPDFView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNPDFView.h; sourceTree = "<group>"; };
28
- 241DF20129B9FD8B003ED990 /* RNPDFView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNPDFView.m; sourceTree = "<group>"; };
29
+ 241DF20129B9FD8B003ED990 /* RNPDFView.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = RNPDFView.mm; sourceTree = "<group>"; };
29
30
  241DF20229B9FD8B003ED990 /* RNPdfRendererModule.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNPdfRendererModule.h; sourceTree = "<group>"; };
30
31
  241DF20329B9FD8B003ED990 /* RNPdfRendererModule.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNPdfRendererModule.m; sourceTree = "<group>"; };
32
+ 248B169D2E10C36D00F84136 /* RNPdfRendererComponentView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNPdfRendererComponentView.h; sourceTree = "<group>"; };
33
+ 248B169E2E10C36D00F84136 /* RNPdfRendererComponentView.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = RNPdfRendererComponentView.mm; sourceTree = "<group>"; };
31
34
  A5AF7CE21FAA17C900C5BDC0 /* libReactNativePdfRendererLibrary.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libReactNativePdfRendererLibrary.a; sourceTree = BUILT_PRODUCTS_DIR; };
32
35
  /* End PBXFileReference section */
33
36
 
@@ -57,10 +60,12 @@
57
60
  A5AF7CE31FAA17C900C5BDC0 /* ReactNativePdfRendererLibrary */ = {
58
61
  isa = PBXGroup;
59
62
  children = (
63
+ 248B169D2E10C36D00F84136 /* RNPdfRendererComponentView.h */,
64
+ 248B169E2E10C36D00F84136 /* RNPdfRendererComponentView.mm */,
60
65
  241DF20229B9FD8B003ED990 /* RNPdfRendererModule.h */,
61
66
  241DF20329B9FD8B003ED990 /* RNPdfRendererModule.m */,
62
67
  241DF20029B9FD8A003ED990 /* RNPDFView.h */,
63
- 241DF20129B9FD8B003ED990 /* RNPDFView.m */,
68
+ 241DF20129B9FD8B003ED990 /* RNPDFView.mm */,
64
69
  );
65
70
  path = ReactNativePdfRendererLibrary;
66
71
  sourceTree = "<group>";
@@ -138,8 +143,9 @@
138
143
  isa = PBXSourcesBuildPhase;
139
144
  buildActionMask = 2147483647;
140
145
  files = (
141
- 241DF20429B9FD8B003ED990 /* RNPDFView.m in Sources */,
146
+ 241DF20429B9FD8B003ED990 /* RNPDFView.mm in Sources */,
142
147
  241DF20529B9FD8B003ED990 /* RNPdfRendererModule.m in Sources */,
148
+ 248B169F2E10C36D00F84136 /* RNPdfRendererComponentView.mm in Sources */,
143
149
  );
144
150
  runOnlyForDeploymentPostprocessing = 0;
145
151
  };
@@ -23,15 +23,21 @@
23
23
  // Created by Douglas Nassif Roma Junior on 08/03/23.
24
24
  //
25
25
 
26
- @import Foundation;
27
- @import UIKit;
28
- @import PDFKit;
26
+ #import <Foundation/Foundation.h>
27
+ #import <UIKit/UIKit.h>
28
+ #import <PDFKit/PDFKit.h>
29
29
 
30
+ #ifdef RCT_NEW_ARCH_ENABLED
31
+ #else
30
32
  #import <React/RCTComponent.h>
33
+ #endif
31
34
 
32
35
  @interface RNPDFView: PDFView
33
36
 
37
+ #ifdef RCT_NEW_ARCH_ENABLED
38
+ #else
34
39
  @property (nonatomic, copy) RCTBubblingEventBlock onPageChange;
40
+ #endif
35
41
 
36
42
  -(void) setDistanceBetweenPages:(NSNumber*) distance;
37
43
  -(void) setParams:(NSDictionary*) params;
@@ -29,16 +29,13 @@
29
29
 
30
30
  -(void) setParams:(NSDictionary*) params {
31
31
  NSString *source = [params objectForKey:@"source"];
32
+ NSString *maxZoomString = [params objectForKey:@"maxZoom"];
33
+ NSString *singlePageString = [params objectForKey:@"singlePage"];
32
34
 
33
- float maxZoom = [params objectForKey:@"maxZoom"] != nil
34
- ? [[params objectForKey:@"maxZoom"] floatValue]
35
- : 0;
36
-
37
- BOOL singlePage = [params objectForKey:@"singlePage"] != nil
38
- ? [[params objectForKey:@"singlePage"] boolValue]
39
- : NO;
40
-
41
- if ([params objectForKey:@"source"] != nil) {
35
+ if (source != nil) {
36
+ float maxZoom = maxZoomString != nil ? [maxZoomString floatValue] : 0;
37
+ BOOL singlePage = singlePageString != nil ? [singlePageString boolValue] : NO;
38
+
42
39
  if (![source hasPrefix:@"file://"]) {
43
40
  source = [NSString stringWithFormat:@"%@%@", @"file://", source];
44
41
  }
@@ -54,7 +51,9 @@
54
51
  }
55
52
  self.displayMode = singlePage ? kPDFDisplaySinglePage : kPDFDisplaySinglePageContinuous;
56
53
 
57
- self.document = pdfDocument;
54
+ dispatch_async(dispatch_get_main_queue(), ^{
55
+ self.document = pdfDocument;
56
+ });
58
57
 
59
58
  dispatch_async(dispatch_get_main_queue(), ^{
60
59
  self.minScaleFactor = self.scaleFactorForSizeToFit;
@@ -0,0 +1,44 @@
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
+ // Created by Douglas Nassif Roma Junior on 08/03/23.
24
+ //
25
+
26
+ #ifdef RCT_NEW_ARCH_ENABLED
27
+
28
+
29
+ #import <UIKit/UIKit.h>
30
+ #import <PDFKit/PDFKit.h>
31
+ #import <React/RCTViewComponentView.h>
32
+
33
+ #import "RNPDFView.h"
34
+
35
+ NS_ASSUME_NONNULL_BEGIN
36
+
37
+ @interface RNPdfRendererComponentView : RCTViewComponentView
38
+
39
+ @end
40
+
41
+ NS_ASSUME_NONNULL_END
42
+
43
+ #endif // RCT_NEW_ARCH_ENABLED
44
+