1
1
mirror of https://github.com/exyte/Macaw.git synced 2024-09-11 05:05:23 +03:00

Test fixes

Extra optional

Fix
This commit is contained in:
Alisa Mylnikova 2018-12-18 19:52:57 +07:00
parent bfd2cfcc56
commit b4510d327d
7 changed files with 128 additions and 23 deletions

View File

@ -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)

View File

@ -24,6 +24,12 @@
],
"node" : "Group"
},
{
"contents" : [
],
"node" : "Group"
},
{
"contents" : [
{
@ -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"

View File

@ -3,10 +3,10 @@ import Foundation
internal class CombineAnimation: BasicAnimation {
let animations: [BasicAnimation]
let toNodes: [Node]?
let toNodes: [Node]
let duration: Double
required init(animations: [BasicAnimation], during: Double = 1.0, delay: Double = 0.0, node: Node? = .none, toNodes: [Node]?) {
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
@ -82,7 +82,7 @@ internal class CombineAnimation: BasicAnimation {
}
public extension Sequence where Iterator.Element: Animation {
public func combine(delay: Double = 0.0, node: Node? = .none, toNodes: [Node]? = nil) -> Animation {
public func combine(delay: Double = 0.0, node: Node? = .none, toNodes: [Node] = []) -> Animation {
var toCombine = [BasicAnimation]()
self.forEach { animation in

View File

@ -7,7 +7,7 @@
//
class ShapeAnimation: AnimationImpl<Shape> {
let toParentGlobalTransfrom: Transform?
let toParentGlobalTransfrom: Transform
convenience init(animatedNode: Shape, finalValue: Shape, toParentGlobalTransfrom: Transform = .identity, animationDuration: Double, delay: Double = 0.0, autostart: Bool = false, fps: UInt = 30) {

View File

@ -9,16 +9,16 @@ import UIKit
extension AnimationProducer {
func createChildAnimations(_ combineAnimation: Animation, globalToPosition: Transform?, animations: [Animation] = []) -> [Animation] {
func createChildAnimations(_ combineAnimation: Animation, globalToPosition: Transform = .identity, animations: [Animation] = []) -> [Animation] {
guard let combine = combineAnimation as? CombineAnimation else {
return animations
}
let globalToPosition = globalToPosition ?? .identity
let globalToPosition = globalToPosition
let during = combine.duration
let delay = combine.delay
let fromNode = combine.node as! Group
let to = combine.toNodes!
let to = combine.toNodes
// Shapes on same hierarhy level
let fromShapes = fromNode.contents.compactMap { $0 as? Shape }
@ -110,13 +110,16 @@ extension AnimationProducer {
func addCombineAnimation(_ combineAnimation: Animation) {
guard let combine = combineAnimation as? CombineAnimation,
let renderer = combine.nodeRenderer,
let view = renderer.view,
let toBounds = combine.toNodes?.group().bounds else {
return
let view = renderer.view else {
return
}
let globalTransform = view.contentLayout.layout(rect: toBounds, into: view.frame.size.toMacaw())
let animations = createChildAnimations(combine, globalToPosition: globalTransform) as! [BasicAnimation]
var animations = combine.animations
if let toBounds = combine.toNodes.group().bounds {
let globalTransform = view.contentLayout.layout(rect: toBounds, into: view.frame.size.toMacaw())
let childAnimations = createChildAnimations(combine, globalToPosition: globalTransform) as! [BasicAnimation]
animations.append(contentsOf: childAnimations)
}
// Reversing
if combine.autoreverses {
@ -164,10 +167,10 @@ extension AnimationProducer {
if let next = combine.next {
longestAnimation?.next = next
}
}
combine.removeFunc = {
combine.removeFunc = {
animations.forEach { animation in
animation.removeFunc?()
}
@ -180,5 +183,3 @@ extension AnimationProducer {
}
}

View File

@ -149,7 +149,7 @@ fileprivate func generateShapeAnimation(from: Shape, to: Shape, animation: Shape
scaleAnimation.duration = duration
let parentPos = AnimationUtils.absolutePosition(animation.nodeRenderer?.parentRenderer)
let fromPos = parentPos.concat(with: from.place)
let toParentPos = animation.toParentGlobalTransfrom ?? parentPos
let toParentPos = animation.toParentGlobalTransfrom
let toPos = toParentPos.concat(with: to.place)
scaleAnimation.fromValue = CATransform3DMakeAffineTransform(fromPos.toCG())
scaleAnimation.toValue = CATransform3DMakeAffineTransform(toPos.toCG())

View File

@ -363,13 +363,11 @@ extension NodeRenderer: AnimationObserver {
}
@discardableResult fileprivate func calculateZPosition(_ nodeRenderer: NodeRenderer?, currentIndex: Int = 0) -> Int {
nodeRenderer?.zPosition = currentIndex
let tag = nodeRenderer?.node()?.tag.first
@discardableResult fileprivate func calculateZPosition(_ nodeRenderer: NodeRenderer, currentIndex: Int = 0) -> Int {
nodeRenderer.zPosition = currentIndex
if let groupRenderer = nodeRenderer as? GroupRenderer {
var i = currentIndex + 1
for child in groupRenderer.renderers {
let tag = child.node()?.tag.first
i = calculateZPosition(child, currentIndex: i)
}
return i