Skip to content

Commit

Permalink
Release 29.9.0
Browse files Browse the repository at this point in the history
6849b7344361b31073f0521e36374770b9c63c42
  • Loading branch information
robot-divkit committed Mar 11, 2024
1 parent f439dae commit 1202f2a
Show file tree
Hide file tree
Showing 150 changed files with 1,556 additions and 1,260 deletions.
6 changes: 6 additions & 0 deletions .mapping.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"DivKit/Actions/DivVideoAction.swift":"divkit/public-ios/DivKit/Actions/DivVideoAction.swift",
"DivKit/Actions/FocusElementActionHandler.swift":"divkit/public-ios/DivKit/Actions/FocusElementActionHandler.swift",
"DivKit/Actions/OverflowMode.swift":"divkit/public-ios/DivKit/Actions/OverflowMode.swift",
"DivKit/Actions/ScrollMode.swift":"divkit/public-ios/DivKit/Actions/ScrollMode.swift",
"DivKit/Actions/SetVariableActionHandler.swift":"divkit/public-ios/DivKit/Actions/SetVariableActionHandler.swift",
"DivKit/Debug/Block+DebugInfo.swift":"divkit/public-ios/DivKit/Debug/Block+DebugInfo.swift",
"DivKit/Debug/DebugParams.swift":"divkit/public-ios/DivKit/Debug/DebugParams.swift",
Expand Down Expand Up @@ -858,6 +859,7 @@
"Specs/DivKit/29.6.0/DivKit.podspec":"divkit/public-ios/Specs/DivKit/29.6.0/DivKit.podspec",
"Specs/DivKit/29.7.0/DivKit.podspec":"divkit/public-ios/Specs/DivKit/29.7.0/DivKit.podspec",
"Specs/DivKit/29.8.0/DivKit.podspec":"divkit/public-ios/Specs/DivKit/29.8.0/DivKit.podspec",
"Specs/DivKit/29.9.0/DivKit.podspec":"divkit/public-ios/Specs/DivKit/29.9.0/DivKit.podspec",
"Specs/DivKitExtensions/24.3.0/DivKitExtensions.podspec":"divkit/public-ios/Specs/DivKitExtensions/24.3.0/DivKitExtensions.podspec",
"Specs/DivKitExtensions/25.0.0/DivKitExtensions.podspec":"divkit/public-ios/Specs/DivKitExtensions/25.0.0/DivKitExtensions.podspec",
"Specs/DivKitExtensions/25.1.0/DivKitExtensions.podspec":"divkit/public-ios/Specs/DivKitExtensions/25.1.0/DivKitExtensions.podspec",
Expand Down Expand Up @@ -900,6 +902,7 @@
"Specs/DivKitExtensions/29.6.0/DivKitExtensions.podspec":"divkit/public-ios/Specs/DivKitExtensions/29.6.0/DivKitExtensions.podspec",
"Specs/DivKitExtensions/29.7.0/DivKitExtensions.podspec":"divkit/public-ios/Specs/DivKitExtensions/29.7.0/DivKitExtensions.podspec",
"Specs/DivKitExtensions/29.8.0/DivKitExtensions.podspec":"divkit/public-ios/Specs/DivKitExtensions/29.8.0/DivKitExtensions.podspec",
"Specs/DivKitExtensions/29.9.0/DivKitExtensions.podspec":"divkit/public-ios/Specs/DivKitExtensions/29.9.0/DivKitExtensions.podspec",
"Specs/DivKit_LayoutKit/28.0.1/DivKit_LayoutKit.podspec":"divkit/public-ios/Specs/DivKit_LayoutKit/28.0.1/DivKit_LayoutKit.podspec",
"Specs/DivKit_LayoutKit/28.1.0/DivKit_LayoutKit.podspec":"divkit/public-ios/Specs/DivKit_LayoutKit/28.1.0/DivKit_LayoutKit.podspec",
"Specs/DivKit_LayoutKit/28.10.0/DivKit_LayoutKit.podspec":"divkit/public-ios/Specs/DivKit_LayoutKit/28.10.0/DivKit_LayoutKit.podspec",
Expand All @@ -924,6 +927,7 @@
"Specs/DivKit_LayoutKit/29.6.0/DivKit_LayoutKit.podspec":"divkit/public-ios/Specs/DivKit_LayoutKit/29.6.0/DivKit_LayoutKit.podspec",
"Specs/DivKit_LayoutKit/29.7.0/DivKit_LayoutKit.podspec":"divkit/public-ios/Specs/DivKit_LayoutKit/29.7.0/DivKit_LayoutKit.podspec",
"Specs/DivKit_LayoutKit/29.8.0/DivKit_LayoutKit.podspec":"divkit/public-ios/Specs/DivKit_LayoutKit/29.8.0/DivKit_LayoutKit.podspec",
"Specs/DivKit_LayoutKit/29.9.0/DivKit_LayoutKit.podspec":"divkit/public-ios/Specs/DivKit_LayoutKit/29.9.0/DivKit_LayoutKit.podspec",
"Specs/DivKit_LayoutKitInterface/28.0.1/DivKit_LayoutKitInterface.podspec":"divkit/public-ios/Specs/DivKit_LayoutKitInterface/28.0.1/DivKit_LayoutKitInterface.podspec",
"Specs/DivKit_LayoutKitInterface/28.1.0/DivKit_LayoutKitInterface.podspec":"divkit/public-ios/Specs/DivKit_LayoutKitInterface/28.1.0/DivKit_LayoutKitInterface.podspec",
"Specs/DivKit_LayoutKitInterface/28.10.0/DivKit_LayoutKitInterface.podspec":"divkit/public-ios/Specs/DivKit_LayoutKitInterface/28.10.0/DivKit_LayoutKitInterface.podspec",
Expand All @@ -948,6 +952,7 @@
"Specs/DivKit_LayoutKitInterface/29.6.0/DivKit_LayoutKitInterface.podspec":"divkit/public-ios/Specs/DivKit_LayoutKitInterface/29.6.0/DivKit_LayoutKitInterface.podspec",
"Specs/DivKit_LayoutKitInterface/29.7.0/DivKit_LayoutKitInterface.podspec":"divkit/public-ios/Specs/DivKit_LayoutKitInterface/29.7.0/DivKit_LayoutKitInterface.podspec",
"Specs/DivKit_LayoutKitInterface/29.8.0/DivKit_LayoutKitInterface.podspec":"divkit/public-ios/Specs/DivKit_LayoutKitInterface/29.8.0/DivKit_LayoutKitInterface.podspec",
"Specs/DivKit_LayoutKitInterface/29.9.0/DivKit_LayoutKitInterface.podspec":"divkit/public-ios/Specs/DivKit_LayoutKitInterface/29.9.0/DivKit_LayoutKitInterface.podspec",
"Specs/DivKit_Serialization/28.0.1/DivKit_Serialization.podspec":"divkit/public-ios/Specs/DivKit_Serialization/28.0.1/DivKit_Serialization.podspec",
"Specs/DivKit_Serialization/28.1.0/DivKit_Serialization.podspec":"divkit/public-ios/Specs/DivKit_Serialization/28.1.0/DivKit_Serialization.podspec",
"Specs/DivKit_Serialization/28.10.0/DivKit_Serialization.podspec":"divkit/public-ios/Specs/DivKit_Serialization/28.10.0/DivKit_Serialization.podspec",
Expand All @@ -972,6 +977,7 @@
"Specs/DivKit_Serialization/29.6.0/DivKit_Serialization.podspec":"divkit/public-ios/Specs/DivKit_Serialization/29.6.0/DivKit_Serialization.podspec",
"Specs/DivKit_Serialization/29.7.0/DivKit_Serialization.podspec":"divkit/public-ios/Specs/DivKit_Serialization/29.7.0/DivKit_Serialization.podspec",
"Specs/DivKit_Serialization/29.8.0/DivKit_Serialization.podspec":"divkit/public-ios/Specs/DivKit_Serialization/29.8.0/DivKit_Serialization.podspec",
"Specs/DivKit_Serialization/29.9.0/DivKit_Serialization.podspec":"divkit/public-ios/Specs/DivKit_Serialization/29.9.0/DivKit_Serialization.podspec",
"Specs/LayoutKit/24.3.0/LayoutKit.podspec":"divkit/public-ios/Specs/LayoutKit/24.3.0/LayoutKit.podspec",
"Specs/LayoutKit/25.0.0/LayoutKit.podspec":"divkit/public-ios/Specs/LayoutKit/25.0.0/LayoutKit.podspec",
"Specs/LayoutKit/25.1.0/LayoutKit.podspec":"divkit/public-ios/Specs/LayoutKit/25.1.0/LayoutKit.podspec",
Expand Down
53 changes: 37 additions & 16 deletions DivKit/Actions/DivActionHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,13 @@ public final class DivActionHandler {
params: UserInterfaceAction.DivActionParams,
sender: AnyObject?
) {
let action: DivActionBase?
switch params.source {
let action: DivActionBase? = switch params.source {
case .visibility:
action = parseAction(type: DivVisibilityActionTemplate.self, json: params.action)
parseAction(type: DivVisibilityActionTemplate.self, json: params.action)
case .disappear:
action = parseAction(type: DivDisappearActionTemplate.self, json: params.action)
parseAction(type: DivDisappearActionTemplate.self, json: params.action)
default:
action = parseAction(type: DivActionTemplate.self, json: params.action)
parseAction(type: DivActionTemplate.self, json: params.action)
}
guard let action else {
return
Expand All @@ -113,6 +112,7 @@ public final class DivActionHandler {
action,
cardId: DivCardID(rawValue: params.cardId),
source: params.source,
prototypeVariables: params.prototypeVariables,
sender: sender
)
}
Expand All @@ -121,9 +121,13 @@ public final class DivActionHandler {
_ action: DivActionBase,
cardId: DivCardID,
source: UserInterfaceAction.DivActionSource,
prototypeVariables: [String: AnyHashable] = [:],
sender: AnyObject?
) {
let expressionResolver = makeExpressionResolver(cardId: cardId)
let expressionResolver = makeExpressionResolver(
cardId: cardId,
prototypeVariables: prototypeVariables
)
let context = DivActionHandlingContext(
cardId: cardId,
expressionResolver: expressionResolver,
Expand Down Expand Up @@ -192,15 +196,19 @@ public final class DivActionHandler {
guard let self else {
return
}
let callbackActions: [DivAction]
switch result {
let callbackActions: [DivAction] = switch result {
case .success:
callbackActions = action.downloadCallbacks?.onSuccessActions ?? []
action.downloadCallbacks?.onSuccessActions ?? []
case .failure:
callbackActions = action.downloadCallbacks?.onFailActions ?? []
action.downloadCallbacks?.onFailActions ?? []
}
callbackActions.forEach {
self.handle($0, cardId: context.cardId, source: source, sender: sender)
self.handle(
$0,
cardId: context.cardId,
source: source,
sender: sender
)
}
}
)
Expand All @@ -226,11 +234,24 @@ public final class DivActionHandler {
}
}

private func makeExpressionResolver(cardId: DivCardID) -> ExpressionResolver {
ExpressionResolver(
variables: variablesStorage.makeVariables(for: cardId),
persistentValuesStorage: persistentValuesStorage,
errorTracker: reporter.asExpressionErrorTracker(cardId: cardId)
private func makeExpressionResolver(
cardId: DivCardID,
prototypeVariables: [String: AnyHashable]
) -> ExpressionResolver {
let variableValueProvider = makeVariableValueProvider(
cardId: cardId,
variablesStorage: variablesStorage,
prototypesStorage: prototypeVariables
)
let functionsProvider = FunctionsProvider(
variableValueProvider: variableValueProvider,
persistentValuesStorage: persistentValuesStorage
)
return ExpressionResolver(
variableValueProvider: variableValueProvider,
functionsProvider: functionsProvider,
errorTracker: reporter.asExpressionErrorTracker(cardId: cardId),
variableTracker: { _ in }
)
}

Expand Down
30 changes: 30 additions & 0 deletions DivKit/Actions/DivActionIntent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ enum DivActionIntent {
case setCurrentItem(id: String, index: Int)
case setNextItem(id: String, overflow: OverflowMode)
case setPreviousItem(id: String, overflow: OverflowMode)
case scroll(id: String, mode: ScrollMode)
case timer(id: String, action: DivTimerAction)
case video(id: String, action: DivVideoAction)
case setStoredValue(storedValue: DivStoredValue)
Expand Down Expand Up @@ -64,6 +65,31 @@ enum DivActionIntent {
return nil
}
self = .setPreviousItem(id: id, overflow: url.overflow)
case "scroll_forward":
guard let id = url.id, let step = url.step else {
return nil
}
self = .scroll(id: id, mode: .forward(step: step, overflow: url.overflow))
case "scroll_backward":
guard let id = url.id, let step = url.step else {
return nil
}
self = .scroll(id: id, mode: .backward(step: step, overflow: url.overflow))
case "scroll_to_position":
guard let id = url.id, let step = url.step else {
return nil
}
self = .scroll(id: id, mode: .position(step: step))
case "scroll_to_start":
guard let id = url.id else {
return nil
}
self = .scroll(id: id, mode: .start)
case "scroll_to_end":
guard let id = url.id else {
return nil
}
self = .scroll(id: id, mode: .end)
case "timer":
guard let id = url.id, let action = url.timerAction else {
return nil
Expand Down Expand Up @@ -171,6 +197,10 @@ extension URL {
return .clamp
}
}

fileprivate var step: CGFloat? {
queryParamValue(forName: "step").flatMap(Int.init).flatMap(CGFloat.init)
}

fileprivate var storedValue: DivStoredValue? {
guard let name = getParam(forName: "name"),
Expand Down
82 changes: 73 additions & 9 deletions DivKit/Actions/DivActionURLHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ public final class DivActionURLHandler {
case let .setPreviousItem(id, overflow):
setPreviousItem(id: id, cardId: cardId, overflow: overflow)
updateCard(.state(cardId))
case let .scroll(id, mode):
setContentOffset(id: id, cardId: cardId, mode: mode)
case let .video(id: id, action: action):
blockStateStorage.setState(
id: id,
Expand Down Expand Up @@ -143,14 +145,62 @@ public final class DivActionURLHandler {
}
}

private func setContentOffset(id: String, cardId: DivCardID, mode: ScrollMode) {
let state: GalleryViewState? = blockStateStorage.getState(id, cardId: cardId)
if let state, let newOffset = getNewOffset(state: state, mode: mode) {
blockStateStorage.setState(
id: id,
cardId: cardId,
state: GalleryViewState(
contentPosition: .offset(newOffset),
itemsCount: state.itemsCount,
isScrolling: state.isScrolling,
scrollRange: state.scrollRange
)
)
updateCard(.state(cardId))
}
}

private func getNewOffset(state: GalleryViewState, mode: ScrollMode) -> CGFloat? {
guard let scrollRange = state.scrollRange, scrollRange > 0 else {
return nil
}
switch mode {
case let .forward(step, overflow):
return getOffset(offset: state.currentOffset + step, scrollRange: scrollRange, overflow: overflow)
case let .backward(step, overflow):
return getOffset(offset: state.currentOffset - step, scrollRange: scrollRange, overflow: overflow)
case let .position(step):
return getOffset(offset: step, scrollRange: scrollRange, overflow: .clamp)
case .start:
return 0
case .end:
return scrollRange
}
}

private func getOffset(
offset: CGFloat,
scrollRange: CGFloat,
overflow: OverflowMode
) -> CGFloat {
switch overflow {
case .ring:
return (offset + scrollRange).truncatingRemainder(dividingBy: scrollRange)
case .clamp:
return offset.clamp(0...scrollRange)
}
}

private func setCurrentItem(id: String, cardId: DivCardID, index: Int) {
switch blockStateStorage.getStateUntyped(id, cardId: cardId) {
case let galleryState as GalleryViewState:
setGalleryCurrentItem(
id: id,
cardId: cardId,
index: index,
itemsCount: galleryState.itemsCount
state: galleryState
)
case let pagerState as PagerViewState:
setPagerCurrentItem(
Expand Down Expand Up @@ -178,7 +228,7 @@ public final class DivActionURLHandler {
id: id,
cardId: cardId,
index: index,
itemsCount: galleryState.itemsCount
state: galleryState
)
case let pagerState as PagerViewState:
let nextIndex = getNextIndex(
Expand Down Expand Up @@ -237,7 +287,7 @@ public final class DivActionURLHandler {
id: id,
cardId: cardId,
index: index,
itemsCount: galleryState.itemsCount
state: galleryState
)
case let pagerState as PagerViewState:
let prevIndex = getPreviousIndex(
Expand Down Expand Up @@ -288,18 +338,20 @@ public final class DivActionURLHandler {
id: String,
cardId: DivCardID,
index: Int,
itemsCount: Int
state: GalleryViewState
) {
let clampedIndex = clamp(index, min: 0, max: max(0, itemsCount - 1))
let clampedIndex = clamp(index, min: 0, max: max(0, state.itemsCount - 1))
guard clampedIndex == index else {
return
}
blockStateStorage.setState(
id: id,
cardId: cardId,
state: GalleryViewState(
contentPageIndex: CGFloat(clampedIndex),
itemsCount: itemsCount
contentPosition: .paging(index: CGFloat(clampedIndex)),
itemsCount: state.itemsCount,
isScrolling: state.isScrolling,
scrollRange: state.scrollRange
)
)
}
Expand Down Expand Up @@ -340,9 +392,21 @@ extension GalleryViewState {
fileprivate var currentItemIndex: Int {
switch contentPosition {
case let .offset(_, firstVisibleItemsIndex):
return firstVisibleItemsIndex
firstVisibleItemsIndex
case let .paging(index):
return Int(index)
Int(index)
}
}

fileprivate var currentOffset: CGFloat {
switch contentPosition {
case let .offset(value, _):
return value
case let .paging(index):
guard let scrollRange, itemsCount > 0 else {
return 0
}
return scrollRange / CGFloat(itemsCount - 1) * index
}
}
}
9 changes: 9 additions & 0 deletions DivKit/Actions/ScrollMode.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Foundation

enum ScrollMode {
case forward(step: CGFloat, overflow: OverflowMode)
case backward(step: CGFloat, overflow: OverflowMode)
case position(step: CGFloat)
case start
case end
}
7 changes: 3 additions & 4 deletions DivKit/Debug/DebugParams.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,10 @@ public struct DebugParams {
#if os(iOS)
extension DebugParams {
public static func showDebugInfo(_ view: ViewType) {
let window: UIWindow?
if #available(iOS 13.0, *) {
window = (UIApplication.shared.connectedScenes.first as? UIWindowScene)?.windows.first
let window: UIWindow? = if #available(iOS 13.0, *) {
(UIApplication.shared.connectedScenes.first as? UIWindowScene)?.windows.first
} else {
window = UIApplication.shared.windows.first
UIApplication.shared.windows.first
}
view.frame.center = window?.center ?? .zero
window?.addSubview(view)
Expand Down
2 changes: 1 addition & 1 deletion DivKit/DivBlockModelingContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public struct DivBlockModelingContext {
private let variableTracker: ExpressionResolver.VariableTracker
public private(set) var parentPath: UIElementPath
private(set) var sizeModifier: DivSizeModifier?
private var prototypesStorage = [String: Any]()
private(set) var prototypesStorage = [String: AnyHashable]()

public init(
cardId: DivCardID,
Expand Down
4 changes: 2 additions & 2 deletions DivKit/DivError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ extension DeserializationError: DivError {
private func getPath(parent: UIElementPath?) -> UIElementPath? {
switch self {
case let .nestedObjectError(field, error):
return error.getPath(parent: parent.map { $0 + field } ?? UIElementPath(field))
error.getPath(parent: parent.map { $0 + field } ?? UIElementPath(field))
default:
return parent
parent
}
}

Expand Down
Loading

0 comments on commit 1202f2a

Please sign in to comment.