mirror of
https://github.com/divkit/divkit.git
synced 2026-06-06 20:07:59 +00:00
Тк reuseId добавили в div-base, решил сделать так: 1) Для Block добавил `reuseId: String?` с дефолтной реализацией nil 2) Добавил хранимое свойство reв DecoratingBlock 3) Присваиваю это свойство в applyBaseProperties предпоследним шагом перед экстеншенами 4) Добавил вычисляемые свойства к `WrapperBlock`, ` 4) Для `TabsView` удалил CollectionCellModel, там все время был один reuseId для всех типов, форс касты `Block` к этому типу 5) Для `GalleryView` и `TabView`: регистрирую `reuse_id` блоков в collectionView, если они ранее не были зареганы 6) Для того, чтобы reuseId работал в `Grid`, добавил reuseId в DecoratingBlock Model https://arcanum.yandex-team.ru/arcadia/divkit/public-ios/LayoutKit/LayoutKit/UI/Blocks/DecoratingBlock+UIViewRenderableBlock.swift?rev=rXXXXXX#L17 dbbb8fd9aeb382b18821a8a5289ff2b0314c1f01
77 lines
2.3 KiB
Swift
77 lines
2.3 KiB
Swift
import CoreGraphics
|
|
|
|
import LayoutKit
|
|
import VGSL
|
|
|
|
extension DivShapeDrawable {
|
|
func makeBlock(
|
|
context: DivBlockModelingContext,
|
|
widthTrait: DivDrawableWidthTrait,
|
|
corners: CGRect.Corners
|
|
) -> Block {
|
|
let expressionResolver = context.expressionResolver
|
|
switch shape {
|
|
case let .divRoundedRectangleShape(roundedRectangle):
|
|
let separatorBlock: Block
|
|
switch widthTrait {
|
|
case .fixed:
|
|
let width = CGFloat(
|
|
roundedRectangle.itemWidth
|
|
.resolveValue(expressionResolver) ?? 0
|
|
)
|
|
separatorBlock = SeparatorBlock(size: width)
|
|
case .resizable:
|
|
separatorBlock = SeparatorBlock()
|
|
}
|
|
let height = CGFloat(
|
|
roundedRectangle
|
|
.itemHeight
|
|
.resolveValue(expressionResolver) ?? 0
|
|
)
|
|
let cornerRadius = CGFloat(
|
|
roundedRectangle
|
|
.cornerRadius
|
|
.resolveValue(expressionResolver) ?? 0
|
|
)
|
|
let blockBorder = stroke.flatMap { BlockBorder(
|
|
color: $0.resolveColor(expressionResolver) ?? .black,
|
|
width: CGFloat($0.resolveWidth(expressionResolver)) / 2
|
|
) }
|
|
return separatorBlock
|
|
.addingVerticalGaps(height / 2 - 0.5)
|
|
.addingDecorations(
|
|
boundary: .clipCorner(radius: cornerRadius, corners: corners),
|
|
border: blockBorder,
|
|
backgroundColor: resolveColor(expressionResolver)
|
|
)
|
|
case .divCircleShape:
|
|
context.addError(message: "Unsupported shape type: circle")
|
|
return EmptyBlock()
|
|
}
|
|
}
|
|
|
|
func resolveWidth(_ context: DivBlockModelingContext) -> CGFloat {
|
|
switch shape {
|
|
case let .divRoundedRectangleShape(rectangle):
|
|
return CGFloat(rectangle.itemWidth.resolveValue(context.expressionResolver) ?? 0)
|
|
case .divCircleShape:
|
|
context.addError(message: "Unsupported shape type: circle")
|
|
return 0
|
|
}
|
|
}
|
|
|
|
func resolveHeight(_ context: DivBlockModelingContext) -> CGFloat {
|
|
switch shape {
|
|
case let .divRoundedRectangleShape(rectangle):
|
|
let expressionResolver = context.expressionResolver
|
|
let stroke = stroke?.resolveWidth(expressionResolver) ?? 0
|
|
return CGFloat(
|
|
Double(rectangle.itemHeight.resolveValue(expressionResolver) ?? 0) + stroke
|
|
)
|
|
case .divCircleShape:
|
|
context.addError(message: "Unsupported shape type: circle")
|
|
return 0
|
|
}
|
|
}
|
|
}
|