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

Added performance update for layer visibility #873

Merged
merged 1 commit into from
Apr 17, 2019
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 @@ -108,10 +108,13 @@ class CompositionLayer: CALayer, KeypathSearchable {

final func displayWithFrame(frame: CGFloat, forceUpdates: Bool) {
transformNode.updateTree(frame, forceUpdates: forceUpdates)
displayContentsWithFrame(frame: frame, forceUpdates: forceUpdates)
maskLayer?.updateWithFrame(frame: frame, forceUpdates: forceUpdates)
contentsLayer.transform = transformNode.globalTransform
let layerVisible = frame.isInRangeOrEqual(inFrame, outFrame)
/// Only update contents if current time is within the layers time bounds.
if layerVisible {
displayContentsWithFrame(frame: frame, forceUpdates: forceUpdates)
maskLayer?.updateWithFrame(frame: frame, forceUpdates: forceUpdates)
}
contentsLayer.transform = transformNode.globalTransform
contentsLayer.opacity = transformNode.opacity
contentsLayer.isHidden = !layerVisible
layerDelegate?.frameUpdated(frame: frame)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ extension Array where Element == LayerModel {
var childLayers = [LayerModel]()

for layer in self {
if let shapeLayer = layer as? ShapeLayerModel {
if layer.hidden == true {
let genericLayer = NullCompositionLayer(layer: layer)
compositionLayers.append(genericLayer)
layerMap[layer.index] = genericLayer
} else if let shapeLayer = layer as? ShapeLayerModel {
let shapeContainer = ShapeCompositionLayer(shapeLayer: shapeLayer)
compositionLayers.append(shapeContainer)
layerMap[layer.index] = shapeContainer
Expand Down
4 changes: 4 additions & 0 deletions lottie-swift/src/Private/Model/Layers/LayerModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ class LayerModel: Codable {
/// The type of matte if any.
let matte: MatteType?

let hidden: Bool

private enum CodingKeys : String, CodingKey {
case name = "nm"
case index = "ind"
Expand All @@ -121,6 +123,7 @@ class LayerModel: Codable {
case masks = "masksProperties"
case timeStretch = "sr"
case matte = "tt"
case hidden = "hd"
}

required init(from decoder: Decoder) throws {
Expand All @@ -138,5 +141,6 @@ class LayerModel: Codable {
self.masks = try container.decodeIfPresent([Mask].self, forKey: .masks)
self.timeStretch = try container.decodeIfPresent(Double.self, forKey: .timeStretch) ?? 1
self.matte = try container.decodeIfPresent(MatteType.self, forKey: .matte)
self.hidden = try container.decodeIfPresent(Bool.self, forKey: .hidden) ?? false
}
}
4 changes: 4 additions & 0 deletions lottie-swift/src/Private/Model/ShapeItems/ShapeItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,19 @@ class ShapeItem: Codable {
/// The type of shape
let type: ShapeType

let hidden: Bool

private enum CodingKeys : String, CodingKey {
case name = "nm"
case type = "ty"
case hidden = "hd"
}

required init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: ShapeItem.CodingKeys.self)
self.name = try container.decodeIfPresent(String.self, forKey: .name) ?? "Layer"
self.type = try container.decode(ShapeType.self, forKey: .type)
self.hidden = try container.decodeIfPresent(Bool.self, forKey: .hidden) ?? false
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ extension Array where Element == ShapeItem {
var nodeTree = NodeTree()

for item in self {
guard item.hidden == false else { continue }
if let fill = item as? Fill {
let node = FillNode(parentNode: nodeTree.rootNode, fill: fill)
nodeTree.rootNode = node
Expand Down