Supported RemoteURLContaining

commit_hash:5bf062bcb9901a0539c83918f64dcffaf18cc02f
This commit is contained in:
burstein
2026-05-26 20:51:10 +03:00
parent edda07be74
commit 6ed5d45cce
22 changed files with 133 additions and 6 deletions
+1
View File
@@ -21162,6 +21162,7 @@
"client/ios/LayoutKit/LayoutKit/Blocks/PageControlBlock.swift":"divkit/public/client/ios/LayoutKit/LayoutKit/Blocks/PageControlBlock.swift",
"client/ios/LayoutKit/LayoutKit/Blocks/PagerBlock.swift":"divkit/public/client/ios/LayoutKit/LayoutKit/Blocks/PagerBlock.swift",
"client/ios/LayoutKit/LayoutKit/Blocks/PinchToZoomBlock.swift":"divkit/public/client/ios/LayoutKit/LayoutKit/Blocks/PinchToZoomBlock.swift",
"client/ios/LayoutKit/LayoutKit/Blocks/RemoteURLContaining.swift":"divkit/public/client/ios/LayoutKit/LayoutKit/Blocks/RemoteURLContaining.swift",
"client/ios/LayoutKit/LayoutKit/Blocks/ResizableBlockMeasure.swift":"divkit/public/client/ios/LayoutKit/LayoutKit/Blocks/ResizableBlockMeasure.swift",
"client/ios/LayoutKit/LayoutKit/Blocks/RoundedRect.swift":"divkit/public/client/ios/LayoutKit/LayoutKit/Blocks/RoundedRect.swift",
"client/ios/LayoutKit/LayoutKit/Blocks/SeparatorBlock.swift":"divkit/public/client/ios/LayoutKit/LayoutKit/Blocks/SeparatorBlock.swift",
@@ -31,6 +31,10 @@ final class LottieAnimationBlock: SizeForwardingBlock {
func getImageHolders() -> [ImageHolder] { [] }
func getRemoteURLs() -> [URL] {
(animationHolder as? RemoteAnimationHolder).map { [$0.url] } ?? []
}
func equals(_ other: Block) -> Bool {
guard let other = other as? LottieAnimationBlock else {
return false
@@ -58,6 +58,10 @@ public final class RiveAnimationBlock: BlockWithTraits {
}
public func getImageHolders() -> [ImageHolder] { [] }
public func getRemoteURLs() -> [URL] {
(animationHolder as? RemoteAnimationHolder).map { [$0.url] } ?? []
}
}
extension RiveAnimationBlock: LayoutCachingDefaultImpl {}
@@ -1,4 +1,5 @@
import CoreGraphics
import Foundation
import VGSL
public final class AnchorBlock: BlockWithLayout, BlockWithTraits {
@@ -152,6 +153,10 @@ public final class AnchorBlock: BlockWithLayout, BlockWithTraits {
contents.flatMap { $0.getImageHolders() }
}
public func getRemoteURLs() -> [URL] {
contents.flatMap { $0.getRemoteURLs() }
}
public func updated(withStates states: BlocksState) throws -> Self {
try Self(
direction: direction,
@@ -56,6 +56,10 @@ extension BackgroundBlock {
public func getImageHolders() -> [ImageHolder] {
child.getImageHolders() + background.getImageHolders()
}
public func getRemoteURLs() -> [URL] {
child.getRemoteURLs() + background.getRemoteURLs()
}
}
extension Block {
@@ -12,6 +12,7 @@ public protocol Block: AnyObject,
CustomDebugStringConvertible,
BlockRenderingImpl,
ImageContaining,
RemoteURLContaining,
LayoutCaching,
ElementStateUpdating,
ElementFocusUpdating,
@@ -545,6 +545,12 @@ extension ContainerBlock: ImageContaining {
}
}
extension ContainerBlock: RemoteURLContaining {
public func getRemoteURLs() -> [URL] {
children.flatMap { $0.content.getRemoteURLs() }
}
}
extension ContainerBlock: ElementStateUpdating {
public func updated(withStates states: BlocksState) throws -> ContainerBlock {
let newChildren = try children.map {
@@ -155,6 +155,12 @@ extension GalleryBlock: ImageContaining {
}
}
extension GalleryBlock: RemoteURLContaining {
public func getRemoteURLs() -> [URL] {
model.items.flatMap { $0.content.getRemoteURLs() }
}
}
extension GalleryBlock: ElementStateUpdating {
public func updated(withStates states: BlocksState) throws -> GalleryBlock {
let newBlocks = try model.items.map { try $0.content.updated(withStates: states) }
@@ -1,4 +1,5 @@
import CoreGraphics
import Foundation
import VGSL
public final class GridBlock: BlockWithTraits, BlockWithLayout {
@@ -142,6 +143,10 @@ public final class GridBlock: BlockWithTraits, BlockWithLayout {
items.flatMap { $0.contents.getImageHolders() }
}
public func getRemoteURLs() -> [URL] {
items.flatMap { $0.contents.getRemoteURLs() }
}
public func intrinsicContentHeight(forWidth width: CGFloat) -> CGFloat {
if case let .fixed(value) = heightTrait {
return value
@@ -1,4 +1,5 @@
import CoreGraphics
import Foundation
import VGSL
final class LaidOutBlock<T: BlockWithLayout>: Block {
@@ -65,6 +66,12 @@ extension LaidOutBlock: ImageContaining {
}
}
extension LaidOutBlock: RemoteURLContaining {
func getRemoteURLs() -> [URL] {
block.getRemoteURLs()
}
}
extension LaidOutBlock {
func updated(withStates states: BlocksState) throws -> LaidOutBlock {
let newBlock = try block.updated(withStates: states)
@@ -1,4 +1,5 @@
import CoreGraphics
import Foundation
import VGSL
public final class LayeredBlock: BlockWithTraits, BlockWithLayout {
@@ -103,6 +104,12 @@ extension LayeredBlock: ImageContaining {
}
}
extension LayeredBlock: RemoteURLContaining {
public func getRemoteURLs() -> [URL] {
children.flatMap { $0.content.getRemoteURLs() }
}
}
extension LayeredBlock: ElementStateUpdating {
public func updated(withStates states: BlocksState) throws -> LayeredBlock {
let newChildren = try children.map {
@@ -48,6 +48,12 @@ extension MaskedBlock: ImageContaining {
}
}
extension MaskedBlock: RemoteURLContaining {
public func getRemoteURLs() -> [URL] {
maskBlock.getRemoteURLs() + maskedBlock.getRemoteURLs()
}
}
extension MaskedBlock: ElementFocusUpdating {
public func updated(path: UIElementPath, isFocused: Bool) throws -> MaskedBlock {
let newMaskBlock = try maskBlock.updated(path: path, isFocused: isFocused)
@@ -106,6 +106,12 @@ extension PagerBlock: ImageContaining {
}
}
extension PagerBlock: RemoteURLContaining {
public func getRemoteURLs() -> [URL] {
gallery.items.flatMap { $0.content.getRemoteURLs() }
}
}
extension PagerBlock: ElementStateUpdating {
public func updated(withStates states: BlocksState) throws -> PagerBlock {
let newBlocks = try gallery.items.map { try $0.content.updated(withStates: states) }
@@ -0,0 +1,9 @@
import Foundation
public protocol RemoteURLContaining {
func getRemoteURLs() -> [URL]
}
extension RemoteURLContaining {
public func getRemoteURLs() -> [URL] { [] }
}
@@ -214,6 +214,12 @@ extension SwitchableContainerBlock: ImageContaining {
}
}
extension SwitchableContainerBlock: RemoteURLContaining {
public func getRemoteURLs() -> [URL] {
items.0.content.getRemoteURLs() + items.1.content.getRemoteURLs()
}
}
extension SwitchableContainerBlock: ElementStateUpdating {
public func updated(withStates states: BlocksState) throws -> SwitchableContainerBlock {
let newItems = try map(items) {
@@ -104,6 +104,12 @@ extension TabsBlock: ImageContaining {
}
}
extension TabsBlock: RemoteURLContaining {
public func getRemoteURLs() -> [URL] {
model.contentsModel.pages.flatMap { $0.block.getRemoteURLs() }
}
}
extension TabsBlock: ElementStateUpdating {
public func updated(withStates states: BlocksState) throws -> TabsBlock {
let newPages = try model.contentsModel.pages
@@ -48,6 +48,10 @@ public final class VideoBlock: BlockWithTraits {
public func getImageHolders() -> [ImageHolder] { [] }
public func getRemoteURLs() -> [URL] {
model.videoData.videos.map(\.url)
}
public func equals(_ other: Block) -> Bool {
guard let other = other as? VideoBlock else {
return false
@@ -53,6 +53,10 @@ public final class VideoBlockLegacy: BlockWithTraits {
preview.asArray()
}
public func getRemoteURLs() -> [URL] {
[videoAssetHolder.url]
}
public func equals(_ other: Block) -> Bool {
guard let other = other as? VideoBlockLegacy else {
return false
@@ -1,4 +1,5 @@
import CoreGraphics
import Foundation
import VGSL
public protocol WrapperBlock: SizeForwardingBlock {
@@ -23,6 +24,10 @@ extension WrapperBlock {
child.getImageHolders()
}
public func getRemoteURLs() -> [URL] {
child.getRemoteURLs()
}
public func updated(withStates states: BlocksState) throws -> Self {
let newChild = try child.updated(withStates: states)
return makeCopyIfChanged(wrapping: newChild)
@@ -377,19 +377,22 @@ private final class DecoratingView: UIControl, BlockViewProtocol, VisibleBoundsT
}
let oldModel = self.model
if self.model?.tooltips.isEmpty ?? true, !model.tooltips.isEmpty {
renderingDelegate?.tooltipAnchorViewAdded(anchorView: self)
} else if self.model?.tooltips.isEmpty == false, model.tooltips.isEmpty {
renderingDelegate?.tooltipAnchorViewRemoved(anchorView: self)
}
let shouldUpdateChildView = model.child !== self.model?.child
|| self.observer !== observer
|| self.renderingDelegate !== renderingDelegate
if oldModel?.tooltips.isEmpty == false, model.tooltips.isEmpty {
renderingDelegate?.tooltipAnchorViewRemoved(anchorView: self)
}
self.model = model
self.observer = observer
self.renderingDelegate = renderingDelegate
if oldModel?.tooltips.isEmpty ?? true, !model.tooltips.isEmpty {
renderingDelegate?.tooltipAnchorViewAdded(anchorView: self)
}
if oldModel?.blurEffect != model.blurEffect {
blurView = model.blurEffect.map { UIVisualEffectView(effect: UIBlurEffect(style: $0.cast())) }
}
@@ -1,3 +1,4 @@
import Foundation
import VGSL
public enum Background: Equatable {
@@ -124,6 +125,26 @@ extension Background: ImageContaining {
}
}
extension Background: RemoteURLContaining {
public func getRemoteURLs() -> [URL] {
switch self {
case let .composite(first, second, _):
first.getRemoteURLs() + second.getRemoteURLs()
case let .withInsets(background, _):
background.getRemoteURLs()
case let .block(block):
block.getRemoteURLs()
case .solidColor,
.tiledImage,
.image,
.ninePatchImage,
.gradient,
.transparentAction:
[]
}
}
}
extension [Background] {
public func composite() -> Element? {
if isEmpty { return nil }
@@ -1,3 +1,4 @@
import Foundation
import VGSL
public class TabPageViewModel {
@@ -49,6 +50,12 @@ extension TabPageViewModel: ImageContaining {
}
}
extension TabPageViewModel: RemoteURLContaining {
public func getRemoteURLs() -> [URL] {
block.getRemoteURLs()
}
}
extension TabPageViewModel: CustomDebugStringConvertible {
public var debugDescription: String {
"""