-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
commit_hash:3382acdf9d443706895eae2c474378499eddd133
- Loading branch information
robot-divkit
committed
Jan 20, 2025
1 parent
5e7bef5
commit baeae01
Showing
337 changed files
with
2,960 additions
and
873 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
import Foundation | ||
|
||
import LayoutKit | ||
|
||
public struct DivActionInfo { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
import Foundation | ||
|
||
import VGSL | ||
|
||
enum DivActionIntent { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
import CoreGraphics | ||
import Foundation | ||
|
||
import LayoutKit | ||
import VGSL | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,83 +1,28 @@ | ||
import CoreGraphics | ||
import Foundation | ||
|
||
import LayoutKit | ||
import VGSL | ||
|
||
extension Block { | ||
func addingDebugInfo(context: DivBlockModelingContext) -> Block { | ||
let debugParams = context.debugParams | ||
guard debugParams.isDebugInfoEnabled else { | ||
return self | ||
} | ||
|
||
let errors = context.errorsStorage.errors | ||
let errorsCount = errors.count | ||
guard errorsCount > 0 else { | ||
guard debugParams.isDebugInfoEnabled, | ||
let debugErrorCollector = context.debugErrorCollector else { | ||
return self | ||
} | ||
|
||
let counterText = errorsCount > maxCount | ||
? "\(maxCount)+" | ||
: "\(errorsCount)" | ||
|
||
let typo = Typo(font: context.fontProvider.font(size: 14)) | ||
.with(color: .white) | ||
|
||
let action = UserInterfaceAction( | ||
payload: .url(DebugInfoBlock.showOverlayURL), | ||
path: context.parentPath + "div_errors_indicator", | ||
accessibilityElement: nil | ||
) | ||
|
||
let counter = TextBlock( | ||
widthTrait: .intrinsic, | ||
text: counterText.with(typo: typo) | ||
) | ||
|
||
let indicator = counter | ||
.addingVerticalGaps(errorsButtonCounterGaps) | ||
.addingHorizontalGaps(calculateCounterHorizontalGaps(counter: counter)) | ||
.addingDecorations( | ||
boundary: .clipCorner(radius: 10), | ||
backgroundColor: .red | ||
) | ||
.addingEdgeInsets(debugParams.errorCounterInsets) | ||
.addingEdgeGaps(2) | ||
.addingAccessibilityID(withTraits: ( | ||
"divLayoutErrorCounter", | ||
.button | ||
)) | ||
.addingDecorations(action: action) | ||
|
||
let debugInfoBlock = DebugInfoBlock( | ||
child: indicator, | ||
showDebugInfo: { | ||
#if os(iOS) | ||
debugParams.showDebugInfo(ErrorListView(errors: errors.map(\.prettyMessage))) | ||
#else | ||
return | ||
#endif | ||
} | ||
let debugBlock = DebugBlock( | ||
errorCollector: debugErrorCollector, | ||
showDebugInfo: debugParams.showDebugInfo | ||
) | ||
|
||
let block = LayeredBlock( | ||
widthTrait: calculatedWidthTrait, | ||
heightTrait: calculatedHeightTrait, | ||
children: [self, debugInfoBlock] | ||
verticalChildrenAlignment: .center, | ||
children: [self, debugBlock] | ||
) | ||
|
||
return block | ||
} | ||
} | ||
|
||
private func calculateCounterHorizontalGaps(counter: Block) -> CGFloat { | ||
let additionalGap = (counter.intrinsicSize.height - counter.intrinsicSize.width) / 2 | ||
return max( | ||
errorsButtonCounterGaps, | ||
errorsButtonCounterGaps + additionalGap | ||
) | ||
} | ||
|
||
private let errorsButtonCounterGaps: CGFloat = 4 | ||
private let maxCount = 9999 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import LayoutKit | ||
import UIKit | ||
import VGSL | ||
|
||
extension DebugBlock: UIViewRenderable { | ||
static func makeBlockView() -> any LayoutKit.BlockView { | ||
DebugBlockView() | ||
} | ||
|
||
func canConfigureBlockView(_ view: any LayoutKit.BlockView) -> Bool { | ||
view is DebugBlockView | ||
} | ||
|
||
func configureBlockView( | ||
_ view: BlockView, | ||
observer _: ElementStateObserver?, | ||
overscrollDelegate _: ScrollDelegate?, | ||
renderingDelegate _: RenderingDelegate? | ||
) { | ||
(view as? DebugBlockView)?.configure( | ||
errorCollector: errorCollector, | ||
showDebugInfo: showDebugInfo | ||
) | ||
} | ||
} | ||
|
||
private final class DebugBlockView: BlockView, VisibleBoundsTrackingContainer { | ||
let effectiveBackgroundColor: UIColor? = nil | ||
let visibleBoundsTrackingSubviews: [VisibleBoundsTrackingView] = [] | ||
|
||
private var showDebugInfo: ((ViewType) -> Void)? | ||
private var errorCollector: DebugErrorCollector? | ||
private let disposePool = AutodisposePool() | ||
|
||
private let errorsLabel: UILabel = { | ||
let label = UILabel(frame: CGRect(origin: .zero, size: CGSize(squareDimension: 50.0))) | ||
label.text = "0" | ||
label.numberOfLines = 1 | ||
label.font = .systemFont(ofSize: 14) | ||
label.textColor = .white | ||
label.textAlignment = .center | ||
label.backgroundColor = .red | ||
label.isHidden = true | ||
return label | ||
}() | ||
|
||
init() { | ||
super.init(frame: .zero) | ||
addSubview(errorsLabel) | ||
accessibilityIdentifier = "divLayoutErrorCounter" | ||
accessibilityTraits = .button | ||
clipsToBounds = true | ||
addGestureRecognizer(UITapGestureRecognizer( | ||
target: self, | ||
action: #selector(handleTapGesture(_:)) | ||
)) | ||
} | ||
|
||
@available(*, unavailable) | ||
required init?(coder _: NSCoder) { | ||
fatalError("init(coder:) has not been implemented") | ||
} | ||
|
||
func configure( | ||
errorCollector: DebugErrorCollector, | ||
showDebugInfo: @escaping (ViewType) -> Void | ||
) { | ||
self.showDebugInfo = showDebugInfo | ||
if self.errorCollector !== errorCollector { | ||
self.errorCollector = errorCollector | ||
errorCollector.observableErrorCount.currentAndNewValues.addObserver { [weak self] _ in | ||
self?.updateCountLabel() | ||
}.dispose(in: disposePool) | ||
} | ||
} | ||
|
||
override func layoutSubviews() { | ||
super.layoutSubviews() | ||
errorsLabel.frame = bounds | ||
layer.cornerRadius = bounds.size.height / 2 | ||
} | ||
|
||
private func updateCountLabel() { | ||
let errorsCount = errorCollector?.totalErrorCount ?? 0 | ||
let isHidden = errorsCount == 0 | ||
isUserInteractionEnabled = !isHidden | ||
errorsLabel.isHidden = isHidden | ||
errorsLabel.text = "\(min(maxCount, errorsCount))" | ||
} | ||
|
||
@objc func handleTapGesture(_: UITapGestureRecognizer) { | ||
guard let showDebugInfo, let errorCollector, errorCollector.totalErrorCount > 0 else { return } | ||
showDebugInfo(ErrorListView(errors: errorCollector.errorList)) | ||
} | ||
} | ||
|
||
private let showOverlayURL = URL(string: "debugInfo://show")! | ||
private let maxCount = 9999 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import Foundation | ||
import LayoutKit | ||
import VGSL | ||
|
||
final class DebugBlock: BlockWithTraits, LayoutCachingDefaultImpl { | ||
let widthTrait = LayoutTrait.fixed(buttonSize) | ||
let heightTrait = LayoutTrait.fixed(buttonSize) | ||
|
||
var intrinsicContentWidth: CGFloat { | ||
widthTrait.fixedValue ?? 0.0 | ||
} | ||
|
||
func intrinsicContentHeight(forWidth _: CGFloat) -> CGFloat { | ||
heightTrait.fixedValue ?? 0.0 | ||
} | ||
|
||
let errorCollector: DebugErrorCollector | ||
let showDebugInfo: (ViewType) -> Void | ||
|
||
init( | ||
errorCollector: DebugErrorCollector, | ||
showDebugInfo: @escaping (ViewType) -> Void | ||
) { | ||
self.errorCollector = errorCollector | ||
self.showDebugInfo = showDebugInfo | ||
} | ||
|
||
func equals(_ other: any LayoutKit.Block) -> Bool { | ||
if self === other { return true } | ||
guard let other = other as? DebugBlock else { return false } | ||
return errorCollector === other.errorCollector | ||
} | ||
|
||
var debugDescription: String { | ||
"DebugBlock errors: \(errorCollector.debugDescription))" | ||
} | ||
|
||
func getImageHolders() -> [any VGSLUI.ImageHolder] { | ||
[] | ||
} | ||
|
||
func updated(withStates _: LayoutKit.BlocksState) throws -> Self { | ||
self | ||
} | ||
} | ||
|
||
private let buttonSize = 50.0 |
Oops, something went wrong.