Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parsing regression in 4.3.0 from addition of parsing layer effects #2208

Merged
merged 4 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ protocol ClassFamily: Decodable {
/// The discriminator key.
static var discriminator: Discriminator { get }

/// The "unknown" fallback case if the type discriminator could not be parsed successfully.
static var unknown: Self { get }

/// Returns the class type of the object corresponding to the value.
func getType() -> AnyObject.Type
}
Expand All @@ -34,7 +37,7 @@ extension KeyedDecodingContainer {
var tmpContainer = container
while !container.isAtEnd {
let typeContainer = try container.nestedContainer(keyedBy: Discriminator.self)
let family: U = try typeContainer.decode(U.self, forKey: U.discriminator)
let family: U = (try? typeContainer.decodeIfPresent(U.self, forKey: U.discriminator)) ?? .unknown
if let type = family.getType() as? T.Type {
list.append(try tmpContainer.decode(type))
}
Expand All @@ -60,7 +63,7 @@ extension KeyedDecodingContainer {
var tmpContainer = container
while !container.isAtEnd {
let typeContainer = try container.nestedContainer(keyedBy: Discriminator.self)
let family: U = try typeContainer.decode(U.self, forKey: U.discriminator)
let family: U = (try? typeContainer.decodeIfPresent(U.self, forKey: U.discriminator)) ?? .unknown
if let type = family.getType() as? T.Type {
list.append(try tmpContainer.decode(type))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ class EffectValue: Codable, DictionaryInitializable {
}

required init(dictionary: [String: Any]) throws {
type = EffectValueType(rawValue: try dictionary.value(for: CodingKeys.type)) ?? .unknown
name = try dictionary.value(for: CodingKeys.name) ?? "Effect"
type = (try? dictionary.value(for: CodingKeys.type)).flatMap(EffectValueType.init(rawValue:)) ?? .unknown
name = (try? dictionary.value(for: CodingKeys.name)) ?? "Effect"
}

// MARK: Internal
Expand Down
5 changes: 5 additions & 0 deletions Sources/Private/Model/Layers/LayerModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ extension LayerType: ClassFamily {
return ShapeLayerModel.self
case .text:
return TextLayerModel.self
case .unknown:
return LayerModel.self
}
}
}
Expand All @@ -40,6 +42,7 @@ public enum LayerType: Int, Codable {
case null
case shape
case text
case unknown

public init(from decoder: Decoder) throws {
self = try LayerType(rawValue: decoder.singleValueContainer().decode(RawValue.self)) ?? .null
Expand Down Expand Up @@ -241,6 +244,8 @@ extension Array where Element == LayerModel {
return try ShapeLayerModel(dictionary: dictionary)
case .text:
return try TextLayerModel(dictionary: dictionary)
case .unknown:
return try LayerModel(dictionary: dictionary)
case .none:
return nil
}
Expand Down
1 change: 1 addition & 0 deletions Tests/Samples/Issues/issue_2206.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Supports Core Animation engine
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading