@onekeyfe/react-native-chart-webview 3.0.56 → 3.0.58
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/margelo/nitro/chartwebview/ChartWebview.kt +13 -4
- package/android/src/main/java/com/margelo/nitro/chartwebview/PooledChartWebView.kt +128 -27
- package/ios/ChartWebview.swift +5 -0
- package/lib/nitrogen/generated/android/c++/JHybridChartWebviewSpec.cpp +9 -0
- package/lib/nitrogen/generated/android/c++/JHybridChartWebviewSpec.hpp +2 -0
- package/lib/nitrogen/generated/android/c++/views/JHybridChartWebviewStateUpdater.cpp +4 -0
- package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/chartwebview/HybridChartWebviewSpec.kt +6 -0
- package/lib/nitrogen/generated/ios/c++/HybridChartWebviewSpecSwift.hpp +7 -0
- package/lib/nitrogen/generated/ios/c++/views/HybridChartWebviewComponent.mm +5 -0
- package/lib/nitrogen/generated/ios/swift/HybridChartWebviewSpec.swift +1 -0
- package/lib/nitrogen/generated/ios/swift/HybridChartWebviewSpec_cxx.swift +24 -0
- package/lib/nitrogen/generated/shared/c++/HybridChartWebviewSpec.cpp +2 -0
- package/lib/nitrogen/generated/shared/c++/HybridChartWebviewSpec.hpp +2 -0
- package/lib/nitrogen/generated/shared/c++/views/HybridChartWebviewComponent.cpp +12 -0
- package/lib/nitrogen/generated/shared/c++/views/HybridChartWebviewComponent.hpp +1 -0
- package/lib/nitrogen/generated/shared/json/ChartWebviewConfig.json +1 -0
- package/lib/nitrogen/nitrogen/generated/android/c++/JHybridChartWebviewSpec.cpp +9 -0
- package/lib/nitrogen/nitrogen/generated/android/c++/JHybridChartWebviewSpec.hpp +2 -0
- package/lib/nitrogen/nitrogen/generated/android/c++/views/JHybridChartWebviewStateUpdater.cpp +4 -0
- package/lib/nitrogen/nitrogen/generated/android/kotlin/com/margelo/nitro/chartwebview/HybridChartWebviewSpec.kt +6 -0
- package/lib/nitrogen/nitrogen/generated/ios/c++/HybridChartWebviewSpecSwift.hpp +7 -0
- package/lib/nitrogen/nitrogen/generated/ios/c++/views/HybridChartWebviewComponent.mm +5 -0
- package/lib/nitrogen/nitrogen/generated/ios/swift/HybridChartWebviewSpec.swift +1 -0
- package/lib/nitrogen/nitrogen/generated/ios/swift/HybridChartWebviewSpec_cxx.swift +24 -0
- package/lib/nitrogen/nitrogen/generated/shared/c++/HybridChartWebviewSpec.cpp +2 -0
- package/lib/nitrogen/nitrogen/generated/shared/c++/HybridChartWebviewSpec.hpp +2 -0
- package/lib/nitrogen/nitrogen/generated/shared/c++/views/HybridChartWebviewComponent.cpp +12 -0
- package/lib/nitrogen/nitrogen/generated/shared/c++/views/HybridChartWebviewComponent.hpp +1 -0
- package/lib/nitrogen/nitrogen/generated/shared/json/ChartWebviewConfig.json +1 -0
- package/lib/typescript/src/ChartWebview.nitro.d.ts +1 -0
- package/lib/typescript/src/ChartWebview.nitro.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +1 -0
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/nitrogen/generated/android/c++/JHybridChartWebviewSpec.cpp +9 -0
- package/nitrogen/generated/android/c++/JHybridChartWebviewSpec.hpp +2 -0
- package/nitrogen/generated/android/c++/views/JHybridChartWebviewStateUpdater.cpp +4 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/chartwebview/HybridChartWebviewSpec.kt +6 -0
- package/nitrogen/generated/ios/c++/HybridChartWebviewSpecSwift.hpp +7 -0
- package/nitrogen/generated/ios/c++/views/HybridChartWebviewComponent.mm +5 -0
- package/nitrogen/generated/ios/swift/HybridChartWebviewSpec.swift +1 -0
- package/nitrogen/generated/ios/swift/HybridChartWebviewSpec_cxx.swift +24 -0
- package/nitrogen/generated/shared/c++/HybridChartWebviewSpec.cpp +2 -0
- package/nitrogen/generated/shared/c++/HybridChartWebviewSpec.hpp +2 -0
- package/nitrogen/generated/shared/c++/views/HybridChartWebviewComponent.cpp +12 -0
- package/nitrogen/generated/shared/c++/views/HybridChartWebviewComponent.hpp +1 -0
- package/nitrogen/generated/shared/json/ChartWebviewConfig.json +1 -0
- package/package.json +1 -1
- package/src/ChartWebview.nitro.ts +8 -0
|
@@ -123,6 +123,15 @@ class HybridChartWebview(val context: ThemedReactContext) : HybridChartWebviewSp
|
|
|
123
123
|
get() = _paramsJson
|
|
124
124
|
set(value) { _paramsJson = value; applySource() }
|
|
125
125
|
|
|
126
|
+
// ANDROID: the host the offline `localBundle` is served under. When set, the
|
|
127
|
+
// offline bundle is served from https://<assetHost>/ so the WebView reuses the
|
|
128
|
+
// real chart origin's same-origin storage (zero migration). Falls back to the
|
|
129
|
+
// built-in appassets host in the pool when null. (iOS ignores this prop.)
|
|
130
|
+
private var _assetHost: String? = null
|
|
131
|
+
override var assetHost: String?
|
|
132
|
+
get() = _assetHost
|
|
133
|
+
set(value) { _assetHost = value; applySource() }
|
|
134
|
+
|
|
126
135
|
// Document-start bridge JS (single source of truth in the TS layer). Stored and
|
|
127
136
|
// handed to the pooled WebView when we claim it, before its first load.
|
|
128
137
|
private var _bridgeScript: String? = null
|
|
@@ -259,7 +268,7 @@ class HybridChartWebview(val context: ThemedReactContext) : HybridChartWebviewSp
|
|
|
259
268
|
if (!bs.isNullOrEmpty()) {
|
|
260
269
|
entry.setBridgeScript(bs)
|
|
261
270
|
entry.warmDriver = this
|
|
262
|
-
entry.setSource(_uri, _localBundle, _entry, _paramsJson)
|
|
271
|
+
entry.setSource(_uri, _localBundle, _entry, _paramsJson, _assetHost)
|
|
263
272
|
}
|
|
264
273
|
if (wantsOwnership()) {
|
|
265
274
|
entry.owner = this
|
|
@@ -299,7 +308,7 @@ class HybridChartWebview(val context: ThemedReactContext) : HybridChartWebviewSp
|
|
|
299
308
|
pooled.owner = this
|
|
300
309
|
pooled.setBridgeScript(_bridgeScript ?: "")
|
|
301
310
|
pooled.attachTo(container)
|
|
302
|
-
pooled.setSource(_uri, _localBundle, _entry, _paramsJson)
|
|
311
|
+
pooled.setSource(_uri, _localBundle, _entry, _paramsJson, _assetHost)
|
|
303
312
|
}
|
|
304
313
|
|
|
305
314
|
// Apply the source synchronously when a source/bridge prop changes. For a
|
|
@@ -315,10 +324,10 @@ class HybridChartWebview(val context: ThemedReactContext) : HybridChartWebviewSp
|
|
|
315
324
|
if (isPooled() && !bs.isNullOrEmpty()) {
|
|
316
325
|
pooled.setBridgeScript(bs)
|
|
317
326
|
pooled.warmDriver = this
|
|
318
|
-
pooled.setSource(_uri, _localBundle, _entry, _paramsJson)
|
|
327
|
+
pooled.setSource(_uri, _localBundle, _entry, _paramsJson, _assetHost)
|
|
319
328
|
} else if (pooled.owner == this) {
|
|
320
329
|
pooled.setBridgeScript(_bridgeScript ?: "")
|
|
321
|
-
pooled.setSource(_uri, _localBundle, _entry, _paramsJson)
|
|
330
|
+
pooled.setSource(_uri, _localBundle, _entry, _paramsJson, _assetHost)
|
|
322
331
|
}
|
|
323
332
|
}
|
|
324
333
|
|
|
@@ -25,6 +25,7 @@ import androidx.webkit.WebViewClientCompat
|
|
|
25
25
|
import androidx.webkit.WebViewCompat
|
|
26
26
|
import androidx.webkit.WebViewFeature
|
|
27
27
|
import org.json.JSONObject
|
|
28
|
+
import java.lang.ref.WeakReference
|
|
28
29
|
import java.net.URLEncoder
|
|
29
30
|
import java.util.concurrent.atomic.AtomicInteger
|
|
30
31
|
|
|
@@ -126,12 +127,12 @@ class PooledChartWebView private constructor(
|
|
|
126
127
|
}
|
|
127
128
|
|
|
128
129
|
// The trusted origin set for the current source: the offline asset origin
|
|
129
|
-
// (https
|
|
130
|
-
// `uri` origin when running in online mode. computeTargetUrl
|
|
131
|
-
// content from
|
|
132
|
-
// the origins the privileged bridge legitimately runs in.
|
|
130
|
+
// (https://<assetHost>, default appassets.androidplatform.net) always, plus the
|
|
131
|
+
// online/fallback `uri` origin when running in online mode. computeTargetUrl
|
|
132
|
+
// serves offline content from `assetHost` and online content from `uri`, so
|
|
133
|
+
// these are exactly the origins the privileged bridge legitimately runs in.
|
|
133
134
|
private fun trustedOriginsFor(uri: String?): Set<String> {
|
|
134
|
-
val origins = linkedSetOf("https://$
|
|
135
|
+
val origins = linkedSetOf("https://$assetHost")
|
|
135
136
|
originOf(uri)?.let { origins.add(it) }
|
|
136
137
|
return origins
|
|
137
138
|
}
|
|
@@ -151,21 +152,25 @@ class PooledChartWebView private constructor(
|
|
|
151
152
|
}
|
|
152
153
|
|
|
153
154
|
/** The host currently displaying this WebView; page events route here. */
|
|
154
|
-
|
|
155
|
+
// Weak (mirror of iOS): the pool entry is immortal, so a strong ref here would
|
|
156
|
+
// pin a disposed host — and its ReactContext/Activity — forever. A GC'd host
|
|
157
|
+
// reads back as null, which makes `entry.owner == this` correctly false.
|
|
158
|
+
private var _ownerRef: WeakReference<HybridChartWebview>? = null
|
|
155
159
|
var owner: HybridChartWebview?
|
|
156
|
-
get() =
|
|
160
|
+
get() = _ownerRef?.get()
|
|
157
161
|
set(value) {
|
|
158
|
-
|
|
162
|
+
_ownerRef = value?.let { WeakReference(it) }
|
|
159
163
|
}
|
|
160
164
|
// The host that warm-booted the page and can drive its symbol / receive its
|
|
161
165
|
// callbacks while there is no VISIBLE owner yet. Separate from `owner` (the
|
|
162
166
|
// YIELD path clears `owner`); callbacks fall back to this so bars-state /
|
|
163
167
|
// load-end aren't dropped during warm. Mirror of the iOS warmDriver.
|
|
164
|
-
|
|
168
|
+
// Weak for the same immortal-pool reason as `owner` above.
|
|
169
|
+
private var _warmDriverRef: WeakReference<HybridChartWebview>? = null
|
|
165
170
|
var warmDriver: HybridChartWebview?
|
|
166
|
-
get() =
|
|
171
|
+
get() = _warmDriverRef?.get()
|
|
167
172
|
set(value) {
|
|
168
|
-
|
|
173
|
+
_warmDriverRef = value?.let { WeakReference(it) }
|
|
169
174
|
}
|
|
170
175
|
|
|
171
176
|
// PERF (Android only): Android's in-process WebView/Chromium does NOT throttle
|
|
@@ -195,14 +200,14 @@ class PooledChartWebView private constructor(
|
|
|
195
200
|
return
|
|
196
201
|
}
|
|
197
202
|
paused = true
|
|
198
|
-
android.util.Log.
|
|
203
|
+
android.util.Log.d(TAG, "pool[$key] PAUSE (renderer idle)")
|
|
199
204
|
runOnUiThread { webView.onPause() }
|
|
200
205
|
}
|
|
201
206
|
|
|
202
207
|
fun resume() {
|
|
203
208
|
if (!paused) return
|
|
204
209
|
paused = false
|
|
205
|
-
android.util.Log.
|
|
210
|
+
android.util.Log.d(TAG, "pool[$key] RESUME")
|
|
206
211
|
runOnUiThread {
|
|
207
212
|
webView.onResume()
|
|
208
213
|
webView.invalidate()
|
|
@@ -212,6 +217,13 @@ class PooledChartWebView private constructor(
|
|
|
212
217
|
private var assetLoader: WebViewAssetLoader? = null
|
|
213
218
|
private var lastLoadedUrl: String? = null
|
|
214
219
|
private var lastLocalBundle: String? = null
|
|
220
|
+
// The host the offline bundle is served under. Defaults to the built-in
|
|
221
|
+
// appassets host (old behavior); when the app passes `assetHost` we serve the
|
|
222
|
+
// bundle under the real chart origin so the WebView reuses that origin's
|
|
223
|
+
// same-origin storage (zero migration). Tracked so an assetHost change rebuilds
|
|
224
|
+
// the asset loader + recomputes the target URL, same as a localBundle change.
|
|
225
|
+
private var assetHost: String = ASSET_HOST
|
|
226
|
+
private var lastAssetHost: String = ASSET_HOST
|
|
215
227
|
|
|
216
228
|
// Last rendered frame, used to mask the brief blank frame while the WebView's
|
|
217
229
|
// surface is torn down and recreated during a reparent (move). Kept until
|
|
@@ -226,6 +238,9 @@ class PooledChartWebView private constructor(
|
|
|
226
238
|
// How long the snapshot overlay stays up after a reparent, giving the WebView
|
|
227
239
|
// time to draw its first frame in the new container (~5 frames).
|
|
228
240
|
private val overlayHideDelayMs = 80L
|
|
241
|
+
// Delay between bounded attach retries (~1 vsync at 60Hz): long enough for the
|
|
242
|
+
// old parent's pending layout / removeView to flush, short enough to stay snappy.
|
|
243
|
+
private val attachRetryDelayMs = 16L
|
|
229
244
|
private val attachGeneration = AtomicInteger(0)
|
|
230
245
|
|
|
231
246
|
val webView: WebView = WebView(context).apply {
|
|
@@ -311,10 +326,18 @@ class PooledChartWebView private constructor(
|
|
|
311
326
|
// hold; removeViewInLayout() is the in-layout fallback if the child is still held.
|
|
312
327
|
private fun forceDetach(parent: ViewGroup) {
|
|
313
328
|
if (webView.parent !== parent) return
|
|
314
|
-
try {
|
|
329
|
+
try {
|
|
330
|
+
parent.endViewTransition(webView)
|
|
331
|
+
} catch (e: Throwable) {
|
|
332
|
+
android.util.Log.w(TAG, "forceDetach: endViewTransition failed", e)
|
|
333
|
+
}
|
|
315
334
|
parent.removeView(webView)
|
|
316
335
|
if (webView.parent === parent) {
|
|
317
|
-
try {
|
|
336
|
+
try {
|
|
337
|
+
parent.removeViewInLayout(webView)
|
|
338
|
+
} catch (e: Throwable) {
|
|
339
|
+
android.util.Log.w(TAG, "forceDetach: removeViewInLayout failed", e)
|
|
340
|
+
}
|
|
318
341
|
parent.requestLayout()
|
|
319
342
|
}
|
|
320
343
|
}
|
|
@@ -340,14 +363,25 @@ class PooledChartWebView private constructor(
|
|
|
340
363
|
// which is attached to the window so its queue keeps draining, instead of the
|
|
341
364
|
// detached webView/old parent whose post() runnables may never run.
|
|
342
365
|
if (retriesLeft > 0) {
|
|
343
|
-
container.post
|
|
366
|
+
// postDelayed (not a tight container.post spin): a small delay lets the
|
|
367
|
+
// old parent's pending layout / removeView flush between attempts, instead
|
|
368
|
+
// of re-checking on the very next vsync before anything could change.
|
|
369
|
+
container.postDelayed({
|
|
344
370
|
attachToContainer(container, generation, retriesLeft = retriesLeft - 1)
|
|
345
|
-
}
|
|
371
|
+
}, attachRetryDelayMs)
|
|
346
372
|
} else {
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
)
|
|
373
|
+
// Last resort before giving up: the old parent never released the WebView
|
|
374
|
+
// through the normal path. Force-detach it and try the attach once more so
|
|
375
|
+
// we don't leave the WebView unparented (the blank-chart symptom).
|
|
376
|
+
(currentParent as? ViewGroup)?.let { forceDetach(it) }
|
|
377
|
+
if (webView.parent == null || webView.parent === container) {
|
|
378
|
+
attachToContainer(container, generation, retriesLeft = 0)
|
|
379
|
+
} else {
|
|
380
|
+
android.util.Log.w(
|
|
381
|
+
TAG,
|
|
382
|
+
"Skip attach key=$key after retries because WebView parent was not cleared: $currentParent",
|
|
383
|
+
)
|
|
384
|
+
}
|
|
351
385
|
}
|
|
352
386
|
return
|
|
353
387
|
}
|
|
@@ -515,13 +549,26 @@ class PooledChartWebView private constructor(
|
|
|
515
549
|
* so reparenting / redundant prop re-applies never reload (which would lose
|
|
516
550
|
* chart state, the whole point of pooling).
|
|
517
551
|
*/
|
|
518
|
-
fun setSource(
|
|
552
|
+
fun setSource(
|
|
553
|
+
uri: String?,
|
|
554
|
+
localBundle: String?,
|
|
555
|
+
entry: String?,
|
|
556
|
+
paramsJson: String?,
|
|
557
|
+
assetHost: String?,
|
|
558
|
+
) {
|
|
519
559
|
// Never load before the document-start bridge is registered — otherwise the
|
|
520
560
|
// page boots without the bridge and its first $private requests are lost. The
|
|
521
561
|
// host re-calls setSource once the bridgeScript prop arrives.
|
|
522
562
|
if (!bridgeRegistered) return
|
|
523
|
-
|
|
563
|
+
// Per-instance asset host: fall back to the built-in appassets host (old
|
|
564
|
+
// behavior) when the app doesn't pass one. Empty string is treated as absent.
|
|
565
|
+
// Sanitize untrusted values before they reach the privileged-bridge origin
|
|
566
|
+
// ("https://$assetHost") and WebViewAssetLoader.setDomain — see sanitizeAssetHost.
|
|
567
|
+
this.assetHost = assetHost?.takeIf { it.isNotEmpty() }
|
|
568
|
+
?.let { sanitizeAssetHost(it) } ?: ASSET_HOST
|
|
569
|
+
if (localBundle != lastLocalBundle || this.assetHost != lastAssetHost) {
|
|
524
570
|
lastLocalBundle = localBundle
|
|
571
|
+
lastAssetHost = this.assetHost
|
|
525
572
|
rebuildAssetLoader(localBundle)
|
|
526
573
|
}
|
|
527
574
|
// Register the document-start bridge scoped to exactly the origin(s) this load
|
|
@@ -567,14 +614,62 @@ class PooledChartWebView private constructor(
|
|
|
567
614
|
}
|
|
568
615
|
}
|
|
569
616
|
|
|
617
|
+
// Validate an incoming assetHost prop before it becomes the trusted bridge
|
|
618
|
+
// origin ("https://$assetHost") and WebViewAssetLoader.setDomain(assetHost). A
|
|
619
|
+
// malformed value (scheme, path, '/', '@'/userinfo, whitespace, port, query)
|
|
620
|
+
// could corrupt the privileged-origin allowlist or throw on the UI thread, so a
|
|
621
|
+
// candidate that is not a bare hostname falls back to the built-in ASSET_HOST.
|
|
622
|
+
private fun sanitizeAssetHost(candidate: String): String {
|
|
623
|
+
val invalid = {
|
|
624
|
+
android.util.Log.w(
|
|
625
|
+
TAG,
|
|
626
|
+
"Ignoring invalid assetHost '$candidate'; falling back to default $ASSET_HOST",
|
|
627
|
+
)
|
|
628
|
+
ASSET_HOST
|
|
629
|
+
}
|
|
630
|
+
// Cheap rejects first: a bare hostname has no whitespace and no '/'.
|
|
631
|
+
if (candidate.any { it.isWhitespace() } || candidate.contains('/')) return invalid()
|
|
632
|
+
return try {
|
|
633
|
+
val uri = java.net.URI("https://$candidate")
|
|
634
|
+
val bareHost =
|
|
635
|
+
uri.host == candidate &&
|
|
636
|
+
uri.path.isNullOrEmpty() &&
|
|
637
|
+
uri.userInfo == null &&
|
|
638
|
+
uri.query == null &&
|
|
639
|
+
uri.port == -1
|
|
640
|
+
if (bareHost) candidate else invalid()
|
|
641
|
+
} catch (e: Exception) {
|
|
642
|
+
invalid()
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
|
|
570
646
|
private fun rebuildAssetLoader(localBundle: String?) {
|
|
571
647
|
if (localBundle.isNullOrEmpty()) {
|
|
572
648
|
assetLoader = null
|
|
573
649
|
return
|
|
574
650
|
}
|
|
651
|
+
// Narrow the path handler to ONLY the offline bundle subtree
|
|
652
|
+
// (/<localBundle>/, e.g. /tradingview-assets/) instead of intercepting all of
|
|
653
|
+
// "/". When the bundle is served under the real chart origin (`assetHost`),
|
|
654
|
+
// intercepting "/" would shadow every web path on that domain; with the narrow
|
|
655
|
+
// handler, unmatched paths fall through to the network — so an `assetHost`
|
|
656
|
+
// that is a real public domain keeps behaving normally off-bundle.
|
|
657
|
+
// computeTargetUrl produces https://<assetHost>/<localBundle>/<entry>, which
|
|
658
|
+
// stays inside this handler's path. (Path built as /<localBundle>/ so a
|
|
659
|
+
// localBundle that already has a trailing slash doesn't double it.)
|
|
660
|
+
val bundleDir = localBundle.trim('/')
|
|
661
|
+
val bundlePath = "/$bundleDir/"
|
|
662
|
+
// WebViewAssetLoader strips the registered prefix before calling the handler,
|
|
663
|
+
// so AssetsPathHandler alone would resolve the remainder against the assets
|
|
664
|
+
// ROOT (assets/<entry>) and lose the bundle namespace. Re-prepend <bundleDir>/
|
|
665
|
+
// so we still serve from assets/<localBundle>/<entry>. Returning null on a
|
|
666
|
+
// miss lets WebViewAssetLoader fall through to the network.
|
|
667
|
+
val assets = WebViewAssetLoader.AssetsPathHandler(webView.context)
|
|
668
|
+
val namespacedHandler =
|
|
669
|
+
WebViewAssetLoader.PathHandler { suffix -> assets.handle("$bundleDir/$suffix") }
|
|
575
670
|
assetLoader = WebViewAssetLoader.Builder()
|
|
576
|
-
.setDomain(
|
|
577
|
-
.addPathHandler(
|
|
671
|
+
.setDomain(assetHost)
|
|
672
|
+
.addPathHandler(bundlePath, namespacedHandler)
|
|
578
673
|
.build()
|
|
579
674
|
}
|
|
580
675
|
|
|
@@ -588,15 +683,21 @@ class PooledChartWebView private constructor(
|
|
|
588
683
|
if (localBundle.isNullOrEmpty()) return null
|
|
589
684
|
val entryPath = entry?.takeIf { it.isNotEmpty() } ?: DEFAULT_ENTRY
|
|
590
685
|
val query = buildQueryFromParamsJson(paramsJson)
|
|
686
|
+
// Normalize the bundle dir the SAME way rebuildAssetLoader does (trim '/'), so
|
|
687
|
+
// the URL has exactly single slashes between host, bundle dir and entry. A raw
|
|
688
|
+
// localBundle like "/tradingview-assets/" would otherwise yield
|
|
689
|
+
// https://host//tradingview-assets//index.html, which misses the registered
|
|
690
|
+
// handler prefix → falls through to the network → blank chart.
|
|
691
|
+
val bundleDir = localBundle.trim('/')
|
|
591
692
|
return buildString {
|
|
592
693
|
append("https://")
|
|
593
|
-
append(
|
|
694
|
+
append(assetHost)
|
|
594
695
|
append('/')
|
|
595
696
|
// Serve the offline bundle from assets/<localBundle>/ (namespaced) rather
|
|
596
697
|
// than the assets root, so it doesn't collide with other bundled assets
|
|
597
698
|
// (e.g. web-embed). The dist uses relative asset paths (PUBLIC_URL='./'),
|
|
598
699
|
// so loading the entry from a subpath resolves the rest correctly.
|
|
599
|
-
append(
|
|
700
|
+
append(bundleDir)
|
|
600
701
|
append('/')
|
|
601
702
|
append(entryPath)
|
|
602
703
|
if (query.isNotEmpty()) {
|
package/ios/ChartWebview.swift
CHANGED
|
@@ -129,6 +129,11 @@ class HybridChartWebview: HybridChartWebviewSpec {
|
|
|
129
129
|
var localBundle: String? { didSet { applySource() } }
|
|
130
130
|
var entry: String? { didSet { applySource() } }
|
|
131
131
|
var paramsJson: String? { didSet { applySource() } }
|
|
132
|
+
// ANDROID ONLY. iOS serves offline content from the onekey-chart:// custom
|
|
133
|
+
// scheme (https can't be intercepted here), so this host stores the prop to
|
|
134
|
+
// satisfy the generated spec but never reads it — offline origin/behavior is
|
|
135
|
+
// unchanged on iOS.
|
|
136
|
+
var assetHost: String?
|
|
132
137
|
|
|
133
138
|
// Document-start bridge JS (single source of truth in the TS layer). Handed to
|
|
134
139
|
// the pooled WebView when we claim it, before its first load.
|
|
@@ -81,6 +81,15 @@ namespace margelo::nitro::chartwebview {
|
|
|
81
81
|
static const auto method = javaClassStatic()->getMethod<void(jni::alias_ref<jni::JString> /* paramsJson */)>("setParamsJson");
|
|
82
82
|
method(_javaPart, paramsJson.has_value() ? jni::make_jstring(paramsJson.value()) : nullptr);
|
|
83
83
|
}
|
|
84
|
+
std::optional<std::string> JHybridChartWebviewSpec::getAssetHost() {
|
|
85
|
+
static const auto method = javaClassStatic()->getMethod<jni::local_ref<jni::JString>()>("getAssetHost");
|
|
86
|
+
auto __result = method(_javaPart);
|
|
87
|
+
return __result != nullptr ? std::make_optional(__result->toStdString()) : std::nullopt;
|
|
88
|
+
}
|
|
89
|
+
void JHybridChartWebviewSpec::setAssetHost(const std::optional<std::string>& assetHost) {
|
|
90
|
+
static const auto method = javaClassStatic()->getMethod<void(jni::alias_ref<jni::JString> /* assetHost */)>("setAssetHost");
|
|
91
|
+
method(_javaPart, assetHost.has_value() ? jni::make_jstring(assetHost.value()) : nullptr);
|
|
92
|
+
}
|
|
84
93
|
std::optional<std::string> JHybridChartWebviewSpec::getBridgeScript() {
|
|
85
94
|
static const auto method = javaClassStatic()->getMethod<jni::local_ref<jni::JString>()>("getBridgeScript");
|
|
86
95
|
auto __result = method(_javaPart);
|
|
@@ -58,6 +58,8 @@ namespace margelo::nitro::chartwebview {
|
|
|
58
58
|
void setEntry(const std::optional<std::string>& entry) override;
|
|
59
59
|
std::optional<std::string> getParamsJson() override;
|
|
60
60
|
void setParamsJson(const std::optional<std::string>& paramsJson) override;
|
|
61
|
+
std::optional<std::string> getAssetHost() override;
|
|
62
|
+
void setAssetHost(const std::optional<std::string>& assetHost) override;
|
|
61
63
|
std::optional<std::string> getBridgeScript() override;
|
|
62
64
|
void setBridgeScript(const std::optional<std::string>& bridgeScript) override;
|
|
63
65
|
std::optional<std::string> getReuseKey() override;
|
|
@@ -52,6 +52,10 @@ void JHybridChartWebviewStateUpdater::updateViewProps(jni::alias_ref<jni::JClass
|
|
|
52
52
|
view->setParamsJson(props.paramsJson.value);
|
|
53
53
|
// TODO: Set isDirty = false
|
|
54
54
|
}
|
|
55
|
+
if (props.assetHost.isDirty) {
|
|
56
|
+
view->setAssetHost(props.assetHost.value);
|
|
57
|
+
// TODO: Set isDirty = false
|
|
58
|
+
}
|
|
55
59
|
if (props.bridgeScript.isDirty) {
|
|
56
60
|
view->setBridgeScript(props.bridgeScript.value);
|
|
57
61
|
// TODO: Set isDirty = false
|
|
@@ -66,6 +66,12 @@ abstract class HybridChartWebviewSpec: HybridView() {
|
|
|
66
66
|
@set:Keep
|
|
67
67
|
abstract var paramsJson: String?
|
|
68
68
|
|
|
69
|
+
@get:DoNotStrip
|
|
70
|
+
@get:Keep
|
|
71
|
+
@set:DoNotStrip
|
|
72
|
+
@set:Keep
|
|
73
|
+
abstract var assetHost: String?
|
|
74
|
+
|
|
69
75
|
@get:DoNotStrip
|
|
70
76
|
@get:Keep
|
|
71
77
|
@set:DoNotStrip
|
|
@@ -86,6 +86,13 @@ namespace margelo::nitro::chartwebview {
|
|
|
86
86
|
inline void setParamsJson(const std::optional<std::string>& paramsJson) noexcept override {
|
|
87
87
|
_swiftPart.setParamsJson(paramsJson);
|
|
88
88
|
}
|
|
89
|
+
inline std::optional<std::string> getAssetHost() noexcept override {
|
|
90
|
+
auto __result = _swiftPart.getAssetHost();
|
|
91
|
+
return __result;
|
|
92
|
+
}
|
|
93
|
+
inline void setAssetHost(const std::optional<std::string>& assetHost) noexcept override {
|
|
94
|
+
_swiftPart.setAssetHost(assetHost);
|
|
95
|
+
}
|
|
89
96
|
inline std::optional<std::string> getBridgeScript() noexcept override {
|
|
90
97
|
auto __result = _swiftPart.getBridgeScript();
|
|
91
98
|
return __result;
|
|
@@ -91,6 +91,11 @@ using namespace margelo::nitro::chartwebview::views;
|
|
|
91
91
|
swiftPart.setParamsJson(newViewProps.paramsJson.value);
|
|
92
92
|
newViewProps.paramsJson.isDirty = false;
|
|
93
93
|
}
|
|
94
|
+
// assetHost: optional
|
|
95
|
+
if (newViewProps.assetHost.isDirty) {
|
|
96
|
+
swiftPart.setAssetHost(newViewProps.assetHost.value);
|
|
97
|
+
newViewProps.assetHost.isDirty = false;
|
|
98
|
+
}
|
|
94
99
|
// bridgeScript: optional
|
|
95
100
|
if (newViewProps.bridgeScript.isDirty) {
|
|
96
101
|
swiftPart.setBridgeScript(newViewProps.bridgeScript.value);
|
|
@@ -15,6 +15,7 @@ public protocol HybridChartWebviewSpec_protocol: HybridObject, HybridView {
|
|
|
15
15
|
var localBundle: String? { get set }
|
|
16
16
|
var entry: String? { get set }
|
|
17
17
|
var paramsJson: String? { get set }
|
|
18
|
+
var assetHost: String? { get set }
|
|
18
19
|
var bridgeScript: String? { get set }
|
|
19
20
|
var reuseKey: String? { get set }
|
|
20
21
|
var pooled: Bool? { get set }
|
|
@@ -210,6 +210,30 @@ open class HybridChartWebviewSpec_cxx {
|
|
|
210
210
|
}
|
|
211
211
|
}
|
|
212
212
|
|
|
213
|
+
public final var assetHost: bridge.std__optional_std__string_ {
|
|
214
|
+
@inline(__always)
|
|
215
|
+
get {
|
|
216
|
+
return { () -> bridge.std__optional_std__string_ in
|
|
217
|
+
if let __unwrappedValue = self.__implementation.assetHost {
|
|
218
|
+
return bridge.create_std__optional_std__string_(std.string(__unwrappedValue))
|
|
219
|
+
} else {
|
|
220
|
+
return .init()
|
|
221
|
+
}
|
|
222
|
+
}()
|
|
223
|
+
}
|
|
224
|
+
@inline(__always)
|
|
225
|
+
set {
|
|
226
|
+
self.__implementation.assetHost = { () -> String? in
|
|
227
|
+
if bridge.has_value_std__optional_std__string_(newValue) {
|
|
228
|
+
let __unwrapped = bridge.get_std__optional_std__string_(newValue)
|
|
229
|
+
return String(__unwrapped)
|
|
230
|
+
} else {
|
|
231
|
+
return nil
|
|
232
|
+
}
|
|
233
|
+
}()
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
213
237
|
public final var bridgeScript: bridge.std__optional_std__string_ {
|
|
214
238
|
@inline(__always)
|
|
215
239
|
get {
|
|
@@ -22,6 +22,8 @@ namespace margelo::nitro::chartwebview {
|
|
|
22
22
|
prototype.registerHybridSetter("entry", &HybridChartWebviewSpec::setEntry);
|
|
23
23
|
prototype.registerHybridGetter("paramsJson", &HybridChartWebviewSpec::getParamsJson);
|
|
24
24
|
prototype.registerHybridSetter("paramsJson", &HybridChartWebviewSpec::setParamsJson);
|
|
25
|
+
prototype.registerHybridGetter("assetHost", &HybridChartWebviewSpec::getAssetHost);
|
|
26
|
+
prototype.registerHybridSetter("assetHost", &HybridChartWebviewSpec::setAssetHost);
|
|
25
27
|
prototype.registerHybridGetter("bridgeScript", &HybridChartWebviewSpec::getBridgeScript);
|
|
26
28
|
prototype.registerHybridSetter("bridgeScript", &HybridChartWebviewSpec::setBridgeScript);
|
|
27
29
|
prototype.registerHybridGetter("reuseKey", &HybridChartWebviewSpec::getReuseKey);
|
|
@@ -54,6 +54,8 @@ namespace margelo::nitro::chartwebview {
|
|
|
54
54
|
virtual void setEntry(const std::optional<std::string>& entry) = 0;
|
|
55
55
|
virtual std::optional<std::string> getParamsJson() = 0;
|
|
56
56
|
virtual void setParamsJson(const std::optional<std::string>& paramsJson) = 0;
|
|
57
|
+
virtual std::optional<std::string> getAssetHost() = 0;
|
|
58
|
+
virtual void setAssetHost(const std::optional<std::string>& assetHost) = 0;
|
|
57
59
|
virtual std::optional<std::string> getBridgeScript() = 0;
|
|
58
60
|
virtual void setBridgeScript(const std::optional<std::string>& bridgeScript) = 0;
|
|
59
61
|
virtual std::optional<std::string> getReuseKey() = 0;
|
|
@@ -65,6 +65,16 @@ namespace margelo::nitro::chartwebview::views {
|
|
|
65
65
|
throw std::runtime_error(std::string("ChartWebview.paramsJson: ") + exc.what());
|
|
66
66
|
}
|
|
67
67
|
}()),
|
|
68
|
+
assetHost([&]() -> CachedProp<std::optional<std::string>> {
|
|
69
|
+
try {
|
|
70
|
+
const react::RawValue* rawValue = rawProps.at("assetHost", nullptr, nullptr);
|
|
71
|
+
if (rawValue == nullptr) return sourceProps.assetHost;
|
|
72
|
+
const auto& [runtime, value] = (std::pair<jsi::Runtime*, jsi::Value>)*rawValue;
|
|
73
|
+
return CachedProp<std::optional<std::string>>::fromRawValue(*runtime, value, sourceProps.assetHost);
|
|
74
|
+
} catch (const std::exception& exc) {
|
|
75
|
+
throw std::runtime_error(std::string("ChartWebview.assetHost: ") + exc.what());
|
|
76
|
+
}
|
|
77
|
+
}()),
|
|
68
78
|
bridgeScript([&]() -> CachedProp<std::optional<std::string>> {
|
|
69
79
|
try {
|
|
70
80
|
const react::RawValue* rawValue = rawProps.at("bridgeScript", nullptr, nullptr);
|
|
@@ -162,6 +172,7 @@ namespace margelo::nitro::chartwebview::views {
|
|
|
162
172
|
localBundle(other.localBundle),
|
|
163
173
|
entry(other.entry),
|
|
164
174
|
paramsJson(other.paramsJson),
|
|
175
|
+
assetHost(other.assetHost),
|
|
165
176
|
bridgeScript(other.bridgeScript),
|
|
166
177
|
reuseKey(other.reuseKey),
|
|
167
178
|
pooled(other.pooled),
|
|
@@ -178,6 +189,7 @@ namespace margelo::nitro::chartwebview::views {
|
|
|
178
189
|
case hashString("localBundle"): return true;
|
|
179
190
|
case hashString("entry"): return true;
|
|
180
191
|
case hashString("paramsJson"): return true;
|
|
192
|
+
case hashString("assetHost"): return true;
|
|
181
193
|
case hashString("bridgeScript"): return true;
|
|
182
194
|
case hashString("reuseKey"): return true;
|
|
183
195
|
case hashString("pooled"): return true;
|
|
@@ -47,6 +47,7 @@ namespace margelo::nitro::chartwebview::views {
|
|
|
47
47
|
CachedProp<std::optional<std::string>> localBundle;
|
|
48
48
|
CachedProp<std::optional<std::string>> entry;
|
|
49
49
|
CachedProp<std::optional<std::string>> paramsJson;
|
|
50
|
+
CachedProp<std::optional<std::string>> assetHost;
|
|
50
51
|
CachedProp<std::optional<std::string>> bridgeScript;
|
|
51
52
|
CachedProp<std::optional<std::string>> reuseKey;
|
|
52
53
|
CachedProp<std::optional<bool>> pooled;
|
|
@@ -81,6 +81,15 @@ namespace margelo::nitro::chartwebview {
|
|
|
81
81
|
static const auto method = javaClassStatic()->getMethod<void(jni::alias_ref<jni::JString> /* paramsJson */)>("setParamsJson");
|
|
82
82
|
method(_javaPart, paramsJson.has_value() ? jni::make_jstring(paramsJson.value()) : nullptr);
|
|
83
83
|
}
|
|
84
|
+
std::optional<std::string> JHybridChartWebviewSpec::getAssetHost() {
|
|
85
|
+
static const auto method = javaClassStatic()->getMethod<jni::local_ref<jni::JString>()>("getAssetHost");
|
|
86
|
+
auto __result = method(_javaPart);
|
|
87
|
+
return __result != nullptr ? std::make_optional(__result->toStdString()) : std::nullopt;
|
|
88
|
+
}
|
|
89
|
+
void JHybridChartWebviewSpec::setAssetHost(const std::optional<std::string>& assetHost) {
|
|
90
|
+
static const auto method = javaClassStatic()->getMethod<void(jni::alias_ref<jni::JString> /* assetHost */)>("setAssetHost");
|
|
91
|
+
method(_javaPart, assetHost.has_value() ? jni::make_jstring(assetHost.value()) : nullptr);
|
|
92
|
+
}
|
|
84
93
|
std::optional<std::string> JHybridChartWebviewSpec::getBridgeScript() {
|
|
85
94
|
static const auto method = javaClassStatic()->getMethod<jni::local_ref<jni::JString>()>("getBridgeScript");
|
|
86
95
|
auto __result = method(_javaPart);
|
|
@@ -58,6 +58,8 @@ namespace margelo::nitro::chartwebview {
|
|
|
58
58
|
void setEntry(const std::optional<std::string>& entry) override;
|
|
59
59
|
std::optional<std::string> getParamsJson() override;
|
|
60
60
|
void setParamsJson(const std::optional<std::string>& paramsJson) override;
|
|
61
|
+
std::optional<std::string> getAssetHost() override;
|
|
62
|
+
void setAssetHost(const std::optional<std::string>& assetHost) override;
|
|
61
63
|
std::optional<std::string> getBridgeScript() override;
|
|
62
64
|
void setBridgeScript(const std::optional<std::string>& bridgeScript) override;
|
|
63
65
|
std::optional<std::string> getReuseKey() override;
|
package/lib/nitrogen/nitrogen/generated/android/c++/views/JHybridChartWebviewStateUpdater.cpp
CHANGED
|
@@ -52,6 +52,10 @@ void JHybridChartWebviewStateUpdater::updateViewProps(jni::alias_ref<jni::JClass
|
|
|
52
52
|
view->setParamsJson(props.paramsJson.value);
|
|
53
53
|
// TODO: Set isDirty = false
|
|
54
54
|
}
|
|
55
|
+
if (props.assetHost.isDirty) {
|
|
56
|
+
view->setAssetHost(props.assetHost.value);
|
|
57
|
+
// TODO: Set isDirty = false
|
|
58
|
+
}
|
|
55
59
|
if (props.bridgeScript.isDirty) {
|
|
56
60
|
view->setBridgeScript(props.bridgeScript.value);
|
|
57
61
|
// TODO: Set isDirty = false
|
|
@@ -66,6 +66,12 @@ abstract class HybridChartWebviewSpec: HybridView() {
|
|
|
66
66
|
@set:Keep
|
|
67
67
|
abstract var paramsJson: String?
|
|
68
68
|
|
|
69
|
+
@get:DoNotStrip
|
|
70
|
+
@get:Keep
|
|
71
|
+
@set:DoNotStrip
|
|
72
|
+
@set:Keep
|
|
73
|
+
abstract var assetHost: String?
|
|
74
|
+
|
|
69
75
|
@get:DoNotStrip
|
|
70
76
|
@get:Keep
|
|
71
77
|
@set:DoNotStrip
|
|
@@ -86,6 +86,13 @@ namespace margelo::nitro::chartwebview {
|
|
|
86
86
|
inline void setParamsJson(const std::optional<std::string>& paramsJson) noexcept override {
|
|
87
87
|
_swiftPart.setParamsJson(paramsJson);
|
|
88
88
|
}
|
|
89
|
+
inline std::optional<std::string> getAssetHost() noexcept override {
|
|
90
|
+
auto __result = _swiftPart.getAssetHost();
|
|
91
|
+
return __result;
|
|
92
|
+
}
|
|
93
|
+
inline void setAssetHost(const std::optional<std::string>& assetHost) noexcept override {
|
|
94
|
+
_swiftPart.setAssetHost(assetHost);
|
|
95
|
+
}
|
|
89
96
|
inline std::optional<std::string> getBridgeScript() noexcept override {
|
|
90
97
|
auto __result = _swiftPart.getBridgeScript();
|
|
91
98
|
return __result;
|
|
@@ -91,6 +91,11 @@ using namespace margelo::nitro::chartwebview::views;
|
|
|
91
91
|
swiftPart.setParamsJson(newViewProps.paramsJson.value);
|
|
92
92
|
newViewProps.paramsJson.isDirty = false;
|
|
93
93
|
}
|
|
94
|
+
// assetHost: optional
|
|
95
|
+
if (newViewProps.assetHost.isDirty) {
|
|
96
|
+
swiftPart.setAssetHost(newViewProps.assetHost.value);
|
|
97
|
+
newViewProps.assetHost.isDirty = false;
|
|
98
|
+
}
|
|
94
99
|
// bridgeScript: optional
|
|
95
100
|
if (newViewProps.bridgeScript.isDirty) {
|
|
96
101
|
swiftPart.setBridgeScript(newViewProps.bridgeScript.value);
|
|
@@ -15,6 +15,7 @@ public protocol HybridChartWebviewSpec_protocol: HybridObject, HybridView {
|
|
|
15
15
|
var localBundle: String? { get set }
|
|
16
16
|
var entry: String? { get set }
|
|
17
17
|
var paramsJson: String? { get set }
|
|
18
|
+
var assetHost: String? { get set }
|
|
18
19
|
var bridgeScript: String? { get set }
|
|
19
20
|
var reuseKey: String? { get set }
|
|
20
21
|
var pooled: Bool? { get set }
|
|
@@ -210,6 +210,30 @@ open class HybridChartWebviewSpec_cxx {
|
|
|
210
210
|
}
|
|
211
211
|
}
|
|
212
212
|
|
|
213
|
+
public final var assetHost: bridge.std__optional_std__string_ {
|
|
214
|
+
@inline(__always)
|
|
215
|
+
get {
|
|
216
|
+
return { () -> bridge.std__optional_std__string_ in
|
|
217
|
+
if let __unwrappedValue = self.__implementation.assetHost {
|
|
218
|
+
return bridge.create_std__optional_std__string_(std.string(__unwrappedValue))
|
|
219
|
+
} else {
|
|
220
|
+
return .init()
|
|
221
|
+
}
|
|
222
|
+
}()
|
|
223
|
+
}
|
|
224
|
+
@inline(__always)
|
|
225
|
+
set {
|
|
226
|
+
self.__implementation.assetHost = { () -> String? in
|
|
227
|
+
if bridge.has_value_std__optional_std__string_(newValue) {
|
|
228
|
+
let __unwrapped = bridge.get_std__optional_std__string_(newValue)
|
|
229
|
+
return String(__unwrapped)
|
|
230
|
+
} else {
|
|
231
|
+
return nil
|
|
232
|
+
}
|
|
233
|
+
}()
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
213
237
|
public final var bridgeScript: bridge.std__optional_std__string_ {
|
|
214
238
|
@inline(__always)
|
|
215
239
|
get {
|
|
@@ -22,6 +22,8 @@ namespace margelo::nitro::chartwebview {
|
|
|
22
22
|
prototype.registerHybridSetter("entry", &HybridChartWebviewSpec::setEntry);
|
|
23
23
|
prototype.registerHybridGetter("paramsJson", &HybridChartWebviewSpec::getParamsJson);
|
|
24
24
|
prototype.registerHybridSetter("paramsJson", &HybridChartWebviewSpec::setParamsJson);
|
|
25
|
+
prototype.registerHybridGetter("assetHost", &HybridChartWebviewSpec::getAssetHost);
|
|
26
|
+
prototype.registerHybridSetter("assetHost", &HybridChartWebviewSpec::setAssetHost);
|
|
25
27
|
prototype.registerHybridGetter("bridgeScript", &HybridChartWebviewSpec::getBridgeScript);
|
|
26
28
|
prototype.registerHybridSetter("bridgeScript", &HybridChartWebviewSpec::setBridgeScript);
|
|
27
29
|
prototype.registerHybridGetter("reuseKey", &HybridChartWebviewSpec::getReuseKey);
|
|
@@ -54,6 +54,8 @@ namespace margelo::nitro::chartwebview {
|
|
|
54
54
|
virtual void setEntry(const std::optional<std::string>& entry) = 0;
|
|
55
55
|
virtual std::optional<std::string> getParamsJson() = 0;
|
|
56
56
|
virtual void setParamsJson(const std::optional<std::string>& paramsJson) = 0;
|
|
57
|
+
virtual std::optional<std::string> getAssetHost() = 0;
|
|
58
|
+
virtual void setAssetHost(const std::optional<std::string>& assetHost) = 0;
|
|
57
59
|
virtual std::optional<std::string> getBridgeScript() = 0;
|
|
58
60
|
virtual void setBridgeScript(const std::optional<std::string>& bridgeScript) = 0;
|
|
59
61
|
virtual std::optional<std::string> getReuseKey() = 0;
|
|
@@ -65,6 +65,16 @@ namespace margelo::nitro::chartwebview::views {
|
|
|
65
65
|
throw std::runtime_error(std::string("ChartWebview.paramsJson: ") + exc.what());
|
|
66
66
|
}
|
|
67
67
|
}()),
|
|
68
|
+
assetHost([&]() -> CachedProp<std::optional<std::string>> {
|
|
69
|
+
try {
|
|
70
|
+
const react::RawValue* rawValue = rawProps.at("assetHost", nullptr, nullptr);
|
|
71
|
+
if (rawValue == nullptr) return sourceProps.assetHost;
|
|
72
|
+
const auto& [runtime, value] = (std::pair<jsi::Runtime*, jsi::Value>)*rawValue;
|
|
73
|
+
return CachedProp<std::optional<std::string>>::fromRawValue(*runtime, value, sourceProps.assetHost);
|
|
74
|
+
} catch (const std::exception& exc) {
|
|
75
|
+
throw std::runtime_error(std::string("ChartWebview.assetHost: ") + exc.what());
|
|
76
|
+
}
|
|
77
|
+
}()),
|
|
68
78
|
bridgeScript([&]() -> CachedProp<std::optional<std::string>> {
|
|
69
79
|
try {
|
|
70
80
|
const react::RawValue* rawValue = rawProps.at("bridgeScript", nullptr, nullptr);
|
|
@@ -162,6 +172,7 @@ namespace margelo::nitro::chartwebview::views {
|
|
|
162
172
|
localBundle(other.localBundle),
|
|
163
173
|
entry(other.entry),
|
|
164
174
|
paramsJson(other.paramsJson),
|
|
175
|
+
assetHost(other.assetHost),
|
|
165
176
|
bridgeScript(other.bridgeScript),
|
|
166
177
|
reuseKey(other.reuseKey),
|
|
167
178
|
pooled(other.pooled),
|
|
@@ -178,6 +189,7 @@ namespace margelo::nitro::chartwebview::views {
|
|
|
178
189
|
case hashString("localBundle"): return true;
|
|
179
190
|
case hashString("entry"): return true;
|
|
180
191
|
case hashString("paramsJson"): return true;
|
|
192
|
+
case hashString("assetHost"): return true;
|
|
181
193
|
case hashString("bridgeScript"): return true;
|
|
182
194
|
case hashString("reuseKey"): return true;
|
|
183
195
|
case hashString("pooled"): return true;
|
|
@@ -47,6 +47,7 @@ namespace margelo::nitro::chartwebview::views {
|
|
|
47
47
|
CachedProp<std::optional<std::string>> localBundle;
|
|
48
48
|
CachedProp<std::optional<std::string>> entry;
|
|
49
49
|
CachedProp<std::optional<std::string>> paramsJson;
|
|
50
|
+
CachedProp<std::optional<std::string>> assetHost;
|
|
50
51
|
CachedProp<std::optional<std::string>> bridgeScript;
|
|
51
52
|
CachedProp<std::optional<std::string>> reuseKey;
|
|
52
53
|
CachedProp<std::optional<bool>> pooled;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChartWebview.nitro.d.ts","sourceRoot":"","sources":["../../../src/ChartWebview.nitro.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EACV,iBAAiB,EACjB,eAAe,EAChB,MAAM,4BAA4B,CAAC;AAKpC,MAAM,WAAW,iBAAkB,SAAQ,eAAe;IAGxD,GAAG,CAAC,EAAE,MAAM,CAAC;IAIb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IAIf,UAAU,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"ChartWebview.nitro.d.ts","sourceRoot":"","sources":["../../../src/ChartWebview.nitro.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EACV,iBAAiB,EACjB,eAAe,EAChB,MAAM,4BAA4B,CAAC;AAKpC,MAAM,WAAW,iBAAkB,SAAQ,eAAe;IAGxD,GAAG,CAAC,EAAE,MAAM,CAAC;IAIb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IAIf,UAAU,CAAC,EAAE,MAAM,CAAC;IAQpB,SAAS,CAAC,EAAE,MAAM,CAAC;IAMnB,YAAY,CAAC,EAAE,MAAM,CAAC;IAItB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB,MAAM,CAAC,EAAE,OAAO,CAAC;IAMjB,MAAM,CAAC,EAAE,OAAO,CAAC;IAUjB,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAIlC,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IACtC,SAAS,CAAC,EAAE,MAAM,IAAI,CAAC;IACvB,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;CACrC;AAED,MAAM,WAAW,mBAAoB,SAAQ,iBAAiB;IAG5D,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACnC,MAAM,IAAI,IAAI,CAAC;IAGf,aAAa,IAAI,IAAI,CAAC;CACvB;AAED,MAAM,MAAM,YAAY,GAAG,UAAU,CAAC,iBAAiB,EAAE,mBAAmB,CAAC,CAAC"}
|
|
@@ -16,6 +16,7 @@ export declare function ChartWebviewView({ bridgeScript, hybridRef, onMessage, o
|
|
|
16
16
|
localBundle?: string | undefined;
|
|
17
17
|
entry?: string | undefined;
|
|
18
18
|
paramsJson?: string | undefined;
|
|
19
|
+
assetHost?: string | undefined;
|
|
19
20
|
bridgeScript?: string | undefined;
|
|
20
21
|
reuseKey?: string | undefined;
|
|
21
22
|
pooled?: boolean | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAGL,KAAK,wBAAwB,EAC9B,MAAM,4BAA4B,CAAC;AAEpC,OAAO,KAAK,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAGnF,YAAY,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACnF,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAO3C,KAAK,oBAAoB,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,IACxD,CAAC,GACD,wBAAwB,CAAC,CAAC,CAAC,CAAC;AAEhC,KAAK,qBAAqB,GAAG,IAAI,CAC/B,iBAAiB,EACjB,WAAW,GAAG,WAAW,GAAG,SAAS,CACtC,GACC,SAAS,GAAG;IACV,SAAS,CAAC,EAAE,oBAAoB,CAAC,CAAC,GAAG,EAAE,GAAG,KAAK,IAAI,CAAC,CAAC;IACrD,SAAS,CAAC,EAAE,oBAAoB,CAAC,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC,CAAC;IAC5D,SAAS,CAAC,EAAE,oBAAoB,CAAC,MAAM,IAAI,CAAC,CAAC;IAC7C,OAAO,CAAC,EAAE,oBAAoB,CAAC,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC,CAAC;CAC3D,CAAC;AAcJ,wBAAgB,gBAAgB,CAAC,EAC/B,YAAY,EACZ,SAAS,EACT,SAAS,EACT,SAAS,EACT,OAAO,EACP,GAAG,KAAK,EACT,EAAE,qBAAqB
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAGL,KAAK,wBAAwB,EAC9B,MAAM,4BAA4B,CAAC;AAEpC,OAAO,KAAK,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAGnF,YAAY,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACnF,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAO3C,KAAK,oBAAoB,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,IACxD,CAAC,GACD,wBAAwB,CAAC,CAAC,CAAC,CAAC;AAEhC,KAAK,qBAAqB,GAAG,IAAI,CAC/B,iBAAiB,EACjB,WAAW,GAAG,WAAW,GAAG,SAAS,CACtC,GACC,SAAS,GAAG;IACV,SAAS,CAAC,EAAE,oBAAoB,CAAC,CAAC,GAAG,EAAE,GAAG,KAAK,IAAI,CAAC,CAAC;IACrD,SAAS,CAAC,EAAE,oBAAoB,CAAC,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC,CAAC;IAC5D,SAAS,CAAC,EAAE,oBAAoB,CAAC,MAAM,IAAI,CAAC,CAAC;IAC7C,OAAO,CAAC,EAAE,oBAAoB,CAAC,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC,CAAC;CAC3D,CAAC;AAcJ,wBAAgB,gBAAgB,CAAC,EAC/B,YAAY,EACZ,SAAS,EACT,SAAS,EACT,SAAS,EACT,OAAO,EACP,GAAG,KAAK,EACT,EAAE,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqDvB"}
|
|
@@ -81,6 +81,15 @@ namespace margelo::nitro::chartwebview {
|
|
|
81
81
|
static const auto method = javaClassStatic()->getMethod<void(jni::alias_ref<jni::JString> /* paramsJson */)>("setParamsJson");
|
|
82
82
|
method(_javaPart, paramsJson.has_value() ? jni::make_jstring(paramsJson.value()) : nullptr);
|
|
83
83
|
}
|
|
84
|
+
std::optional<std::string> JHybridChartWebviewSpec::getAssetHost() {
|
|
85
|
+
static const auto method = javaClassStatic()->getMethod<jni::local_ref<jni::JString>()>("getAssetHost");
|
|
86
|
+
auto __result = method(_javaPart);
|
|
87
|
+
return __result != nullptr ? std::make_optional(__result->toStdString()) : std::nullopt;
|
|
88
|
+
}
|
|
89
|
+
void JHybridChartWebviewSpec::setAssetHost(const std::optional<std::string>& assetHost) {
|
|
90
|
+
static const auto method = javaClassStatic()->getMethod<void(jni::alias_ref<jni::JString> /* assetHost */)>("setAssetHost");
|
|
91
|
+
method(_javaPart, assetHost.has_value() ? jni::make_jstring(assetHost.value()) : nullptr);
|
|
92
|
+
}
|
|
84
93
|
std::optional<std::string> JHybridChartWebviewSpec::getBridgeScript() {
|
|
85
94
|
static const auto method = javaClassStatic()->getMethod<jni::local_ref<jni::JString>()>("getBridgeScript");
|
|
86
95
|
auto __result = method(_javaPart);
|
|
@@ -58,6 +58,8 @@ namespace margelo::nitro::chartwebview {
|
|
|
58
58
|
void setEntry(const std::optional<std::string>& entry) override;
|
|
59
59
|
std::optional<std::string> getParamsJson() override;
|
|
60
60
|
void setParamsJson(const std::optional<std::string>& paramsJson) override;
|
|
61
|
+
std::optional<std::string> getAssetHost() override;
|
|
62
|
+
void setAssetHost(const std::optional<std::string>& assetHost) override;
|
|
61
63
|
std::optional<std::string> getBridgeScript() override;
|
|
62
64
|
void setBridgeScript(const std::optional<std::string>& bridgeScript) override;
|
|
63
65
|
std::optional<std::string> getReuseKey() override;
|
|
@@ -52,6 +52,10 @@ void JHybridChartWebviewStateUpdater::updateViewProps(jni::alias_ref<jni::JClass
|
|
|
52
52
|
view->setParamsJson(props.paramsJson.value);
|
|
53
53
|
// TODO: Set isDirty = false
|
|
54
54
|
}
|
|
55
|
+
if (props.assetHost.isDirty) {
|
|
56
|
+
view->setAssetHost(props.assetHost.value);
|
|
57
|
+
// TODO: Set isDirty = false
|
|
58
|
+
}
|
|
55
59
|
if (props.bridgeScript.isDirty) {
|
|
56
60
|
view->setBridgeScript(props.bridgeScript.value);
|
|
57
61
|
// TODO: Set isDirty = false
|
package/nitrogen/generated/android/kotlin/com/margelo/nitro/chartwebview/HybridChartWebviewSpec.kt
CHANGED
|
@@ -66,6 +66,12 @@ abstract class HybridChartWebviewSpec: HybridView() {
|
|
|
66
66
|
@set:Keep
|
|
67
67
|
abstract var paramsJson: String?
|
|
68
68
|
|
|
69
|
+
@get:DoNotStrip
|
|
70
|
+
@get:Keep
|
|
71
|
+
@set:DoNotStrip
|
|
72
|
+
@set:Keep
|
|
73
|
+
abstract var assetHost: String?
|
|
74
|
+
|
|
69
75
|
@get:DoNotStrip
|
|
70
76
|
@get:Keep
|
|
71
77
|
@set:DoNotStrip
|
|
@@ -86,6 +86,13 @@ namespace margelo::nitro::chartwebview {
|
|
|
86
86
|
inline void setParamsJson(const std::optional<std::string>& paramsJson) noexcept override {
|
|
87
87
|
_swiftPart.setParamsJson(paramsJson);
|
|
88
88
|
}
|
|
89
|
+
inline std::optional<std::string> getAssetHost() noexcept override {
|
|
90
|
+
auto __result = _swiftPart.getAssetHost();
|
|
91
|
+
return __result;
|
|
92
|
+
}
|
|
93
|
+
inline void setAssetHost(const std::optional<std::string>& assetHost) noexcept override {
|
|
94
|
+
_swiftPart.setAssetHost(assetHost);
|
|
95
|
+
}
|
|
89
96
|
inline std::optional<std::string> getBridgeScript() noexcept override {
|
|
90
97
|
auto __result = _swiftPart.getBridgeScript();
|
|
91
98
|
return __result;
|
|
@@ -91,6 +91,11 @@ using namespace margelo::nitro::chartwebview::views;
|
|
|
91
91
|
swiftPart.setParamsJson(newViewProps.paramsJson.value);
|
|
92
92
|
newViewProps.paramsJson.isDirty = false;
|
|
93
93
|
}
|
|
94
|
+
// assetHost: optional
|
|
95
|
+
if (newViewProps.assetHost.isDirty) {
|
|
96
|
+
swiftPart.setAssetHost(newViewProps.assetHost.value);
|
|
97
|
+
newViewProps.assetHost.isDirty = false;
|
|
98
|
+
}
|
|
94
99
|
// bridgeScript: optional
|
|
95
100
|
if (newViewProps.bridgeScript.isDirty) {
|
|
96
101
|
swiftPart.setBridgeScript(newViewProps.bridgeScript.value);
|
|
@@ -15,6 +15,7 @@ public protocol HybridChartWebviewSpec_protocol: HybridObject, HybridView {
|
|
|
15
15
|
var localBundle: String? { get set }
|
|
16
16
|
var entry: String? { get set }
|
|
17
17
|
var paramsJson: String? { get set }
|
|
18
|
+
var assetHost: String? { get set }
|
|
18
19
|
var bridgeScript: String? { get set }
|
|
19
20
|
var reuseKey: String? { get set }
|
|
20
21
|
var pooled: Bool? { get set }
|
|
@@ -210,6 +210,30 @@ open class HybridChartWebviewSpec_cxx {
|
|
|
210
210
|
}
|
|
211
211
|
}
|
|
212
212
|
|
|
213
|
+
public final var assetHost: bridge.std__optional_std__string_ {
|
|
214
|
+
@inline(__always)
|
|
215
|
+
get {
|
|
216
|
+
return { () -> bridge.std__optional_std__string_ in
|
|
217
|
+
if let __unwrappedValue = self.__implementation.assetHost {
|
|
218
|
+
return bridge.create_std__optional_std__string_(std.string(__unwrappedValue))
|
|
219
|
+
} else {
|
|
220
|
+
return .init()
|
|
221
|
+
}
|
|
222
|
+
}()
|
|
223
|
+
}
|
|
224
|
+
@inline(__always)
|
|
225
|
+
set {
|
|
226
|
+
self.__implementation.assetHost = { () -> String? in
|
|
227
|
+
if bridge.has_value_std__optional_std__string_(newValue) {
|
|
228
|
+
let __unwrapped = bridge.get_std__optional_std__string_(newValue)
|
|
229
|
+
return String(__unwrapped)
|
|
230
|
+
} else {
|
|
231
|
+
return nil
|
|
232
|
+
}
|
|
233
|
+
}()
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
213
237
|
public final var bridgeScript: bridge.std__optional_std__string_ {
|
|
214
238
|
@inline(__always)
|
|
215
239
|
get {
|
|
@@ -22,6 +22,8 @@ namespace margelo::nitro::chartwebview {
|
|
|
22
22
|
prototype.registerHybridSetter("entry", &HybridChartWebviewSpec::setEntry);
|
|
23
23
|
prototype.registerHybridGetter("paramsJson", &HybridChartWebviewSpec::getParamsJson);
|
|
24
24
|
prototype.registerHybridSetter("paramsJson", &HybridChartWebviewSpec::setParamsJson);
|
|
25
|
+
prototype.registerHybridGetter("assetHost", &HybridChartWebviewSpec::getAssetHost);
|
|
26
|
+
prototype.registerHybridSetter("assetHost", &HybridChartWebviewSpec::setAssetHost);
|
|
25
27
|
prototype.registerHybridGetter("bridgeScript", &HybridChartWebviewSpec::getBridgeScript);
|
|
26
28
|
prototype.registerHybridSetter("bridgeScript", &HybridChartWebviewSpec::setBridgeScript);
|
|
27
29
|
prototype.registerHybridGetter("reuseKey", &HybridChartWebviewSpec::getReuseKey);
|
|
@@ -54,6 +54,8 @@ namespace margelo::nitro::chartwebview {
|
|
|
54
54
|
virtual void setEntry(const std::optional<std::string>& entry) = 0;
|
|
55
55
|
virtual std::optional<std::string> getParamsJson() = 0;
|
|
56
56
|
virtual void setParamsJson(const std::optional<std::string>& paramsJson) = 0;
|
|
57
|
+
virtual std::optional<std::string> getAssetHost() = 0;
|
|
58
|
+
virtual void setAssetHost(const std::optional<std::string>& assetHost) = 0;
|
|
57
59
|
virtual std::optional<std::string> getBridgeScript() = 0;
|
|
58
60
|
virtual void setBridgeScript(const std::optional<std::string>& bridgeScript) = 0;
|
|
59
61
|
virtual std::optional<std::string> getReuseKey() = 0;
|
|
@@ -65,6 +65,16 @@ namespace margelo::nitro::chartwebview::views {
|
|
|
65
65
|
throw std::runtime_error(std::string("ChartWebview.paramsJson: ") + exc.what());
|
|
66
66
|
}
|
|
67
67
|
}()),
|
|
68
|
+
assetHost([&]() -> CachedProp<std::optional<std::string>> {
|
|
69
|
+
try {
|
|
70
|
+
const react::RawValue* rawValue = rawProps.at("assetHost", nullptr, nullptr);
|
|
71
|
+
if (rawValue == nullptr) return sourceProps.assetHost;
|
|
72
|
+
const auto& [runtime, value] = (std::pair<jsi::Runtime*, jsi::Value>)*rawValue;
|
|
73
|
+
return CachedProp<std::optional<std::string>>::fromRawValue(*runtime, value, sourceProps.assetHost);
|
|
74
|
+
} catch (const std::exception& exc) {
|
|
75
|
+
throw std::runtime_error(std::string("ChartWebview.assetHost: ") + exc.what());
|
|
76
|
+
}
|
|
77
|
+
}()),
|
|
68
78
|
bridgeScript([&]() -> CachedProp<std::optional<std::string>> {
|
|
69
79
|
try {
|
|
70
80
|
const react::RawValue* rawValue = rawProps.at("bridgeScript", nullptr, nullptr);
|
|
@@ -162,6 +172,7 @@ namespace margelo::nitro::chartwebview::views {
|
|
|
162
172
|
localBundle(other.localBundle),
|
|
163
173
|
entry(other.entry),
|
|
164
174
|
paramsJson(other.paramsJson),
|
|
175
|
+
assetHost(other.assetHost),
|
|
165
176
|
bridgeScript(other.bridgeScript),
|
|
166
177
|
reuseKey(other.reuseKey),
|
|
167
178
|
pooled(other.pooled),
|
|
@@ -178,6 +189,7 @@ namespace margelo::nitro::chartwebview::views {
|
|
|
178
189
|
case hashString("localBundle"): return true;
|
|
179
190
|
case hashString("entry"): return true;
|
|
180
191
|
case hashString("paramsJson"): return true;
|
|
192
|
+
case hashString("assetHost"): return true;
|
|
181
193
|
case hashString("bridgeScript"): return true;
|
|
182
194
|
case hashString("reuseKey"): return true;
|
|
183
195
|
case hashString("pooled"): return true;
|
|
@@ -47,6 +47,7 @@ namespace margelo::nitro::chartwebview::views {
|
|
|
47
47
|
CachedProp<std::optional<std::string>> localBundle;
|
|
48
48
|
CachedProp<std::optional<std::string>> entry;
|
|
49
49
|
CachedProp<std::optional<std::string>> paramsJson;
|
|
50
|
+
CachedProp<std::optional<std::string>> assetHost;
|
|
50
51
|
CachedProp<std::optional<std::string>> bridgeScript;
|
|
51
52
|
CachedProp<std::optional<std::string>> reuseKey;
|
|
52
53
|
CachedProp<std::optional<bool>> pooled;
|
package/package.json
CHANGED
|
@@ -20,6 +20,14 @@ export interface ChartWebviewProps extends HybridViewProps {
|
|
|
20
20
|
// '{"symbol":"BTC","type":"market","theme":"dark"}'). Kept as a string so the
|
|
21
21
|
// native side stays free of a structured-prop dependency.
|
|
22
22
|
paramsJson?: string;
|
|
23
|
+
// ANDROID ONLY: the host the offline `localBundle` is served under, so Android
|
|
24
|
+
// can reuse the real TradingView origin (e.g. "tradingview.onekey.so") and read
|
|
25
|
+
// the existing same-origin WebView storage with zero migration. When omitted,
|
|
26
|
+
// Android falls back to the built-in "appassets.androidplatform.net" host
|
|
27
|
+
// (identical to the old behavior). IGNORED on iOS, which always serves offline
|
|
28
|
+
// content from the onekey-chart:// custom scheme (https can't be intercepted
|
|
29
|
+
// there).
|
|
30
|
+
assetHost?: string;
|
|
23
31
|
|
|
24
32
|
// JS injected into the page at document-start (before any page JS), wiring the
|
|
25
33
|
// page's outbound channels to the native transport. Single source of truth in
|