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

Task/fix boy animation #512

Merged
merged 4 commits into from
Dec 20, 2018
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
6 changes: 6 additions & 0 deletions Macaw.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,8 @@
5BAE204C208E1EF4006BF277 /* SVGCanvas.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BAE201E208E1211006BF277 /* SVGCanvas.swift */; };
5BAE2058208F24DE006BF277 /* SceneSerialization.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BAE2057208F24DE006BF277 /* SceneSerialization.swift */; };
5BAEA9C9206CEAA20049AAAE /* viewBox.svg in Resources */ = {isa = PBXBuildFile; fileRef = 5BAEA9C8206CEAA20049AAAE /* viewBox.svg */; };
5BC2CA0D21C7B8F500AC46D9 /* CombinationAnimationGenerator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BC2CA0C21C7B8F400AC46D9 /* CombinationAnimationGenerator.swift */; };
5BC2CA0E21C7B8F900AC46D9 /* CombinationAnimationGenerator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BC2CA0C21C7B8F400AC46D9 /* CombinationAnimationGenerator.swift */; };
5BFEF5CE20B80A83008DAC11 /* BlendEffect.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BFEF5CC20B80A82008DAC11 /* BlendEffect.swift */; };
5BFEF5CF20B80A83008DAC11 /* BlendEffect.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BFEF5CC20B80A82008DAC11 /* BlendEffect.swift */; };
5BFEF5D020B80A83008DAC11 /* ColorMatrixEffect.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BFEF5CD20B80A83008DAC11 /* ColorMatrixEffect.swift */; };
Expand Down Expand Up @@ -894,6 +896,7 @@
5BAE2035208E163C006BF277 /* clip.reference */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = clip.reference; sourceTree = "<group>"; };
5BAE2057208F24DE006BF277 /* SceneSerialization.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SceneSerialization.swift; sourceTree = "<group>"; };
5BAEA9C8206CEAA20049AAAE /* viewBox.svg */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = viewBox.svg; sourceTree = "<group>"; };
5BC2CA0C21C7B8F400AC46D9 /* CombinationAnimationGenerator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CombinationAnimationGenerator.swift; sourceTree = "<group>"; };
5BFEF5CC20B80A82008DAC11 /* BlendEffect.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BlendEffect.swift; sourceTree = "<group>"; };
5BFEF5CD20B80A83008DAC11 /* ColorMatrixEffect.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ColorMatrixEffect.swift; sourceTree = "<group>"; };
5BFEF5D420BC1C1E008DAC11 /* paths-data-18-f-manual.svg */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "paths-data-18-f-manual.svg"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1121,6 +1124,7 @@
57E5E0FC1E3B393900D1CB28 /* OpacityGenerator.swift */,
5B7D7ED221300D4A00B5ED00 /* TimingFunction.swift */,
57E5E0FE1E3B393900D1CB28 /* TransformGenerator.swift */,
5BC2CA0C21C7B8F400AC46D9 /* CombinationAnimationGenerator.swift */,
);
path = animation_generators;
sourceTree = "<group>";
Expand Down Expand Up @@ -2094,6 +2098,7 @@
5B6E194220AC58F900454E7E /* Color.swift in Sources */,
57614B551F83D15600875933 /* Common_iOS.swift in Sources */,
57614B561F83D15600875933 /* Common_macOS.swift in Sources */,
5BC2CA0E21C7B8F900AC46D9 /* CombinationAnimationGenerator.swift in Sources */,
57614B571F83D15600875933 /* MDisplayLink.swift in Sources */,
57614B591F83D15600875933 /* Event.swift in Sources */,
57614B5B1F83D15600875933 /* Interpolable.swift in Sources */,
Expand Down Expand Up @@ -2233,6 +2238,7 @@
5B6E194120AC58F900454E7E /* Color.swift in Sources */,
A718CD4D1F45C28F00966E06 /* Common_macOS.swift in Sources */,
57F1087A1F53C92000DC365B /* MDisplayLink.swift in Sources */,
5BC2CA0D21C7B8F500AC46D9 /* CombinationAnimationGenerator.swift in Sources */,
57E5E1741E3B393900D1CB28 /* Event.swift in Sources */,
57E5E15D1E3B393900D1CB28 /* Interpolable.swift in Sources */,
57E5E1731E3B393900D1CB28 /* Variable.swift in Sources */,
Expand Down
6 changes: 3 additions & 3 deletions MacawTests/Animation/AnimationUtilsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ class AnimationUtilsTests: XCTestCase {
XCTAssert(aRenderer?.zPosition == 1)
XCTAssert(bRenderer?.zPosition == 2)
XCTAssert(cRenderer?.zPosition == 3)
XCTAssert(dRenderer?.zPosition == 4 )
XCTAssert(eRenderer?.zPosition == 5 )
XCTAssert(fRenderer?.zPosition == 6 )
XCTAssert(dRenderer?.zPosition == 4)
XCTAssert(eRenderer?.zPosition == 5)
XCTAssert(fRenderer?.zPosition == 6)
}
}
5 changes: 3 additions & 2 deletions MacawTests/MacawSVGTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,9 @@ class MacawSVGTests: XCTestCase {

func createJSON(_ testResourcePath: String) {
do {
let node = try SVGParser.parse(fullPath: testResourcePath)
let path = testResourcePath.replacingOccurrences(of: ".svg", with: ".reference")
let bundle = Bundle(for: type(of: TestUtils()))
let node = try SVGParser.parse(resource: testResourcePath, fromBundle: bundle)
let path = testResourcePath + ".reference"
try getJSONData(node: node).write(to: URL(fileURLWithPath: path))
} catch {
XCTFail(error.localizedDescription)
Expand Down
105 changes: 105 additions & 0 deletions MacawTests/w3cSVGTests/struct-use-12-f-manual.reference
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@
],
"node" : "Group"
},
{
"contents" : [

],
"node" : "Group"
},
{
"contents" : [
{
Expand All @@ -47,6 +53,105 @@
}
],
"node" : "Group"
},
{
"contents" : [
{
"contents" : [
{
"contents" : [

],
"node" : "Group"
}
],
"node" : "Group"
}
],
"node" : "Group"
}
],
"node" : "Group"
},
{
"contents" : [
{
"contents" : [

],
"node" : "Group"
},
{
"contents" : [

],
"node" : "Group"
}
],
"node" : "Group"
},
{
"contents" : [
{
"contents" : [
{
"contents" : [

],
"node" : "Group"
}
],
"node" : "Group"
}
],
"node" : "Group"
},
{
"contents" : [
{
"contents" : [

],
"node" : "Group"
},
{
"contents" : [

],
"node" : "Group"
}
],
"node" : "Group"
},
{
"contents" : [
{
"contents" : [

],
"node" : "Group"
},
{
"contents" : [

],
"node" : "Group"
}
],
"node" : "Group"
},
{
"contents" : [
{
"contents" : [
{
"contents" : [

],
"node" : "Group"
}
],
"node" : "Group"
}
],
"node" : "Group"
Expand Down
69 changes: 1 addition & 68 deletions Source/animation/AnimationProducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ class AnimationProducer {
}

// MARK: - Sequence animation
fileprivate func addAnimationSequence(_ animationSequnce: Animation) {
func addAnimationSequence(_ animationSequnce: Animation) {
guard let sequence = animationSequnce as? AnimationSequence else {
return
}
Expand Down Expand Up @@ -197,73 +197,6 @@ class AnimationProducer {
}
}

// MARK: - Combine animation
fileprivate func addCombineAnimation(_ combineAnimation: Animation) {
guard let combine = combineAnimation as? CombineAnimation else {
return
}

// Reversing
if combine.autoreverses {
combine.animations.forEach { animation in
animation.autoreverses = true
}
}

// repeat count
if combine.repeatCount > 0.00001 {
var sequence = [Animation]()

for _ in 0..<Int(combine.repeatCount) {
sequence.append(combine)
}

combine.repeatCount = 0.0
addAnimationSequence(sequence.sequence())
return
}

// Looking for longest animation
var longestAnimation: BasicAnimation?
combine.animations.forEach { animation in
guard let longest = longestAnimation else {
longestAnimation = animation
return
}

if longest.getDuration() < animation.getDuration() {
longestAnimation = animation
}
}

// Attaching completion empty animation and potential next animation
if let completion = combine.completion {
let completionAnimation = EmptyAnimation(completion: completion)
if let next = combine.next {
completionAnimation.next = next
}

longestAnimation?.next = completionAnimation

} else {
if let next = combine.next {
longestAnimation?.next = next
}

}

combine.removeFunc = { [weak combine] in
combine?.animations.forEach { animation in
animation.removeFunc?()
}
}

// Launching
combine.animations.forEach { animation in
self.addAnimation(animation)
}
}

// MARK: - Empty Animation
fileprivate func executeCompletion(_ emptyAnimation: BasicAnimation) {
emptyAnimation.completion?()
Expand Down
9 changes: 9 additions & 0 deletions Source/animation/AnimationUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ class AnimationUtils {
parentRenderer = parentRenderer?.parentRenderer
}

var rootRenderer = nodeRenderer
while rootRenderer?.parentRenderer != nil {
rootRenderer = rootRenderer?.parentRenderer
}
if let view = rootRenderer?.view, let bounds = rootRenderer?.node()?.bounds {
let a = view.contentLayout.layout(rect: bounds, into: view.bounds.size.toMacaw())
transform = transform.concat(with: a)
}

return transform
}

Expand Down
10 changes: 7 additions & 3 deletions Source/animation/types/CombineAnimation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ import Foundation
internal class CombineAnimation: BasicAnimation {

let animations: [BasicAnimation]
let toNodes: [Node]
let duration: Double

required init(animations: [BasicAnimation], delay: Double = 0.0, node: Node? = .none) {
required init(animations: [BasicAnimation], during: Double = 1.0, delay: Double = 0.0, node: Node? = .none, toNodes: [Node] = []) {
self.animations = animations
self.duration = during
self.toNodes = toNodes

super.init()

Expand Down Expand Up @@ -78,12 +82,12 @@ internal class CombineAnimation: BasicAnimation {
}

public extension Sequence where Iterator.Element: Animation {
public func combine(delay: Double = 0.0, node: Node? = .none) -> Animation {
public func combine(delay: Double = 0.0, node: Node? = .none, toNodes: [Node] = []) -> Animation {

var toCombine = [BasicAnimation]()
self.forEach { animation in
toCombine.append(animation as! BasicAnimation)
}
return CombineAnimation(animations: toCombine, delay: delay, node: node ?? toCombine.first?.node)
return CombineAnimation(animations: toCombine, delay: delay, node: node ?? toCombine.first?.node, toNodes: toNodes)
}
}
Loading