@papyrus-sdk/engine-native 0.2.22-beta.6 → 0.2.22-beta.8
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/android/src/main/java/com/papyrus/engine/PapyrusComicDocumentView.java +164 -26
- package/android/src/main/java/com/papyrus/engine/PapyrusComicPageLayout.java +21 -0
- package/android/src/main/java/com/papyrus/engine/PapyrusNativeEngineModule.java +12 -0
- package/android/src/main/java/com/papyrus/engine/PapyrusPdfViewerView.java +195 -5
- package/android/src/main/java/com/papyrus/engine/PapyrusPdfViewerViewManager.java +20 -1
- package/android/src/main/java/com/papyrus/engine/PapyrusSelectionMenuIcon.java +48 -0
- package/android/src/main/java/com/papyrus/engine/PapyrusTextAnnotationModel.java +22 -0
- package/android/src/main/java/com/papyrus/engine/PapyrusTextDocumentView.java +239 -17
- package/android/src/main/java/com/papyrus/engine/PapyrusTextDocumentViewManager.java +6 -0
- package/dist/index.d.mts +137 -1
- package/dist/index.d.ts +137 -1
- package/dist/index.js +37 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +37 -0
- package/dist/index.mjs.map +1 -1
- package/ios/PapyrusComicDocumentView.m +200 -27
- package/ios/PapyrusNativeEngine.m +12 -0
- package/ios/PapyrusPdfDocumentView.h +5 -0
- package/ios/PapyrusPdfDocumentView.m +96 -11
- package/ios/PapyrusPdfDocumentViewManager.m +3 -0
- package/ios/PapyrusSelectionMenu.h +27 -0
- package/ios/PapyrusTextAnnotationRange.h +2 -0
- package/ios/PapyrusTextAnnotationRange.m +29 -0
- package/ios/PapyrusTextDocumentView.h +5 -0
- package/ios/PapyrusTextDocumentView.m +233 -14
- package/ios/PapyrusTextDocumentViewManager.m +5 -0
- package/package.json +3 -3
|
@@ -5,6 +5,8 @@ import android.graphics.Bitmap;
|
|
|
5
5
|
import android.graphics.BitmapFactory;
|
|
6
6
|
import android.graphics.Color;
|
|
7
7
|
import android.os.SystemClock;
|
|
8
|
+
import android.view.GestureDetector;
|
|
9
|
+
import android.view.MotionEvent;
|
|
8
10
|
import android.view.ScaleGestureDetector;
|
|
9
11
|
import android.view.View;
|
|
10
12
|
import android.widget.FrameLayout;
|
|
@@ -49,6 +51,7 @@ public final class PapyrusComicDocumentView extends FrameLayout {
|
|
|
49
51
|
private float zoom = 1f;
|
|
50
52
|
private long lastPageEvent;
|
|
51
53
|
private final ScaleGestureDetector scaleDetector;
|
|
54
|
+
private final GestureDetector tapDetector;
|
|
52
55
|
private final Set<String> emittedErrors = new HashSet<>();
|
|
53
56
|
private float lastPanX;
|
|
54
57
|
private float lastPanY;
|
|
@@ -57,7 +60,7 @@ public final class PapyrusComicDocumentView extends FrameLayout {
|
|
|
57
60
|
|
|
58
61
|
public PapyrusComicDocumentView(Context context) {
|
|
59
62
|
super(context);
|
|
60
|
-
recyclerView = new
|
|
63
|
+
recyclerView = new PapyrusComicRecyclerView(context);
|
|
61
64
|
recyclerView.setOverScrollMode(View.OVER_SCROLL_NEVER);
|
|
62
65
|
adapter = new ComicAdapter();
|
|
63
66
|
recyclerView.setAdapter(adapter);
|
|
@@ -69,9 +72,21 @@ public final class PapyrusComicDocumentView extends FrameLayout {
|
|
|
69
72
|
});
|
|
70
73
|
scaleDetector = new ScaleGestureDetector(context, new ScaleGestureDetector.SimpleOnScaleGestureListener() {
|
|
71
74
|
@Override public boolean onScale(ScaleGestureDetector detector) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
+
// Keep gesture frames native. Reflect the final zoom to React Native
|
|
76
|
+
// only once; per-frame bridge writes can feed stale zoom back into
|
|
77
|
+
// the view and cause visible jitter during a pinch.
|
|
78
|
+
applyZoom(zoom * detector.getScaleFactor(), detector.getFocusX(), detector.getFocusY());
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
@Override public void onScaleEnd(ScaleGestureDetector detector) {
|
|
82
|
+
emitZoom();
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
tapDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
|
|
86
|
+
@Override public boolean onDown(MotionEvent event) { return true; }
|
|
87
|
+
@Override public boolean onDoubleTap(MotionEvent event) {
|
|
88
|
+
if (scaleDetector.isInProgress()) return false;
|
|
89
|
+
applyZoom(zoom > 1.05f ? 1f : 2f, event.getX(), event.getY());
|
|
75
90
|
emitZoom();
|
|
76
91
|
return true;
|
|
77
92
|
}
|
|
@@ -98,7 +113,13 @@ public final class PapyrusComicDocumentView extends FrameLayout {
|
|
|
98
113
|
if (clamped != currentPage) { currentPage = clamped; scrollToCurrentPage(); }
|
|
99
114
|
}
|
|
100
115
|
public void setLayoutMode(String value) {
|
|
101
|
-
|
|
116
|
+
String nextMode = "continuous".equals(value) ? "continuous" : "single";
|
|
117
|
+
if (!nextMode.equals(layoutMode)) {
|
|
118
|
+
panX = PapyrusComicPageLayout.panForLayout(panX, recyclerView.getWidth(), zoom, "continuous".equals(nextMode));
|
|
119
|
+
panY = 0;
|
|
120
|
+
adapter.setPan(panX, panY);
|
|
121
|
+
}
|
|
122
|
+
layoutMode = nextMode;
|
|
102
123
|
int orientation = "continuous".equals(layoutMode) ? RecyclerView.VERTICAL : RecyclerView.HORIZONTAL;
|
|
103
124
|
boolean reverse = orientation == RecyclerView.HORIZONTAL && "rtl".equals(readingDirection);
|
|
104
125
|
layoutManager = new LinearLayoutManager(getContext(), orientation, reverse);
|
|
@@ -112,14 +133,40 @@ public final class PapyrusComicDocumentView extends FrameLayout {
|
|
|
112
133
|
public void setFitMode(String value) { fitMode = value == null ? "width" : value; adapter.notifyDataSetChanged(); }
|
|
113
134
|
public void setReadingDirection(String value) { readingDirection = "rtl".equals(value) ? "rtl" : "ltr"; setLayoutMode(layoutMode); }
|
|
114
135
|
public void setZoom(float value) {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
136
|
+
applyZoom(value, recyclerView.getWidth() / 2f, recyclerView.getHeight() / 2f);
|
|
137
|
+
}
|
|
138
|
+
private void applyZoom(float value, float focusX, float focusY) {
|
|
139
|
+
float next = Math.max(1f, Math.min(5f, value));
|
|
140
|
+
if (Math.abs(next - zoom) < 0.0001f) return;
|
|
141
|
+
float previous = zoom;
|
|
142
|
+
int position = layoutManager == null ? RecyclerView.NO_POSITION : layoutManager.findFirstVisibleItemPosition();
|
|
143
|
+
View anchor = position == RecyclerView.NO_POSITION ? null : layoutManager.findViewByPosition(position);
|
|
144
|
+
int top = anchor == null ? 0 : anchor.getTop();
|
|
145
|
+
zoom = next;
|
|
146
|
+
if ("continuous".equals(layoutMode)) {
|
|
147
|
+
panX = PapyrusComicPageLayout.clampPanX(focusX - (focusX - panX) * next / previous, recyclerView.getWidth(), next);
|
|
148
|
+
panY = 0;
|
|
149
|
+
adapter.setZoom(next);
|
|
150
|
+
adapter.setPan(panX, 0);
|
|
151
|
+
if (anchor != null) layoutManager.scrollToPositionWithOffset(position,
|
|
152
|
+
PapyrusComicPageLayout.zoomAnchorTop(top, focusY, previous, next));
|
|
153
|
+
recyclerView.requestLayout();
|
|
154
|
+
} else {
|
|
155
|
+
if (next == 1f) { panX = 0; panY = 0; adapter.setPan(0, 0); }
|
|
156
|
+
adapter.setZoom(next);
|
|
157
|
+
}
|
|
118
158
|
}
|
|
119
159
|
public void setPageTheme(String value) { pageTheme = value == null ? "normal" : value; applyTheme(); }
|
|
120
160
|
|
|
121
161
|
@Override public boolean dispatchTouchEvent(android.view.MotionEvent event) {
|
|
122
162
|
scaleDetector.onTouchEvent(event);
|
|
163
|
+
if (event.getPointerCount() == 1 && !scaleDetector.isInProgress()) {
|
|
164
|
+
tapDetector.onTouchEvent(event);
|
|
165
|
+
}
|
|
166
|
+
if (event.getActionMasked() == android.view.MotionEvent.ACTION_POINTER_UP && event.getPointerCount() > 1) {
|
|
167
|
+
int remaining = event.getActionIndex() == 0 ? 1 : 0;
|
|
168
|
+
lastPanX = event.getX(remaining); lastPanY = event.getY(remaining);
|
|
169
|
+
}
|
|
123
170
|
if (event.getActionMasked() == android.view.MotionEvent.ACTION_DOWN) {
|
|
124
171
|
lastPanX = event.getX();
|
|
125
172
|
lastPanY = event.getY();
|
|
@@ -129,7 +176,13 @@ public final class PapyrusComicDocumentView extends FrameLayout {
|
|
|
129
176
|
|
|
130
177
|
@Override public boolean onInterceptTouchEvent(android.view.MotionEvent event) {
|
|
131
178
|
if (scaleDetector.isInProgress()) return true;
|
|
132
|
-
if (zoom > 1f && event.getPointerCount() == 1 && event.getActionMasked() == android.view.MotionEvent.ACTION_MOVE)
|
|
179
|
+
if (zoom > 1f && event.getPointerCount() == 1 && event.getActionMasked() == android.view.MotionEvent.ACTION_MOVE) {
|
|
180
|
+
if ("continuous".equals(layoutMode)) {
|
|
181
|
+
float dx = Math.abs(event.getX() - lastPanX), dy = Math.abs(event.getY() - lastPanY);
|
|
182
|
+
return dx > android.view.ViewConfiguration.get(getContext()).getScaledTouchSlop() && dx > dy;
|
|
183
|
+
}
|
|
184
|
+
return true;
|
|
185
|
+
}
|
|
133
186
|
return super.onInterceptTouchEvent(event);
|
|
134
187
|
}
|
|
135
188
|
|
|
@@ -137,6 +190,14 @@ public final class PapyrusComicDocumentView extends FrameLayout {
|
|
|
137
190
|
if (scaleDetector.isInProgress()) return true;
|
|
138
191
|
if (zoom > 1f && event.getPointerCount() == 1) {
|
|
139
192
|
if (event.getActionMasked() == android.view.MotionEvent.ACTION_MOVE) {
|
|
193
|
+
if ("continuous".equals(layoutMode)) {
|
|
194
|
+
panX = PapyrusComicPageLayout.clampPanX(panX + event.getX() - lastPanX, recyclerView.getWidth(), zoom);
|
|
195
|
+
recyclerView.scrollBy(0, Math.round(lastPanY - event.getY()));
|
|
196
|
+
lastPanX = event.getX(); lastPanY = event.getY();
|
|
197
|
+
adapter.setPan(panX, 0);
|
|
198
|
+
emitCurrentPage();
|
|
199
|
+
return true;
|
|
200
|
+
}
|
|
140
201
|
panX += event.getX() - lastPanX;
|
|
141
202
|
panY += event.getY() - lastPanY;
|
|
142
203
|
lastPanX = event.getX();
|
|
@@ -181,11 +242,12 @@ public final class PapyrusComicDocumentView extends FrameLayout {
|
|
|
181
242
|
payload.putDouble("zoom", zoom);
|
|
182
243
|
context.getJSModule(RCTEventEmitter.class).receiveEvent(getId(), "onZoomChanged", payload);
|
|
183
244
|
}
|
|
184
|
-
private void emitError(String key, String message) {
|
|
245
|
+
private void emitError(String key, String message, String sourceEngineId, int sourceGeneration) {
|
|
185
246
|
synchronized (emittedErrors) {
|
|
186
247
|
if (!emittedErrors.add(key)) return;
|
|
187
248
|
}
|
|
188
249
|
post(() -> {
|
|
250
|
+
if (!sourceEngineId.equals(engineId) || sourceGeneration != generation) return;
|
|
189
251
|
ReactContext context = (ReactContext) getContext();
|
|
190
252
|
com.facebook.react.bridge.WritableMap payload = Arguments.createMap();
|
|
191
253
|
payload.putString("message", message == null ? "Unable to decode comic page" : message);
|
|
@@ -217,7 +279,7 @@ public final class PapyrusComicDocumentView extends FrameLayout {
|
|
|
217
279
|
}
|
|
218
280
|
@Override public void onBindViewHolder(@NonNull ComicHolder holder, int position) {
|
|
219
281
|
RecyclerView.LayoutParams itemParams = (RecyclerView.LayoutParams) holder.itemView.getLayoutParams();
|
|
220
|
-
itemParams.width = Math.max(1, recyclerView.getWidth());
|
|
282
|
+
itemParams.width = "continuous".equals(layoutMode) ? PapyrusComicPageLayout.zoomedWidth(recyclerView.getWidth(), zoom) : Math.max(1, recyclerView.getWidth());
|
|
221
283
|
itemParams.height = Math.max(1, recyclerView.getHeight());
|
|
222
284
|
holder.itemView.setLayoutParams(itemParams);
|
|
223
285
|
final int logicalPage = position;
|
|
@@ -225,10 +287,12 @@ public final class PapyrusComicDocumentView extends FrameLayout {
|
|
|
225
287
|
final int docGeneration = generation;
|
|
226
288
|
final int token = ++holder.bindToken;
|
|
227
289
|
holder.image.setImageDrawable(null);
|
|
228
|
-
|
|
229
|
-
holder.image.
|
|
230
|
-
holder.image.
|
|
231
|
-
holder.image.
|
|
290
|
+
boolean continuous = "continuous".equals(layoutMode);
|
|
291
|
+
holder.image.setScaleX(continuous ? 1f : imageZoom);
|
|
292
|
+
holder.image.setScaleY(continuous ? 1f : imageZoom);
|
|
293
|
+
holder.image.setTranslationX(continuous ? 0f : imagePanX);
|
|
294
|
+
holder.image.setTranslationY(continuous ? 0f : imagePanY);
|
|
295
|
+
holder.itemView.setTranslationX(continuous ? imagePanX : 0f);
|
|
232
296
|
String key = id + ":" + docGeneration + ":" + logicalPage;
|
|
233
297
|
Bitmap cached = BITMAPS.get(key);
|
|
234
298
|
if (cached != null) {
|
|
@@ -245,16 +309,16 @@ public final class PapyrusComicDocumentView extends FrameLayout {
|
|
|
245
309
|
bounds.inJustDecodeBounds = true;
|
|
246
310
|
BitmapFactory.decodeFile(path, bounds);
|
|
247
311
|
if (bounds.outWidth <= 0 || bounds.outHeight <= 0) {
|
|
248
|
-
emitError(key, "Unsupported or corrupt comic image");
|
|
312
|
+
emitError(key, "Unsupported or corrupt comic image", id, docGeneration);
|
|
249
313
|
return;
|
|
250
314
|
}
|
|
251
315
|
if (bounds.outWidth > 20000 || bounds.outHeight > 20000 || (long) bounds.outWidth * (long) bounds.outHeight > 80_000_000L) {
|
|
252
|
-
emitError(key, "Comic image exceeds supported dimensions");
|
|
316
|
+
emitError(key, "Comic image exceeds supported dimensions", id, docGeneration);
|
|
253
317
|
return;
|
|
254
318
|
}
|
|
255
319
|
if (bounds.outWidth > 0 && bounds.outHeight > 0) {
|
|
256
320
|
post(() -> {
|
|
257
|
-
if (holder.bindToken == token) applyPageHeightForImage(holder, bounds.outWidth, bounds.outHeight);
|
|
321
|
+
if (holder.bindToken == token && id.equals(engineId) && docGeneration == generation) applyPageHeightForImage(holder, bounds.outWidth, bounds.outHeight);
|
|
258
322
|
});
|
|
259
323
|
int maxEdge = Math.max(getWidth(), getHeight()) * 2;
|
|
260
324
|
int sample = 1;
|
|
@@ -265,7 +329,7 @@ public final class PapyrusComicDocumentView extends FrameLayout {
|
|
|
265
329
|
bitmap = BitmapFactory.decodeFile(path, options);
|
|
266
330
|
}
|
|
267
331
|
} catch (Throwable error) {
|
|
268
|
-
emitError(key, error.getMessage());
|
|
332
|
+
emitError(key, error.getMessage(), id, docGeneration);
|
|
269
333
|
}
|
|
270
334
|
if (bitmap == null) return;
|
|
271
335
|
BITMAPS.put(key, bitmap);
|
|
@@ -279,16 +343,37 @@ public final class PapyrusComicDocumentView extends FrameLayout {
|
|
|
279
343
|
});
|
|
280
344
|
}
|
|
281
345
|
@Override public int getItemCount() { return pageCount; }
|
|
346
|
+
@Override public void onViewAttachedToWindow(@NonNull ComicHolder holder) {
|
|
347
|
+
super.onViewAttachedToWindow(holder);
|
|
348
|
+
// Prefetched/scrapped holders can be attached without another bind after a pinch.
|
|
349
|
+
// Synchronize their geometry too, so an old viewport-width cell cannot clip the image.
|
|
350
|
+
boolean continuous = "continuous".equals(layoutMode);
|
|
351
|
+
RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) holder.itemView.getLayoutParams();
|
|
352
|
+
params.width = continuous ? PapyrusComicPageLayout.zoomedWidth(recyclerView.getWidth(), zoom) : Math.max(1, recyclerView.getWidth());
|
|
353
|
+
holder.itemView.setLayoutParams(params);
|
|
354
|
+
holder.itemView.setTranslationX(continuous ? imagePanX : 0f);
|
|
355
|
+
holder.image.setScaleX(continuous ? 1f : imageZoom);
|
|
356
|
+
holder.image.setScaleY(continuous ? 1f : imageZoom);
|
|
357
|
+
holder.image.setTranslationX(continuous ? 0f : imagePanX);
|
|
358
|
+
holder.image.setTranslationY(continuous ? 0f : imagePanY);
|
|
359
|
+
if (holder.image.getDrawable() instanceof android.graphics.drawable.BitmapDrawable) {
|
|
360
|
+
Bitmap bitmap = ((android.graphics.drawable.BitmapDrawable) holder.image.getDrawable()).getBitmap();
|
|
361
|
+
applyPageHeightForImage(holder, bitmap.getWidth(), bitmap.getHeight());
|
|
362
|
+
}
|
|
363
|
+
holder.itemView.forceLayout();
|
|
364
|
+
recyclerView.requestLayout();
|
|
365
|
+
}
|
|
282
366
|
private void applyPageHeightForImage(ComicHolder holder, int imageWidth, int imageHeight) {
|
|
283
367
|
if (!(holder.itemView.getLayoutParams() instanceof RecyclerView.LayoutParams)) return;
|
|
284
368
|
RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) holder.itemView.getLayoutParams();
|
|
285
|
-
int height = PapyrusComicPageLayout.
|
|
369
|
+
int height = PapyrusComicPageLayout.zoomedHeight(
|
|
286
370
|
imageWidth,
|
|
287
371
|
imageHeight,
|
|
288
372
|
recyclerView.getWidth(),
|
|
289
373
|
recyclerView.getHeight(),
|
|
290
374
|
layoutMode,
|
|
291
|
-
fitMode
|
|
375
|
+
fitMode,
|
|
376
|
+
zoom
|
|
292
377
|
);
|
|
293
378
|
if (params.height != height) {
|
|
294
379
|
params.height = height;
|
|
@@ -299,6 +384,22 @@ public final class PapyrusComicDocumentView extends FrameLayout {
|
|
|
299
384
|
private void configurePageImage(ComicHolder holder, Bitmap bitmap) {
|
|
300
385
|
boolean widthFit = "single".equals(layoutMode) && "width".equals(fitMode) && recyclerView.getWidth() > 0;
|
|
301
386
|
ScrollView.LayoutParams params;
|
|
387
|
+
FrameLayout cell = (FrameLayout) holder.itemView;
|
|
388
|
+
if ("continuous".equals(layoutMode)) {
|
|
389
|
+
if (holder.image.getParent() != cell) {
|
|
390
|
+
((android.view.ViewGroup) holder.image.getParent()).removeView(holder.image);
|
|
391
|
+
cell.addView(holder.image, new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
|
|
392
|
+
}
|
|
393
|
+
holder.pageScrollView.setVisibility(View.GONE);
|
|
394
|
+
holder.image.setScaleType(ImageView.ScaleType.FIT_CENTER);
|
|
395
|
+
holder.pageScrollView.scrollTo(0, 0);
|
|
396
|
+
return;
|
|
397
|
+
}
|
|
398
|
+
if (holder.image.getParent() != holder.pageScrollView) {
|
|
399
|
+
((android.view.ViewGroup) holder.image.getParent()).removeView(holder.image);
|
|
400
|
+
holder.pageScrollView.addView(holder.image);
|
|
401
|
+
}
|
|
402
|
+
holder.pageScrollView.setVisibility(View.VISIBLE);
|
|
302
403
|
if (widthFit) {
|
|
303
404
|
int width = recyclerView.getWidth();
|
|
304
405
|
int height = Math.max(1, Math.round(width * ((float) bitmap.getHeight() / (float) bitmap.getWidth())));
|
|
@@ -307,7 +408,7 @@ public final class PapyrusComicDocumentView extends FrameLayout {
|
|
|
307
408
|
holder.pageScrollView.setVerticalScrollBarEnabled(height > recyclerView.getHeight());
|
|
308
409
|
holder.pageScrollView.setFillViewport(false);
|
|
309
410
|
} else {
|
|
310
|
-
params = new ScrollView.LayoutParams(LayoutParams.MATCH_PARENT,
|
|
411
|
+
params = new ScrollView.LayoutParams(LayoutParams.MATCH_PARENT, Math.max(1, recyclerView.getHeight()));
|
|
311
412
|
holder.image.setScaleType(ImageView.ScaleType.FIT_CENTER);
|
|
312
413
|
holder.pageScrollView.setVerticalScrollBarEnabled(false);
|
|
313
414
|
holder.pageScrollView.setFillViewport(true);
|
|
@@ -321,8 +422,18 @@ public final class PapyrusComicDocumentView extends FrameLayout {
|
|
|
321
422
|
RecyclerView.ViewHolder holder = recyclerView.getChildViewHolder(child);
|
|
322
423
|
if (holder instanceof ComicHolder) {
|
|
323
424
|
ImageView image = ((ComicHolder) holder).image;
|
|
324
|
-
|
|
325
|
-
|
|
425
|
+
if ("continuous".equals(layoutMode)) {
|
|
426
|
+
RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
|
|
427
|
+
params.width = PapyrusComicPageLayout.zoomedWidth(recyclerView.getWidth(), value);
|
|
428
|
+
child.setLayoutParams(params);
|
|
429
|
+
image.setScaleX(1f); image.setScaleY(1f);
|
|
430
|
+
if (image.getDrawable() instanceof android.graphics.drawable.BitmapDrawable) {
|
|
431
|
+
Bitmap bitmap = ((android.graphics.drawable.BitmapDrawable) image.getDrawable()).getBitmap();
|
|
432
|
+
applyPageHeightForImage((ComicHolder) holder, bitmap.getWidth(), bitmap.getHeight());
|
|
433
|
+
}
|
|
434
|
+
} else {
|
|
435
|
+
image.setScaleX(value); image.setScaleY(value);
|
|
436
|
+
}
|
|
326
437
|
}
|
|
327
438
|
}
|
|
328
439
|
}
|
|
@@ -334,12 +445,39 @@ public final class PapyrusComicDocumentView extends FrameLayout {
|
|
|
334
445
|
RecyclerView.ViewHolder holder = recyclerView.getChildViewHolder(child);
|
|
335
446
|
if (holder instanceof ComicHolder) {
|
|
336
447
|
ImageView image = ((ComicHolder) holder).image;
|
|
337
|
-
|
|
338
|
-
|
|
448
|
+
if ("continuous".equals(layoutMode)) {
|
|
449
|
+
child.setTranslationX(x);
|
|
450
|
+
image.setTranslationX(0f); image.setTranslationY(0f);
|
|
451
|
+
} else {
|
|
452
|
+
child.setTranslationX(0f);
|
|
453
|
+
image.setTranslationX(x); image.setTranslationY(y);
|
|
454
|
+
}
|
|
339
455
|
}
|
|
340
456
|
}
|
|
341
457
|
}
|
|
342
458
|
}
|
|
459
|
+
// React Native owns the outer view layout and can consume child requestLayout.
|
|
460
|
+
// Remeasure the native list when late image dimensions replace placeholder cells.
|
|
461
|
+
private static final class PapyrusComicRecyclerView extends RecyclerView {
|
|
462
|
+
private boolean layoutPending;
|
|
463
|
+
PapyrusComicRecyclerView(Context context) { super(context); }
|
|
464
|
+
@Override public void requestLayout() {
|
|
465
|
+
super.requestLayout();
|
|
466
|
+
if (layoutPending) return;
|
|
467
|
+
layoutPending = true;
|
|
468
|
+
post(() -> {
|
|
469
|
+
try {
|
|
470
|
+
int width = getWidth(), height = getHeight();
|
|
471
|
+
if (width <= 0 || height <= 0) return;
|
|
472
|
+
forceLayout();
|
|
473
|
+
measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY),
|
|
474
|
+
MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
|
|
475
|
+
layout(getLeft(), getTop(), getLeft() + width, getTop() + height);
|
|
476
|
+
} finally { layoutPending = false; }
|
|
477
|
+
});
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
|
|
343
481
|
private static final class ComicHolder extends RecyclerView.ViewHolder {
|
|
344
482
|
final ScrollView pageScrollView;
|
|
345
483
|
final ImageView image;
|
|
@@ -14,4 +14,25 @@ final class PapyrusComicPageLayout {
|
|
|
14
14
|
int proposedHeight = Math.max(1, Math.round(Math.max(1, viewportWidth) * ratio));
|
|
15
15
|
return "page".equals(fitMode) ? Math.min(safeViewportHeight, proposedHeight) : proposedHeight;
|
|
16
16
|
}
|
|
17
|
+
static int zoomedWidth(int viewportWidth, float zoom) {
|
|
18
|
+
return Math.max(1, Math.round(Math.max(1, viewportWidth) * Math.max(1f, Math.min(5f, zoom))));
|
|
19
|
+
}
|
|
20
|
+
static int zoomedHeight(int imageWidth, int imageHeight, int viewportWidth, int viewportHeight,
|
|
21
|
+
String layoutMode, String fitMode, float zoom) {
|
|
22
|
+
int base = itemHeight(imageWidth, imageHeight, viewportWidth, viewportHeight, layoutMode, fitMode);
|
|
23
|
+
return "continuous".equals(layoutMode) ? Math.max(1, Math.round(base * Math.max(1f, Math.min(5f, zoom)))) : base;
|
|
24
|
+
}
|
|
25
|
+
static float clampPanX(float x, int viewportWidth, float zoom) {
|
|
26
|
+
return Math.max(-Math.max(0, zoomedWidth(viewportWidth, zoom) - viewportWidth), Math.min(0f, x));
|
|
27
|
+
}
|
|
28
|
+
static int zoomAnchorTop(int oldTop, float focusY, float oldZoom, float newZoom) {
|
|
29
|
+
return Math.round(focusY + (oldTop - focusY) * newZoom / Math.max(1f, oldZoom));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
static float panForLayout(float x, int viewportWidth, float zoom, boolean toContinuous) {
|
|
33
|
+
float halfOverflow = Math.max(0, zoomedWidth(viewportWidth, zoom) - viewportWidth) / 2f;
|
|
34
|
+
return toContinuous ? clampPanX(x - halfOverflow, viewportWidth, zoom)
|
|
35
|
+
: Math.max(-halfOverflow, Math.min(halfOverflow, x + halfOverflow));
|
|
36
|
+
}
|
|
37
|
+
|
|
17
38
|
}
|
|
@@ -130,6 +130,18 @@ public class PapyrusNativeEngineModule extends ReactContextBaseJavaModule {
|
|
|
130
130
|
promise.resolve(text.substring(start, end));
|
|
131
131
|
}
|
|
132
132
|
|
|
133
|
+
@ReactMethod
|
|
134
|
+
public void resolveTextAnnotationRange(String engineId,int generation,ReadableMap anchor,Promise promise) {
|
|
135
|
+
executor.execute(()->{
|
|
136
|
+
try {
|
|
137
|
+
String text=PapyrusTextStore.getText(engineId,generation);
|
|
138
|
+
int[] range=PapyrusTextAnnotationModel.resolve(text,anchor.getInt("start"),anchor.getInt("end"),anchor.getString("quote"),anchor.hasKey("prefix")&&!anchor.isNull("prefix")?anchor.getString("prefix"):null,anchor.hasKey("suffix")&&!anchor.isNull("suffix")?anchor.getString("suffix"):null);
|
|
139
|
+
if(range==null){promise.resolve(null);return;}
|
|
140
|
+
WritableMap result=Arguments.createMap();result.putInt("start",range[0]);result.putInt("end",range[1]);promise.resolve(result);
|
|
141
|
+
} catch(Exception error){promise.reject("papyrus_text_anchor_invalid",error);}
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
|
|
133
145
|
@ReactMethod
|
|
134
146
|
public void searchTextRanges(String engineId, int generation, String query, Promise promise) {
|
|
135
147
|
executor.execute(() -> {
|