@quran.ws/qvp-react-native 0.7.0 → 0.9.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.
- package/README.md +86 -32
- package/android/build.gradle +16 -8
- package/android/src/main/java/ws/quran/qvp/rn/Codes.kt +34 -0
- package/android/src/main/java/ws/quran/qvp/rn/Marshal.kt +78 -30
- package/android/src/main/java/ws/quran/qvp/rn/QvpModule.kt +105 -50
- package/android/src/main/java/ws/quran/qvp/rn/QvpPageViewManager.kt +1 -0
- package/android/src/main/java/ws/quran/qvp/rn/QvpRnPageView.kt +55 -14
- package/android/src/main/java/ws/quran/qvp/rn/QvpRnWords.kt +26 -0
- package/ios/QvpModule.m +167 -0
- package/ios/QvpModule.swift +508 -0
- package/ios/QvpRnBytes.swift +66 -0
- package/ios/QvpRnCodes.swift +33 -0
- package/ios/QvpRnMarshal.swift +360 -0
- package/ios/QvpRnPageView.swift +467 -0
- package/ios/QvpRnPassageView.swift +160 -0
- package/ios/vendor/QvpEngine.json +4 -0
- package/ios/vendor/QvpKit/QvpDress.swift +390 -0
- package/ios/vendor/QvpKit/QvpEngine.swift +55 -0
- package/ios/vendor/QvpKit/QvpPage.swift +469 -0
- package/ios/vendor/QvpKit/QvpPageCache.swift +176 -0
- package/ios/vendor/QvpKit/QvpPageCanvas.swift +1031 -0
- package/ios/vendor/QvpKit/QvpPageView.swift +711 -0
- package/ios/vendor/QvpKit/QvpPassage.swift +240 -0
- package/ios/vendor/QvpKit/QvpViewPolicy.swift +26 -0
- package/ios/vendor/QvpKit/QvpZoom.swift +200 -0
- package/ios/vendor/QvpKit/QvpZoomSpring.swift +22 -0
- package/ios/vendor/QvpKit/Types.swift +440 -0
- package/ios/vendor-qvpkit.sh +36 -0
- package/package.json +10 -3
- package/qvp-react-native.podspec +97 -0
- package/src/codes.ts +33 -0
- package/src/index.tsx +171 -55
|
@@ -3,27 +3,71 @@ package ws.quran.qvp.rn
|
|
|
3
3
|
import com.facebook.react.bridge.*
|
|
4
4
|
import com.facebook.react.module.annotations.ReactModule
|
|
5
5
|
import com.facebook.react.uimanager.UIManagerHelper
|
|
6
|
+
import java.util.concurrent.CountDownLatch
|
|
7
|
+
import java.util.concurrent.ExecutorService
|
|
8
|
+
import java.util.concurrent.Executors
|
|
9
|
+
import java.util.concurrent.RejectedExecutionException
|
|
6
10
|
import ws.quran.qvp.*
|
|
7
11
|
import ws.quran.qvp.Target
|
|
8
12
|
|
|
9
13
|
/**
|
|
10
14
|
* Promise-based queries on the page behind a `<QvpPageView />` (looked up by react tag) plus engine-wide
|
|
11
|
-
* helpers and the atlas.
|
|
12
|
-
*
|
|
15
|
+
* helpers and the atlas. Names follow docs/API.md.
|
|
16
|
+
*
|
|
17
|
+
* Two threads run the calls. The query thread, which this module owns, runs every call that reads
|
|
18
|
+
* only what a page fixed when it loaded: its words, ayahs, lines, text, search, metadata and crop
|
|
19
|
+
* box. It also runs the engine-wide helpers and owns the atlases. A long query on it does not hold
|
|
20
|
+
* up a frame. The view keeps the page open while a query reads it ([QvpRnPageView.read]). Every
|
|
21
|
+
* call that reads or changes the layout, the view, styles, colours, the selection, the mask, the
|
|
22
|
+
* reveal or the dress runs on the UI thread, where the view draws.
|
|
13
23
|
*/
|
|
14
24
|
@ReactModule(name = QvpModule.NAME)
|
|
15
25
|
class QvpModule(private val ctx: ReactApplicationContext) : ReactContextBaseJavaModule(ctx) {
|
|
16
26
|
override fun getName() = NAME
|
|
27
|
+
/** The query thread. The atlases below are touched only on it. */
|
|
28
|
+
private val queries: ExecutorService = Executors.newSingleThreadExecutor { r -> Thread(r, "qvp-rn-query").apply { isDaemon = true } }
|
|
17
29
|
private val atlases = HashMap<Int, QvpAtlas>()
|
|
18
30
|
private val atlasByUri = HashMap<String, Int>()
|
|
19
31
|
private var nextAtlas = 1
|
|
20
32
|
|
|
21
33
|
private fun view(tag: Int): QvpRnPageView? = QvpRegistry.get(tag) ?: runCatching { UIManagerHelper.getUIManagerForReactTag(ctx, tag)?.resolveView(tag) as? QvpRnPageView }.getOrNull()
|
|
22
34
|
// Every @ReactMethod must be `void` for the TurboModule interop layer: these helpers return Unit on purpose.
|
|
23
|
-
private fun
|
|
35
|
+
private fun settle(promise: Promise, block: () -> Any?) {
|
|
36
|
+
try { promise.resolve(Marshal.toJs(block())) } catch (e: Throwable) { promise.reject("qvp", e.message ?: e.toString(), e) }
|
|
37
|
+
}
|
|
38
|
+
private fun ui(promise: Promise, block: () -> Any?) { UiThreadUtil.runOnUiThread { settle(promise, block) } }
|
|
39
|
+
/** Run [task] on the query thread, or reject when the module is gone. */
|
|
40
|
+
private fun queue(promise: Promise, task: () -> Unit) {
|
|
41
|
+
try { queries.execute(task) } catch (e: RejectedExecutionException) { promise.reject("qvp", "QvpModule was invalidated", e) }
|
|
42
|
+
}
|
|
43
|
+
/** An engine-wide call, or an atlas call, on the query thread. */
|
|
44
|
+
private fun off(promise: Promise, block: () -> Any?) = queue(promise) { settle(promise, block) }
|
|
45
|
+
/**
|
|
46
|
+
* A read-only page query on the query thread, with the page held open until it returns. A view
|
|
47
|
+
* the registry does not hold (not attached yet, or detached) is found through the UIManager,
|
|
48
|
+
* which only the UI thread may call, so that query runs there as before.
|
|
49
|
+
*/
|
|
50
|
+
private fun readPage(tag: Int, promise: Promise, block: (QvpRnPageView, QvpPage) -> Any?) = queue(promise) {
|
|
51
|
+
val v = QvpRegistry.get(tag)
|
|
52
|
+
if (v == null) withPage(tag, promise, block)
|
|
53
|
+
else settle(promise) { v.read { p -> block(v, p ?: throw IllegalStateException("QvpPageView $tag has no page loaded")) } }
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* A page call on the UI thread that the queries queued before it see done, and that is done
|
|
57
|
+
* before the queries queued after it start: the query thread waits for it. It holds no page
|
|
58
|
+
* open while it waits, so the UI thread never waits for it in turn.
|
|
59
|
+
*/
|
|
60
|
+
private fun inOrder(tag: Int, promise: Promise, block: (QvpRnPageView, QvpPage) -> Any?) = queue(promise) {
|
|
61
|
+
val done = CountDownLatch(1)
|
|
24
62
|
UiThreadUtil.runOnUiThread {
|
|
25
|
-
try {
|
|
63
|
+
try {
|
|
64
|
+
settle(promise) {
|
|
65
|
+
val v = view(tag) ?: throw IllegalStateException("no QvpPageView with tag $tag")
|
|
66
|
+
block(v, v.page ?: throw IllegalStateException("QvpPageView $tag has no page loaded"))
|
|
67
|
+
}
|
|
68
|
+
} finally { done.countDown() }
|
|
26
69
|
}
|
|
70
|
+
try { done.await() } catch (_: InterruptedException) { Thread.currentThread().interrupt() }
|
|
27
71
|
}
|
|
28
72
|
private fun withPage(tag: Int, promise: Promise, block: (QvpRnPageView, QvpPage) -> Any?) {
|
|
29
73
|
ui(promise) {
|
|
@@ -32,60 +76,65 @@ class QvpModule(private val ctx: ReactApplicationContext) : ReactContextBaseJava
|
|
|
32
76
|
block(v, p)
|
|
33
77
|
}
|
|
34
78
|
}
|
|
35
|
-
private fun withAtlas(id: Int, promise: Promise, block: (QvpAtlas) -> Any?)
|
|
79
|
+
private fun withAtlas(id: Int, promise: Promise, block: (QvpAtlas) -> Any?) = off(promise) { block(atlases[id] ?: throw IllegalStateException("no atlas $id")) }
|
|
36
80
|
private fun opt(m: ReadableMap?): Map<String, Any?> = m?.toHashMap() ?: emptyMap()
|
|
37
|
-
|
|
38
|
-
|
|
81
|
+
/** A target argument as plain values. A query reads its arguments this way on the calling
|
|
82
|
+
* thread, before it is queued, since the bridge's argument objects belong to the call. */
|
|
83
|
+
private fun plain(d: Dynamic): Any? = when (d.type) {
|
|
84
|
+
ReadableType.String -> d.asString(); ReadableType.Number -> d.asDouble(); ReadableType.Array -> d.asArray()?.toArrayList(); ReadableType.Map -> d.asMap()?.toHashMap(); else -> null }
|
|
85
|
+
private fun tgt(d: Dynamic, p: QvpPage): Target = Marshal.target(plain(d), p)
|
|
39
86
|
private fun ints(a: ReadableArray?): IntArray = a?.toArrayList()?.mapNotNull { (it as? Number)?.toInt() }?.toIntArray() ?: IntArray(0)
|
|
40
87
|
|
|
41
88
|
// ── page facts ──
|
|
42
|
-
@ReactMethod fun info(tag: Int, promise: Promise) =
|
|
43
|
-
@ReactMethod fun words(tag: Int, promise: Promise) =
|
|
44
|
-
@ReactMethod fun word(tag: Int, index: Int, promise: Promise) =
|
|
45
|
-
@ReactMethod fun ayahs(tag: Int, promise: Promise) =
|
|
46
|
-
@ReactMethod fun lines(tag: Int, promise: Promise) =
|
|
47
|
-
@ReactMethod fun decorations(tag: Int, promise: Promise) =
|
|
48
|
-
@ReactMethod fun findWord(tag: Int, s: Int, a: Int, w: Int, promise: Promise) =
|
|
49
|
-
@ReactMethod fun targetWords(tag: Int, target: Dynamic, promise: Promise) =
|
|
50
|
-
@ReactMethod fun wordForm(tag: Int, index: Int, form: String?, promise: Promise) =
|
|
51
|
-
@ReactMethod fun hasForm(tag: Int, form: String?, promise: Promise) =
|
|
52
|
-
@ReactMethod fun attachWords(tag: Int, json: String, promise: Promise) =
|
|
89
|
+
@ReactMethod fun info(tag: Int, promise: Promise) = readPage(tag, promise) { v, p -> Marshal.pageInfo(p, v.words(p).forms) + mapOf("loadMs" to v.loadMs, "bytes" to v.pageBytes) }
|
|
90
|
+
@ReactMethod fun words(tag: Int, promise: Promise) = readPage(tag, promise) { v, p -> v.words(p).all() }
|
|
91
|
+
@ReactMethod fun word(tag: Int, index: Int, promise: Promise) = readPage(tag, promise) { v, p -> v.words(p).word(index) }
|
|
92
|
+
@ReactMethod fun ayahs(tag: Int, promise: Promise) = readPage(tag, promise) { _, p -> p.ayahs.map { Marshal.ayah(it) } }
|
|
93
|
+
@ReactMethod fun lines(tag: Int, promise: Promise) = readPage(tag, promise) { _, p -> p.lines.map { Marshal.line(it) } }
|
|
94
|
+
@ReactMethod fun decorations(tag: Int, promise: Promise) = readPage(tag, promise) { _, p -> p.decorations.map { Marshal.decoration(it) } }
|
|
95
|
+
@ReactMethod fun findWord(tag: Int, s: Int, a: Int, w: Int, promise: Promise) = readPage(tag, promise) { _, p -> p.findWord(s, a, w) }
|
|
96
|
+
@ReactMethod fun targetWords(tag: Int, target: Dynamic, promise: Promise) { val t = plain(target); readPage(tag, promise) { _, p -> p.targetWords(Marshal.target(t, p)).toList() } }
|
|
97
|
+
@ReactMethod fun wordForm(tag: Int, index: Int, form: String?, promise: Promise) = readPage(tag, promise) { _, p -> p.wordForm(index, Marshal.form(form)) }
|
|
98
|
+
@ReactMethod fun hasForm(tag: Int, form: String?, promise: Promise) = readPage(tag, promise) { _, p -> p.hasForm(Marshal.form(form)) }
|
|
99
|
+
@ReactMethod fun attachWords(tag: Int, json: String, promise: Promise) = inOrder(tag, promise) { v, p -> v.attachWords(p, json) }
|
|
53
100
|
|
|
54
101
|
// ── metadata ──
|
|
55
|
-
@ReactMethod fun surahs(tag: Int, promise: Promise) =
|
|
56
|
-
@ReactMethod fun divisions(tag: Int, promise: Promise) =
|
|
102
|
+
@ReactMethod fun surahs(tag: Int, promise: Promise) = readPage(tag, promise) { _, p -> p.surahs().map { Marshal.surah(it) } }
|
|
103
|
+
@ReactMethod fun divisions(tag: Int, promise: Promise) = readPage(tag, promise) { _, p -> p.divisions().map { Marshal.division(it) } }
|
|
57
104
|
@ReactMethod fun surahHeaders(tag: Int, promise: Promise) = withPage(tag, promise) { _, p -> p.surahHeaders().map { Marshal.surahHeader(it) } }
|
|
58
105
|
@ReactMethod fun surahHeadersView(tag: Int, promise: Promise) = withPage(tag, promise) { _, p -> p.surahHeadersView().map { Marshal.surahHeader(it) } }
|
|
59
|
-
@ReactMethod fun ayahMarks(tag: Int, promise: Promise) =
|
|
60
|
-
@ReactMethod fun
|
|
61
|
-
@ReactMethod fun
|
|
62
|
-
@ReactMethod fun
|
|
63
|
-
@ReactMethod fun
|
|
64
|
-
@ReactMethod fun
|
|
65
|
-
@ReactMethod fun
|
|
66
|
-
@ReactMethod fun
|
|
106
|
+
@ReactMethod fun ayahMarks(tag: Int, promise: Promise) = readPage(tag, promise) { _, p -> p.ayahMarks().map { Marshal.ayahMark(it) } }
|
|
107
|
+
@ReactMethod fun ayahMarksView(tag: Int, promise: Promise) = withPage(tag, promise) { _, p -> p.ayahMarksView().map { Marshal.ayahMark(it) } }
|
|
108
|
+
@ReactMethod fun rosettes(tag: Int, promise: Promise) = readPage(tag, promise) { _, p -> p.rosettes().map { Marshal.rosette(it) } }
|
|
109
|
+
@ReactMethod fun sajdahs(tag: Int, promise: Promise) = readPage(tag, promise) { _, p -> p.sajdahs().map { Marshal.sajdah(it) } }
|
|
110
|
+
@ReactMethod fun ayahKeys(tag: Int, promise: Promise) = readPage(tag, promise) { _, p -> p.ayahKeys().map { mapOf("surah" to it.first, "ayah" to it.second, "ayahKey" to "${it.first}:${it.second}") } }
|
|
111
|
+
@ReactMethod fun ayahWordCount(tag: Int, s: Int, a: Int, promise: Promise) = readPage(tag, promise) { _, p -> p.ayahWordCount(s, a).let { mapOf("count" to it.first, "isComplete" to it.second) } }
|
|
112
|
+
@ReactMethod fun reciteMap(tag: Int, s: Int, a: Int, n: Int, promise: Promise) = readPage(tag, promise) { _, p -> p.reciteMap(s, a, n)?.toList() }
|
|
113
|
+
@ReactMethod fun wordLabel(tag: Int, i: Int, promise: Promise) = readPage(tag, promise) { _, p -> p.wordLabel(i) }
|
|
114
|
+
@ReactMethod fun ayahLabel(tag: Int, i: Int, promise: Promise) = readPage(tag, promise) { _, p -> p.ayahLabel(i) }
|
|
67
115
|
|
|
68
116
|
// ── text & search ──
|
|
69
|
-
@ReactMethod fun text(tag: Int, target: Dynamic, opts: ReadableMap?, promise: Promise) =
|
|
70
|
-
|
|
71
|
-
@ReactMethod fun search(tag: Int, query: String, opts: ReadableMap?, promise: Promise) =
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
@ReactMethod fun
|
|
75
|
-
@ReactMethod fun arabic(op: String, s: String, promise: Promise) = ui(promise) { when (op) { "strip" -> QvpEngine.strip(s); "fold" -> QvpEngine.fold(s); "normalize" -> QvpEngine.normalize(s); "loose", "looseKey" -> QvpEngine.looseKey(s); else -> s } }
|
|
117
|
+
@ReactMethod fun text(tag: Int, target: Dynamic, opts: ReadableMap?, promise: Promise) { val t = plain(target); val o = opt(opts)
|
|
118
|
+
readPage(tag, promise) { _, p -> p.text(Marshal.target(t, p), Marshal.form(o["form"]), (o["wordSep"] as? String) ?: " ", (o["lineSep"] as? String) ?: "\n") } }
|
|
119
|
+
@ReactMethod fun search(tag: Int, query: String, opts: ReadableMap?, promise: Promise) { val o = opt(opts)
|
|
120
|
+
readPage(tag, promise) { _, p -> p.search(query, Marshal.form(o["form"], Form.SEARCH), Marshal.searchMode(o["mode"]), o["normalize"] != false, o["looseMatch"] != false, (o["limit"] as? Number)?.toInt() ?: 0).map { Marshal.match(it) } } }
|
|
121
|
+
@ReactMethod fun citation(tag: Int, words: ReadableArray, promise: Promise) { val ws = ints(words); readPage(tag, promise) { _, p -> p.citation(ws) } }
|
|
122
|
+
@ReactMethod fun arabic(op: String, s: String, promise: Promise) = off(promise) { when (op) { "strip" -> QvpEngine.strip(s); "fold" -> QvpEngine.fold(s); "normalize" -> QvpEngine.normalize(s); "loose", "looseKey" -> QvpEngine.looseKey(s); else -> s } }
|
|
76
123
|
|
|
77
124
|
// ── hit testing / layout (the view already does gestures; these are for scroll-into-view etc.) ──
|
|
78
125
|
private fun hitOptions(o: Map<String, Any?>) = QvpHitOptions((o["maxDistance"] as? Number)?.toFloat() ?: QvpDefaults.TAP_DISTANCE, (o["gapBias"] as? Number)?.toFloat() ?: QvpDefaults.GAP_BIAS, o["preferExact"] != false)
|
|
79
|
-
/** Exact
|
|
126
|
+
/** Exact hit at a point in page units: the outline under the point, else the box of a word or a decoration. */
|
|
80
127
|
@ReactMethod fun hitTestExact(tag: Int, x: Double, y: Double, promise: Promise) = withPage(tag, promise) { _, p -> p.hitTestExact(x.toFloat(), y.toFloat())?.let { Marshal.hit(p, it) } }
|
|
81
128
|
/** Gap-aware hit at a point in page units. */
|
|
82
129
|
@ReactMethod fun hitTest(tag: Int, x: Double, y: Double, opts: ReadableMap?, promise: Promise) = withPage(tag, promise) { _, p -> p.hitTest(x.toFloat(), y.toFloat(), hitOptions(opt(opts)))?.let { Marshal.hit(p, it) } }
|
|
83
|
-
/** Exact
|
|
130
|
+
/** Exact hit at a point in view dp (density and pan/zoom removed here, the layout in the engine). */
|
|
84
131
|
@ReactMethod fun hitTestExactView(tag: Int, x: Double, y: Double, promise: Promise) = withPage(tag, promise) { v, p -> val d = v.resources.displayMetrics.density
|
|
85
|
-
p.
|
|
132
|
+
val (lx, ly) = p.viewToLayout(QvpView(v.inner.viewScale, v.inner.viewOx, v.inner.viewOy), (x * d).toFloat(), (y * d).toFloat())
|
|
133
|
+
p.hitTestExactView(lx, ly)?.let { Marshal.hit(p, it) } }
|
|
86
134
|
@ReactMethod fun hitTestView(tag: Int, x: Double, y: Double, opts: ReadableMap?, promise: Promise) = withPage(tag, promise) { v, p ->
|
|
87
135
|
val o = opt(opts); val d = v.resources.displayMetrics.density
|
|
88
|
-
p.
|
|
136
|
+
val (lx, ly) = p.viewToLayout(QvpView(v.inner.viewScale, v.inner.viewOx, v.inner.viewOy), (x * d).toFloat(), (y * d).toFloat())
|
|
137
|
+
p.hitTestView(lx, ly, hitOptions(o))?.let { Marshal.hit(p, it) } }
|
|
89
138
|
@ReactMethod fun wordBoundsView(tag: Int, i: Int, promise: Promise) = withPage(tag, promise) { v, p -> val d = v.resources.displayMetrics.density
|
|
90
139
|
p.wordBoundsView(i)?.let { b -> mapOf("x0" to (v.inner.viewOx + b[0] * v.inner.viewScale) / d, "y0" to (v.inner.viewOy + b[1] * v.inner.viewScale) / d, "x1" to (v.inner.viewOx + b[2] * v.inner.viewScale) / d, "y1" to (v.inner.viewOy + b[3] * v.inner.viewScale) / d) } }
|
|
91
140
|
@ReactMethod fun currentLayout(tag: Int, promise: Promise) = withPage(tag, promise) { _, p -> p.currentLayout?.let { Marshal.layout(it) } }
|
|
@@ -96,7 +145,7 @@ class QvpModule(private val ctx: ReactApplicationContext) : ReactContextBaseJava
|
|
|
96
145
|
@ReactMethod fun layoutWastedFraction(tag: Int, promise: Promise) = withPage(tag, promise) { v, p -> p.layoutWastedFraction(v.inner.layoutSpec()) }
|
|
97
146
|
/** The page's height at the printed pitch for the spec this view lays out with. */
|
|
98
147
|
@ReactMethod fun layoutPrintedHeight(tag: Int, promise: Promise) = withPage(tag, promise) { v, p -> p.layoutPrintedHeight(v.inner.layoutSpec()) }
|
|
99
|
-
@ReactMethod fun grid(tag: Int, promise: Promise) =
|
|
148
|
+
@ReactMethod fun grid(tag: Int, promise: Promise) = readPage(tag, promise) { _, p -> mapOf("lines" to p.grid.lines, "lineSpacing" to p.grid.lineSpacing) }
|
|
100
149
|
@ReactMethod fun stats(tag: Int, promise: Promise) = ui(promise) { view(tag)?.stats() }
|
|
101
150
|
@ReactMethod fun invalidate(tag: Int, promise: Promise) = ui(promise) { view(tag)?.inner?.invalidate(); null }
|
|
102
151
|
|
|
@@ -120,13 +169,13 @@ class QvpModule(private val ctx: ReactApplicationContext) : ReactContextBaseJava
|
|
|
120
169
|
@ReactMethod fun revealStepOf(tag: Int, i: Int, promise: Promise) = withPage(tag, promise) { _, p -> p.revealStepOf(i).toDouble() }
|
|
121
170
|
|
|
122
171
|
// ── crop ──
|
|
123
|
-
@ReactMethod fun cropBounds(tag: Int, target: Dynamic, opts: ReadableMap?, promise: Promise) =
|
|
124
|
-
|
|
172
|
+
@ReactMethod fun cropBounds(tag: Int, target: Dynamic, opts: ReadableMap?, promise: Promise) { val t = plain(target); val o = opt(opts)
|
|
173
|
+
readPage(tag, promise) { _, p -> p.cropBounds(Marshal.target(t, p), (o["pad"] as? Number)?.toFloat() ?: QvpDefaults.CROP_PAD, o["keepAyahMarks"] != false)?.let { Marshal.cropBounds(it) } } }
|
|
125
174
|
@ReactMethod fun cropSvg(tag: Int, target: Dynamic, opts: ReadableMap?, promise: Promise) = withPage(tag, promise) { _, p ->
|
|
126
175
|
val o = opt(opts); p.cropSvg(tgt(target, p), (o["pad"] as? Number)?.toFloat() ?: QvpDefaults.CROP_PAD, o["keepAyahMarks"] != false, Marshal.color(o["background"], 0)) }
|
|
127
176
|
|
|
128
177
|
// ── atlas ──
|
|
129
|
-
@ReactMethod fun loadAtlas(uri: String, promise: Promise) =
|
|
178
|
+
@ReactMethod fun loadAtlas(uri: String, promise: Promise) = off(promise) {
|
|
130
179
|
atlasByUri[uri] ?: run {
|
|
131
180
|
val bytes = when {
|
|
132
181
|
uri.startsWith("asset://") -> ctx.assets.open(uri.removePrefix("asset://")).use { it.readBytes() }
|
|
@@ -139,7 +188,7 @@ class QvpModule(private val ctx: ReactApplicationContext) : ReactContextBaseJava
|
|
|
139
188
|
val id = nextAtlas++; atlases[id] = QvpAtlas(bytes); atlasByUri[uri] = id; id
|
|
140
189
|
}
|
|
141
190
|
}
|
|
142
|
-
@ReactMethod fun freeAtlas(id: Int, promise: Promise) =
|
|
191
|
+
@ReactMethod fun freeAtlas(id: Int, promise: Promise) = off(promise) { atlases.remove(id)?.close(); atlasByUri.entries.removeAll { it.value == id }; null }
|
|
143
192
|
@ReactMethod fun atlasPageOf(id: Int, s: Int, a: Int, promise: Promise) = withAtlas(id, promise) { it.pageOf(s, a) }
|
|
144
193
|
@ReactMethod fun atlasPageRange(id: Int, page: Int, promise: Promise) = withAtlas(id, promise) { it.pageRange(page)?.let { r -> mapOf("first" to mapOf("surah" to r.first.first, "ayah" to r.first.second), "last" to mapOf("surah" to r.second.first, "ayah" to r.second.second)) } }
|
|
145
194
|
@ReactMethod fun atlasPageCount(id: Int, promise: Promise) = withAtlas(id, promise) { it.pageCount() }
|
|
@@ -186,19 +235,25 @@ class QvpModule(private val ctx: ReactApplicationContext) : ReactContextBaseJava
|
|
|
186
235
|
@ReactMethod fun dressRevision(tag: Int, promise: Promise) = withPage(tag, promise) { _, p -> p.dressRevision() }
|
|
187
236
|
|
|
188
237
|
// ── names ──
|
|
189
|
-
@ReactMethod fun markName(m: Int, promise: Promise) =
|
|
190
|
-
@ReactMethod fun markFromName(s: String, promise: Promise) =
|
|
191
|
-
@ReactMethod fun markCategory(m: Int, promise: Promise) =
|
|
192
|
-
@ReactMethod fun engineName(promise: Promise) =
|
|
238
|
+
@ReactMethod fun markName(m: Int, promise: Promise) = off(promise) { QvpEngine.markName(m) }
|
|
239
|
+
@ReactMethod fun markFromName(s: String, promise: Promise) = off(promise) { QvpEngine.markFromName(s) }
|
|
240
|
+
@ReactMethod fun markCategory(m: Int, promise: Promise) = off(promise) { QvpEngine.markCategory(m) }
|
|
241
|
+
@ReactMethod fun engineName(promise: Promise) = off(promise) { QvpEngine.engineName() }
|
|
193
242
|
/** Every name table, read from the engine; the JavaScript side resolves names with these. */
|
|
194
243
|
override fun getConstants(): Map<String, Any> = mapOf("version" to QvpEngine.version(), "formatVersion" to QvpEngine.formatVersion(),
|
|
195
244
|
"marks" to QvpEngine.names(QvpEngine.Names.MARK), "kinds" to QvpEngine.names(QvpEngine.Names.KIND),
|
|
196
245
|
"families" to QvpEngine.names(QvpEngine.Names.FAMILY), "categories" to QvpEngine.names(QvpEngine.Names.CATEGORY),
|
|
197
246
|
"decorations" to QvpEngine.names(QvpEngine.Names.DECORATION), "divisions" to QvpEngine.names(QvpEngine.Names.DIVISION),
|
|
198
247
|
"places" to QvpEngine.names(QvpEngine.Names.PLACE),
|
|
199
|
-
|
|
248
|
+
// the whole defaults table by camelCase name, as the decimals the header states
|
|
249
|
+
"defaults" to QvpDefaults.decimal)
|
|
200
250
|
|
|
201
|
-
override fun invalidate() {
|
|
251
|
+
override fun invalidate() {
|
|
252
|
+
// The atlases belong to the query thread: free them there, after the queries already queued.
|
|
253
|
+
runCatching { queries.execute { atlases.values.forEach { it.close() }; atlases.clear(); atlasByUri.clear() } }
|
|
254
|
+
queries.shutdown()
|
|
255
|
+
QvpOrnamentSets.clear(); super.invalidate()
|
|
256
|
+
}
|
|
202
257
|
companion object { const val NAME = "QvpModule" }
|
|
203
258
|
}
|
|
204
259
|
|
|
@@ -24,6 +24,7 @@ class QvpPageViewManager : SimpleViewManager<QvpRnPageView>() {
|
|
|
24
24
|
@ReactProp(name = "padBottom", defaultFloat = 0f) fun setPadBottom(v: QvpRnPageView, f: Float) = v.setPadBottomDp(f)
|
|
25
25
|
@ReactProp(name = "padSide", defaultFloat = 0f) fun setPadSide(v: QvpRnPageView, f: Float) = v.setPadSideDp(f)
|
|
26
26
|
@ReactProp(name = "lineSpacing", defaultFloat = 1f) fun setLineSpacing(v: QvpRnPageView, f: Float) = v.setLineSpacingProp(f)
|
|
27
|
+
@ReactProp(name = "reflowBreaks") fun setReflowBreaks(v: QvpRnPageView, s: String?) = v.setReflowBreaksProp(s)
|
|
27
28
|
@ReactProp(name = "fillHeight", defaultBoolean = false) fun setFillHeight(v: QvpRnPageView, b: Boolean) = v.setFillHeightProp(b)
|
|
28
29
|
@ReactProp(name = "surahFrames", defaultBoolean = true) fun setSurahFrames(v: QvpRnPageView, b: Boolean) = v.setSurahFramesProp(b)
|
|
29
30
|
@ReactProp(name = "paperColor") fun setPaperColor(v: QvpRnPageView, s: String?) { v.paperColor = if (s.isNullOrBlank()) 0 else QvpColor.argb(QvpColor.parse(s)); v.invalidate() }
|
|
@@ -5,6 +5,10 @@ import android.util.Log
|
|
|
5
5
|
import com.facebook.react.bridge.Arguments
|
|
6
6
|
import com.facebook.react.uimanager.ThemedReactContext
|
|
7
7
|
import android.widget.FrameLayout
|
|
8
|
+
import java.util.concurrent.ConcurrentHashMap
|
|
9
|
+
import java.util.concurrent.locks.ReentrantReadWriteLock
|
|
10
|
+
import kotlin.concurrent.read
|
|
11
|
+
import kotlin.concurrent.write
|
|
8
12
|
import ws.quran.qvp.*
|
|
9
13
|
import ws.quran.qvp.Target
|
|
10
14
|
|
|
@@ -13,6 +17,11 @@ import ws.quran.qvp.Target
|
|
|
13
17
|
* URI, and reconciles the declarative props (theme / styles / highlights / mask / reveal) against engine
|
|
14
18
|
* handles so JS never sees a handle. Every decision (hit-test, layout, style resolution, bands, masks)
|
|
15
19
|
* is the engine's; this class only marshals and forwards.
|
|
20
|
+
*
|
|
21
|
+
* The module reads the page from its query thread while this view draws on the UI thread (see
|
|
22
|
+
* [read]). Those reads touch only what the page fixed when it loaded, so the two do not meet,
|
|
23
|
+
* except where the page is closed, replaced, or given a words sidecar: each of these holds
|
|
24
|
+
* [lock] for writing, and waits for a query in progress to finish.
|
|
16
25
|
*/
|
|
17
26
|
class QvpRnPageView(private val ctx: ThemedReactContext) : FrameLayout(ctx) {
|
|
18
27
|
private val density = ctx.resources.displayMetrics.density
|
|
@@ -20,7 +29,22 @@ class QvpRnPageView(private val ctx: ThemedReactContext) : FrameLayout(ctx) {
|
|
|
20
29
|
val inner = QvpPageView(ctx).also { addView(it, LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)) }
|
|
21
30
|
var page: QvpPage?
|
|
22
31
|
get() = inner.page
|
|
23
|
-
set(v) { inner.page = v }
|
|
32
|
+
private set(v) { inner.page = v }
|
|
33
|
+
|
|
34
|
+
/** Read by the module's queries, written where the page closes, changes, or takes a sidecar. */
|
|
35
|
+
private val lock = ReentrantReadWriteLock()
|
|
36
|
+
/** Run [block] on the page in view, held open until the block returns: null when no page is loaded.
|
|
37
|
+
* The block must not wait for the UI thread, which can be waiting for this lock. */
|
|
38
|
+
fun <T> read(block: (QvpPage?) -> T): T = lock.read { block(page) }
|
|
39
|
+
/** Attach a words sidecar. Queries in progress finish first, and the word records built
|
|
40
|
+
* before it are dropped, since the forms they hold have changed. */
|
|
41
|
+
fun attachWords(p: QvpPage, json: String): Int = lock.write { p.attachWords(json).also { dropWords() } }
|
|
42
|
+
|
|
43
|
+
private val wordsLock = Any()
|
|
44
|
+
private var words: QvpRnWords? = null
|
|
45
|
+
/** The word records of [p], built on first use and kept until the page changes or takes a sidecar. */
|
|
46
|
+
fun words(p: QvpPage): QvpRnWords = synchronized(wordsLock) { words?.takeIf { it.page === p } ?: QvpRnWords(p).also { words = it } }
|
|
47
|
+
private fun dropWords() = synchronized(wordsLock) { words = null }
|
|
24
48
|
var paperColor: Int get() = inner.paperColor; set(v) { inner.paperColor = v; inner.invalidate() }
|
|
25
49
|
var selectionBand: Int get() = inner.selectionBand; set(v) { inner.selectionBand = v }
|
|
26
50
|
var selectionEnabled: Boolean get() = inner.selectionEnabled; set(v) { inner.selectionEnabled = v }
|
|
@@ -68,7 +92,7 @@ class QvpRnPageView(private val ctx: ThemedReactContext) : FrameLayout(ctx) {
|
|
|
68
92
|
var pageBytes = 0; private set
|
|
69
93
|
|
|
70
94
|
init {
|
|
71
|
-
inner.onWordTap = { w, h -> page?.let { p -> emit("onWordTap", mapOf("word" to
|
|
95
|
+
inner.onWordTap = { w, h -> page?.let { p -> emit("onWordTap", mapOf("word" to words(p).word(w.index), "hit" to Marshal.hit(p, h))) } }
|
|
72
96
|
inner.onDecorationTap = { d, h -> page?.let { p -> emit("onDecorationTap", mapOf("decoration" to Marshal.decoration(d), "hit" to Marshal.hit(p, h))) } }
|
|
73
97
|
inner.onEmptyTap = { emit("onEmptyTap", emptyMap()) }
|
|
74
98
|
// The engine says a flick turns the page and by how many, in reading order. Which page
|
|
@@ -81,12 +105,16 @@ class QvpRnPageView(private val ctx: ThemedReactContext) : FrameLayout(ctx) {
|
|
|
81
105
|
override fun onAttachedToWindow() { super.onAttachedToWindow(); QvpRegistry.register(this) }
|
|
82
106
|
override fun onDetachedFromWindow() { QvpRegistry.unregister(this); super.onDetachedFromWindow() }
|
|
83
107
|
|
|
84
|
-
fun destroy() { QvpRegistry.unregister(this); page?.close(); page = null; loadedKey = null }
|
|
108
|
+
fun destroy() { QvpRegistry.unregister(this); lock.write { page?.close(); page = null; dropWords() }; loadedKey = null }
|
|
85
109
|
|
|
86
110
|
/** Padding props arrive in dp. */
|
|
87
111
|
fun setPadTopDp(v: Float) { inner.padTop = v * density; layoutDirty = true }
|
|
88
112
|
fun setPadBottomDp(v: Float) { inner.padBottom = v * density; layoutDirty = true }
|
|
89
113
|
fun setPadSideDp(v: Float) { inner.padSide = v * density; layoutDirty = true }
|
|
114
|
+
fun setReflowBreaksProp(v: String?) {
|
|
115
|
+
inner.reflowBreaks = QvpBreaks.entries.find { it.name.equals(v, ignoreCase = true) } ?: QvpBreaks.FITTED
|
|
116
|
+
layoutDirty = true
|
|
117
|
+
}
|
|
90
118
|
fun setLineSpacingProp(v: Float) { inner.lineSpacing = v; layoutDirty = true }
|
|
91
119
|
|
|
92
120
|
// ── the reader's zoom control ──
|
|
@@ -142,15 +170,27 @@ class QvpRnPageView(private val ctx: ThemedReactContext) : FrameLayout(ctx) {
|
|
|
142
170
|
if (key == loadedKey) return
|
|
143
171
|
// drop everything bound to the old page: handles die with it
|
|
144
172
|
themeHandle = 0; appliedTheme = null; styleHandles.clear(); highlightHandles.clear(); appliedMask = null; appliedReveal = null; appliedRevealAt = null; appliedInk = null; appliedDress = null; revealStepCount = 0
|
|
145
|
-
|
|
146
|
-
if (key == null) return
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
val p
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
173
|
+
loadedKey = key
|
|
174
|
+
if (key == null) { lock.write { page?.close(); page = null; dropWords() }; return }
|
|
175
|
+
// Load the new page before the swap, so a query sees the old page or the new one and
|
|
176
|
+
// never a view with no page. A load that fails leaves no page, as before.
|
|
177
|
+
val p: QvpPage
|
|
178
|
+
val bytes: ByteArray
|
|
179
|
+
val ms: Double
|
|
180
|
+
try {
|
|
181
|
+
bytes = pageBase64?.let { Base64.decode(it, Base64.DEFAULT) } ?: readUri(pageUri!!)
|
|
182
|
+
val t0 = System.nanoTime()
|
|
183
|
+
p = QvpPage(bytes); p.buildPaths()
|
|
184
|
+
ms = (System.nanoTime() - t0) / 1e6
|
|
185
|
+
// No query sees the page before the swap below, so the sidecar needs no lock.
|
|
186
|
+
wordsUri?.let { runCatching { p.attachWords(readUri(it)) }.onFailure { e -> Log.w("QvpRn", "words sidecar: $e") } }
|
|
187
|
+
} catch (e: Exception) {
|
|
188
|
+
lock.write { page?.close(); page = null; dropWords() }
|
|
189
|
+
throw e
|
|
190
|
+
}
|
|
191
|
+
lock.write { val old = page; page = p; dropWords(); loadMs = ms; pageBytes = bytes.size; old?.close() }
|
|
192
|
+
layoutDirty = true
|
|
193
|
+
emit("onPageLoad", Marshal.pageInfo(p, words(p).forms) + mapOf("loadMs" to loadMs, "bytes" to pageBytes, "uri" to pageUri))
|
|
154
194
|
}
|
|
155
195
|
|
|
156
196
|
private fun applyInk(p: QvpPage) {
|
|
@@ -257,9 +297,10 @@ class QvpRnPageView(private val ctx: ThemedReactContext) : FrameLayout(ctx) {
|
|
|
257
297
|
"engineVersion" to QvpEngine.version(), "viewScale" to inner.viewScale, "layout" to page?.currentLayout?.let { Marshal.layout(it) })
|
|
258
298
|
}
|
|
259
299
|
|
|
260
|
-
/** Views by react tag, so the module can find the page behind a `viewTag` without going through the
|
|
300
|
+
/** Views by react tag, so the module can find the page behind a `viewTag` without going through the
|
|
301
|
+
* UIManager. The UI thread registers views and the module's query thread looks them up. */
|
|
261
302
|
object QvpRegistry {
|
|
262
|
-
private val views =
|
|
303
|
+
private val views = ConcurrentHashMap<Int, QvpRnPageView>()
|
|
263
304
|
fun register(v: QvpRnPageView) { if (v.id > 0) views[v.id] = v }
|
|
264
305
|
fun unregister(v: QvpRnPageView) { views.entries.removeAll { it.value === v } }
|
|
265
306
|
fun get(tag: Int): QvpRnPageView? = views[tag]
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
package ws.quran.qvp.rn
|
|
2
|
+
|
|
3
|
+
import ws.quran.qvp.Form
|
|
4
|
+
import ws.quran.qvp.QvpPage
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The bridge record of each word of one page, built the first time the word is asked for and
|
|
8
|
+
* kept. A record holds the word's text forms, its label and the names of its paths. The words
|
|
9
|
+
* sidecar is attached once per page, so a record does not change until the next attach, and
|
|
10
|
+
* the view drops this table then. The module's query thread and the UI thread can both call it.
|
|
11
|
+
*/
|
|
12
|
+
class QvpRnWords(val page: QvpPage) {
|
|
13
|
+
/** The forms this page has. Each one is a scan of every word in the engine, so read them once. */
|
|
14
|
+
val forms: List<Form> by lazy { Marshal.forms(page) }
|
|
15
|
+
private val records = arrayOfNulls<Map<String, Any?>>(page.nWords)
|
|
16
|
+
|
|
17
|
+
/** The record of word [index], or null when the page has no such word. */
|
|
18
|
+
@Synchronized
|
|
19
|
+
fun word(index: Int): Map<String, Any?>? {
|
|
20
|
+
val w = page.words.getOrNull(index) ?: return null
|
|
21
|
+
return records[index] ?: Marshal.word(page, w, forms).also { records[index] = it }
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Every word's record, in page order. */
|
|
25
|
+
fun all(): List<Map<String, Any?>> = List(page.nWords) { word(it)!! }
|
|
26
|
+
}
|
package/ios/QvpModule.m
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
// @quran.ws/qvp-react-native, iOS. What React Native sees of the module and the two views: the
|
|
2
|
+
// module's methods (QvpModule.swift implements them) and the views' props and events. The names
|
|
3
|
+
// are those of the Android module, so src/index.tsx has no platform branch.
|
|
4
|
+
#import <React/RCTBridgeModule.h>
|
|
5
|
+
#import <React/RCTViewManager.h>
|
|
6
|
+
|
|
7
|
+
@interface RCT_EXTERN_MODULE(QvpModule, NSObject)
|
|
8
|
+
RCT_EXTERN_METHOD(info:(nonnull NSNumber *)tag resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
9
|
+
RCT_EXTERN_METHOD(words:(nonnull NSNumber *)tag resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
10
|
+
RCT_EXTERN_METHOD(word:(nonnull NSNumber *)tag index:(nonnull NSNumber *)index resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
11
|
+
RCT_EXTERN_METHOD(ayahs:(nonnull NSNumber *)tag resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
12
|
+
RCT_EXTERN_METHOD(lines:(nonnull NSNumber *)tag resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
13
|
+
RCT_EXTERN_METHOD(decorations:(nonnull NSNumber *)tag resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
14
|
+
RCT_EXTERN_METHOD(findWord:(nonnull NSNumber *)tag s:(nonnull NSNumber *)s a:(nonnull NSNumber *)a w:(nonnull NSNumber *)w resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
15
|
+
RCT_EXTERN_METHOD(targetWords:(nonnull NSNumber *)tag target:(id)target resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
16
|
+
RCT_EXTERN_METHOD(wordForm:(nonnull NSNumber *)tag index:(nonnull NSNumber *)index form:(NSString *)form resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
17
|
+
RCT_EXTERN_METHOD(hasForm:(nonnull NSNumber *)tag form:(NSString *)form resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
18
|
+
RCT_EXTERN_METHOD(attachWords:(nonnull NSNumber *)tag json:(NSString *)json resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
19
|
+
RCT_EXTERN_METHOD(surahs:(nonnull NSNumber *)tag resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
20
|
+
RCT_EXTERN_METHOD(divisions:(nonnull NSNumber *)tag resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
21
|
+
RCT_EXTERN_METHOD(surahHeaders:(nonnull NSNumber *)tag resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
22
|
+
RCT_EXTERN_METHOD(surahHeadersView:(nonnull NSNumber *)tag resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
23
|
+
RCT_EXTERN_METHOD(ayahMarks:(nonnull NSNumber *)tag resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
24
|
+
RCT_EXTERN_METHOD(ayahMarksView:(nonnull NSNumber *)tag resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
25
|
+
RCT_EXTERN_METHOD(rosettes:(nonnull NSNumber *)tag resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
26
|
+
RCT_EXTERN_METHOD(sajdahs:(nonnull NSNumber *)tag resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
27
|
+
RCT_EXTERN_METHOD(ayahKeys:(nonnull NSNumber *)tag resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
28
|
+
RCT_EXTERN_METHOD(ayahWordCount:(nonnull NSNumber *)tag s:(nonnull NSNumber *)s a:(nonnull NSNumber *)a resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
29
|
+
RCT_EXTERN_METHOD(reciteMap:(nonnull NSNumber *)tag s:(nonnull NSNumber *)s a:(nonnull NSNumber *)a n:(nonnull NSNumber *)n resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
30
|
+
RCT_EXTERN_METHOD(wordLabel:(nonnull NSNumber *)tag i:(nonnull NSNumber *)i resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
31
|
+
RCT_EXTERN_METHOD(ayahLabel:(nonnull NSNumber *)tag i:(nonnull NSNumber *)i resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
32
|
+
RCT_EXTERN_METHOD(text:(nonnull NSNumber *)tag target:(id)target opts:(NSDictionary *)opts resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
33
|
+
RCT_EXTERN_METHOD(search:(nonnull NSNumber *)tag query:(NSString *)query opts:(NSDictionary *)opts resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
34
|
+
RCT_EXTERN_METHOD(citation:(nonnull NSNumber *)tag words:(NSArray *)words resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
35
|
+
RCT_EXTERN_METHOD(arabic:(NSString *)op s:(NSString *)s resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
36
|
+
RCT_EXTERN_METHOD(hitTestExact:(nonnull NSNumber *)tag x:(nonnull NSNumber *)x y:(nonnull NSNumber *)y resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
37
|
+
RCT_EXTERN_METHOD(hitTest:(nonnull NSNumber *)tag x:(nonnull NSNumber *)x y:(nonnull NSNumber *)y opts:(NSDictionary *)opts resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
38
|
+
RCT_EXTERN_METHOD(hitTestExactView:(nonnull NSNumber *)tag x:(nonnull NSNumber *)x y:(nonnull NSNumber *)y resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
39
|
+
RCT_EXTERN_METHOD(hitTestView:(nonnull NSNumber *)tag x:(nonnull NSNumber *)x y:(nonnull NSNumber *)y opts:(NSDictionary *)opts resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
40
|
+
RCT_EXTERN_METHOD(wordBoundsView:(nonnull NSNumber *)tag i:(nonnull NSNumber *)i resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
41
|
+
RCT_EXTERN_METHOD(currentLayout:(nonnull NSNumber *)tag resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
42
|
+
RCT_EXTERN_METHOD(relayout:(nonnull NSNumber *)tag resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
43
|
+
RCT_EXTERN_METHOD(resetView:(nonnull NSNumber *)tag resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
44
|
+
RCT_EXTERN_METHOD(layoutLineSpacingToFill:(nonnull NSNumber *)tag max:(nonnull NSNumber *)max resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
45
|
+
RCT_EXTERN_METHOD(layoutWastedFraction:(nonnull NSNumber *)tag resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
46
|
+
RCT_EXTERN_METHOD(layoutPrintedHeight:(nonnull NSNumber *)tag resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
47
|
+
RCT_EXTERN_METHOD(grid:(nonnull NSNumber *)tag resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
48
|
+
RCT_EXTERN_METHOD(stats:(nonnull NSNumber *)tag resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
49
|
+
RCT_EXTERN_METHOD(invalidate:(nonnull NSNumber *)tag resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
50
|
+
RCT_EXTERN_METHOD(select:(nonnull NSNumber *)tag anchor:(nonnull NSNumber *)anchor focus:(nonnull NSNumber *)focus resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
51
|
+
RCT_EXTERN_METHOD(clearSelection:(nonnull NSNumber *)tag resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
52
|
+
RCT_EXTERN_METHOD(selection:(nonnull NSNumber *)tag resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
53
|
+
RCT_EXTERN_METHOD(selectionText:(nonnull NSNumber *)tag form:(NSString *)form includeCitation:(BOOL)includeCitation resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
54
|
+
RCT_EXTERN_METHOD(unmaskNext:(nonnull NSNumber *)tag n:(nonnull NSNumber *)n resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
55
|
+
RCT_EXTERN_METHOD(maskBack:(nonnull NSNumber *)tag n:(nonnull NSNumber *)n resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
56
|
+
RCT_EXTERN_METHOD(unmaskWord:(nonnull NSNumber *)tag i:(nonnull NSNumber *)i resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
57
|
+
RCT_EXTERN_METHOD(maskWord:(nonnull NSNumber *)tag i:(nonnull NSNumber *)i resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
58
|
+
RCT_EXTERN_METHOD(unmaskAll:(nonnull NSNumber *)tag resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
59
|
+
RCT_EXTERN_METHOD(maskAll:(nonnull NSNumber *)tag resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
60
|
+
RCT_EXTERN_METHOD(maskHidden:(nonnull NSNumber *)tag resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
61
|
+
RCT_EXTERN_METHOD(maskWords:(nonnull NSNumber *)tag resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
62
|
+
RCT_EXTERN_METHOD(revealStepCount:(nonnull NSNumber *)tag resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
63
|
+
RCT_EXTERN_METHOD(revealPosition:(nonnull NSNumber *)tag resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
64
|
+
RCT_EXTERN_METHOD(revealStepOf:(nonnull NSNumber *)tag i:(nonnull NSNumber *)i resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
65
|
+
RCT_EXTERN_METHOD(cropBounds:(nonnull NSNumber *)tag target:(id)target opts:(NSDictionary *)opts resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
66
|
+
RCT_EXTERN_METHOD(cropSvg:(nonnull NSNumber *)tag target:(id)target opts:(NSDictionary *)opts resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
67
|
+
RCT_EXTERN_METHOD(loadAtlas:(NSString *)uri resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
68
|
+
RCT_EXTERN_METHOD(freeAtlas:(nonnull NSNumber *)id resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
69
|
+
RCT_EXTERN_METHOD(atlasPageOf:(nonnull NSNumber *)id s:(nonnull NSNumber *)s a:(nonnull NSNumber *)a resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
70
|
+
RCT_EXTERN_METHOD(atlasPageRange:(nonnull NSNumber *)id page:(nonnull NSNumber *)page resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
71
|
+
RCT_EXTERN_METHOD(atlasPageCount:(nonnull NSNumber *)id resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
72
|
+
RCT_EXTERN_METHOD(atlasSurah:(nonnull NSNumber *)id n:(nonnull NSNumber *)n resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
73
|
+
RCT_EXTERN_METHOD(atlasSurahs:(nonnull NSNumber *)id resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
74
|
+
RCT_EXTERN_METHOD(atlasPageOfSurah:(nonnull NSNumber *)id n:(nonnull NSNumber *)n resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
75
|
+
RCT_EXTERN_METHOD(atlasDivision:(nonnull NSNumber *)id division:(NSString *)division n:(nonnull NSNumber *)n resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
76
|
+
RCT_EXTERN_METHOD(atlasDivisionOf:(nonnull NSNumber *)id division:(NSString *)division s:(nonnull NSNumber *)s a:(nonnull NSNumber *)a resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
77
|
+
RCT_EXTERN_METHOD(atlasJuzOf:(nonnull NSNumber *)id s:(nonnull NSNumber *)s a:(nonnull NSNumber *)a resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
78
|
+
RCT_EXTERN_METHOD(atlasPagesOfJuz:(nonnull NSNumber *)id n:(nonnull NSNumber *)n resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
79
|
+
RCT_EXTERN_METHOD(atlasSearchSurahs:(nonnull NSNumber *)id text:(NSString *)text resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
80
|
+
RCT_EXTERN_METHOD(loadOrnaments:(NSString *)uri resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
81
|
+
RCT_EXTERN_METHOD(freeOrnaments:(nonnull NSNumber *)id resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
82
|
+
RCT_EXTERN_METHOD(ornamentCount:(nonnull NSNumber *)id resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
83
|
+
RCT_EXTERN_METHOD(ornamentInfo:(nonnull NSNumber *)id index:(nonnull NSNumber *)index resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
84
|
+
RCT_EXTERN_METHOD(ornamentPart:(nonnull NSNumber *)id index:(nonnull NSNumber *)index part:(nonnull NSNumber *)part resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
85
|
+
RCT_EXTERN_METHOD(ornamentList:(nonnull NSNumber *)id resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
86
|
+
RCT_EXTERN_METHOD(ornamentFind:(nonnull NSNumber *)id kind:(NSString *)kind style:(NSString *)style resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
87
|
+
RCT_EXTERN_METHOD(dress:(nonnull NSNumber *)tag id:(nonnull NSNumber *)id spec:(NSDictionary *)spec resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
88
|
+
RCT_EXTERN_METHOD(undress:(nonnull NSNumber *)tag resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
89
|
+
RCT_EXTERN_METHOD(dressClamp:(nonnull NSNumber *)tag scale:(nonnull NSNumber *)scale offsetX:(nonnull NSNumber *)offsetX offsetY:(nonnull NSNumber *)offsetY viewportW:(nonnull NSNumber *)viewportW viewportH:(nonnull NSNumber *)viewportH resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
90
|
+
RCT_EXTERN_METHOD(dressView:(nonnull NSNumber *)tag scale:(nonnull NSNumber *)scale viewportW:(nonnull NSNumber *)viewportW resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
91
|
+
RCT_EXTERN_METHOD(dressInfo:(nonnull NSNumber *)tag resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
92
|
+
RCT_EXTERN_METHOD(dressRevision:(nonnull NSNumber *)tag resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
93
|
+
RCT_EXTERN_METHOD(markName:(nonnull NSNumber *)m resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
94
|
+
RCT_EXTERN_METHOD(markFromName:(NSString *)s resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
95
|
+
RCT_EXTERN_METHOD(markCategory:(nonnull NSNumber *)m resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
96
|
+
RCT_EXTERN_METHOD(engineName:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
97
|
+
@end
|
|
98
|
+
|
|
99
|
+
/// `<QvpPageView />`: props go onto QvpRnPageView, which applies each batch in one pass.
|
|
100
|
+
@interface QvpPageViewManager : RCTViewManager
|
|
101
|
+
@end
|
|
102
|
+
|
|
103
|
+
@implementation QvpPageViewManager
|
|
104
|
+
RCT_EXPORT_MODULE()
|
|
105
|
+
- (UIView *)view { return [[NSClassFromString(@"QvpRnPageView") alloc] initWithFrame:CGRectZero]; }
|
|
106
|
+
RCT_EXPORT_VIEW_PROPERTY(pageUri, NSString)
|
|
107
|
+
RCT_EXPORT_VIEW_PROPERTY(pageBase64, NSString)
|
|
108
|
+
RCT_EXPORT_VIEW_PROPERTY(wordsUri, NSString)
|
|
109
|
+
RCT_EXPORT_VIEW_PROPERTY(padTop, CGFloat)
|
|
110
|
+
RCT_EXPORT_VIEW_PROPERTY(padBottom, CGFloat)
|
|
111
|
+
RCT_EXPORT_VIEW_PROPERTY(padSide, CGFloat)
|
|
112
|
+
RCT_EXPORT_VIEW_PROPERTY(lineSpacing, CGFloat)
|
|
113
|
+
RCT_EXPORT_VIEW_PROPERTY(reflowBreaks, NSString)
|
|
114
|
+
RCT_EXPORT_VIEW_PROPERTY(fillHeight, BOOL)
|
|
115
|
+
RCT_EXPORT_VIEW_PROPERTY(surahFrames, BOOL)
|
|
116
|
+
RCT_EXPORT_VIEW_PROPERTY(paperColor, NSString)
|
|
117
|
+
RCT_EXPORT_VIEW_PROPERTY(defaultInk, NSString)
|
|
118
|
+
RCT_EXPORT_VIEW_PROPERTY(selectionBand, NSString)
|
|
119
|
+
RCT_EXPORT_VIEW_PROPERTY(selectionEnabled, BOOL)
|
|
120
|
+
RCT_EXPORT_VIEW_PROPERTY(zoomEnabled, BOOL)
|
|
121
|
+
RCT_EXPORT_VIEW_PROPERTY(zoomMode, NSString)
|
|
122
|
+
RCT_EXPORT_VIEW_PROPERTY(zoomStep, NSInteger)
|
|
123
|
+
RCT_EXPORT_VIEW_PROPERTY(hitMaxDistance, CGFloat)
|
|
124
|
+
RCT_EXPORT_VIEW_PROPERTY(theme, NSDictionary)
|
|
125
|
+
RCT_EXPORT_VIEW_PROPERTY(styles, NSArray)
|
|
126
|
+
RCT_EXPORT_VIEW_PROPERTY(highlights, NSArray)
|
|
127
|
+
RCT_REMAP_VIEW_PROPERTY(mask, maskProp, NSDictionary)
|
|
128
|
+
RCT_EXPORT_VIEW_PROPERTY(reveal, NSDictionary)
|
|
129
|
+
RCT_EXPORT_VIEW_PROPERTY(dress, NSDictionary)
|
|
130
|
+
RCT_EXPORT_VIEW_PROPERTY(onWordTap, RCTDirectEventBlock)
|
|
131
|
+
RCT_EXPORT_VIEW_PROPERTY(onDecorationTap, RCTDirectEventBlock)
|
|
132
|
+
RCT_EXPORT_VIEW_PROPERTY(onEmptyTap, RCTDirectEventBlock)
|
|
133
|
+
RCT_EXPORT_VIEW_PROPERTY(onSelectionChanged, RCTDirectEventBlock)
|
|
134
|
+
RCT_EXPORT_VIEW_PROPERTY(onPageLoad, RCTDirectEventBlock)
|
|
135
|
+
RCT_EXPORT_VIEW_PROPERTY(onRevealChanged, RCTDirectEventBlock)
|
|
136
|
+
RCT_EXPORT_VIEW_PROPERTY(onSwipe, RCTDirectEventBlock)
|
|
137
|
+
RCT_EXPORT_VIEW_PROPERTY(onZoomChanged, RCTDirectEventBlock)
|
|
138
|
+
RCT_EXPORT_VIEW_PROPERTY(onDressChanged, RCTDirectEventBlock)
|
|
139
|
+
RCT_EXPORT_VIEW_PROPERTY(onError, RCTDirectEventBlock)
|
|
140
|
+
@end
|
|
141
|
+
|
|
142
|
+
/// `<QvpPassageView />`: props go onto QvpRnPassageView, which applies each batch in one pass.
|
|
143
|
+
@interface QvpPassageViewManager : RCTViewManager
|
|
144
|
+
@end
|
|
145
|
+
|
|
146
|
+
@implementation QvpPassageViewManager
|
|
147
|
+
RCT_EXPORT_MODULE()
|
|
148
|
+
- (UIView *)view { return [[NSClassFromString(@"QvpRnPassageView") alloc] initWithFrame:CGRectZero]; }
|
|
149
|
+
RCT_EXPORT_VIEW_PROPERTY(pageUris, NSStringArray)
|
|
150
|
+
RCT_EXPORT_VIEW_PROPERTY(surah, NSInteger)
|
|
151
|
+
RCT_EXPORT_VIEW_PROPERTY(from, NSInteger)
|
|
152
|
+
RCT_EXPORT_VIEW_PROPERTY(to, NSInteger)
|
|
153
|
+
RCT_EXPORT_VIEW_PROPERTY(basmalah, BOOL)
|
|
154
|
+
RCT_EXPORT_VIEW_PROPERTY(scale, CGFloat)
|
|
155
|
+
RCT_EXPORT_VIEW_PROPERTY(lineHeight, CGFloat)
|
|
156
|
+
RCT_EXPORT_VIEW_PROPERTY(lineSpacing, CGFloat)
|
|
157
|
+
RCT_EXPORT_VIEW_PROPERTY(padding, CGFloat)
|
|
158
|
+
RCT_EXPORT_VIEW_PROPERTY(align, NSString)
|
|
159
|
+
RCT_EXPORT_VIEW_PROPERTY(maxRows, NSInteger)
|
|
160
|
+
RCT_EXPORT_VIEW_PROPERTY(keepAyahMark, BOOL)
|
|
161
|
+
RCT_EXPORT_VIEW_PROPERTY(ellipsisWidth, CGFloat)
|
|
162
|
+
RCT_EXPORT_VIEW_PROPERTY(maxStretch, CGFloat)
|
|
163
|
+
RCT_EXPORT_VIEW_PROPERTY(ink, NSString)
|
|
164
|
+
RCT_EXPORT_VIEW_PROPERTY(paperColor, NSString)
|
|
165
|
+
RCT_EXPORT_VIEW_PROPERTY(onPassageLayout, RCTDirectEventBlock)
|
|
166
|
+
RCT_EXPORT_VIEW_PROPERTY(onError, RCTDirectEventBlock)
|
|
167
|
+
@end
|