react-native-pdf-renderer 1.0.5 → 1.1.0-beta.2

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/.gitattributes CHANGED
@@ -1,2 +1,2 @@
1
1
  *.pbxproj -text
2
- Sample/** linguist-documentation
2
+ Sample/** linguist-vendored
package/README.md CHANGED
@@ -109,7 +109,7 @@ This lib is only possible thanks to the community help:
109
109
  - RecyclerView `notifyDataSetChanged()` not working on React Native: https://stackoverflow.com/a/49381907/2826279
110
110
  - Add pinch to zoom on RecyclerView: https://stackoverflow.com/a/37895783/2826279
111
111
  - Using `Matrix` to handle zoom in a View: https://stackoverflow.com/a/55299327/2826279
112
- - Daniel Felipe Sartório for the help with Android native
112
+ - **Daniel Felipe Sartório** for the help with Android native code
113
113
 
114
114
  ## Star History
115
115
 
@@ -23,6 +23,7 @@
23
23
  package com.github.douglasjunior.reactNativePdfRenderer.modules;
24
24
 
25
25
  import android.annotation.SuppressLint;
26
+ import android.content.Context;
26
27
  import android.content.res.Resources;
27
28
  import android.graphics.Bitmap;
28
29
  import android.graphics.Canvas;
@@ -67,12 +68,16 @@ public class PdfRendererRecyclerView extends RecyclerView {
67
68
 
68
69
  public PdfRendererRecyclerView(@NonNull ReactApplicationContext context, ViewGroup parent) {
69
70
  super(context);
70
- LinearLayoutManager lm = new LinearLayoutManager(context);
71
+
72
+ LayoutManager lm = new LayoutManager(context);
71
73
  lm.setOrientation(LinearLayoutManager.VERTICAL);
72
- this.setLayoutManager(lm);
74
+
73
75
  PdfRendererAdapter adapter = new PdfRendererAdapter();
76
+
77
+ this.setLayoutManager(lm);
74
78
  this.setAdapter(adapter);
75
79
  this.addOnScrollListener(new ScrollListener());
80
+
76
81
  mReactApplicationContext = context;
77
82
  mParent = parent;
78
83
  mMatrix = new Matrix();
@@ -156,11 +161,32 @@ public class PdfRendererRecyclerView extends RecyclerView {
156
161
  mMatrix.postTranslate((w - scale * mWidth) / 2f, (h - scale * mHeight) / 2f);
157
162
  }
158
163
 
164
+ private boolean isScrollingInsideZoomedArea() {
165
+ float[] values = new float[9];
166
+ mMatrix.getValues(values);
167
+
168
+ float scaleY = Math.min(Math.max(values[Matrix.MSCALE_Y], mMinZoom), mMaxZoom);
169
+ float posY = values[Matrix.MTRANS_Y];
170
+
171
+ float maxPosY = mHeight - mHeight * scaleY;
172
+
173
+ return posY < 0 && posY > maxPosY;
174
+ }
175
+
159
176
  @Override
160
177
  @SuppressLint("ClickableViewAccessibility")
161
178
  public boolean onTouchEvent(MotionEvent e) {
162
179
  mScaleDetector.onTouchEvent(e);
163
180
  mGestureDetector.onTouchEvent(e);
181
+
182
+ /*
183
+ * Disables the RecyclerView scroll when scrolling inside zoomed area
184
+ * https://github.com/douglasjunior/react-native-pdf-renderer/issues/3
185
+ */
186
+ if (isScrollingInsideZoomedArea()) {
187
+ return true;
188
+ }
189
+
164
190
  return super.onTouchEvent(e);
165
191
  }
166
192
 
@@ -381,4 +407,27 @@ public class PdfRendererRecyclerView extends RecyclerView {
381
407
  dispatchPageChangeEvent();
382
408
  }
383
409
  }
410
+
411
+ class LayoutManager extends LinearLayoutManager {
412
+ public LayoutManager(Context context) {
413
+ super(context);
414
+ }
415
+
416
+ @Override
417
+ public int scrollVerticallyBy(int dy, Recycler recycler, State state) {
418
+ /*
419
+ * Reduces the scroll speed when zoomed
420
+ * https://github.com/douglasjunior/react-native-pdf-renderer/issues/3
421
+ */
422
+
423
+ float[] values = new float[9];
424
+ mMatrix.getValues(values);
425
+
426
+ float scaleY = values[Matrix.MSCALE_Y];
427
+
428
+ int dyWithScale = Math.round(dy / scaleY);
429
+
430
+ return super.scrollVerticallyBy(dyWithScale, recycler, state);
431
+ }
432
+ }
384
433
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "react-native-pdf-renderer",
3
3
  "displayName": "React-Native Pdf Renderer",
4
- "version": "1.0.5",
4
+ "version": "1.1.0-beta.2",
5
5
  "description": "⚛ A zoomable, blazing fast, zero dependencies, pure native, typed PDF Renderer for Android and iOS.",
6
6
  "main": "dist",
7
7
  "license": "MIT",
@@ -1,14 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
- <plist version="1.0">
4
- <dict>
5
- <key>SchemeUserState</key>
6
- <dict>
7
- <key>RNPdfRendererView.xcscheme_^#shared#^_</key>
8
- <dict>
9
- <key>orderHint</key>
10
- <integer>0</integer>
11
- </dict>
12
- </dict>
13
- </dict>
14
- </plist>