@onekeyfe/react-native-native-list 6.7.0-6 → 6.7.0-61

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.
Files changed (216) hide show
  1. package/README.md +312 -375
  2. package/android/src/main/java/com/onekey/nativelist/HybridNativeList.kt +14 -1
  3. package/android/src/main/java/com/onekey/nativelist/NativeListAccessoryStack.kt +250 -9
  4. package/android/src/main/java/com/onekey/nativelist/NativeListActivityDetailsView.kt +50 -13
  5. package/android/src/main/java/com/onekey/nativelist/NativeListActivityRenderer.kt +25 -3
  6. package/android/src/main/java/com/onekey/nativelist/NativeListAdapter.kt +17 -1
  7. package/android/src/main/java/com/onekey/nativelist/NativeListButtonGroupRenderer.kt +102 -0
  8. package/android/src/main/java/com/onekey/nativelist/NativeListContainerSlotAdapter.kt +12 -0
  9. package/android/src/main/java/com/onekey/nativelist/NativeListDataRowRenderer.kt +102 -7
  10. package/android/src/main/java/com/onekey/nativelist/NativeListGeneratedIcons.kt +47 -0
  11. package/android/src/main/java/com/onekey/nativelist/NativeListIdentityRenderer.kt +225 -11
  12. package/android/src/main/java/com/onekey/nativelist/NativeListLeadingVisual.kt +152 -33
  13. package/android/src/main/java/com/onekey/nativelist/NativeListMarketRenderer.kt +92 -28
  14. package/android/src/main/java/com/onekey/nativelist/NativeListMediaPlaceholderView.kt +244 -0
  15. package/android/src/main/java/com/onekey/nativelist/NativeListMediaPreviewSlot.kt +66 -31
  16. package/android/src/main/java/com/onekey/nativelist/NativeListMediaTileRenderer.kt +32 -11
  17. package/android/src/main/java/com/onekey/nativelist/NativeListMessageRenderer.kt +25 -0
  18. package/android/src/main/java/com/onekey/nativelist/NativeListModels.kt +209 -3
  19. package/android/src/main/java/com/onekey/nativelist/NativeListPrimitives.kt +120 -287
  20. package/android/src/main/java/com/onekey/nativelist/NativeListRendererRegistry.kt +2 -0
  21. package/android/src/main/java/com/onekey/nativelist/NativeListRendererRowView.kt +7 -0
  22. package/android/src/main/java/com/onekey/nativelist/NativeListResolvedText.kt +8 -3
  23. package/android/src/main/java/com/onekey/nativelist/NativeListSectionHeaderRenderer.kt +69 -0
  24. package/android/src/main/java/com/onekey/nativelist/NativeListTextView.kt +130 -1
  25. package/android/src/main/java/com/onekey/nativelist/NativeListView.kt +1978 -136
  26. package/android/src/test/java/com/margelo/nitro/nativelist/NativeListActivityHostClipPolicyTest.kt +35 -0
  27. package/android/src/test/java/com/margelo/nitro/nativelist/NativeListDescriptionTouchPolicyTest.kt +153 -0
  28. package/android/src/test/java/com/margelo/nitro/nativelist/NativeListIdentityTrailingAxisTest.kt +36 -0
  29. package/android/src/test/java/com/margelo/nitro/nativelist/NativeListLeadingSlotFrameTest.kt +68 -0
  30. package/android/src/test/java/com/margelo/nitro/nativelist/NativeListLeadingVisualClipPolicyTest.kt +44 -0
  31. package/android/src/test/java/com/margelo/nitro/nativelist/NativeListPressPolicyTest.kt +10 -0
  32. package/docs/ROW_TEMPLATES.md +78 -14
  33. package/docs/SPEC.md +1318 -16
  34. package/docs/STYLE_SPEC.md +18 -0
  35. package/ios/HybridNativeList.swift +21 -2
  36. package/ios/NativeListAccessoryStack.swift +237 -51
  37. package/ios/NativeListActivityDetailsView.swift +43 -16
  38. package/ios/NativeListActivityRenderer.swift +8 -2
  39. package/ios/NativeListButtonGroupRenderer.swift +89 -0
  40. package/ios/NativeListDataRowRenderer.swift +167 -30
  41. package/ios/NativeListDesignAssets.swift +13 -75
  42. package/ios/NativeListGeneratedIcons.swift +55 -0
  43. package/ios/NativeListIconBinding.swift +171 -0
  44. package/ios/NativeListIdentityRenderer.swift +256 -39
  45. package/ios/NativeListLeadingVisual.swift +127 -28
  46. package/ios/NativeListMarketRenderer.swift +120 -31
  47. package/ios/NativeListMediaPlaceholderView.swift +189 -0
  48. package/ios/NativeListMediaPreviewSlot.swift +122 -61
  49. package/ios/NativeListMediaTileRenderer.swift +15 -11
  50. package/ios/NativeListMessageRenderer.swift +34 -1
  51. package/ios/NativeListMetricCardRenderer.swift +4 -2
  52. package/ios/NativeListModels.swift +42 -2
  53. package/ios/NativeListRendererRegistry.swift +1 -0
  54. package/ios/NativeListResolvedText.swift +17 -5
  55. package/ios/NativeListRowHost.swift +14 -0
  56. package/ios/NativeListSectionHeaderRenderer.swift +100 -4
  57. package/ios/NativeListTextLabel.swift +106 -0
  58. package/ios/RNCNativeListView.swift +1097 -60
  59. package/ios/tests/NativeListAccessoryStackTests.swift +101 -0
  60. package/ios/tests/NativeListAccountSelectorLayoutTests.swift +96 -0
  61. package/ios/tests/NativeListActivityPresentationTests.swift +423 -0
  62. package/ios/tests/NativeListIdentityTitleIconLayoutTests.swift +81 -0
  63. package/ios/tests/NativeListLeadingVisualPairBackdropTests.swift +50 -0
  64. package/ios/tests/NativeListLifecycleTests.swift +2959 -4
  65. package/ios/tests/NativeListMarketMetricsTests.swift +117 -0
  66. package/ios/tests/NativeListMediaVisibilityTests.swift +41 -7
  67. package/ios/tests/NativeListSharedIconTests.swift +236 -0
  68. package/lib/module/NativeList.js +236 -38
  69. package/lib/module/NativeList.web.js +163 -45
  70. package/lib/module/index.js +1 -1
  71. package/lib/module/models.js +3 -0
  72. package/lib/module/selection.js +1 -1
  73. package/lib/module/validation.js +1263 -48
  74. package/lib/module/web/NativeListGeneratedIcons.js +31 -0
  75. package/lib/module/web/NativeListWebEngine.js +513 -275
  76. package/lib/module/web/templates/ActivityRowRenderer.js +41 -54
  77. package/lib/module/web/templates/ButtonGroupRowRenderer.js +47 -0
  78. package/lib/module/web/templates/DataRowRenderer.js +56 -5
  79. package/lib/module/web/templates/IdentityRowRenderer.js +161 -7
  80. package/lib/module/web/templates/MarketTableRowRenderer.js +36 -19
  81. package/lib/module/web/templates/MediaTileRowRenderer.js +84 -25
  82. package/lib/module/web/templates/MessageRowRenderer.js +18 -2
  83. package/lib/module/web/templates/RowContainerStyle.js +1 -0
  84. package/lib/module/web/templates/RowRendererRegistry.js +3 -0
  85. package/lib/module/web/templates/SectionHeaderRowRenderer.js +36 -2
  86. package/lib/nitrogen/generated/android/c++/JHybridNativeListSpec.cpp +26 -0
  87. package/lib/nitrogen/generated/android/c++/JHybridNativeListSpec.hpp +4 -0
  88. package/lib/nitrogen/generated/android/c++/views/JHybridNativeListStateUpdater.cpp +10 -0
  89. package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/HybridNativeListSpec.kt +20 -0
  90. package/lib/nitrogen/generated/ios/c++/HybridNativeListSpecSwift.hpp +14 -0
  91. package/lib/nitrogen/generated/ios/c++/views/HybridNativeListComponent.mm +12 -0
  92. package/lib/nitrogen/generated/ios/swift/HybridNativeListSpec.swift +2 -0
  93. package/lib/nitrogen/generated/ios/swift/HybridNativeListSpec_cxx.swift +43 -0
  94. package/lib/nitrogen/generated/shared/c++/HybridNativeListSpec.cpp +4 -0
  95. package/lib/nitrogen/generated/shared/c++/HybridNativeListSpec.hpp +4 -0
  96. package/lib/nitrogen/generated/shared/c++/views/HybridNativeListComponent.cpp +4 -0
  97. package/lib/nitrogen/generated/shared/c++/views/HybridNativeListComponent.hpp +6 -0
  98. package/lib/nitrogen/generated/shared/json/NativeListConfig.json +2 -0
  99. package/lib/typescript/src/NativeList.d.ts +3 -3
  100. package/lib/typescript/src/NativeList.nitro.d.ts +2 -0
  101. package/lib/typescript/src/NativeList.types.d.ts +20 -2
  102. package/lib/typescript/src/index.d.ts +2 -2
  103. package/lib/typescript/src/models.d.ts +134 -17
  104. package/lib/typescript/src/validation.d.ts +20 -0
  105. package/lib/typescript/src/web/NativeListGeneratedIcons.d.ts +2 -0
  106. package/lib/typescript/src/web/NativeListWebEngine.d.ts +32 -1
  107. package/lib/typescript/src/web/templates/ButtonGroupRowRenderer.d.ts +14 -0
  108. package/lib/typescript/src/web/templates/IdentityRowRenderer.d.ts +1 -1
  109. package/lib/typescript/src/web/templates/MessageRowRenderer.d.ts +9 -3
  110. package/nitrogen/generated/android/c++/JHybridNativeListSpec.cpp +26 -0
  111. package/nitrogen/generated/android/c++/JHybridNativeListSpec.hpp +4 -0
  112. package/nitrogen/generated/android/c++/views/JHybridNativeListStateUpdater.cpp +10 -0
  113. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/HybridNativeListSpec.kt +20 -0
  114. package/nitrogen/generated/ios/c++/HybridNativeListSpecSwift.hpp +14 -0
  115. package/nitrogen/generated/ios/c++/views/HybridNativeListComponent.mm +12 -0
  116. package/nitrogen/generated/ios/swift/HybridNativeListSpec.swift +2 -0
  117. package/nitrogen/generated/ios/swift/HybridNativeListSpec_cxx.swift +43 -0
  118. package/nitrogen/generated/shared/c++/HybridNativeListSpec.cpp +4 -0
  119. package/nitrogen/generated/shared/c++/HybridNativeListSpec.hpp +4 -0
  120. package/nitrogen/generated/shared/c++/views/HybridNativeListComponent.cpp +4 -0
  121. package/nitrogen/generated/shared/c++/views/HybridNativeListComponent.hpp +6 -0
  122. package/nitrogen/generated/shared/json/NativeListConfig.json +2 -0
  123. package/package.json +16 -10
  124. package/react-native-native-list.podspec +2 -6
  125. package/scripts/generate-icons.mjs +150 -0
  126. package/scripts/generate-icons.test.mjs +288 -0
  127. package/scripts/native-list-icons.json +260 -0
  128. package/src/NativeList.nitro.ts +2 -0
  129. package/src/NativeList.tsx +439 -91
  130. package/src/NativeList.types.ts +24 -2
  131. package/src/NativeList.web.tsx +286 -88
  132. package/src/index.ts +2 -0
  133. package/src/models.ts +272 -144
  134. package/src/selection.ts +1 -0
  135. package/src/validation.ts +3041 -146
  136. package/src/web/NativeListGeneratedIcons.ts +28 -0
  137. package/src/web/NativeListWebEngine.ts +818 -343
  138. package/src/web/templates/ActivityRowRenderer.ts +71 -91
  139. package/src/web/templates/ButtonGroupRowRenderer.ts +58 -0
  140. package/src/web/templates/DataRowRenderer.ts +121 -20
  141. package/src/web/templates/IdentityRowRenderer.ts +234 -9
  142. package/src/web/templates/MarketTableRowRenderer.ts +53 -33
  143. package/src/web/templates/MediaTileRowRenderer.ts +90 -28
  144. package/src/web/templates/MessageRowRenderer.ts +23 -7
  145. package/src/web/templates/RowContainerStyle.ts +2 -0
  146. package/src/web/templates/RowRendererRegistry.ts +11 -1
  147. package/src/web/templates/SectionHeaderRowRenderer.ts +47 -4
  148. package/ios/Resources/NativeListIcons.xcassets/Contents.json +0 -1
  149. package/ios/Resources/NativeListIcons.xcassets/onekey_arrow_bottom.imageset/Contents.json +0 -1
  150. package/ios/Resources/NativeListIcons.xcassets/onekey_arrow_bottom.imageset/icon.svg +0 -1
  151. package/ios/Resources/NativeListIcons.xcassets/onekey_arrow_top.imageset/Contents.json +0 -1
  152. package/ios/Resources/NativeListIcons.xcassets/onekey_arrow_top.imageset/icon.svg +0 -1
  153. package/ios/Resources/NativeListIcons.xcassets/onekey_badge_verified_solid.imageset/Contents.json +0 -1
  154. package/ios/Resources/NativeListIcons.xcassets/onekey_badge_verified_solid.imageset/icon.svg +0 -1
  155. package/ios/Resources/NativeListIcons.xcassets/onekey_chart_trending_up.imageset/Contents.json +0 -1
  156. package/ios/Resources/NativeListIcons.xcassets/onekey_chart_trending_up.imageset/icon.svg +0 -1
  157. package/ios/Resources/NativeListIcons.xcassets/onekey_checkbox_checked.imageset/Contents.json +0 -1
  158. package/ios/Resources/NativeListIcons.xcassets/onekey_checkbox_checked.imageset/icon.svg +0 -1
  159. package/ios/Resources/NativeListIcons.xcassets/onekey_checkbox_indeterminate.imageset/Contents.json +0 -1
  160. package/ios/Resources/NativeListIcons.xcassets/onekey_checkbox_indeterminate.imageset/icon.svg +0 -1
  161. package/ios/Resources/NativeListIcons.xcassets/onekey_chevron_bottom.imageset/Contents.json +0 -1
  162. package/ios/Resources/NativeListIcons.xcassets/onekey_chevron_bottom.imageset/icon.svg +0 -1
  163. package/ios/Resources/NativeListIcons.xcassets/onekey_chevron_grabber_ver.imageset/Contents.json +0 -1
  164. package/ios/Resources/NativeListIcons.xcassets/onekey_chevron_grabber_ver.imageset/icon.svg +0 -1
  165. package/ios/Resources/NativeListIcons.xcassets/onekey_chevron_right_small.imageset/Contents.json +0 -1
  166. package/ios/Resources/NativeListIcons.xcassets/onekey_chevron_right_small.imageset/icon.svg +0 -1
  167. package/ios/Resources/NativeListIcons.xcassets/onekey_chevron_top.imageset/Contents.json +0 -1
  168. package/ios/Resources/NativeListIcons.xcassets/onekey_chevron_top.imageset/icon.svg +0 -1
  169. package/ios/Resources/NativeListIcons.xcassets/onekey_dot_hor.imageset/Contents.json +0 -1
  170. package/ios/Resources/NativeListIcons.xcassets/onekey_dot_hor.imageset/icon.svg +0 -1
  171. package/ios/Resources/NativeListIcons.xcassets/onekey_drag.imageset/Contents.json +0 -1
  172. package/ios/Resources/NativeListIcons.xcassets/onekey_drag.imageset/icon.svg +0 -1
  173. package/ios/Resources/NativeListIcons.xcassets/onekey_error_solid.imageset/Contents.json +0 -1
  174. package/ios/Resources/NativeListIcons.xcassets/onekey_error_solid.imageset/icon.svg +0 -1
  175. package/ios/Resources/NativeListIcons.xcassets/onekey_image_square_waves.imageset/Contents.json +0 -1
  176. package/ios/Resources/NativeListIcons.xcassets/onekey_image_square_waves.imageset/icon.svg +0 -1
  177. package/ios/Resources/NativeListIcons.xcassets/onekey_info_circle.imageset/Contents.json +0 -1
  178. package/ios/Resources/NativeListIcons.xcassets/onekey_info_circle.imageset/icon.svg +0 -1
  179. package/ios/Resources/NativeListIcons.xcassets/onekey_minus_circle.imageset/Contents.json +0 -1
  180. package/ios/Resources/NativeListIcons.xcassets/onekey_minus_circle.imageset/icon.svg +0 -1
  181. package/ios/Resources/NativeListIcons.xcassets/onekey_minus_circle_solid.imageset/Contents.json +0 -1
  182. package/ios/Resources/NativeListIcons.xcassets/onekey_minus_circle_solid.imageset/icon.svg +0 -1
  183. package/ios/Resources/NativeListIcons.xcassets/onekey_pencil.imageset/Contents.json +0 -1
  184. package/ios/Resources/NativeListIcons.xcassets/onekey_pencil.imageset/icon.svg +0 -1
  185. package/ios/Resources/NativeListIcons.xcassets/onekey_plus_circle.imageset/Contents.json +0 -1
  186. package/ios/Resources/NativeListIcons.xcassets/onekey_plus_circle.imageset/icon.svg +0 -1
  187. package/ios/Resources/NativeListIcons.xcassets/onekey_plus_small.imageset/Contents.json +0 -1
  188. package/ios/Resources/NativeListIcons.xcassets/onekey_plus_small.imageset/icon.svg +0 -1
  189. package/ios/Resources/NativeListIcons.xcassets/onekey_questionmark_solid.imageset/Contents.json +0 -1
  190. package/ios/Resources/NativeListIcons.xcassets/onekey_questionmark_solid.imageset/icon.svg +0 -1
  191. package/ios/Resources/NativeListIcons.xcassets/onekey_selector_account_error_custom.imageset/Contents.json +0 -15
  192. package/ios/Resources/NativeListIcons.xcassets/onekey_selector_account_error_custom.imageset/icon.svg +0 -14
  193. package/ios/Resources/NativeListIcons.xcassets/onekey_selector_all_networks_solid.imageset/Contents.json +0 -15
  194. package/ios/Resources/NativeListIcons.xcassets/onekey_selector_all_networks_solid.imageset/icon.svg +0 -12
  195. package/ios/Resources/NativeListIcons.xcassets/onekey_selector_apple_brand.imageset/Contents.json +0 -15
  196. package/ios/Resources/NativeListIcons.xcassets/onekey_selector_apple_brand.imageset/icon.svg +0 -6
  197. package/ios/Resources/NativeListIcons.xcassets/onekey_selector_bot_illus.imageset/Contents.json +0 -15
  198. package/ios/Resources/NativeListIcons.xcassets/onekey_selector_bot_illus.imageset/icon.svg +0 -15
  199. package/ios/Resources/NativeListIcons.xcassets/onekey_selector_crossed_small_solid.imageset/Contents.json +0 -15
  200. package/ios/Resources/NativeListIcons.xcassets/onekey_selector_crossed_small_solid.imageset/icon.svg +0 -3
  201. package/ios/Resources/NativeListIcons.xcassets/onekey_selector_globus_outline.imageset/Contents.json +0 -15
  202. package/ios/Resources/NativeListIcons.xcassets/onekey_selector_globus_outline.imageset/icon.svg +0 -7
  203. package/ios/Resources/NativeListIcons.xcassets/onekey_selector_google_illus.imageset/Contents.json +0 -15
  204. package/ios/Resources/NativeListIcons.xcassets/onekey_selector_google_illus.imageset/icon.svg +0 -18
  205. package/ios/Resources/NativeListIcons.xcassets/onekey_selector_lock_solid.imageset/Contents.json +0 -15
  206. package/ios/Resources/NativeListIcons.xcassets/onekey_selector_lock_solid.imageset/icon.svg +0 -7
  207. package/ios/Resources/NativeListIcons.xcassets/onekey_shield_exclamation.imageset/Contents.json +0 -1
  208. package/ios/Resources/NativeListIcons.xcassets/onekey_shield_exclamation.imageset/icon.svg +0 -1
  209. package/ios/Resources/NativeListIcons.xcassets/onekey_speaker_promote.imageset/Contents.json +0 -1
  210. package/ios/Resources/NativeListIcons.xcassets/onekey_speaker_promote.imageset/icon.svg +0 -1
  211. package/ios/Resources/NativeListIcons.xcassets/onekey_star.imageset/Contents.json +0 -1
  212. package/ios/Resources/NativeListIcons.xcassets/onekey_star.imageset/icon.svg +0 -1
  213. package/ios/Resources/NativeListIcons.xcassets/onekey_star_solid.imageset/Contents.json +0 -1
  214. package/ios/Resources/NativeListIcons.xcassets/onekey_star_solid.imageset/icon.svg +0 -1
  215. package/ios/Resources/NativeListIcons.xcassets/onekey_swap_hor.imageset/Contents.json +0 -1
  216. package/ios/Resources/NativeListIcons.xcassets/onekey_swap_hor.imageset/icon.svg +0 -1
@@ -0,0 +1,189 @@
1
+ import UIKit
2
+
3
+ /// Loading sheen and failed hatch drawn over a media tile while it has no picture.
4
+ /// Geometry mirrors the Web renderer (`MediaTileRowRenderer.ts`) and Android
5
+ /// (`NativeListMediaPlaceholderView.kt`) so every platform draws the same placeholder.
6
+ final class NativeListMediaPlaceholderView: UIView {
7
+ enum State { case hidden, loading, failed }
8
+
9
+ private static let sweepPeriod: CFTimeInterval = 1.6
10
+ private static let sweepKey = "nativeListMediaSweep"
11
+
12
+ private let sheen = CAGradientLayer()
13
+ private let hatch = CAShapeLayer()
14
+ private let hatchMask = CAGradientLayer()
15
+ private let picture = CAShapeLayer()
16
+ private let pictureCut = CAShapeLayer()
17
+ private let slash = CAShapeLayer()
18
+ private(set) var state: State = .hidden
19
+ private var laidOutSize: CGSize = .zero
20
+ private var loadingFill: UIColor = .clear
21
+
22
+ override init(frame: CGRect) {
23
+ super.init(frame: frame)
24
+ isUserInteractionEnabled = false
25
+ isHidden = true
26
+ clipsToBounds = true
27
+ layer.borderWidth = 1 / UIScreen.main.scale
28
+ sheen.startPoint = CGPoint(x: 0, y: 0.5)
29
+ sheen.endPoint = CGPoint(x: 1, y: 0.5)
30
+ sheen.locations = [0, 0.5, 1]
31
+ hatch.lineWidth = 1
32
+ hatch.fillColor = nil
33
+ hatchMask.type = .radial
34
+ hatchMask.startPoint = CGPoint(x: 0.5, y: 0.5)
35
+ // CSS `radial-gradient(circle ...)` defaults to the farthest corner.
36
+ hatchMask.endPoint = CGPoint(x: 0.5 + 0.7071, y: 0.5 + 0.7071)
37
+ hatchMask.colors = [UIColor.clear.cgColor, UIColor.clear.cgColor, UIColor.black.cgColor, UIColor.black.cgColor]
38
+ hatchMask.locations = [0, 0.22, 0.7, 1]
39
+ hatch.mask = hatchMask
40
+ for shape in [picture, slash] {
41
+ shape.fillColor = nil
42
+ shape.lineCap = .round
43
+ shape.lineJoin = .round
44
+ }
45
+ pictureCut.fillRule = .evenOdd
46
+ pictureCut.fillColor = UIColor.black.cgColor
47
+ [hatch, sheen, picture, slash].forEach(layer.addSublayer)
48
+ NotificationCenter.default.addObserver(
49
+ self, selector: #selector(restartSweep),
50
+ name: UIApplication.willEnterForegroundNotification, object: nil)
51
+ }
52
+ required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }
53
+
54
+ func applyTheme(_ theme: [String: Any]?) {
55
+ loadingFill = nativeListColor(theme, "strongBackground", "#0000000F")
56
+ if state == .loading { backgroundColor = loadingFill }
57
+ let glyph = nativeListColor(theme, "disabledText", "#8C8C8C")
58
+ let glyphColor = glyph.withAlphaComponent(glyph.cgAlpha * 0.7).cgColor
59
+ picture.strokeColor = glyphColor
60
+ slash.strokeColor = glyphColor
61
+ let separator = nativeListColor(theme, "separator", "#E5E7EB")
62
+ layer.borderColor = separator.withAlphaComponent(separator.cgAlpha * 0.6).cgColor
63
+ hatch.strokeColor = nativeListColor(theme, "primaryText", "#202020").withAlphaComponent(0.045).cgColor
64
+ let dark = nativeListIsDark(nativeListColor(theme, "rowBackground", "#FFFFFF"))
65
+ let shine = UIColor.white.withAlphaComponent(dark ? 0.07 : 0.75)
66
+ sheen.colors = [shine.withAlphaComponent(0).cgColor, shine.cgColor, shine.withAlphaComponent(0).cgColor]
67
+ }
68
+
69
+ func setState(_ next: State) {
70
+ guard next != state else { return }
71
+ state = next
72
+ isHidden = next == .hidden
73
+ // The failed state sits on the cell's own fill; while loading nothing else paints the slot.
74
+ backgroundColor = next == .loading ? loadingFill : .clear
75
+ CATransaction.begin()
76
+ CATransaction.setDisableActions(true)
77
+ sheen.isHidden = next != .loading
78
+ hatch.isHidden = next != .failed
79
+ slash.isHidden = next != .failed
80
+ picture.mask = next == .failed ? pictureCut : nil
81
+ CATransaction.commit()
82
+ restartSweep()
83
+ }
84
+
85
+ override func layoutSubviews() {
86
+ super.layoutSubviews()
87
+ guard bounds.size != laidOutSize else { return }
88
+ laidOutSize = bounds.size
89
+ CATransaction.begin()
90
+ CATransaction.setDisableActions(true)
91
+ layoutHatch()
92
+ layoutGlyph()
93
+ let width = bounds.width, height = bounds.height
94
+ sheen.bounds = CGRect(x: 0, y: 0, width: width * 0.6, height: height * 2)
95
+ sheen.position = CGPoint(x: width * 0.6, y: height / 2)
96
+ // CSS skewX(-12deg).
97
+ sheen.setAffineTransform(CGAffineTransform(a: 1, b: 0, c: -tan(12 * .pi / 180), d: 1, tx: 0, ty: 0))
98
+ CATransaction.commit()
99
+ restartSweep()
100
+ }
101
+
102
+ override func didMoveToWindow() {
103
+ super.didMoveToWindow()
104
+ restartSweep()
105
+ }
106
+
107
+ @objc private func restartSweep() {
108
+ sheen.removeAnimation(forKey: Self.sweepKey)
109
+ guard state == .loading, window != nil, bounds.width > 0 else { return }
110
+ let width = bounds.width
111
+ guard !UIAccessibility.isReduceMotionEnabled else {
112
+ sheen.opacity = 0.6
113
+ return
114
+ }
115
+ sheen.opacity = 1
116
+ let sweep = CAKeyframeAnimation(keyPath: "position.x")
117
+ // Band left edge travels from -80% to 130% of the tile, then rests for 30% of the period.
118
+ sweep.values = [width * -0.5, width * 1.6, width * 1.6]
119
+ sweep.keyTimes = [0, 0.7, 1]
120
+ sweep.timingFunctions = [
121
+ CAMediaTimingFunction(controlPoints: 0.4, 0, 0.2, 1), CAMediaTimingFunction(name: .linear),
122
+ ]
123
+ sweep.duration = Self.sweepPeriod
124
+ sweep.repeatCount = .infinity
125
+ sweep.isRemovedOnCompletion = false
126
+ // Every tile derives its phase from the shared media clock so the grid sweeps in step,
127
+ // including cells that are recycled mid-period.
128
+ sweep.timeOffset = CACurrentMediaTime().truncatingRemainder(dividingBy: Self.sweepPeriod)
129
+ sheen.add(sweep, forKey: Self.sweepKey)
130
+ }
131
+
132
+ private func layoutHatch() {
133
+ hatch.frame = bounds
134
+ hatchMask.frame = bounds
135
+ let path = UIBezierPath()
136
+ // Lines along x + y = c, 7pt apart measured perpendicular to the stripes.
137
+ let step = 7 * CGFloat(2).squareRoot()
138
+ var c: CGFloat = 0
139
+ while c <= bounds.width + bounds.height {
140
+ path.move(to: CGPoint(x: c, y: 0))
141
+ path.addLine(to: CGPoint(x: 0, y: c))
142
+ c += step
143
+ }
144
+ hatch.path = path.cgPath
145
+ }
146
+
147
+ private func layoutGlyph() {
148
+ let size = min(bounds.width * 0.28, 44)
149
+ let scale = size / 24
150
+ let origin = CGPoint(x: (bounds.width - size) / 2, y: (bounds.height - size) / 2)
151
+ var transform = CGAffineTransform(translationX: origin.x, y: origin.y).scaledBy(x: scale, y: scale)
152
+ let frame = UIBezierPath(roundedRect: CGRect(x: 3, y: 3, width: 18, height: 18), cornerRadius: 4)
153
+ frame.append(UIBezierPath(ovalIn: CGRect(x: 7.4, y: 7.4, width: 3.2, height: 3.2)))
154
+ let ridge = UIBezierPath()
155
+ ridge.move(to: CGPoint(x: 5, y: 20.5))
156
+ ridge.addLine(to: CGPoint(x: 14.5, y: 11))
157
+ ridge.addLine(to: CGPoint(x: 21, y: 17.5))
158
+ frame.append(ridge)
159
+ picture.frame = bounds
160
+ picture.lineWidth = 1.5 * scale
161
+ picture.path = frame.cgPath.copy(using: &transform)
162
+ let line = UIBezierPath()
163
+ line.move(to: CGPoint(x: 3, y: 3))
164
+ line.addLine(to: CGPoint(x: 21, y: 21))
165
+ slash.frame = bounds
166
+ slash.lineWidth = 1.5 * scale
167
+ slash.path = line.cgPath.copy(using: &transform)
168
+ let band = UIBezierPath()
169
+ band.move(to: CGPoint(x: 2.6, y: -0.6))
170
+ band.addLine(to: CGPoint(x: 24.6, y: 21.4))
171
+ band.addLine(to: CGPoint(x: 21.4, y: 24.6))
172
+ band.addLine(to: CGPoint(x: -0.6, y: 2.6))
173
+ band.close()
174
+ let cut = UIBezierPath(rect: bounds)
175
+ if let bandPath = band.cgPath.copy(using: &transform) { cut.append(UIBezierPath(cgPath: bandPath)) }
176
+ pictureCut.frame = bounds
177
+ pictureCut.path = cut.cgPath
178
+ }
179
+ }
180
+
181
+ private extension UIColor {
182
+ var cgAlpha: CGFloat { cgColor.alpha }
183
+ }
184
+
185
+ func nativeListIsDark(_ color: UIColor) -> Bool {
186
+ var red: CGFloat = 0, green: CGFloat = 0, blue: CGFloat = 0, alpha: CGFloat = 0
187
+ guard color.getRed(&red, green: &green, blue: &blue, alpha: &alpha) else { return false }
188
+ return red * 299 + green * 587 + blue * 114 < 500
189
+ }
@@ -1,4 +1,5 @@
1
1
  import AVFoundation
2
+ import OneKeyImage
2
3
  import UIKit
3
4
 
4
5
  private final class NativeListPausedVideoView: UIView {
@@ -17,6 +18,18 @@ final class NativeListMediaPreviewSlot {
17
18
  private let image = NativeListImageSlot()
18
19
  private let video = NativeListPausedVideoView()
19
20
  private let frameView = UIImageView()
21
+ private final class PendingFrame {
22
+ private let lock = NSLock()
23
+ private var buffer: CVPixelBuffer?
24
+ init(_ buffer: CVPixelBuffer) { self.buffer = buffer }
25
+ func take() -> CVPixelBuffer? { lock.lock(); defer { lock.unlock() }; let value = buffer; buffer = nil; return value }
26
+ func cancel() { lock.lock(); buffer = nil; lock.unlock() }
27
+ }
28
+ private var pendingFrame: PendingFrame?
29
+ private var requestedEdge: Int?
30
+ private var subscription: OneKeyMediaPreviewCache.Subscription?
31
+ private var extractionLease: UUID?
32
+ private static let frameWorker = DispatchQueue(label: "onekey.native-list.frame", qos: .userInitiated)
20
33
  private var videoOutput: AVPlayerItemVideoOutput?
21
34
  private static let frameContext = CIContext(options: [.cacheIntermediates: false])
22
35
  private static let frameCaptureAttempts = 6
@@ -26,6 +39,7 @@ final class NativeListMediaPreviewSlot {
26
39
  private var playerGeneration = 0
27
40
  private var result: Bool?
28
41
  private var completion: ((Bool) -> Void)?
42
+ private(set) var createdPlayerCount = 0
29
43
  private var player: AVPlayer?
30
44
  private var itemObservation: NSKeyValueObservation?
31
45
  private var readyObservation: NSKeyValueObservation?
@@ -49,7 +63,7 @@ final class NativeListMediaPreviewSlot {
49
63
  video.onWindowChanged = { [weak self] in self?.observeViewport(); self?.updateVisibility() }
50
64
  video.onLayoutChanged = { [weak self] in self?.updateVisibility() }
51
65
  lifecycleObservers = [
52
- NotificationCenter.default.addObserver(forName: UIApplication.willResignActiveNotification, object: nil, queue: .main) { [weak self] _ in self?.releasePlayer() },
66
+ NotificationCenter.default.addObserver(forName: UIApplication.willResignActiveNotification, object: nil, queue: .main) { [weak self] _ in self?.cancelPreview() },
53
67
  NotificationCenter.default.addObserver(forName: UIApplication.didBecomeActiveNotification, object: nil, queue: .main) { [weak self] _ in self?.updateVisibility() },
54
68
  ]
55
69
  }
@@ -87,7 +101,7 @@ final class NativeListMediaPreviewSlot {
87
101
  let candidate = candidateGeneration
88
102
  resumeVideo = nil
89
103
  viewportObservations.removeAll()
90
- releasePlayer()
104
+ cancelPreview()
91
105
  guard attempt < order.count else {
92
106
  result = false
93
107
  completion?(false)
@@ -113,81 +127,108 @@ final class NativeListMediaPreviewSlot {
113
127
  image.view.isHidden = true
114
128
  video.isHidden = false
115
129
  guard let url = URL(string: source.string("uri")), !source.string("uri").isEmpty else { finished(false); return }
130
+ let headers = (source.dictionary("headers") ?? [:]).compactMapValues { $0 as? String }
131
+ let fitKey = coverFit(fit ?? source.string("contentFit"))
116
132
  resumeVideo = { [weak self] in
117
- guard let self, self.epoch == token, self.candidateGeneration == candidate, self.player == nil else { return }
118
- self.playerGeneration &+= 1
119
- let generation = self.playerGeneration
120
- let asset = AVURLAsset(url: url, options: ["AVURLAssetHTTPHeaderFieldsKey": source.dictionary("headers") ?? [:]])
121
- let item = AVPlayerItem(asset: asset)
122
- item.preferredForwardBufferDuration = 1
123
- let output = AVPlayerItemVideoOutput(pixelBufferAttributes: [
124
- kCVPixelBufferPixelFormatTypeKey as String: kCVPixelFormatType_32BGRA,
125
- ])
126
- item.add(output)
127
- self.videoOutput = output
128
- let player = AVPlayer(playerItem: item)
129
- player.isMuted = true
130
- player.pause()
131
- self.player = player
132
- self.video.playerLayer.player = player
133
- self.itemObservation = item.observe(\.status, options: [.initial, .new]) { [weak self] item, _ in
134
- DispatchQueue.main.async {
135
- guard let self, self.playerGeneration == generation else { return }
136
- if item.status == .failed { finished(false) }
137
- }
138
- }
139
- self.readyObservation = self.video.playerLayer.observe(\.isReadyForDisplay, options: [.initial, .new]) { [weak self] layer, _ in
140
- DispatchQueue.main.async {
141
- guard let self, self.playerGeneration == generation else { return }
142
- guard layer.isReadyForDisplay else { return }
133
+ guard let self, self.epoch == token, self.candidateGeneration == candidate,
134
+ self.subscription == nil, self.frameView.image == nil, !self.video.bounds.isEmpty else { return }
135
+ let edge = OneKeyMediaPreviewCache.targetEdge(max(self.video.bounds.width, self.video.bounds.height) * (self.video.window?.screen.scale ?? 1))
136
+ self.requestedEdge = edge
137
+ self.subscription = OneKeyMediaPreviewCache.shared.request(uri: url.absoluteString, headers: headers,
138
+ edge: edge, fit: fitKey, policy: source.string("cachePolicy", default: "memory-disk"),
139
+ onImage: { [weak self] still in
140
+ guard let self, self.epoch == token, self.candidateGeneration == candidate else { return }
141
+ self.subscription = nil
142
+ self.frameView.image = still; self.frameView.isHidden = false
143
+ self.viewportObservations.removeAll()
143
144
  finished(true)
144
- self.captureFirstFrame(generation: generation, attemptsLeft: Self.frameCaptureAttempts)
145
- }
146
- }
145
+ }, onExtract: { [weak self] lease in
146
+ guard let self, self.epoch == token, self.candidateGeneration == candidate else { return }
147
+ self.extractionLease = lease
148
+ self.updateVisibility()
149
+ guard self.extractionLease == lease, self.requestedEdge == edge else { return }
150
+ self.startPlayer(url: url, headers: headers, edge: edge, lease: lease)
151
+ }, onRevoked: { [weak self] in
152
+ self?.extractionLease = nil; self?.pendingFrame?.cancel(); self?.pendingFrame = nil; self?.releasePlayer()
153
+ },
154
+ onFailure: { [weak self] in
155
+ guard let self, self.epoch == token, self.candidateGeneration == candidate else { return }
156
+ self.subscription = nil; finished(false)
157
+ })
147
158
  }
148
159
  observeViewport()
149
160
  updateVisibility()
150
161
  }
151
162
 
152
- /// A paused item may not have handed its preroll frame to the output yet, so copying retries
153
- /// on later runloop turns. If no frame arrives the paused player stays attached.
154
- private func captureFirstFrame(generation: Int, attemptsLeft: Int) {
163
+ private func coverFit(_ fit: String) -> String { fit == "cover" ? "cover" : "contain" }
164
+
165
+ private func startPlayer(url: URL, headers: [String: String], edge: Int, lease: UUID) {
166
+ createdPlayerCount += 1
167
+ self.playerGeneration &+= 1
168
+ let generation = self.playerGeneration
169
+ let asset = AVURLAsset(url: url, options: ["AVURLAssetHTTPHeaderFieldsKey": headers])
170
+ let item = AVPlayerItem(asset: asset)
171
+ item.preferredForwardBufferDuration = 1
172
+ let output = AVPlayerItemVideoOutput(pixelBufferAttributes: [
173
+ kCVPixelBufferPixelFormatTypeKey as String: kCVPixelFormatType_32BGRA,
174
+ ])
175
+ item.add(output)
176
+ self.videoOutput = output
177
+ let player = AVPlayer(playerItem: item)
178
+ player.isMuted = true
179
+ player.pause()
180
+ self.player = player
181
+ self.video.playerLayer.player = player
182
+ self.itemObservation = item.observe(\.status, options: [.initial, .new]) { [weak self] item, _ in
183
+ DispatchQueue.main.async {
184
+ guard let self, self.playerGeneration == generation else { return }
185
+ if item.status == .failed { OneKeyMediaPreviewCache.shared.fail(lease) }
186
+ }
187
+ }
188
+ self.readyObservation = self.video.playerLayer.observe(\.isReadyForDisplay, options: [.initial, .new]) { [weak self] layer, _ in
189
+ DispatchQueue.main.async {
190
+ guard let self, self.playerGeneration == generation, layer.isReadyForDisplay else { return }
191
+ self.readyObservation = nil
192
+ self.captureFirstFrame(generation: generation, attemptsLeft: Self.frameCaptureAttempts, edge: edge, lease: lease)
193
+ }
194
+ }
195
+ }
196
+
197
+ /// Capture only the buffer on UI; CI normalizes orientation and size on a worker.
198
+ private func captureFirstFrame(generation: Int, attemptsLeft: Int, edge: Int, lease: UUID) {
155
199
  guard playerGeneration == generation, let player, let item = player.currentItem, let output = videoOutput else { return }
156
200
  let time = item.currentTime()
157
- if let buffer = output.copyPixelBuffer(forItemTime: time, itemTimeForDisplay: nil),
158
- let still = Self.frameContext.createCGImage(CIImage(cvPixelBuffer: buffer), from: CGRect(
159
- x: 0, y: 0, width: CVPixelBufferGetWidth(buffer), height: CVPixelBufferGetHeight(buffer))) {
160
- let transform = item.tracks.lazy.compactMap(\.assetTrack).first { $0.mediaType == .video }?.preferredTransform
161
- frameView.image = UIImage(cgImage: still, scale: 1, orientation: Self.orientation(transform))
162
- frameView.isHidden = false
163
- resumeVideo = nil
164
- viewportObservations.removeAll()
201
+ if let buffer = output.copyPixelBuffer(forItemTime: time, itemTimeForDisplay: nil) {
202
+ let transform = item.tracks.lazy.compactMap(\.assetTrack).first { $0.mediaType == .video }?.preferredTransform ?? .identity
165
203
  releasePlayer()
204
+ let pending = PendingFrame(buffer)
205
+ pendingFrame = pending
206
+ Self.frameWorker.async { [weak self] in
207
+ guard let buffer = pending.take() else { return }
208
+ var image = CIImage(cvPixelBuffer: buffer).transformed(by: transform)
209
+ let origin = image.extent.origin
210
+ image = image.transformed(by: CGAffineTransform(translationX: -origin.x, y: -origin.y))
211
+ let scale = min(1, CGFloat(edge) / max(image.extent.width, image.extent.height))
212
+ image = image.transformed(by: CGAffineTransform(scaleX: scale, y: scale))
213
+ let still = Self.frameContext.createCGImage(image, from: image.extent).map { UIImage(cgImage: $0) }
214
+ DispatchQueue.main.async {
215
+ guard let self, self.extractionLease == lease else { return }
216
+ if let still { OneKeyMediaPreviewCache.shared.complete(lease, image: still) }
217
+ else { OneKeyMediaPreviewCache.shared.fail(lease) }
218
+ }
219
+ }
166
220
  return
167
221
  }
168
- guard attemptsLeft > 1 else { return }
169
- // An exact seek re-delivers the paused preroll frame to newly attached outputs.
170
- if attemptsLeft == Self.frameCaptureAttempts {
171
- player.seek(to: time, toleranceBefore: .zero, toleranceAfter: .zero)
172
- }
222
+ guard attemptsLeft > 1 else { OneKeyMediaPreviewCache.shared.fail(lease); return }
223
+ if attemptsLeft == Self.frameCaptureAttempts { player.seek(to: time, toleranceBefore: .zero, toleranceAfter: .zero) }
173
224
  DispatchQueue.main.asyncAfter(deadline: .now() + 0.05) { [weak self] in
174
- self?.captureFirstFrame(generation: generation, attemptsLeft: attemptsLeft - 1)
175
- }
176
- }
177
-
178
- private static func orientation(_ transform: CGAffineTransform?) -> UIImage.Orientation {
179
- guard let transform else { return .up }
180
- switch (transform.a, transform.b, transform.c, transform.d) {
181
- case (0, 1, -1, 0): return .right
182
- case (0, -1, 1, 0): return .left
183
- case (-1, 0, 0, -1): return .down
184
- default: return .up
225
+ self?.captureFirstFrame(generation: generation, attemptsLeft: attemptsLeft - 1, edge: edge, lease: lease)
185
226
  }
186
227
  }
187
228
 
188
229
  private func observeViewport() {
189
230
  viewportObservations.removeAll()
190
- guard resumeVideo != nil, video.window != nil else { return }
231
+ guard resumeVideo != nil, frameView.image == nil, video.window != nil else { return }
191
232
  var ancestor = video.superview
192
233
  while let current = ancestor {
193
234
  if let scrollView = current as? UIScrollView {
@@ -223,8 +264,24 @@ final class NativeListMediaPreviewSlot {
223
264
  }
224
265
 
225
266
  private func updateVisibility() {
267
+ if let requestedEdge, let window = video.window, !video.bounds.isEmpty {
268
+ let edge = OneKeyMediaPreviewCache.targetEdge(max(video.bounds.width, video.bounds.height) * window.screen.scale)
269
+ if edge != requestedEdge {
270
+ cancelPreview(); self.requestedEdge = nil
271
+ frameView.image = nil; frameView.isHidden = true; result = nil
272
+ observeViewport()
273
+ }
274
+ }
226
275
  if Self.intersectsViewport(video) && UIApplication.shared.applicationState == .active { resumeVideo?() }
227
- else { releasePlayer() }
276
+ else { cancelPreview() }
277
+ }
278
+ private func cancelPreview() {
279
+ let previous = subscription
280
+ subscription = nil
281
+ OneKeyMediaPreviewCache.shared.cancel(previous)
282
+ extractionLease = nil
283
+ pendingFrame?.cancel(); pendingFrame = nil
284
+ releasePlayer()
228
285
  }
229
286
  private func releasePlayer() {
230
287
  playerGeneration &+= 1
@@ -241,10 +298,11 @@ final class NativeListMediaPreviewSlot {
241
298
  candidateGeneration &+= 1
242
299
  resumeVideo = nil
243
300
  viewportObservations.removeAll()
244
- releasePlayer()
301
+ cancelPreview()
245
302
  image.recycle()
246
303
  image.view.isHidden = false
247
304
  video.isHidden = true
305
+ requestedEdge = nil
248
306
  frameView.image = nil
249
307
  frameView.isHidden = true
250
308
  identity = nil
@@ -252,6 +310,9 @@ final class NativeListMediaPreviewSlot {
252
310
  completion = nil
253
311
  }
254
312
  deinit {
313
+ pendingFrame?.cancel()
314
+ let pending = subscription
315
+ DispatchQueue.main.async { OneKeyMediaPreviewCache.shared.cancel(pending) }
255
316
  lifecycleObservers.forEach(NotificationCenter.default.removeObserver)
256
317
  player?.pause()
257
318
  player?.replaceCurrentItem(with: nil)
@@ -11,7 +11,7 @@ final class NativeListMediaTileCell: NativeListRendererCell {
11
11
  private let picture = UIView()
12
12
  private let image = NativeListMediaPreviewSlot()
13
13
  private let network = NativeListImageSlot()
14
- private let errorIcon = UIImageView()
14
+ private let placeholderView = NativeListMediaPlaceholderView()
15
15
  private let title = NativeListTextLabel()
16
16
  private let subtitle = NativeListTextLabel()
17
17
  private let badge = NativeListTextLabel()
@@ -50,7 +50,7 @@ final class NativeListMediaTileCell: NativeListRendererCell {
50
50
  closeStack.addArrangedSubview(close)
51
51
  [picture, metadata, closeStack].forEach(root.addArrangedSubview)
52
52
  picture.translatesAutoresizingMaskIntoConstraints = false
53
- [image.view, errorIcon, badge].forEach {
53
+ [image.view, placeholderView, badge].forEach {
54
54
  picture.addSubview($0)
55
55
  $0.translatesAutoresizingMaskIntoConstraints = false
56
56
  }
@@ -60,17 +60,16 @@ final class NativeListMediaTileCell: NativeListRendererCell {
60
60
  image.view.leadingAnchor.constraint(equalTo: picture.leadingAnchor),
61
61
  image.view.topAnchor.constraint(equalTo: picture.topAnchor),
62
62
  image.view.heightAnchor.constraint(equalTo: picture.heightAnchor), imageWidth, imageHeight,
63
- errorIcon.centerXAnchor.constraint(equalTo: image.view.centerXAnchor),
64
- errorIcon.centerYAnchor.constraint(equalTo: image.view.centerYAnchor),
65
- errorIcon.widthAnchor.constraint(equalToConstant: 24),
66
- errorIcon.heightAnchor.constraint(equalToConstant: 24),
63
+ placeholderView.leadingAnchor.constraint(equalTo: image.view.leadingAnchor),
64
+ placeholderView.trailingAnchor.constraint(equalTo: image.view.trailingAnchor),
65
+ placeholderView.topAnchor.constraint(equalTo: image.view.topAnchor),
66
+ placeholderView.bottomAnchor.constraint(equalTo: image.view.bottomAnchor),
67
67
  badge.trailingAnchor.constraint(equalTo: image.view.trailingAnchor),
68
68
  badge.bottomAnchor.constraint(equalTo: image.view.bottomAnchor),
69
69
  badge.heightAnchor.constraint(equalToConstant: 24),
70
70
  network.view.widthAnchor.constraint(equalToConstant: 14),
71
71
  network.view.heightAnchor.constraint(equalToConstant: 14),
72
72
  ])
73
- errorIcon.contentMode = .scaleAspectFit
74
73
  badge.textAlignment = .center
75
74
  badge.layer.cornerRadius = 10
76
75
  badge.layer.borderWidth = 2
@@ -87,6 +86,7 @@ final class NativeListMediaTileCell: NativeListRendererCell {
87
86
  _ item: NativeListItem, theme: [String: Any]?, layout: String,
88
87
  checkboxState: (NativeListItem, NativeSelectionTarget?, String) -> String
89
88
  ) {
89
+
90
90
  let style = item.data.dictionary("style") ?? [:]
91
91
  imageStyle = style.dictionary("image") ?? [:]
92
92
  let hp = CGFloat(style.double("horizontalPadding", default: 10))
@@ -121,9 +121,7 @@ final class NativeListMediaTileCell: NativeListRendererCell {
121
121
  badge.layer.borderColor = nativeListColor(theme, "rowBackground", "#FFFFFF").cgColor
122
122
  let state = item.data.string("imageState")
123
123
  let placeholder = theme?.string("strongBackground", default: "#0000000F") ?? "#0000000F"
124
- errorIcon.isHidden = state != "error"
125
- errorIcon.image = nativeListIcon(named: "ImageSquareWavesOutline")
126
- errorIcon.tintColor = UIColor(nativeListHex: "#00000044", fallback: .lightGray)
124
+ placeholderView.applyTheme(theme)
127
125
  let media = item.data.dictionary("media")
128
126
  if state != "empty", state != "error", let source = media?.dictionary("source") ?? item.data.dictionary("image") {
129
127
  // Legacy source-backed media had a transparent container. Clear only a fill this
@@ -132,11 +130,13 @@ final class NativeListMediaTileCell: NativeListRendererCell {
132
130
  image.view.backgroundColor = .clear
133
131
  ownsImageFill = false
134
132
  }
133
+ // Set before binding: a cached result completes synchronously inside bind.
134
+ placeholderView.setState(.loading)
135
135
  image.bind(
136
136
  source, key: "\(item.key):media", fit: imageStyle["contentFit"] as? String,
137
137
  placeholder: placeholder, probeOrder: media?["probeOrder"] as? [String] ?? ["image"]
138
138
  ) { [weak self] loaded in
139
- self?.errorIcon.isHidden = loaded
139
+ self?.placeholderView.setState(loaded ? .hidden : .failed)
140
140
  self?.ownsImageFill = !loaded
141
141
  self?.image.view.backgroundColor = loaded ? .clear : UIColor(nativeListHex: placeholder, fallback: .lightGray)
142
142
  }
@@ -144,6 +144,7 @@ final class NativeListMediaTileCell: NativeListRendererCell {
144
144
  image.recycle()
145
145
  image.view.backgroundColor =
146
146
  state == "error" ? nativeListColor(theme, "strongBackground", "#0000000F") : .clear
147
+ placeholderView.setState(state == "error" ? .failed : .hidden)
147
148
  ownsImageFill = true
148
149
  }
149
150
  if let source = item.data.dictionary("networkImage") {
@@ -164,6 +165,7 @@ final class NativeListMediaTileCell: NativeListRendererCell {
164
165
  close.setTitle("×", for: .normal)
165
166
  close.titleLabel?.font = nativeListFont(ofSize: 16, weight: .medium, fonts: fonts)
166
167
  close.setTitleColor(nativeListColor(theme, "primaryText", "#202020"), for: .normal)
168
+
167
169
  }
168
170
  override func layoutSubviews() {
169
171
  let width = CGFloat(
@@ -180,6 +182,7 @@ final class NativeListMediaTileCell: NativeListRendererCell {
180
182
  default: shape == "circle"
181
183
  ? Double(min(width, imageHeight.constant) / 2) : shape == "square" ? 0 : 10))
182
184
  image.view.clipsToBounds = true
185
+ placeholderView.layer.cornerRadius = image.view.layer.cornerRadius
183
186
  super.layoutSubviews()
184
187
  }
185
188
  @objc private func closePressed() {
@@ -187,6 +190,7 @@ final class NativeListMediaTileCell: NativeListRendererCell {
187
190
  }
188
191
  override func recycleContent() {
189
192
  image.recycle()
193
+ placeholderView.setState(.hidden)
190
194
  network.recycle()
191
195
  closeKey = ""
192
196
  picture.alpha = 1
@@ -29,7 +29,9 @@ enum NativeListMessageRenderer {
29
29
  body = NativeListResolvedText(
30
30
  item.data.string("body"), style: style.dictionary("body"), size: 14,
31
31
  color: nativeListColor(theme, "secondaryText", "#646464"), lineHeight: 20,
32
- lines: item.data.int("bodyLines", default: 3), fonts: fonts)
32
+ lines: item.data.int("bodyLines", default: 3),
33
+ breakMode: item.data.int("bodyLines", default: 3) == 0 ? .byWordWrapping : .byTruncatingTail,
34
+ fonts: fonts)
33
35
  time = NativeListResolvedText(
34
36
  item.data.string("time"), style: style.dictionary("time"), size: 12,
35
37
  color: nativeListColor(theme, "disabledText", "#8D8D8D"), lineHeight: 16, lines: 1,
@@ -150,6 +152,11 @@ enum NativeListMessageRenderer {
150
152
  }
151
153
 
152
154
  final class NativeListMessageCell: NativeListRendererCell {
155
+ private let topWarningBorder = CALayer()
156
+ private let bottomWarningBorder = CALayer()
157
+ private var warningBorderWidth: CGFloat = 0
158
+ private var warningBorderColor = UIColor.clear
159
+ private var isInlineWarning = false
153
160
  override class func measure(
154
161
  _ item: NativeListItem, width: CGFloat, theme: [String: Any]?, layout: String,
155
162
  fonts: NativeListFontFamilies
@@ -167,6 +174,10 @@ final class NativeListMessageCell: NativeListRendererCell {
167
174
  _ item: NativeListItem, theme: [String: Any]?, layout: String,
168
175
  checkboxState: (NativeListItem, NativeSelectionTarget?, String) -> String
169
176
  ) {
177
+ let container = item.data.dictionary("style")?.dictionary("container") ?? [:]
178
+ isInlineWarning = item.data.string("presentation") == "inlineWarning"
179
+ warningBorderWidth = isInlineWarning ? CGFloat(container.double("borderWidth")) : 0
180
+ warningBorderColor = UIColor(nativeListHex: container.string("borderColor"), fallback: .clear)
170
181
  let resolved = NativeListMessageRenderer.Resolved(
171
182
  item, theme: theme, layout: layout, fonts: fonts)
172
183
  views.bind(resolved, item: item, theme: theme, fonts: fonts)
@@ -174,5 +185,27 @@ final class NativeListMessageCell: NativeListRendererCell {
174
185
  top: resolved.verticalPadding, left: resolved.horizontalPadding,
175
186
  bottom: resolved.verticalPadding, right: resolved.horizontalPadding)
176
187
  }
188
+ override func applyAppearance() {
189
+ super.applyAppearance()
190
+ if isInlineWarning {
191
+ layer.cornerRadius = 0
192
+ contentView.layer.cornerRadius = 0
193
+ contentView.layer.borderWidth = 0
194
+ topWarningBorder.backgroundColor = warningBorderColor.cgColor
195
+ bottomWarningBorder.backgroundColor = warningBorderColor.cgColor
196
+ if topWarningBorder.superlayer == nil { contentView.layer.addSublayer(topWarningBorder) }
197
+ if bottomWarningBorder.superlayer == nil { contentView.layer.addSublayer(bottomWarningBorder) }
198
+ } else {
199
+ topWarningBorder.removeFromSuperlayer()
200
+ bottomWarningBorder.removeFromSuperlayer()
201
+ }
202
+ }
203
+ override func layoutSubviews() {
204
+ super.layoutSubviews()
205
+ let height = max(0, warningBorderWidth)
206
+ topWarningBorder.frame = CGRect(x: 0, y: 0, width: contentView.bounds.width, height: height)
207
+ bottomWarningBorder.frame = CGRect(
208
+ x: 0, y: contentView.bounds.height - height, width: contentView.bounds.width, height: height)
209
+ }
177
210
  override func recycleContent() { views.recycle() }
178
211
  }
@@ -374,7 +374,7 @@ final class NativeListMetricCardCell: NativeListRendererCell {
374
374
  }
375
375
 
376
376
  private final class NativeListMetricVisual: UIView {
377
- private let icon = UIImageView()
377
+ private let icon = NativeListIconImageView()
378
378
  private let image = NativeListImageSlot()
379
379
  init() {
380
380
  super.init(frame: .zero)
@@ -389,6 +389,8 @@ private final class NativeListMetricVisual: UIView {
389
389
  }
390
390
  required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }
391
391
  func bind(_ visual: [String: Any], key: String, placeholder: String) {
392
+ let iconUpdate = NativeListIconUpdate(self)
393
+ defer { iconUpdate.finish() }
392
394
  backgroundColor = UIColor(
393
395
  nativeListHex: visual.string("backgroundColor", default: "#0000000F"), fallback: .lightGray)
394
396
  layer.cornerRadius = visual.string("shape") == "square" ? 0 : 8
@@ -397,7 +399,7 @@ private final class NativeListMetricVisual: UIView {
397
399
  image.view.isHidden = true
398
400
  if kind == "icon" {
399
401
  image.recycle()
400
- icon.image = nativeListIcon(named: visual.string("name"))
402
+ icon.bindIcon(visual.string("name"))
401
403
  icon.tintColor = UIColor(
402
404
  nativeListHex: visual.string("tintColor", default: "#00000072"), fallback: .darkGray)
403
405
  } else if let source = kind == "stackedImages"