-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
robot-divkit
committed
May 16, 2023
1 parent
a3c2f9f
commit 8283519
Showing
69 changed files
with
2,218 additions
and
289 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
enum DivVideoAction { | ||
case play | ||
case pause | ||
} |
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,21 +1,5 @@ | ||
public struct DivFlagsInfo { | ||
public let isTextSelectingEnabled: Bool | ||
public let appendVariablesEnabled: Bool | ||
public let metalImageRenderingEnabled: Bool | ||
public init() {} | ||
|
||
public init( | ||
isTextSelectingEnabled: Bool, | ||
appendVariablesEnabled: Bool, | ||
metalImageRenderingEnabled: Bool | ||
) { | ||
self.isTextSelectingEnabled = isTextSelectingEnabled | ||
self.appendVariablesEnabled = appendVariablesEnabled | ||
self.metalImageRenderingEnabled = metalImageRenderingEnabled | ||
} | ||
|
||
public static let `default` = DivFlagsInfo( | ||
isTextSelectingEnabled: false, | ||
appendVariablesEnabled: true, | ||
metalImageRenderingEnabled: false | ||
) | ||
public static let `default` = DivFlagsInfo() | ||
} |
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,3 +1,3 @@ | ||
public enum DivKitInfo { | ||
public static let version = "24.3.0" | ||
public static let version = "25.0.0" | ||
} |
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 |
---|---|---|
@@ -0,0 +1,117 @@ | ||
import BaseTinyPublic | ||
import Foundation | ||
|
||
fileprivate typealias GetOrDefaultWithTransform<U, T> = (String, U) throws -> T | ||
fileprivate typealias GetOrDefault<T> = GetOrDefaultWithTransform<T, T> | ||
|
||
enum ValueFunctions: String, CaseIterable { | ||
case getIntegerValue | ||
case getNumberValue | ||
case getStringValue | ||
case getUrlValue | ||
case getColorValue | ||
case getBooleanValue | ||
|
||
func getDeclaration(resolver: ExpressionResolver) | ||
-> [AnyCalcExpression.Symbol: AnyCalcExpression.SymbolEvaluator] { | ||
[ | ||
.function( | ||
rawValue, | ||
arity: getFunction(resolver: resolver).arity | ||
): getFunction(resolver: resolver) | ||
.symbolEvaluator, | ||
] | ||
} | ||
|
||
func getFunction(resolver: ExpressionResolver) -> Function { | ||
switch self { | ||
case .getIntegerValue: | ||
let function: GetOrDefault<Int> = resolver.getValueFunction() | ||
return FunctionBinary(impl: function) | ||
case .getNumberValue: | ||
let function: GetOrDefault<Double> = resolver.getValueFunction() | ||
return FunctionBinary(impl: function) | ||
case .getStringValue: | ||
let function: GetOrDefault<String> = resolver.getValueFunction() | ||
return FunctionBinary(impl: function) | ||
case .getUrlValue: | ||
let fromUrlFunction: GetOrDefault<URL> = resolver.getValueFunction() | ||
let fromStringFunction: GetOrDefaultWithTransform<String, URL> = resolver | ||
.getValueFunctionWithTransform { | ||
guard let url = URL(string: $0) else { | ||
throw AnyCalcExpression.Error.toURL($0) | ||
} | ||
return url | ||
} | ||
return OverloadedFunction(functions: [ | ||
FunctionBinary(impl: fromUrlFunction), | ||
FunctionBinary(impl: fromStringFunction), | ||
]) | ||
case .getColorValue: | ||
let fromColorFunction: GetOrDefault<Color> = resolver.getValueFunction() | ||
let fromStringFunction: GetOrDefaultWithTransform<String, Color> = resolver | ||
.getValueFunctionWithTransform { | ||
guard let color = Color.color(withHexString: $0) else { | ||
throw AnyCalcExpression.Error.toColor($0) | ||
} | ||
return color | ||
} | ||
return OverloadedFunction(functions: [ | ||
FunctionBinary(impl: fromColorFunction), | ||
FunctionBinary(impl: fromStringFunction), | ||
]) | ||
case .getBooleanValue: | ||
let function: GetOrDefault<Bool> = resolver.getValueFunction() | ||
return FunctionBinary(impl: function) | ||
} | ||
} | ||
} | ||
|
||
extension ExpressionResolver { | ||
fileprivate func getValueFunction<T>() -> GetOrDefault<T> { | ||
{ name, fallbackValue in | ||
guard let value = self.getValue(name) else { | ||
return fallbackValue | ||
} | ||
let typpedValue: T? = value as? T | ||
if typpedValue == nil { | ||
DivKitLogger.warning("The type of the variable \(name) is not \(T.self)") | ||
} | ||
return typpedValue ?? fallbackValue | ||
} | ||
} | ||
|
||
fileprivate func getValueFunctionWithTransform< | ||
T, | ||
U | ||
>(transform: @escaping (U) throws -> T) -> GetOrDefaultWithTransform<U, T> { | ||
{ name, fallbackValue in | ||
guard let value = self.getValue(name) else { | ||
return try transform(fallbackValue) | ||
} | ||
let typpedValue: T? = value as? T | ||
if typpedValue == nil { | ||
DivKitLogger.warning("The type of the variable \(name) is not \(T.self)") | ||
} | ||
return try typpedValue ?? transform(fallbackValue) | ||
} | ||
} | ||
} | ||
|
||
extension AnyCalcExpression.Error { | ||
fileprivate static func toColor(_ value: Any?) -> AnyCalcExpression.Error { | ||
.message( | ||
"Failed to get Color from (\(formatValue(value))). Unable to convert value to Color." | ||
) | ||
} | ||
|
||
fileprivate static func toURL(_ value: Any?) -> AnyCalcExpression.Error { | ||
.message( | ||
"Failed to get URL from (\(formatValue(value))). Unable to convert value to URL." | ||
) | ||
} | ||
|
||
private static func formatValue(_ value: Any?) -> String { | ||
(value as? CustomStringConvertible)?.description ?? "" | ||
} | ||
} |
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
Oops, something went wrong.