Skip to content

Commit

Permalink
Performance fix, see comment
Browse files Browse the repository at this point in the history
  • Loading branch information
OskarGroth committed Nov 3, 2016
1 parent fb5c638 commit c7ebcb8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
Binary file not shown.
9 changes: 8 additions & 1 deletion FlatButton/FlatButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,14 @@ public class FlatButton: NSButton, CALayerDelegate {
let borderColor = bgColor
layer?.animate(color: bgColor.cgColor, keyPath: "backgroundColor", duration: duration)
layer?.animate(color: borderColor.cgColor, keyPath: "borderColor", duration: duration)
titleLayer.animate(color: titleColor.cgColor, keyPath: "foregroundColor", duration: duration)

/* I started seeing high (~5%) background CPU usage in apps using
FlatButton, and was able to track it down to background CATextLayer animation calls
happening constantly, originating from the call below. It could be a CATextLayer bug.
For now I'm going with setting the color instantly as it fixes this issue. */
//titleLayer.animate(color: titleColor.cgColor, keyPath: "foregroundColor", duration: duration)
titleLayer.foregroundColor = titleColor.cgColor

iconLayer.animate(color: imageColor.cgColor, keyPath: "backgroundColor", duration: duration)
}

Expand Down

0 comments on commit c7ebcb8

Please sign in to comment.