mirror of
https://github.com/divkit/divkit.git
synced 2026-06-06 20:07:59 +00:00
Extension handler support in DivState
This commit is contained in:
@@ -18,7 +18,17 @@ import LayoutKit
|
||||
public protocol DivExtensionHandler: AccessibilityContaining {
|
||||
/// A unique identifier for the extension.
|
||||
var id: String { get }
|
||||
|
||||
|
||||
/// Notifies extension handler that div will be processed by DivKit.
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - div: The `DivBase` to which extension handler is attached.
|
||||
/// - context: The context in which the block is being modeled.
|
||||
func accept(
|
||||
div: DivBase,
|
||||
context: DivBlockModelingContext
|
||||
)
|
||||
|
||||
/// Applies additional properties to the block before the base properties.
|
||||
///
|
||||
/// - Parameters:
|
||||
@@ -49,6 +59,11 @@ public protocol DivExtensionHandler: AccessibilityContaining {
|
||||
}
|
||||
|
||||
extension DivExtensionHandler {
|
||||
public func accept(
|
||||
div: DivBase,
|
||||
context: DivBlockModelingContext
|
||||
) {}
|
||||
|
||||
public func applyBeforeBaseProperties(
|
||||
to block: Block,
|
||||
div _: DivBase,
|
||||
|
||||
@@ -14,6 +14,12 @@ extension DivBase {
|
||||
customAccessibilityParams: CustomAccessibilityParams = .default,
|
||||
clipToBounds: Bool = true
|
||||
) throws -> Block {
|
||||
let extensionHandlers = context.getExtensionHandlers(for: self)
|
||||
|
||||
extensionHandlers.forEach {
|
||||
$0.accept(div: self, context: context)
|
||||
}
|
||||
|
||||
let expressionResolver = context.expressionResolver
|
||||
let statePath = context.parentDivStatePath ?? DivData.rootPath
|
||||
|
||||
@@ -26,7 +32,7 @@ extension DivBase {
|
||||
|
||||
var block = try block()
|
||||
|
||||
let extensionHandlers = context.getExtensionHandlers(for: self)
|
||||
|
||||
extensionHandlers.forEach {
|
||||
block = $0.applyBeforeBaseProperties(to: block, div: self, context: context)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user