@onekeyfe/react-native-image 6.7.0-alpha.475 → 6.8.0-11
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 +144 -86
- package/android/build.gradle +1 -0
- package/android/consumer-rules.pro +9 -0
- package/android/src/main/AndroidManifest.xml +12 -1
- package/android/src/main/java/com/margelo/nitro/onekeyimage/OneKeyIcon.kt +5 -1
- package/android/src/main/java/com/margelo/nitro/onekeyimage/OneKeyImage.kt +240 -6
- package/android/src/main/java/com/margelo/nitro/onekeyimage/OneKeyImageCache.kt +4 -0
- package/android/src/main/java/com/margelo/nitro/onekeyimage/OneKeyImageGlideModule.kt +17 -0
- package/android/src/main/java/com/margelo/nitro/onekeyimage/OneKeyImageGlideRegistry.kt +1 -0
- package/android/src/main/java/com/margelo/nitro/onekeyimage/OneKeyImageSafety.kt +41 -0
- package/android/src/main/java/com/margelo/nitro/onekeyimage/OneKeyImageStartupPrewarm.kt +1106 -0
- package/android/src/main/java/com/margelo/nitro/onekeyimage/OneKeyImageStartupProvider.kt +54 -0
- package/android/src/main/java/com/margelo/nitro/onekeyimage/OneKeyMainThreadDecode.kt +541 -0
- package/android/src/main/java/com/margelo/nitro/onekeyimage/OneKeyMediaPreviewCache.kt +1 -1
- package/android/src/main/java/com/margelo/nitro/onekeyimage/OneKeyNamedSVG.kt +758 -61
- package/android/src/test/java/com/margelo/nitro/onekeyimage/OneKeyStartupPrewarmTest.kt +600 -0
- package/ios/OneKeyAvatarImageLoader.swift +1 -1
- package/ios/OneKeyIcon.swift +6 -0
- package/ios/OneKeyImage.swift +85 -2
- package/ios/OneKeyImageCache.swift +2 -0
- package/ios/OneKeyImageCoderBridge.m +42 -1
- package/ios/OneKeyImageRequestContext.swift +16 -2
- package/ios/OneKeyImageStartupPrewarm.swift +602 -0
- package/ios/OneKeyMainThreadDecode.swift +338 -0
- package/ios/OneKeyMediaPreviewCache.swift +20 -12
- package/ios/OneKeyNamedSVG.swift +437 -9
- package/ios/tests/OneKeyIconTests.swift +238 -0
- package/ios/tests/OneKeyImageInfrastructureTests.swift +611 -0
- package/ios/tests/OneKeyMediaPreviewCacheTests.swift +49 -0
- package/lib/module/index.js +5 -1
- package/package.json +1 -1
- package/src/index.tsx +23 -2
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import UIKit
|
|
2
|
+
import SDWebImage
|
|
2
3
|
import XCTest
|
|
3
4
|
|
|
4
5
|
@testable import OneKeyImage
|
|
@@ -63,6 +64,40 @@ final class OneKeyIconTests: XCTestCase {
|
|
|
63
64
|
return bytes
|
|
64
65
|
}
|
|
65
66
|
|
|
67
|
+
func testDiskRasterSurvivesDecodedMemoryEviction() throws {
|
|
68
|
+
let name = "DotVerSolid"
|
|
69
|
+
let color = "rgba(0,0,0,1)"
|
|
70
|
+
let scale: CGFloat = 1.375
|
|
71
|
+
let ownerBundle = Bundle(for: HybridOneKeyIcon.self)
|
|
72
|
+
let bundleURL = try XCTUnwrap(ownerBundle.url(forResource: "OneKeyIcons", withExtension: "bundle")
|
|
73
|
+
?? Bundle.main.url(forResource: "OneKeyIcons", withExtension: "bundle"))
|
|
74
|
+
let bundle = try XCTUnwrap(Bundle(url: bundleURL))
|
|
75
|
+
let manifestURL = try XCTUnwrap(bundle.url(forResource: "manifest", withExtension: "json"))
|
|
76
|
+
let manifest = try XCTUnwrap(JSONSerialization.jsonObject(with: Data(contentsOf: manifestURL)) as? [String: [String: Any]])
|
|
77
|
+
let entry = try XCTUnwrap(manifest[name])
|
|
78
|
+
let digest = try XCTUnwrap(entry["digest"] as? String)
|
|
79
|
+
let mode = entry["recolorMode"] as? String ?? "raster"
|
|
80
|
+
let colorKey = mode == "raster" ? color : mode == "multiple" ? "1.0" : ""
|
|
81
|
+
let key = "\(name)|\(digest)|37|29|\(scale)|\(mode)|\(colorKey)"
|
|
82
|
+
let disk = OneKeyNamedSVG.shared.rasterDiskCacheForTesting
|
|
83
|
+
let original = try XCTUnwrap(resolve(name, color: color, width: 37, height: 29, scale: scale))
|
|
84
|
+
OneKeyNamedSVG.shared.flushStartupForTesting(forceClose: false)
|
|
85
|
+
eventually("Worker output is persisted as a PNG") { disk.diskImageData(forKey: key) != nil }
|
|
86
|
+
let persisted = try XCTUnwrap(disk.imageFromDiskCache(forKey: key))
|
|
87
|
+
XCTAssertEqual(persisted.cgImage?.width, 37)
|
|
88
|
+
XCTAssertEqual(persisted.cgImage?.height, 29)
|
|
89
|
+
XCTAssertEqual(try pixels(persisted), try pixels(original))
|
|
90
|
+
|
|
91
|
+
// Exhaust the real decoded LRU; the next request must leave its memory fast path.
|
|
92
|
+
for width in 122...250 {
|
|
93
|
+
XCTAssertNotNil(resolve(name, color: color, width: width, height: 25, scale: scale))
|
|
94
|
+
}
|
|
95
|
+
XCTAssertNil(OneKeyNamedSVG.shared.cachedRender(name: name, color: color,
|
|
96
|
+
width: 37, height: 29, scale: scale))
|
|
97
|
+
let restored = try XCTUnwrap(resolve(name, color: color, width: 37, height: 29, scale: scale))
|
|
98
|
+
XCTAssertEqual(try pixels(restored), try pixels(original))
|
|
99
|
+
}
|
|
100
|
+
|
|
66
101
|
func testNamedColorEndpointsRetainCSSAlpha() throws {
|
|
67
102
|
for (alpha, expected) in [("1", 255), ("0.5", 128), ("0", 0)] {
|
|
68
103
|
let image = try XCTUnwrap(resolve("DotVerSolid", color: "rgba(255,0,0,\(alpha))", width: 192, height: 192))
|
|
@@ -481,4 +516,207 @@ final class OneKeyIconTests: XCTestCase {
|
|
|
481
516
|
try save(screenshot, name: "ios-production-gallery")
|
|
482
517
|
gallery.forEach { $0.onDropView() }
|
|
483
518
|
}
|
|
519
|
+
|
|
520
|
+
func testStartupPrewarmDiskRenderAndSynchronousBridgeRequest() throws {
|
|
521
|
+
let tempFile = FileManager.default.temporaryDirectory
|
|
522
|
+
.appendingPathComponent("onekey-icon-startup-test-\(UUID().uuidString).json")
|
|
523
|
+
defer {
|
|
524
|
+
OneKeyNamedSVG.shared.resetStartupForTesting(fileURL: nil)
|
|
525
|
+
try? FileManager.default.removeItem(at: tempFile)
|
|
526
|
+
}
|
|
527
|
+
OneKeyNamedSVG.shared.resetStartupForTesting(fileURL: tempFile)
|
|
528
|
+
let rasterPath = try XCTUnwrap(
|
|
529
|
+
OneKeyNamedSVG.shared.rasterDiskCachePathForTesting(
|
|
530
|
+
name: "DotVerSolid",
|
|
531
|
+
color: "rgba(0,0,0,1)",
|
|
532
|
+
width: 48,
|
|
533
|
+
height: 48,
|
|
534
|
+
scale: 2
|
|
535
|
+
)
|
|
536
|
+
)
|
|
537
|
+
let rasterURL = URL(fileURLWithPath: rasterPath)
|
|
538
|
+
let fileManager = FileManager.default
|
|
539
|
+
if fileManager.fileExists(atPath: rasterPath) {
|
|
540
|
+
try fileManager.removeItem(at: rasterURL)
|
|
541
|
+
}
|
|
542
|
+
defer { try? fileManager.removeItem(at: rasterURL) }
|
|
543
|
+
|
|
544
|
+
// Poll for the worker's atomic write independently of the frame decode budget.
|
|
545
|
+
OneKeyNamedSVG.shared.clearMemoryCacheForTesting()
|
|
546
|
+
OneKeyMainThreadDecode.resetForTesting()
|
|
547
|
+
_ = try XCTUnwrap(resolve("DotVerSolid", color: "rgba(0,0,0,1)", width: 48, height: 48, scale: 2))
|
|
548
|
+
eventually("Disk raster written for DotVerSolid 48x48") {
|
|
549
|
+
fileManager.fileExists(atPath: rasterPath)
|
|
550
|
+
}
|
|
551
|
+
let originalRasterData = try Data(contentsOf: rasterURL)
|
|
552
|
+
|
|
553
|
+
// 1. Synchronous callback from a disk hit on the BottomTabs bridge path.
|
|
554
|
+
OneKeyNamedSVG.shared.clearMemoryCacheForTesting()
|
|
555
|
+
OneKeyMainThreadDecode.resetForTesting()
|
|
556
|
+
var syncCallbackFired = false
|
|
557
|
+
let owner = NSObject()
|
|
558
|
+
OneKeyNamedSVGBridge.request(
|
|
559
|
+
owner: owner,
|
|
560
|
+
name: "DotVerSolid",
|
|
561
|
+
color: "rgba(0,0,0,1)",
|
|
562
|
+
width: 48,
|
|
563
|
+
height: 48,
|
|
564
|
+
scale: 2
|
|
565
|
+
) { image in
|
|
566
|
+
XCTAssertNotNil(image)
|
|
567
|
+
syncCallbackFired = true
|
|
568
|
+
}
|
|
569
|
+
XCTAssertTrue(syncCallbackFired, "Bridge request must invoke completion synchronously on main thread when cached")
|
|
570
|
+
|
|
571
|
+
// 2. diskRender size bound (>192px and >32KiB rejected) and metrics recording.
|
|
572
|
+
OneKeyNamedSVG.shared.clearMemoryCacheForTesting()
|
|
573
|
+
OneKeyMainThreadDecode.resetForTesting()
|
|
574
|
+
XCTAssertNil(
|
|
575
|
+
OneKeyNamedSVG.shared.diskRender(
|
|
576
|
+
name: "DotVerSolid",
|
|
577
|
+
color: "rgba(0,0,0,1)",
|
|
578
|
+
width: 200,
|
|
579
|
+
height: 200,
|
|
580
|
+
scale: 2
|
|
581
|
+
)
|
|
582
|
+
)
|
|
583
|
+
try Data(repeating: 0, count: OneKeyMainThreadDecode.maximumEncodedBytes + 1024)
|
|
584
|
+
.write(to: rasterURL, options: .atomic)
|
|
585
|
+
XCTAssertNil(
|
|
586
|
+
OneKeyNamedSVG.shared.diskRender(
|
|
587
|
+
name: "DotVerSolid",
|
|
588
|
+
color: "rgba(0,0,0,1)",
|
|
589
|
+
width: 48,
|
|
590
|
+
height: 48,
|
|
591
|
+
scale: 2
|
|
592
|
+
)
|
|
593
|
+
)
|
|
594
|
+
XCTAssertEqual(OneKeyMainThreadDecode.metricsSnapshot().limitRejections, 1)
|
|
595
|
+
try originalRasterData.write(to: rasterURL, options: .atomic)
|
|
596
|
+
OneKeyMainThreadDecode.resetForTesting()
|
|
597
|
+
XCTAssertNotNil(
|
|
598
|
+
OneKeyNamedSVG.shared.diskRender(
|
|
599
|
+
name: "DotVerSolid",
|
|
600
|
+
color: "rgba(0,0,0,1)",
|
|
601
|
+
width: 48,
|
|
602
|
+
height: 48,
|
|
603
|
+
scale: 2
|
|
604
|
+
)
|
|
605
|
+
)
|
|
606
|
+
XCTAssertEqual(OneKeyMainThreadDecode.metricsSnapshot().hits, 1)
|
|
607
|
+
|
|
608
|
+
// 2b. Synchronous diskRender must not wait on SDImageCache.ioQueue when a concurrent
|
|
609
|
+
// write or cache cleanup is occupying ioQueue, and must handle removed files cleanly.
|
|
610
|
+
if let ioQueue = OneKeyNamedSVG.shared.rasterDiskCacheForTesting.value(forKey: "ioQueue")
|
|
611
|
+
as? DispatchQueue
|
|
612
|
+
{
|
|
613
|
+
OneKeyNamedSVG.shared.clearMemoryCacheForTesting()
|
|
614
|
+
OneKeyMainThreadDecode.resetForTesting()
|
|
615
|
+
let ioEntered = DispatchSemaphore(value: 0)
|
|
616
|
+
let ioRelease = DispatchSemaphore(value: 0)
|
|
617
|
+
let ioFinished = DispatchSemaphore(value: 0)
|
|
618
|
+
ioQueue.async {
|
|
619
|
+
ioEntered.signal()
|
|
620
|
+
_ = ioRelease.wait(timeout: .now() + 2)
|
|
621
|
+
ioFinished.signal()
|
|
622
|
+
}
|
|
623
|
+
XCTAssertEqual(ioEntered.wait(timeout: .now() + 1), .success)
|
|
624
|
+
let writerDone = DispatchSemaphore(value: 0)
|
|
625
|
+
DispatchQueue.global(qos: .utility).async {
|
|
626
|
+
OneKeyNamedSVG.shared.rasterDiskCacheForTesting.storeImageData(
|
|
627
|
+
toDisk: originalRasterData,
|
|
628
|
+
forKey: "concurrent-writer-probe"
|
|
629
|
+
)
|
|
630
|
+
writerDone.signal()
|
|
631
|
+
}
|
|
632
|
+
var finishedWhileIoBlocked = false
|
|
633
|
+
let hitWhileBusy = OneKeyNamedSVG.shared.diskRender(
|
|
634
|
+
name: "DotVerSolid",
|
|
635
|
+
color: "rgba(0,0,0,1)",
|
|
636
|
+
width: 48,
|
|
637
|
+
height: 48,
|
|
638
|
+
scale: 2
|
|
639
|
+
)
|
|
640
|
+
finishedWhileIoBlocked = (ioFinished.wait(timeout: .now()) == .timedOut)
|
|
641
|
+
ioRelease.signal()
|
|
642
|
+
_ = ioFinished.wait(timeout: .now() + 2)
|
|
643
|
+
_ = writerDone.wait(timeout: .now() + 2)
|
|
644
|
+
OneKeyNamedSVG.shared.rasterDiskCacheForTesting.removeImageFromDisk(
|
|
645
|
+
forKey: "concurrent-writer-probe"
|
|
646
|
+
)
|
|
647
|
+
XCTAssertNotNil(hitWhileBusy)
|
|
648
|
+
XCTAssertTrue(
|
|
649
|
+
finishedWhileIoBlocked,
|
|
650
|
+
"diskRender must read directly without waiting for SDImageCache.ioQueue"
|
|
651
|
+
)
|
|
652
|
+
}
|
|
653
|
+
try? FileManager.default.removeItem(at: rasterURL)
|
|
654
|
+
OneKeyNamedSVG.shared.clearMemoryCacheForTesting()
|
|
655
|
+
OneKeyMainThreadDecode.resetForTesting()
|
|
656
|
+
XCTAssertNil(
|
|
657
|
+
OneKeyNamedSVG.shared.diskRender(
|
|
658
|
+
name: "DotVerSolid",
|
|
659
|
+
color: "rgba(0,0,0,1)",
|
|
660
|
+
width: 48,
|
|
661
|
+
height: 48,
|
|
662
|
+
scale: 2
|
|
663
|
+
)
|
|
664
|
+
)
|
|
665
|
+
XCTAssertEqual(OneKeyMainThreadDecode.metricsSnapshot().diskMisses, 1)
|
|
666
|
+
try originalRasterData.write(to: rasterURL, options: .atomic)
|
|
667
|
+
|
|
668
|
+
// 3. App Lock multi-burst window + launch-generation eviction.
|
|
669
|
+
OneKeyNamedSVG.shared.resetStartupForTesting(fileURL: tempFile)
|
|
670
|
+
_ = OneKeyNamedSVG.shared.cachedRender(
|
|
671
|
+
name: "DotVerSolid",
|
|
672
|
+
color: "rgba(0,0,0,1)",
|
|
673
|
+
width: 48,
|
|
674
|
+
height: 48,
|
|
675
|
+
scale: 2
|
|
676
|
+
)
|
|
677
|
+
// Simulate first 3s quiet flush while still on App Lock (< 8 icons): recording stays open.
|
|
678
|
+
OneKeyNamedSVG.shared.flushStartupForTesting(forceClose: false)
|
|
679
|
+
_ = OneKeyNamedSVG.shared.cachedRender(
|
|
680
|
+
name: "BotIllus",
|
|
681
|
+
color: "rgba(0,0,0,1)",
|
|
682
|
+
width: 48,
|
|
683
|
+
height: 48,
|
|
684
|
+
scale: 2
|
|
685
|
+
)
|
|
686
|
+
OneKeyNamedSVG.shared.flushStartupForTesting(forceClose: true)
|
|
687
|
+
|
|
688
|
+
let firstLaunchEntries = try JSONDecoder().decode(
|
|
689
|
+
[OneKeyNamedSVG.StartupEntry].self,
|
|
690
|
+
from: Data(contentsOf: tempFile)
|
|
691
|
+
)
|
|
692
|
+
XCTAssertEqual(firstLaunchEntries.map(\.name), ["DotVerSolid", "BotIllus"])
|
|
693
|
+
XCTAssertEqual(firstLaunchEntries.map(\.launch), [1, 1])
|
|
694
|
+
|
|
695
|
+
// Simulate prewarm on launch 2, then only "BotIllus" is seen for 3 launches.
|
|
696
|
+
for expectedLaunch in 2...4 {
|
|
697
|
+
OneKeyNamedSVG.shared.clearMemoryCacheForTesting()
|
|
698
|
+
OneKeyNamedSVG.shared.resetStartupForTesting(fileURL: tempFile)
|
|
699
|
+
OneKeyNamedSVG.shared.prewarmStartupSet()
|
|
700
|
+
XCTAssertGreaterThanOrEqual(OneKeyNamedSVG.shared.startupMetricsSnapshot().entryCount, 1)
|
|
701
|
+
_ = OneKeyNamedSVG.shared.cachedRender(
|
|
702
|
+
name: "BotIllus",
|
|
703
|
+
color: "rgba(0,0,0,1)",
|
|
704
|
+
width: 48,
|
|
705
|
+
height: 48,
|
|
706
|
+
scale: 2
|
|
707
|
+
)
|
|
708
|
+
OneKeyNamedSVG.shared.flushStartupForTesting(forceClose: true)
|
|
709
|
+
let currentEntries = try JSONDecoder().decode(
|
|
710
|
+
[OneKeyNamedSVG.StartupEntry].self,
|
|
711
|
+
from: Data(contentsOf: tempFile)
|
|
712
|
+
)
|
|
713
|
+
if expectedLaunch < 4 {
|
|
714
|
+
XCTAssertEqual(currentEntries.map(\.name), ["BotIllus", "DotVerSolid"])
|
|
715
|
+
} else {
|
|
716
|
+
// Launch 4: DotVerSolid (launch 1) has age 4 - 1 == 3 >= startupMaxLaunchAge(3) and is evicted.
|
|
717
|
+
XCTAssertEqual(currentEntries.map(\.name), ["BotIllus"])
|
|
718
|
+
XCTAssertEqual(currentEntries.first?.launch, 4)
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
}
|
|
484
722
|
}
|