Skip to content

Commit

Permalink
Release 30.2.0
Browse files Browse the repository at this point in the history
79bd0343d44eebd1d4bd8ebab5336b0871e79a14
  • Loading branch information
robot-divkit committed May 27, 2024
1 parent ad3a7d2 commit 8642362
Show file tree
Hide file tree
Showing 34 changed files with 800 additions and 830 deletions.
10 changes: 7 additions & 3 deletions .mapping.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,12 @@
"DivKit/Expressions/ExpressionLink.swift":"divkit/public-ios/DivKit/Expressions/ExpressionLink.swift",
"DivKit/Expressions/ExpressionResolver.swift":"divkit/public-ios/DivKit/Expressions/ExpressionResolver.swift",
"DivKit/Expressions/ExpressionValueConverter.swift":"divkit/public-ios/DivKit/Expressions/ExpressionValueConverter.swift",
"DivKit/Expressions/Functions/AnyHashableExtensions.swift":"divkit/public-ios/DivKit/Expressions/Functions/AnyHashableExtensions.swift",
"DivKit/Expressions/Functions/ArrayFunctions.swift":"divkit/public-ios/DivKit/Expressions/Functions/ArrayFunctions.swift",
"DivKit/Expressions/Functions/BooleanOperators.swift":"divkit/public-ios/DivKit/Expressions/Functions/BooleanOperators.swift",
"DivKit/Expressions/Functions/CastFunctions.swift":"divkit/public-ios/DivKit/Expressions/Functions/CastFunctions.swift",
"DivKit/Expressions/Functions/ColorFunctions.swift":"divkit/public-ios/DivKit/Expressions/Functions/ColorFunctions.swift",
"DivKit/Expressions/Functions/ComparisonOperators.swift":"divkit/public-ios/DivKit/Expressions/Functions/ComparisonOperators.swift",
"DivKit/Expressions/Functions/DatetimeFunctions.swift":"divkit/public-ios/DivKit/Expressions/Functions/DatetimeFunctions.swift",
"DivKit/Expressions/Functions/DateTimeFunctions.swift":"divkit/public-ios/DivKit/Expressions/Functions/DateTimeFunctions.swift",
"DivKit/Expressions/Functions/DictFunctions.swift":"divkit/public-ios/DivKit/Expressions/Functions/DictFunctions.swift",
"DivKit/Expressions/Functions/EqualityOperators.swift":"divkit/public-ios/DivKit/Expressions/Functions/EqualityOperators.swift",
"DivKit/Expressions/Functions/Function.swift":"divkit/public-ios/DivKit/Expressions/Functions/Function.swift",
Expand Down Expand Up @@ -746,7 +745,7 @@
"LayoutKit/LayoutKit/ViewModels/VideoBlockViewState.swift":"divkit/public-ios/LayoutKit/LayoutKit/ViewModels/VideoBlockViewState.swift",
"LayoutKit/LayoutKit/ViewModels/VisibilityActionPerformer/VisibilityActionPerformer.swift":"divkit/public-ios/LayoutKit/LayoutKit/ViewModels/VisibilityActionPerformer/VisibilityActionPerformer.swift",
"LayoutKit/LayoutKit/ViewModels/VisibilityActionPerformer/VisibilityActionPerformers.swift":"divkit/public-ios/LayoutKit/LayoutKit/ViewModels/VisibilityActionPerformer/VisibilityActionPerformers.swift",
"LayoutKit/LayoutKit/ViewModels/VisibilityActionPerformer/VisibilityCheckParam.swift":"divkit/public-ios/LayoutKit/LayoutKit/ViewModels/VisibilityActionPerformer/VisibilityCheckParam.swift",
"LayoutKit/LayoutKit/ViewModels/VisibilityActionPerformer/VisibilityParams.swift":"divkit/public-ios/LayoutKit/LayoutKit/ViewModels/VisibilityActionPerformer/VisibilityParams.swift",
"Package.swift":"divkit/public-ios/Package.swift",
"README.md":"divkit/public-ios/README.md",
"Serialization/Deserializable.swift":"divkit/public-ios/Serialization/Deserializable.swift",
Expand Down Expand Up @@ -878,6 +877,7 @@
"Specs/DivKit/29.9.0/DivKit.podspec":"divkit/public-ios/Specs/DivKit/29.9.0/DivKit.podspec",
"Specs/DivKit/30.0.0/DivKit.podspec":"divkit/public-ios/Specs/DivKit/30.0.0/DivKit.podspec",
"Specs/DivKit/30.1.0/DivKit.podspec":"divkit/public-ios/Specs/DivKit/30.1.0/DivKit.podspec",
"Specs/DivKit/30.2.0/DivKit.podspec":"divkit/public-ios/Specs/DivKit/30.2.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 @@ -931,6 +931,7 @@
"Specs/DivKitExtensions/29.9.0/DivKitExtensions.podspec":"divkit/public-ios/Specs/DivKitExtensions/29.9.0/DivKitExtensions.podspec",
"Specs/DivKitExtensions/30.0.0/DivKitExtensions.podspec":"divkit/public-ios/Specs/DivKitExtensions/30.0.0/DivKitExtensions.podspec",
"Specs/DivKitExtensions/30.1.0/DivKitExtensions.podspec":"divkit/public-ios/Specs/DivKitExtensions/30.1.0/DivKitExtensions.podspec",
"Specs/DivKitExtensions/30.2.0/DivKitExtensions.podspec":"divkit/public-ios/Specs/DivKitExtensions/30.2.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 Down Expand Up @@ -966,6 +967,7 @@
"Specs/DivKit_LayoutKit/29.9.0/DivKit_LayoutKit.podspec":"divkit/public-ios/Specs/DivKit_LayoutKit/29.9.0/DivKit_LayoutKit.podspec",
"Specs/DivKit_LayoutKit/30.0.0/DivKit_LayoutKit.podspec":"divkit/public-ios/Specs/DivKit_LayoutKit/30.0.0/DivKit_LayoutKit.podspec",
"Specs/DivKit_LayoutKit/30.1.0/DivKit_LayoutKit.podspec":"divkit/public-ios/Specs/DivKit_LayoutKit/30.1.0/DivKit_LayoutKit.podspec",
"Specs/DivKit_LayoutKit/30.2.0/DivKit_LayoutKit.podspec":"divkit/public-ios/Specs/DivKit_LayoutKit/30.2.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 Down Expand Up @@ -1001,6 +1003,7 @@
"Specs/DivKit_LayoutKitInterface/29.9.0/DivKit_LayoutKitInterface.podspec":"divkit/public-ios/Specs/DivKit_LayoutKitInterface/29.9.0/DivKit_LayoutKitInterface.podspec",
"Specs/DivKit_LayoutKitInterface/30.0.0/DivKit_LayoutKitInterface.podspec":"divkit/public-ios/Specs/DivKit_LayoutKitInterface/30.0.0/DivKit_LayoutKitInterface.podspec",
"Specs/DivKit_LayoutKitInterface/30.1.0/DivKit_LayoutKitInterface.podspec":"divkit/public-ios/Specs/DivKit_LayoutKitInterface/30.1.0/DivKit_LayoutKitInterface.podspec",
"Specs/DivKit_LayoutKitInterface/30.2.0/DivKit_LayoutKitInterface.podspec":"divkit/public-ios/Specs/DivKit_LayoutKitInterface/30.2.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 Down Expand Up @@ -1036,6 +1039,7 @@
"Specs/DivKit_Serialization/29.9.0/DivKit_Serialization.podspec":"divkit/public-ios/Specs/DivKit_Serialization/29.9.0/DivKit_Serialization.podspec",
"Specs/DivKit_Serialization/30.0.0/DivKit_Serialization.podspec":"divkit/public-ios/Specs/DivKit_Serialization/30.0.0/DivKit_Serialization.podspec",
"Specs/DivKit_Serialization/30.1.0/DivKit_Serialization.podspec":"divkit/public-ios/Specs/DivKit_Serialization/30.1.0/DivKit_Serialization.podspec",
"Specs/DivKit_Serialization/30.2.0/DivKit_Serialization.podspec":"divkit/public-ios/Specs/DivKit_Serialization/30.2.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
2 changes: 1 addition & 1 deletion DivKit/DivFlagsInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public struct DivFlagsInfo {

/// Creates an instance of `DivFlagsInfo`.
public init(
imageLoadingOptimizationEnabled: Bool = false
imageLoadingOptimizationEnabled: Bool = true
) {
self.imageLoadingOptimizationEnabled = imageLoadingOptimizationEnabled
}
Expand Down
2 changes: 1 addition & 1 deletion DivKit/DivImageHolderFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ final class DefaultImageHolderFactory: DivImageHolderFactory {

init(
requestPerformer: URLRequestPerforming,
imageLoadingOptimizationEnabled: Bool
imageLoadingOptimizationEnabled: Bool = true
) {
self.requester = NetworkURLResourceRequester(performer: requestPerformer)
self.imageLoadingOptimizationEnabled = imageLoadingOptimizationEnabled
Expand Down
2 changes: 1 addition & 1 deletion DivKit/DivKitInfo.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
public enum DivKitInfo {
public static let version = "30.1.0"
public static let version = "30.2.0"
}
14 changes: 0 additions & 14 deletions DivKit/Expressions/CalcExpression/CalcExpression.swift
Original file line number Diff line number Diff line change
Expand Up @@ -295,17 +295,6 @@ extension UnicodeScalarView {
}
}

func scanHex() -> String? {
scanCharacters {
switch $0 {
case "0"..."9", "A"..."F", "a"..."f":
true
default:
false
}
}
}

func scanExponent() -> String? {
let start = self
if let e = scanCharacter({ $0 == "e" || $0 == "E" }) {
Expand All @@ -323,9 +312,6 @@ extension UnicodeScalarView {
var endOfInt = self
let sign = scanCharacter { $0 == "-" } ?? ""
if let integer = scanInteger() {
if integer == "0", scanCharacter("x") {
return .integer("\(sign)0x\(scanHex() ?? "")")
}
endOfInt = self
if scanCharacter(".") {
guard let fraction = scanInteger() else {
Expand Down
2 changes: 1 addition & 1 deletion DivKit/Expressions/ExpressionError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public struct ExpressionError: LocalizedError, CustomStringConvertible {

static func incorrectType(_ expectedType: String, _ value: AnyHashable) -> Error {
ExpressionError(
"Incorrect value type: expected \"\(expectedType)\", got \"\(value.actualType)\"."
"Incorrect value type: expected \(expectedType), got \(formatTypeForError(value))."
)
}

Expand Down
26 changes: 24 additions & 2 deletions DivKit/Expressions/ExpressionValueConverter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@ enum ExpressionValueConverter {
}
}

extension AnyHashable {
var isBool: Bool {
if let number = self as? NSNumber {
return UnicodeScalar(UInt8(number.objCType.pointee)) == "c"
}
return false
}
}

func formatArgForError(_ value: Any) -> String {
switch value {
case is String:
Expand All @@ -76,6 +85,8 @@ func formatArgForError(_ value: Any) -> String {

func formatTypeForError(_ type: Any.Type) -> String {
switch type {
case is String.Type:
"String"
case is Bool.Type:
"Boolean"
case is Int.Type:
Expand All @@ -88,15 +99,26 @@ func formatTypeForError(_ type: Any.Type) -> String {
"DateTime"
case is [AnyHashable].Type:
"Array"
case is [String: AnyHashable].Type:
case is [String: AnyHashable].Type, is [AnyHashable: AnyHashable].Type:
"Dict"
default:
String(describing: type)
}
}

func formatTypeForError(_ value: Any) -> String {
formatTypeForError(type(of: value))
let valueType = type(of: value)
if valueType is AnyHashable.Type, let hashableValue = value as? AnyHashable {
switch type(of: hashableValue.base) {
case is Double.Type, is Int.Type, is Int64.Type:
return "Number"
case is NSNull.Type:
return "Null"
default:
return formatTypeForError(hashableValue.base)
}
}
return formatTypeForError(valueType)
}

private func formatValue(_ value: Any) -> String {
Expand Down
23 changes: 0 additions & 23 deletions DivKit/Expressions/Functions/AnyHashableExtensions.swift

This file was deleted.

52 changes: 26 additions & 26 deletions DivKit/Expressions/Functions/ArrayFunctions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,47 +53,47 @@ extension [String: Function] {
}
}

private var _getArray = FunctionBinary<[AnyHashable], Int, [AnyHashable]> {
private let _getArray = FunctionBinary<[AnyHashable], Int, [AnyHashable]> {
try $0.getArray(index: $1)
}

private var _getBoolean = FunctionBinary<[AnyHashable], Int, Bool> {
private let _getBoolean = FunctionBinary<[AnyHashable], Int, Bool> {
try $0.getBoolean(index: $1)
}

private var _getColor = FunctionBinary<[AnyHashable], Int, Color> {
private let _getColor = FunctionBinary<[AnyHashable], Int, Color> {
try $0.getColor(index: $1)
}

private var _getDict = FunctionBinary<[AnyHashable], Int, Dict> {
private let _getDict = FunctionBinary<[AnyHashable], Int, Dict> {
try $0.getDict(index: $1)
}

private var _getInteger = FunctionBinary<[AnyHashable], Int, Int> {
private let _getInteger = FunctionBinary<[AnyHashable], Int, Int> {
try $0.getInteger(index: $1)
}

private var _getNumber = FunctionBinary<[AnyHashable], Int, Double> {
private let _getNumber = FunctionBinary<[AnyHashable], Int, Double> {
try $0.getNumber(index: $1)
}

private var _getString = FunctionBinary<[AnyHashable], Int, String> {
private let _getString = FunctionBinary<[AnyHashable], Int, String> {
try $0.getString(index: $1)
}

private var _getUrl = FunctionBinary<[AnyHashable], Int, URL> {
private let _getUrl = FunctionBinary<[AnyHashable], Int, URL> {
try $0.getUrl(index: $1)
}

private var _getOptArray = FunctionBinary<[AnyHashable], Int, [AnyHashable]> {
private let _getOptArray = FunctionBinary<[AnyHashable], Int, [AnyHashable]> {
(try? $0.getArray(index: $1)) ?? []
}

private var _getOptBoolean = FunctionTernary<[AnyHashable], Int, Bool, Bool> {
private let _getOptBoolean = FunctionTernary<[AnyHashable], Int, Bool, Bool> {
(try? $0.getBoolean(index: $1)) ?? $2
}

private var _getOptColor = OverloadedFunction(functions: [
private let _getOptColor = OverloadedFunction(functions: [
FunctionTernary<[AnyHashable], Int, Color, Color> {
(try? $0.getColor(index: $1)) ?? $2
},
Expand All @@ -105,23 +105,23 @@ private var _getOptColor = OverloadedFunction(functions: [
},
])

private var _getOptDict = FunctionBinary<[AnyHashable], Int, Dict> {
private let _getOptDict = FunctionBinary<[AnyHashable], Int, Dict> {
(try? $0.getDict(index: $1)) ?? [:]
}

private var _getOptInteger = FunctionTernary<[AnyHashable], Int, Int, Int> {
private let _getOptInteger = FunctionTernary<[AnyHashable], Int, Int, Int> {
(try? $0.getInteger(index: $1)) ?? $2
}

private var _getOptNumber = FunctionTernary<[AnyHashable], Int, Double, Double> {
private let _getOptNumber = FunctionTernary<[AnyHashable], Int, Double, Double> {
(try? $0.getNumber(index: $1)) ?? $2
}

private var _getOptString = FunctionTernary<[AnyHashable], Int, String, String> {
private let _getOptString = FunctionTernary<[AnyHashable], Int, String, String> {
(try? $0.getString(index: $1)) ?? $2
}

private var _getOptUrl = OverloadedFunction(functions: [
private let _getOptUrl = OverloadedFunction(functions: [
FunctionTernary<[AnyHashable], Int, URL, URL> {
(try? $0.getUrl(index: $1)) ?? $2
},
Expand All @@ -137,31 +137,31 @@ extension [AnyHashable] {
fileprivate func getArray(index: Int) throws -> [AnyHashable] {
let value = try getValue(index: index)
guard let arrayValue = value as? [AnyHashable] else {
throw ExpressionError.incorrectType("array", value)
throw ExpressionError.incorrectType("Array", value)
}
return arrayValue
}

fileprivate func getDict(index: Int) throws -> Dict {
let value = try getValue(index: index)
guard let dictValue = value as? Dict else {
throw ExpressionError.incorrectType("dict", value)
throw ExpressionError.incorrectType("Dict", value)
}
return dictValue
}

fileprivate func getBoolean(index: Int) throws -> Bool {
let value = try getValue(index: index)
guard value.isBool, let boolValue = value as? Bool else {
throw ExpressionError.incorrectType("boolean", value)
throw ExpressionError.incorrectType("Boolean", value)
}
return boolValue
}

fileprivate func getColor(index: Int) throws -> Color {
let value = try getValue(index: index)
guard let stringValue = value as? String else {
throw ExpressionError.incorrectType("color", value)
throw ExpressionError.incorrectType("Color", value)
}
guard let color = Color.color(withHexString: stringValue) else {
throw ExpressionError("Unable to convert value to Color, expected format #AARRGGBB.")
Expand All @@ -172,7 +172,7 @@ extension [AnyHashable] {
fileprivate func getInteger(index: Int) throws -> Int {
let value = try getValue(index: index)
if value.isBool {
throw ExpressionError.incorrectType("integer", value)
throw ExpressionError.incorrectType("Integer", value)
}
guard let intValue = value as? Int else {
if let doubleValue = value as? Double {
Expand All @@ -181,29 +181,29 @@ extension [AnyHashable] {
}
throw ExpressionError("Cannot convert value to integer.")
}
throw ExpressionError.incorrectType("integer", value)
throw ExpressionError.incorrectType("Integer", value)
}
return intValue
}

fileprivate func getNumber(index: Int) throws -> Double {
let value = try getValue(index: index)
if value.isBool {
throw ExpressionError.incorrectType("number", value)
throw ExpressionError.incorrectType("Number", value)
}
if let numberValue = value as? Double {
return numberValue
}
if let intValue = value as? Int {
return Double(intValue)
}
throw ExpressionError.incorrectType("number", value)
throw ExpressionError.incorrectType("Number", value)
}

fileprivate func getString(index: Int) throws -> String {
let value = try getValue(index: index)
guard let stringValue = value as? String else {
throw ExpressionError.incorrectType("string", value)
throw ExpressionError.incorrectType("String", value)
}
return stringValue
}
Expand All @@ -214,7 +214,7 @@ extension [AnyHashable] {
let stringValue = value as? String,
let url = URL(string: stringValue)
else {
throw ExpressionError.incorrectType("url", value)
throw ExpressionError.incorrectType("Url", value)
}
return url
}
Expand Down
Loading

0 comments on commit 8642362

Please sign in to comment.