react-native-pdf-renderer 0.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.
- package/.eslintrc.js +4 -0
- package/.gitattributes +1 -0
- package/.github/FUNDING.yml +6 -0
- package/.github/ISSUE_TEMPLATE/start-a-new-issue.md +20 -0
- package/.prettierrc.js +7 -0
- package/LICENSE +21 -0
- package/README.md +84 -0
- package/ReactNativePdfRenderer.podspec +21 -0
- package/android/build.gradle +62 -0
- package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/android/gradle/wrapper/gradle-wrapper.properties +5 -0
- package/android/gradlew +234 -0
- package/android/gradlew.bat +89 -0
- package/android/local.properties +8 -0
- package/android/src/main/AndroidManifest.xml +5 -0
- package/android/src/main/java/com/github/douglasjunior/reactNativePdfRenderer/PdfRendererPackage.java +51 -0
- package/android/src/main/java/com/github/douglasjunior/reactNativePdfRenderer/modules/PdfRendererRecyclerView.java +351 -0
- package/android/src/main/java/com/github/douglasjunior/reactNativePdfRenderer/modules/PdfRendererViewManager.java +110 -0
- package/babel.config.js +3 -0
- package/dist/.gitkeep +0 -0
- package/ios/ReactNativePdfRenderer.xcodeproj/project.pbxproj +326 -0
- package/ios/ReactNativePdfRenderer.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
- package/ios/ReactNativePdfRenderer.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
- package/ios/ReactNativePdfRenderer.xcodeproj/project.xcworkspace/xcuserdata/douglas.junior.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- package/ios/ReactNativePdfRenderer.xcodeproj/xcuserdata/douglas.junior.xcuserdatad/xcschemes/xcschememanagement.plist +14 -0
- package/ios/ReactNativePdfRendererLibrary/RNPDFView.h +36 -0
- package/ios/ReactNativePdfRendererLibrary/RNPDFView.m +30 -0
- package/ios/ReactNativePdfRendererLibrary/RNPdfRendererModule.h +34 -0
- package/ios/ReactNativePdfRendererLibrary/RNPdfRendererModule.m +112 -0
- package/package.json +52 -0
- package/src/PdfRendererView.tsx +41 -0
- package/src/index.ts +2 -0
- package/tsconfig.json +3 -0
|
@@ -0,0 +1,351 @@
|
|
|
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 android.annotation.SuppressLint;
|
|
26
|
+
import android.content.res.Resources;
|
|
27
|
+
import android.graphics.Bitmap;
|
|
28
|
+
import android.graphics.Canvas;
|
|
29
|
+
import android.graphics.Color;
|
|
30
|
+
import android.graphics.Matrix;
|
|
31
|
+
import android.graphics.pdf.PdfRenderer;
|
|
32
|
+
import android.os.ParcelFileDescriptor;
|
|
33
|
+
import android.util.Log;
|
|
34
|
+
import android.util.TypedValue;
|
|
35
|
+
import android.view.GestureDetector;
|
|
36
|
+
import android.view.MotionEvent;
|
|
37
|
+
import android.view.ScaleGestureDetector;
|
|
38
|
+
import android.view.ViewGroup;
|
|
39
|
+
import android.widget.ImageView;
|
|
40
|
+
|
|
41
|
+
import androidx.annotation.NonNull;
|
|
42
|
+
import androidx.core.view.ViewCompat;
|
|
43
|
+
import androidx.recyclerview.widget.LinearLayoutManager;
|
|
44
|
+
import androidx.recyclerview.widget.RecyclerView;
|
|
45
|
+
|
|
46
|
+
import com.facebook.react.bridge.Arguments;
|
|
47
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
|
48
|
+
import com.facebook.react.bridge.WritableMap;
|
|
49
|
+
import com.facebook.react.uimanager.events.RCTEventEmitter;
|
|
50
|
+
|
|
51
|
+
import java.io.File;
|
|
52
|
+
import java.io.IOException;
|
|
53
|
+
import java.util.Arrays;
|
|
54
|
+
|
|
55
|
+
public class PdfRendererRecyclerView extends RecyclerView {
|
|
56
|
+
private final ViewGroup mParent;
|
|
57
|
+
private final GestureDetector mGestureDetector;
|
|
58
|
+
private boolean mRequestedLayout = false;
|
|
59
|
+
private float mMaxZoom = 5;
|
|
60
|
+
private float mDistanceBetweenPages = 0;
|
|
61
|
+
private int mWidth;
|
|
62
|
+
private int mHeight;
|
|
63
|
+
private int mCurrentItemPosition = -1;
|
|
64
|
+
private ReactApplicationContext mReactApplicationContext;
|
|
65
|
+
private ScaleGestureDetector mScaleDetector;
|
|
66
|
+
private Matrix mMatrix;
|
|
67
|
+
|
|
68
|
+
public PdfRendererRecyclerView(@NonNull ReactApplicationContext context, ViewGroup parent) {
|
|
69
|
+
super(context);
|
|
70
|
+
LinearLayoutManager lm = new LinearLayoutManager(context);
|
|
71
|
+
lm.setOrientation(LinearLayoutManager.VERTICAL);
|
|
72
|
+
this.setLayoutManager(lm);
|
|
73
|
+
PdfRendererAdapter adapter = new PdfRendererAdapter();
|
|
74
|
+
this.setAdapter(adapter);
|
|
75
|
+
this.addOnScrollListener(new ScrollListener());
|
|
76
|
+
mReactApplicationContext = context;
|
|
77
|
+
mParent = parent;
|
|
78
|
+
mMatrix = new Matrix();
|
|
79
|
+
mScaleDetector = new ScaleGestureDetector(getContext(), new ScaleListener());
|
|
80
|
+
mGestureDetector = new GestureDetector(context, new GestureListener());
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
public void setDistanceBetweenPages(float distanceBetweenPages) {
|
|
84
|
+
mDistanceBetweenPages = TypedValue.applyDimension(
|
|
85
|
+
TypedValue.COMPLEX_UNIT_DIP,
|
|
86
|
+
distanceBetweenPages,
|
|
87
|
+
Resources.getSystem().getDisplayMetrics()
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
public void setMaxZoom(float maxZoom) {
|
|
92
|
+
this.mMaxZoom = maxZoom;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
public void closeAdapter() {
|
|
96
|
+
try {
|
|
97
|
+
PdfRendererAdapter adapter = (PdfRendererAdapter) getAdapter();
|
|
98
|
+
adapter.close();
|
|
99
|
+
adapter.notifyDataSetChanged();
|
|
100
|
+
} catch (Exception ex) {
|
|
101
|
+
ex.printStackTrace();
|
|
102
|
+
// do nothing
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
public void updateSource(String source) throws IOException {
|
|
107
|
+
mCurrentItemPosition = -1;
|
|
108
|
+
PdfRendererAdapter adapter = (PdfRendererAdapter) getAdapter();
|
|
109
|
+
adapter.updateSource(source);
|
|
110
|
+
adapter.notifyDataSetChanged();
|
|
111
|
+
dispatchPageChangeEvent();
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
private void dispatchPageChangeEvent() {
|
|
115
|
+
int position = ((LinearLayoutManager) getLayoutManager()).findLastCompletelyVisibleItemPosition();
|
|
116
|
+
|
|
117
|
+
if (position < 0) {
|
|
118
|
+
position = ((LinearLayoutManager) getLayoutManager()).findLastVisibleItemPosition();
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (position != mCurrentItemPosition) {
|
|
122
|
+
mCurrentItemPosition = position;
|
|
123
|
+
|
|
124
|
+
PdfRendererAdapter adapter = (PdfRendererAdapter) getAdapter();
|
|
125
|
+
|
|
126
|
+
WritableMap event = Arguments.createMap();
|
|
127
|
+
event.putInt("position", position);
|
|
128
|
+
event.putInt("total", adapter.getItemCount());
|
|
129
|
+
|
|
130
|
+
mReactApplicationContext
|
|
131
|
+
.getJSModule(RCTEventEmitter.class)
|
|
132
|
+
.receiveEvent(mParent.getId(), "pageChange", event);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
@Override
|
|
137
|
+
protected void dispatchDraw(@NonNull Canvas canvas) {
|
|
138
|
+
canvas.save();
|
|
139
|
+
canvas.concat(mMatrix);
|
|
140
|
+
super.dispatchDraw(canvas);
|
|
141
|
+
canvas.restore();
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
@Override
|
|
145
|
+
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
|
146
|
+
mWidth = MeasureSpec.getSize(widthMeasureSpec);
|
|
147
|
+
mHeight = MeasureSpec.getSize(heightMeasureSpec);
|
|
148
|
+
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
@Override
|
|
152
|
+
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
|
|
153
|
+
super.onSizeChanged(w,h,oldw,oldh);
|
|
154
|
+
float scale = Math.max(w / mWidth, h / mHeight);
|
|
155
|
+
mMatrix.setScale(scale, scale);
|
|
156
|
+
mMatrix.postTranslate((w - scale * mWidth) / 2f, (h - scale * mHeight) / 2f);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
@Override
|
|
160
|
+
@SuppressLint("ClickableViewAccessibility")
|
|
161
|
+
public boolean onTouchEvent(MotionEvent e) {
|
|
162
|
+
mScaleDetector.onTouchEvent(e);
|
|
163
|
+
mGestureDetector.onTouchEvent(e);
|
|
164
|
+
if (mScaleDetector.isInProgress()) {
|
|
165
|
+
return true;
|
|
166
|
+
}
|
|
167
|
+
return super.onTouchEvent(e);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
@Override
|
|
171
|
+
public void destroyDrawingCache() {
|
|
172
|
+
super.destroyDrawingCache();
|
|
173
|
+
closeAdapter();
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
@Override
|
|
177
|
+
public boolean onInterceptTouchEvent(MotionEvent ev) {
|
|
178
|
+
try {
|
|
179
|
+
return super.onInterceptTouchEvent(ev);
|
|
180
|
+
} catch (IllegalArgumentException ex) {
|
|
181
|
+
ex.printStackTrace();
|
|
182
|
+
}
|
|
183
|
+
return false;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
public void forceRequestLayout() {
|
|
187
|
+
mRequestedLayout = false;
|
|
188
|
+
requestLayout();
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
private void validateMatrixLimits() {
|
|
192
|
+
float[] values = new float[9];
|
|
193
|
+
mMatrix.getValues(values);
|
|
194
|
+
|
|
195
|
+
Log.d("mMatrix1", Arrays.toString(values) + "");
|
|
196
|
+
Log.d("size", mWidth + " | " + mHeight);
|
|
197
|
+
|
|
198
|
+
float scaleX = Math.min(Math.max(values[0], 1), mMaxZoom);
|
|
199
|
+
float posX = values[2];
|
|
200
|
+
|
|
201
|
+
float scaleY = Math.min(Math.max(values[4], 1), mMaxZoom);
|
|
202
|
+
float posY = values[5];
|
|
203
|
+
|
|
204
|
+
float maxPosX = mWidth - mWidth * scaleX;
|
|
205
|
+
float maxPosY = mHeight - mHeight * scaleY;
|
|
206
|
+
|
|
207
|
+
if (posX > 0.0f)
|
|
208
|
+
posX = 0.0f;
|
|
209
|
+
else if (posX < maxPosX)
|
|
210
|
+
posX = maxPosX;
|
|
211
|
+
|
|
212
|
+
if (posY > 0.0f)
|
|
213
|
+
posY = 0.0f;
|
|
214
|
+
else if (posY < maxPosY)
|
|
215
|
+
posY = maxPosY;
|
|
216
|
+
|
|
217
|
+
values[0] = scaleX;
|
|
218
|
+
values[2] = posX;
|
|
219
|
+
values[4] = scaleY;
|
|
220
|
+
values[5] = posY;
|
|
221
|
+
|
|
222
|
+
mMatrix.setValues(values);
|
|
223
|
+
|
|
224
|
+
Log.d("mMatrix2", Arrays.toString(values) + "");
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Fix a problem with React Native layout
|
|
229
|
+
* https://stackoverflow.com/a/49381907/2826279
|
|
230
|
+
*/
|
|
231
|
+
@SuppressLint("WrongCall")
|
|
232
|
+
@Override
|
|
233
|
+
public void requestLayout() {
|
|
234
|
+
super.requestLayout();
|
|
235
|
+
if (!mRequestedLayout) {
|
|
236
|
+
mRequestedLayout = true;
|
|
237
|
+
this.post(() -> {
|
|
238
|
+
onLayout(false, getLeft(), getTop(), getRight(), getBottom());
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
private class ScaleListener extends ScaleGestureDetector.SimpleOnScaleGestureListener {
|
|
244
|
+
@Override
|
|
245
|
+
public boolean onScale(ScaleGestureDetector detector) {
|
|
246
|
+
float factor = detector.getScaleFactor();
|
|
247
|
+
mMatrix.postScale(factor, factor, getWidth() / 2f, getHeight() / 2f);
|
|
248
|
+
validateMatrixLimits();
|
|
249
|
+
ViewCompat.postInvalidateOnAnimation(PdfRendererRecyclerView.this);
|
|
250
|
+
return true;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
private class GestureListener extends GestureDetector.SimpleOnGestureListener {
|
|
255
|
+
@Override
|
|
256
|
+
public boolean onScroll(MotionEvent e1, MotionEvent e2, float dX, float dY) {
|
|
257
|
+
mMatrix.postTranslate(-dX, -dY);
|
|
258
|
+
validateMatrixLimits();
|
|
259
|
+
ViewCompat.postInvalidateOnAnimation(PdfRendererRecyclerView.this);
|
|
260
|
+
return true;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
class PdfRendererAdapter extends Adapter<PdfRendererAdapter.ViewHolder> {
|
|
265
|
+
|
|
266
|
+
private ParcelFileDescriptor mFileDescriptor;
|
|
267
|
+
private PdfRenderer mPdfRenderer;
|
|
268
|
+
|
|
269
|
+
public void updateSource(String source) throws IOException {
|
|
270
|
+
if (source == null || source.isEmpty()) return;
|
|
271
|
+
File file = new File(source.replace("file://", ""));
|
|
272
|
+
mFileDescriptor = ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY);
|
|
273
|
+
mPdfRenderer = new PdfRenderer(mFileDescriptor);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
public void close() throws IOException {
|
|
277
|
+
mPdfRenderer.close();
|
|
278
|
+
mFileDescriptor.close();
|
|
279
|
+
mPdfRenderer = null;
|
|
280
|
+
mFileDescriptor = null;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
@NonNull
|
|
284
|
+
@Override
|
|
285
|
+
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
|
286
|
+
ImageView imageView = new ImageView(parent.getContext());
|
|
287
|
+
imageView.setBackgroundColor(Color.WHITE);
|
|
288
|
+
LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, 0);
|
|
289
|
+
imageView.setLayoutParams(params);
|
|
290
|
+
ViewHolder viewHolder = new ViewHolder(parent, imageView);
|
|
291
|
+
return viewHolder;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
@Override
|
|
295
|
+
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
|
|
296
|
+
if (mPdfRenderer == null) return;
|
|
297
|
+
|
|
298
|
+
PdfRenderer.Page page = mPdfRenderer.openPage(position);
|
|
299
|
+
Bitmap bitmap = Bitmap.createBitmap(page.getWidth(), page.getHeight(), Bitmap.Config.ARGB_4444);
|
|
300
|
+
page.render(bitmap, null, null, PdfRenderer.Page.RENDER_MODE_FOR_DISPLAY);
|
|
301
|
+
|
|
302
|
+
ImageView imageView = holder.getImageView();
|
|
303
|
+
imageView.setImageBitmap(bitmap);
|
|
304
|
+
|
|
305
|
+
LayoutParams lp = (LayoutParams) imageView.getLayoutParams();
|
|
306
|
+
lp.width = LayoutParams.MATCH_PARENT;
|
|
307
|
+
int parentWidth = holder.getParentView().getWidth();
|
|
308
|
+
lp.height = Math.round(((float) parentWidth / (float) page.getWidth()) * (float) page.getHeight());
|
|
309
|
+
lp.setMargins(0, 0, 0, (int) mDistanceBetweenPages);
|
|
310
|
+
imageView.setLayoutParams(lp);
|
|
311
|
+
|
|
312
|
+
page.close();
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
@Override
|
|
316
|
+
public int getItemCount() {
|
|
317
|
+
if (mPdfRenderer == null) return 0;
|
|
318
|
+
return mPdfRenderer.getPageCount();
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* Provide a reference to the type of views that you are using
|
|
323
|
+
* (custom ViewHolder).
|
|
324
|
+
*/
|
|
325
|
+
public class ViewHolder extends RecyclerView.ViewHolder {
|
|
326
|
+
|
|
327
|
+
private final ViewGroup mParentView;
|
|
328
|
+
|
|
329
|
+
public ViewHolder(ViewGroup parentView, ImageView imageView) {
|
|
330
|
+
super(imageView);
|
|
331
|
+
mParentView = parentView;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
public ViewGroup getParentView() {
|
|
335
|
+
return mParentView;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
public ImageView getImageView() {
|
|
339
|
+
return (ImageView) this.itemView;
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
class ScrollListener extends OnScrollListener {
|
|
345
|
+
|
|
346
|
+
@Override
|
|
347
|
+
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
|
|
348
|
+
dispatchPageChangeEvent();
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
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 android.util.Log;
|
|
26
|
+
import android.view.ViewGroup;
|
|
27
|
+
import android.widget.LinearLayout;
|
|
28
|
+
|
|
29
|
+
import androidx.annotation.NonNull;
|
|
30
|
+
import androidx.annotation.Nullable;
|
|
31
|
+
|
|
32
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
|
33
|
+
import com.facebook.react.common.MapBuilder;
|
|
34
|
+
import com.facebook.react.uimanager.SimpleViewManager;
|
|
35
|
+
import com.facebook.react.uimanager.ThemedReactContext;
|
|
36
|
+
import com.facebook.react.uimanager.annotations.ReactProp;
|
|
37
|
+
|
|
38
|
+
import java.io.IOException;
|
|
39
|
+
import java.util.Map;
|
|
40
|
+
|
|
41
|
+
public class PdfRendererViewManager extends SimpleViewManager<ViewGroup> {
|
|
42
|
+
|
|
43
|
+
private ReactApplicationContext mReactApplicationContext;
|
|
44
|
+
|
|
45
|
+
public PdfRendererViewManager(ReactApplicationContext reactApplicationContext) {
|
|
46
|
+
this.mReactApplicationContext = reactApplicationContext;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
@NonNull
|
|
50
|
+
@Override
|
|
51
|
+
public String getName() {
|
|
52
|
+
return "RNPdfRendererView";
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
@NonNull
|
|
56
|
+
@Override
|
|
57
|
+
protected ViewGroup createViewInstance(@NonNull ThemedReactContext themedReactContext) {
|
|
58
|
+
LinearLayout layout = new LinearLayout(themedReactContext);
|
|
59
|
+
layout.setOrientation(LinearLayout.VERTICAL);
|
|
60
|
+
|
|
61
|
+
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
|
|
62
|
+
|
|
63
|
+
PdfRendererRecyclerView recyclerView = new PdfRendererRecyclerView(mReactApplicationContext, layout);
|
|
64
|
+
recyclerView.setLayoutParams(params);
|
|
65
|
+
|
|
66
|
+
layout.addView(recyclerView);
|
|
67
|
+
|
|
68
|
+
layout.setClipToOutline(true);
|
|
69
|
+
|
|
70
|
+
return layout;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
@Nullable
|
|
74
|
+
@Override
|
|
75
|
+
public Map<String, Object> getExportedCustomBubblingEventTypeConstants() {
|
|
76
|
+
Map map = super.getExportedCustomBubblingEventTypeConstants();
|
|
77
|
+
map.put("pageChange", MapBuilder.of(
|
|
78
|
+
"phasedRegistrationNames",
|
|
79
|
+
MapBuilder.of("bubbled", "onPageChange")
|
|
80
|
+
));
|
|
81
|
+
return map;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
@ReactProp(name = "source")
|
|
85
|
+
public void setSource(ViewGroup layout, @Nullable String source) throws IOException {
|
|
86
|
+
Log.d("PdfRendererViewManager", "setSource");
|
|
87
|
+
PdfRendererRecyclerView recyclerView = (PdfRendererRecyclerView) layout.getChildAt(0);
|
|
88
|
+
|
|
89
|
+
if (source != null) {
|
|
90
|
+
recyclerView.updateSource(source);
|
|
91
|
+
} else {
|
|
92
|
+
recyclerView.closeAdapter();
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
recyclerView.forceRequestLayout();
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
@ReactProp(name = "distanceBetweenPages")
|
|
99
|
+
public void setDistanceBetweenPages(ViewGroup layout, @Nullable float distanceBetweenPages) {
|
|
100
|
+
PdfRendererRecyclerView recyclerView = (PdfRendererRecyclerView) layout.getChildAt(0);
|
|
101
|
+
recyclerView.setDistanceBetweenPages(distanceBetweenPages);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
@ReactProp(name = "maxZoom")
|
|
105
|
+
public void setMaxZoom(ViewGroup layout, @Nullable float maxZoom) {
|
|
106
|
+
PdfRendererRecyclerView recyclerView = (PdfRendererRecyclerView) layout.getChildAt(0);
|
|
107
|
+
recyclerView.setMaxZoom(maxZoom);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
}
|
package/babel.config.js
ADDED
package/dist/.gitkeep
ADDED
|
File without changes
|