Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
Motion
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Dmitriy Stepanets
Motion
Commits
959610e1
Unverified
Commit
959610e1
authored
Jun 10, 2017
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
reworked MotionTransition+MotionStringConvertible
parent
682b0543
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
120 additions
and
95 deletions
+120
-95
Sources/MotionTransition+MotionStringConvertible.swift
+120
-95
No files found.
Sources/MotionTransition+MotionStringConvertible.swift
View file @
959610e1
...
@@ -28,105 +28,130 @@
...
@@ -28,105 +28,130 @@
import
UIKit
import
UIKit
/// used to construct MotionTransition from motionTransitionsString
extension
MotionTransition
:
MotionStringConvertible
{
extension
MotionTransition
:
MotionStringConvertible
{
public
static
func
from
(
node
:
ExprNode
)
->
MotionTransition
?
{
/**
let
name
:
String
=
node
.
name
Used to construct MotionTransitions from motionTransitionsString.
let
parameters
:
[
ExprNode
]
=
(
node
as?
CallNode
)?
.
arguments
??
[]
- Parameter node: An ExprNode.
- Returns: An optional MotionTransition.
*/
public
static
func
from
(
node
:
ExprNode
)
->
MotionTransition
?
{
let
name
:
String
=
node
.
name
let
parameters
:
[
ExprNode
]
=
(
node
as?
CallNode
)?
.
arguments
??
[]
switch
name
{
switch
name
{
case
"fade"
:
case
"fade"
:
return
.
fade
return
.
fade
case
"opacity"
:
return
MotionTransition
.
fade
(
to
:
parameters
.
getFloat
(
0
)
??
1
)
case
"opacity"
:
case
"position"
:
return
MotionTransition
.
fade
(
to
:
parameters
.
getFloat
(
0
)
??
1
)
return
.
position
(
to
:
CGPoint
(
x
:
parameters
.
getCGFloat
(
0
)
??
0
,
y
:
parameters
.
getCGFloat
(
1
)
??
0
))
case
"size"
:
case
"position"
:
return
.
size
(
CGSize
(
width
:
parameters
.
getCGFloat
(
0
)
??
0
,
height
:
parameters
.
getCGFloat
(
1
)
??
0
))
return
.
position
(
to
:
CGPoint
(
x
:
parameters
.
getCGFloat
(
0
)
??
0
,
y
:
parameters
.
getCGFloat
(
1
)
??
0
))
case
"scale"
:
if
parameters
.
count
==
1
{
case
"size"
:
return
.
scale
(
to
:
parameters
.
getCGFloat
(
0
)
??
1
)
return
.
size
(
CGSize
(
width
:
parameters
.
getCGFloat
(
0
)
??
0
,
height
:
parameters
.
getCGFloat
(
1
)
??
0
))
}
else
{
return
.
scale
(
x
:
parameters
.
getCGFloat
(
0
)
??
1
,
case
"scale"
:
y
:
parameters
.
getCGFloat
(
1
)
??
1
,
return
1
==
parameters
.
count
?
.
scale
(
to
:
parameters
.
getCGFloat
(
0
)
??
1
)
:
.
scale
(
x
:
parameters
.
getCGFloat
(
0
)
??
1
,
z
:
parameters
.
getCGFloat
(
2
)
??
1
)
y
:
parameters
.
getCGFloat
(
1
)
??
1
,
}
z
:
parameters
.
getCGFloat
(
2
)
??
1
)
case
"rotate"
:
if
parameters
.
count
==
1
{
case
"rotate"
:
return
.
rotate
(
parameters
.
getCGFloat
(
0
)
??
0
)
return
1
==
parameters
.
count
?
.
rotate
(
parameters
.
getCGFloat
(
0
)
??
0
)
:
.
rotate
(
x
:
parameters
.
getCGFloat
(
0
)
??
0
,
}
else
{
y
:
parameters
.
getCGFloat
(
1
)
??
0
,
return
.
rotate
(
x
:
parameters
.
getCGFloat
(
0
)
??
0
,
z
:
parameters
.
getCGFloat
(
2
)
??
0
)
y
:
parameters
.
getCGFloat
(
1
)
??
0
,
z
:
parameters
.
getCGFloat
(
2
)
??
0
)
case
"translate"
:
}
return
.
translate
(
x
:
parameters
.
getCGFloat
(
0
)
??
0
,
case
"translate"
:
y
:
parameters
.
getCGFloat
(
1
)
??
0
,
return
.
translate
(
x
:
parameters
.
getCGFloat
(
0
)
??
0
,
z
:
parameters
.
getCGFloat
(
2
)
??
0
)
y
:
parameters
.
getCGFloat
(
1
)
??
0
,
z
:
parameters
.
getCGFloat
(
2
)
??
0
)
case
"overlay"
:
case
"overlay"
:
return
.
overlay
(
color
:
UIColor
(
red
:
parameters
.
getCGFloat
(
0
)
??
1
,
return
.
overlay
(
color
:
UIColor
(
red
:
parameters
.
getCGFloat
(
0
)
??
1
,
green
:
parameters
.
getCGFloat
(
1
)
??
1
,
green
:
parameters
.
getCGFloat
(
1
)
??
1
,
blue
:
parameters
.
getCGFloat
(
2
)
??
1
,
blue
:
parameters
.
getCGFloat
(
2
)
??
1
,
alpha
:
1
),
alpha
:
1
),
opacity
:
parameters
.
getCGFloat
(
3
)
??
1
)
opacity
:
parameters
.
getCGFloat
(
3
)
??
1
)
case
"duration"
:
if
let
duration
=
parameters
.
getDouble
(
0
)
{
case
"duration"
:
return
.
duration
(
duration
)
if
let
v
=
parameters
.
getDouble
(
0
)
{
}
return
.
duration
(
v
)
case
"preferredDurationMatchesLongest"
:
}
return
.
preferredDurationMatchesLongest
case
"delay"
:
case
"preferredDurationMatchesLongest"
:
if
let
delay
=
parameters
.
getDouble
(
0
)
{
return
.
preferredDurationMatchesLongest
return
.
delay
(
delay
)
}
case
"delay"
:
case
"spring"
:
if
let
v
=
parameters
.
getDouble
(
0
)
{
if
#available(iOS 9, *)
{
return
.
delay
(
v
)
return
.
spring
(
stiffness
:
parameters
.
getCGFloat
(
0
)
??
250
,
damping
:
parameters
.
getCGFloat
(
1
)
??
30
)
}
}
case
"timingFunction"
:
case
"spring"
:
if
let
c1
=
parameters
.
getFloat
(
0
),
if
#available(iOS 9, *)
{
let
c2
=
parameters
.
getFloat
(
1
),
return
.
spring
(
stiffness
:
parameters
.
getCGFloat
(
0
)
??
250
,
damping
:
parameters
.
getCGFloat
(
1
)
??
30
)
let
c3
=
parameters
.
getFloat
(
2
),
}
let
c4
=
parameters
.
getFloat
(
3
)
{
return
.
timingFunction
(
CAMediaTimingFunction
(
controlPoints
:
c1
,
c2
,
c3
,
c4
))
case
"timingFunction"
:
}
else
if
let
name
=
parameters
.
get
(
0
)?
.
name
,
let
timingFunction
=
CAMediaTimingFunction
.
from
(
mediaTimingFunctionType
:
name
)
{
if
let
c1
=
parameters
.
getFloat
(
0
),
return
.
timingFunction
(
timingFunction
)
let
c2
=
parameters
.
getFloat
(
1
),
}
let
c3
=
parameters
.
getFloat
(
2
),
case
"arc"
:
let
c4
=
parameters
.
getFloat
(
3
)
{
return
.
arc
(
intensity
:
parameters
.
getCGFloat
(
0
)
??
1
)
return
.
timingFunction
(
CAMediaTimingFunction
(
controlPoints
:
c1
,
c2
,
c3
,
c4
))
case
"cascade"
:
}
else
if
let
name
=
parameters
.
get
(
0
)?
.
name
,
var
cascadeDirection
=
CascadeDirection
.
topToBottom
let
timingFunction
=
CAMediaTimingFunction
.
from
(
mediaTimingFunctionType
:
name
)
{
if
let
directionString
=
parameters
.
get
(
1
)?
.
name
,
return
.
timingFunction
(
timingFunction
)
let
direction
=
CascadeDirection
(
directionString
)
{
}
cascadeDirection
=
direction
}
case
"arc"
:
return
.
cascade
(
delta
:
parameters
.
getDouble
(
0
)
??
0.02
,
direction
:
cascadeDirection
,
animationDelayUntilMatchedViews
:
parameters
.
getBool
(
2
)
??
false
)
return
.
arc
(
intensity
:
parameters
.
getCGFloat
(
0
)
??
1
)
case
"source"
:
if
let
motionIdentifier
=
parameters
.
get
(
0
)?
.
name
{
case
"cascade"
:
return
.
motionIdentifier
(
motionIdentifier
)
var
cascadeDirection
=
CascadeDirection
.
topToBottom
}
case
"useGlobalCoordinateSpace"
:
if
let
directionString
=
parameters
.
get
(
1
)?
.
name
,
return
.
useGlobalCoordinateSpace
let
direction
=
CascadeDirection
(
directionString
)
{
case
"useSameParentCoordinateSpace"
:
cascadeDirection
=
direction
return
.
useSameParentCoordinateSpace
}
case
"ignoreSubviewTransitions"
:
return
.
ignoreSubviewTransitions
(
recursive
:
parameters
.
getBool
(
0
)
??
false
)
return
.
cascade
(
delta
:
parameters
.
getDouble
(
0
)
??
0.02
,
direction
:
cascadeDirection
,
animationDelayUntilMatchedViews
:
parameters
.
getBool
(
2
)
??
false
)
case
"zPosition"
:
if
let
zPosition
=
parameters
.
getCGFloat
(
0
)
{
case
"source"
:
return
.
zPosition
(
zPosition
)
if
let
v
=
parameters
.
get
(
0
)?
.
name
{
}
return
.
motionIdentifier
(
v
)
case
"useOptimizedSnapshot"
:
}
return
.
useOptimizedSnapshot
case
"useNormalSnapshot"
:
case
"useGlobalCoordinateSpace"
:
return
.
useNormalSnapshot
return
.
useGlobalCoordinateSpace
case
"useLayerRenderSnapshot"
:
return
.
useLayerRenderSnapshot
case
"useSameParentCoordinateSpace"
:
case
"useNoSnapshot"
:
return
.
useSameParentCoordinateSpace
return
.
useNoSnapshot
case
"forceAnimate"
:
case
"ignoreSubviewTransitions"
:
return
.
forceAnimate
return
.
ignoreSubviewTransitions
(
recursive
:
parameters
.
getBool
(
0
)
??
false
)
default
:
break
case
"zPosition"
:
if
let
zPosition
=
parameters
.
getCGFloat
(
0
)
{
return
.
zPosition
(
zPosition
)
}
case
"useOptimizedSnapshot"
:
return
.
useOptimizedSnapshot
case
"useNormalSnapshot"
:
return
.
useNormalSnapshot
case
"useLayerRenderSnapshot"
:
return
.
useLayerRenderSnapshot
case
"useNoSnapshot"
:
return
.
useNoSnapshot
case
"forceAnimate"
:
return
.
forceAnimate
default
:
break
}
return
nil
}
}
return
nil
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment