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
6df970aa
Unverified
Commit
6df970aa
authored
Jun 11, 2017
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
reworked TransitionPreprocessor
parent
5c4a028f
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
123 additions
and
62 deletions
+123
-62
Sources/Preprocessors/CascadePreprocessor.swift
+6
-15
Sources/TransitionPreprocessor.swift
+117
-47
No files found.
Sources/Preprocessors/CascadePreprocessor.swift
View file @
6df970aa
...
...
@@ -35,37 +35,28 @@ public enum CascadeDirection {
case
rightToLeft
case
radial
(
center
:
CGPoint
)
case
inverseRadial
(
center
:
CGPoint
)
var
comparator
:
(
UIView
,
UIView
)
->
Bool
{
switch
self
{
case
.
topToBottom
:
return
{
return
$0
.
frame
.
minY
<
$1
.
frame
.
minY
}
case
.
bottomToTop
:
return
{
return
$0
.
frame
.
maxY
==
$1
.
frame
.
maxY
?
$0
.
frame
.
maxX
>
$1
.
frame
.
maxX
:
$0
.
frame
.
maxY
>
$1
.
frame
.
maxY
}
case
.
leftToRight
:
return
{
return
$0
.
frame
.
minX
<
$1
.
frame
.
minX
}
case
.
rightToLeft
:
return
{
return
$0
.
frame
.
maxX
>
$1
.
frame
.
maxX
}
case
.
radial
(
let
center
):
return
{
return
$0
.
center
.
distance
(
center
)
<
$1
.
center
.
distance
(
center
)
}
case
.
inverseRadial
(
let
center
):
return
{
return
$0
.
center
.
distance
(
center
)
>
$1
.
center
.
distance
(
center
)
}
}
}
init
?(
_
string
:
String
)
{
switch
string
{
case
"bottomToTop"
:
self
=
.
bottomToTop
case
"leftToRight"
:
self
=
.
leftToRight
case
"rightToLeft"
:
self
=
.
rightToLeft
case
"topToBottom"
:
self
=
.
topToBottom
default
:
return
nil
}
}
}
class
CascadePreprocessor
:
MotionPreprocessor
{
...
...
Sources/TransitionPreprocessor.swift
View file @
6df970aa
...
...
@@ -36,6 +36,7 @@ public enum MotionTransitionType {
case
down
}
case
none
case
auto
case
push
(
direction
:
Direction
)
case
pull
(
direction
:
Direction
)
...
...
@@ -51,80 +52,117 @@ public enum MotionTransitionType {
indirect
case
selectBy
(
presenting
:
MotionTransitionType
,
dismissing
:
MotionTransitionType
)
/**
Sets the presenting and dismissing transitions.
- Parameter presenting: A MotionTransitionType.
- Returns: A MotionTransitionType.
*/
public
static
func
autoReverse
(
presenting
:
MotionTransitionType
)
->
MotionTransitionType
{
return
.
selectBy
(
presenting
:
presenting
,
dismissing
:
presenting
.
reversed
())
}
case
none
/// Returns a reversal transition.
func
reversed
()
->
MotionTransitionType
{
switch
self
{
case
.
push
(
direction
:
.
up
):
return
.
pull
(
direction
:
.
down
)
case
.
push
(
direction
:
.
right
):
return
.
pull
(
direction
:
.
left
)
case
.
push
(
direction
:
.
down
):
return
.
pull
(
direction
:
.
up
)
case
.
push
(
direction
:
.
left
):
return
.
pull
(
direction
:
.
right
)
case
.
pull
(
direction
:
.
up
):
return
.
push
(
direction
:
.
down
)
case
.
pull
(
direction
:
.
right
):
return
.
push
(
direction
:
.
left
)
case
.
pull
(
direction
:
.
down
):
return
.
push
(
direction
:
.
up
)
case
.
pull
(
direction
:
.
left
):
return
.
push
(
direction
:
.
right
)
case
.
cover
(
direction
:
.
up
):
return
.
uncover
(
direction
:
.
down
)
case
.
cover
(
direction
:
.
right
):
return
.
uncover
(
direction
:
.
left
)
case
.
cover
(
direction
:
.
down
):
return
.
uncover
(
direction
:
.
up
)
case
.
cover
(
direction
:
.
left
):
return
.
uncover
(
direction
:
.
right
)
case
.
uncover
(
direction
:
.
up
):
return
.
cover
(
direction
:
.
down
)
case
.
uncover
(
direction
:
.
right
):
return
.
cover
(
direction
:
.
left
)
case
.
uncover
(
direction
:
.
down
):
return
.
cover
(
direction
:
.
up
)
case
.
uncover
(
direction
:
.
left
):
return
.
cover
(
direction
:
.
right
)
case
.
slide
(
direction
:
.
up
):
return
.
slide
(
direction
:
.
down
)
case
.
slide
(
direction
:
.
down
):
return
.
slide
(
direction
:
.
up
)
case
.
slide
(
direction
:
.
left
):
return
.
slide
(
direction
:
.
right
)
case
.
slide
(
direction
:
.
right
):
return
.
slide
(
direction
:
.
left
)
case
.
zoomSlide
(
direction
:
.
up
):
return
.
zoomSlide
(
direction
:
.
down
)
case
.
zoomSlide
(
direction
:
.
down
):
return
.
zoomSlide
(
direction
:
.
up
)
case
.
zoomSlide
(
direction
:
.
left
):
return
.
zoomSlide
(
direction
:
.
right
)
case
.
zoomSlide
(
direction
:
.
right
):
return
.
zoomSlide
(
direction
:
.
left
)
case
.
pageIn
(
direction
:
.
up
):
return
.
pageOut
(
direction
:
.
down
)
case
.
pageIn
(
direction
:
.
right
):
return
.
pageOut
(
direction
:
.
left
)
case
.
pageIn
(
direction
:
.
down
):
return
.
pageOut
(
direction
:
.
up
)
case
.
pageIn
(
direction
:
.
left
):
return
.
pageOut
(
direction
:
.
right
)
case
.
pageOut
(
direction
:
.
up
):
return
.
pageIn
(
direction
:
.
down
)
case
.
pageOut
(
direction
:
.
right
):
return
.
pageIn
(
direction
:
.
left
)
case
.
pageOut
(
direction
:
.
down
):
return
.
pageIn
(
direction
:
.
up
)
case
.
pageOut
(
direction
:
.
left
):
return
.
pageIn
(
direction
:
.
right
)
case
.
zoom
:
return
.
zoomOut
case
.
zoomOut
:
return
.
zoom
...
...
@@ -132,44 +170,50 @@ public enum MotionTransitionType {
return
self
}
}
public
var
label
:
String
?
{
let
mirror
=
Mirror
(
reflecting
:
self
)
if
let
associated
=
mirror
.
children
.
first
{
let
valuesMirror
=
Mirror
(
reflecting
:
associated
.
value
)
if
!
valuesMirror
.
children
.
isEmpty
{
let
parameters
=
valuesMirror
.
children
.
map
{
".
\(
$0
.
value
)
"
}
.
joined
(
separator
:
","
)
return
".
\(
associated
.
label
??
""
)
(
\(
parameters
)
)"
}
return
".
\(
associated
.
label
??
""
)
(.
\(
associated
.
value
)
)"
}
return
".
\(
self
)
"
}
}
class
TransitionPreprocessor
:
MotionPreprocessor
{
/// A reference to a MotionContext.
/// A reference to a MotionContext
instance
.
weak
var
context
:
MotionContext
!
/// A reference to a Motion instance.
weak
var
motion
:
Motion
?
/**
An initializer that accepts a given Motion instance.
- Parameter motion: A Motion instance.
*/
init
(
motion
:
Motion
)
{
self
.
motion
=
motion
}
/**
Shifts the transition by a given size.
- Parameter direction: A MotionTransitionType.Direction.
- Parameter isAppearing: A boolean indicating whether it is appearing
or not.
- Parameter size: An optional CGSize.
- Parameter transpose: A boolean indicating to change the `x` point for `y`
and `y` point for `x`.
- Returns: A CGPoint.
*/
func
shift
(
direction
:
MotionTransitionType
.
Direction
,
isAppearing
:
Bool
,
size
:
CGSize
?
=
nil
,
transpose
:
Bool
=
false
)
->
CGPoint
{
let
size
=
size
??
context
.
container
.
bounds
.
size
let
rtn
:
CGPoint
let
point
:
CGPoint
switch
direction
{
case
.
left
,
.
right
:
rtn
=
CGPoint
(
x
:
(
direction
==
.
right
)
==
isAppearing
?
-
size
.
width
:
size
.
width
,
y
:
0
)
point
=
CGPoint
(
x
:
(
.
right
==
direction
)
==
isAppearing
?
-
size
.
width
:
size
.
width
,
y
:
0
)
case
.
up
,
.
down
:
rtn
=
CGPoint
(
x
:
0
,
y
:
(
direction
==
.
dow
n
)
==
isAppearing
?
-
size
.
height
:
size
.
height
)
point
=
CGPoint
(
x
:
0
,
y
:
(
.
down
==
directio
n
)
==
isAppearing
?
-
size
.
height
:
size
.
height
)
}
if
transpose
{
return
CGPoint
(
x
:
rtn
.
y
,
y
:
rtn
.
x
)
return
CGPoint
(
x
:
point
.
y
,
y
:
point
.
x
)
}
return
rtn
return
point
}
/**
...
...
@@ -178,40 +222,48 @@ class TransitionPreprocessor: MotionPreprocessor {
- Parameter toViews: An Array of UIViews.
*/
func
process
(
fromViews
:
[
UIView
],
toViews
:
[
UIView
])
{
guard
let
motion
=
motion
else
{
return
}
var
defaultAnimation
=
motion
.
defaultAnimation
let
inNavigationController
=
motion
.
isNavigationController
let
inTabBarController
=
motion
.
isTabBarController
let
toViewController
=
motion
.
toViewController
let
fromViewController
=
motion
.
fromViewController
let
presenting
=
motion
.
isPresenting
let
fromOverFullScreen
=
motion
.
fromOverFullScreen
let
toOverFullScreen
=
motion
.
toOverFullScreen
let
toView
=
motion
.
toView
let
fromView
=
motion
.
fromView
let
animators
=
motion
.
animators
guard
let
m
=
motion
else
{
return
}
var
defaultAnimation
=
m
.
defaultAnimation
let
isNavigationController
=
m
.
isNavigationController
let
isTabBarController
=
m
.
isTabBarController
let
toViewController
=
m
.
toViewController
let
fromViewController
=
m
.
fromViewController
let
isPresenting
=
m
.
isPresenting
let
fromOverFullScreen
=
m
.
fromOverFullScreen
let
toOverFullScreen
=
m
.
toOverFullScreen
let
toView
=
m
.
toView
let
fromView
=
m
.
fromView
let
animators
=
m
.
animators
if
case
.
auto
=
defaultAnimation
{
if
in
NavigationController
,
let
navAnim
=
toViewController
?
.
navigationController
?
.
motionNavigationTransitionType
{
if
is
NavigationController
,
let
navAnim
=
toViewController
?
.
navigationController
?
.
motionNavigationTransitionType
{
defaultAnimation
=
navAnim
}
else
if
inTabBarController
,
let
tabAnim
=
toViewController
?
.
tabBarController
?
.
motionTabBarTransitionType
{
}
else
if
isTabBarController
,
let
tabAnim
=
toViewController
?
.
tabBarController
?
.
motionTabBarTransitionType
{
defaultAnimation
=
tabAnim
}
else
if
let
modalAnim
=
(
presenting
?
toViewController
:
fromViewController
)?
.
motionModalTransitionType
{
}
else
if
let
modalAnim
=
(
isPresenting
?
toViewController
:
fromViewController
)?
.
motionModalTransitionType
{
defaultAnimation
=
modalAnim
}
}
if
case
.
selectBy
(
let
presentAnim
,
let
dismissAnim
)
=
defaultAnimation
{
defaultAnimation
=
p
resenting
?
presentAnim
:
dismissAnim
defaultAnimation
=
isP
resenting
?
presentAnim
:
dismissAnim
}
if
case
.
auto
=
defaultAnimation
{
if
animators
!.
contains
(
where
:
{
$0
.
canAnimate
(
view
:
toView
,
isAppearing
:
true
)
||
$0
.
canAnimate
(
view
:
fromView
,
isAppearing
:
false
)
})
{
defaultAnimation
=
.
none
}
else
if
inNavigationController
{
defaultAnimation
=
presenting
?
.
push
(
direction
:
.
left
)
:
.
pull
(
direction
:
.
right
)
}
else
if
inTabBarController
{
defaultAnimation
=
presenting
?
.
slide
(
direction
:
.
left
)
:
.
slide
(
direction
:
.
right
)
}
else
if
isNavigationController
{
defaultAnimation
=
isPresenting
?
.
push
(
direction
:
.
left
)
:
.
pull
(
direction
:
.
right
)
}
else
if
isTabBarController
{
defaultAnimation
=
isPresenting
?
.
slide
(
direction
:
.
left
)
:
.
slide
(
direction
:
.
right
)
}
else
{
defaultAnimation
=
.
fade
}
...
...
@@ -229,79 +281,97 @@ class TransitionPreprocessor: MotionPreprocessor {
.
shadow
(
radius
:
5
),
.
shadow
(
offset
:
.
zero
),
.
masksToBounds
(
false
)]
switch
defaultAnimation
{
case
.
push
(
let
direction
):
context
[
toView
]
!.
append
(
contentsOf
:
[
.
translate
(
to
:
shift
(
direction
:
direction
,
isAppearing
:
true
)),
.
shadow
(
opacity
:
0
),
.
beginWith
(
transitions
:
shadowState
),
.
timingFunction
(
.
deceleration
)])
context
[
fromView
]
!.
append
(
contentsOf
:
[
.
translate
(
to
:
shift
(
direction
:
direction
,
isAppearing
:
false
)
/
3
),
.
overlay
(
color
:
.
black
,
opacity
:
0.1
),
.
timingFunction
(
.
deceleration
)])
case
.
pull
(
let
direction
):
motion
.
insertToViewFirst
=
true
m
.
insertToViewFirst
=
true
context
[
fromView
]
!.
append
(
contentsOf
:
[
.
translate
(
to
:
shift
(
direction
:
direction
,
isAppearing
:
false
)),
.
shadow
(
opacity
:
0
),
.
beginWith
(
transitions
:
shadowState
)])
context
[
toView
]
!.
append
(
contentsOf
:
[
.
translate
(
to
:
shift
(
direction
:
direction
,
isAppearing
:
true
)
/
3
),
.
overlay
(
color
:
.
black
,
opacity
:
0.1
)])
case
.
slide
(
let
direction
):
context
[
fromView
]
!.
append
(
contentsOf
:
[
.
translate
(
to
:
shift
(
direction
:
direction
,
isAppearing
:
false
))])
context
[
toView
]
!.
append
(
contentsOf
:
[
.
translate
(
to
:
shift
(
direction
:
direction
,
isAppearing
:
true
))])
case
.
zoomSlide
(
let
direction
):
context
[
fromView
]
!.
append
(
contentsOf
:
[
.
translate
(
to
:
shift
(
direction
:
direction
,
isAppearing
:
false
)),
.
scale
(
to
:
0.8
)])
context
[
toView
]
!.
append
(
contentsOf
:
[
.
translate
(
to
:
shift
(
direction
:
direction
,
isAppearing
:
true
)),
.
scale
(
to
:
0.8
)])
case
.
cover
(
let
direction
):
context
[
toView
]
!.
append
(
contentsOf
:
[
.
translate
(
to
:
shift
(
direction
:
direction
,
isAppearing
:
true
)),
.
shadow
(
opacity
:
0
),
.
beginWith
(
transitions
:
shadowState
),
.
timingFunction
(
.
deceleration
)])
context
[
fromView
]
!.
append
(
contentsOf
:
[
.
overlay
(
color
:
.
black
,
opacity
:
0.1
),
.
timingFunction
(
.
deceleration
)])
case
.
uncover
(
let
direction
):
motion
.
insertToViewFirst
=
true
m
.
insertToViewFirst
=
true
context
[
fromView
]
!.
append
(
contentsOf
:
[
.
translate
(
to
:
shift
(
direction
:
direction
,
isAppearing
:
false
)),
.
shadow
(
opacity
:
0
),
.
beginWith
(
transitions
:
shadowState
)])
context
[
toView
]
!.
append
(
contentsOf
:
[
.
overlay
(
color
:
.
black
,
opacity
:
0.1
)])
case
.
pageIn
(
let
direction
):
context
[
toView
]
!.
append
(
contentsOf
:
[
.
translate
(
to
:
shift
(
direction
:
direction
,
isAppearing
:
true
)),
.
shadow
(
opacity
:
0
),
.
beginWith
(
transitions
:
shadowState
),
.
timingFunction
(
.
deceleration
)])
context
[
fromView
]
!.
append
(
contentsOf
:
[
.
scale
(
to
:
0.7
),
.
overlay
(
color
:
.
black
,
opacity
:
0.1
),
.
timingFunction
(
.
deceleration
)])
case
.
pageOut
(
let
direction
):
motion
.
insertToViewFirst
=
true
m
.
insertToViewFirst
=
true
context
[
fromView
]
!.
append
(
contentsOf
:
[
.
translate
(
to
:
shift
(
direction
:
direction
,
isAppearing
:
false
)),
.
shadow
(
opacity
:
0
),
.
beginWith
(
transitions
:
shadowState
)])
context
[
toView
]
!.
append
(
contentsOf
:
[
.
scale
(
to
:
0.7
),
.
overlay
(
color
:
.
black
,
opacity
:
0.1
)])
case
.
fade
:
// TODO: clean up this. overFullScreen logic shouldn't be here
if
!
(
fromOverFullScreen
&&
!
p
resenting
)
{
if
!
(
fromOverFullScreen
&&
!
isP
resenting
)
{
context
[
toView
]
=
[
.
fade
]
}
#if os(tvOS)
context
[
fromView
]
=
[
.
fade
]
#else
if
(
!
p
resenting
&&
toOverFullScreen
)
||
!
fromView
.
isOpaque
||
(
fromView
.
backgroundColor
?
.
alphaComponent
??
1
)
<
1
{
if
(
!
isP
resenting
&&
toOverFullScreen
)
||
!
fromView
.
isOpaque
||
(
fromView
.
backgroundColor
?
.
alphaComponent
??
1
)
<
1
{
context
[
fromView
]
=
[
.
fade
]
}
#endif
context
[
toView
]
!.
append
(
.
preferredDurationMatchesLongest
)
context
[
fromView
]
!.
append
(
.
preferredDurationMatchesLongest
)
case
.
zoom
:
motion
.
insertToViewFirst
=
true
m
.
insertToViewFirst
=
true
context
[
fromView
]
!.
append
(
contentsOf
:
[
.
scale
(
to
:
1.3
),
.
fade
])
context
[
toView
]
!.
append
(
contentsOf
:
[
.
scale
(
to
:
0.7
)])
case
.
zoomOut
:
context
[
toView
]
!.
append
(
contentsOf
:
[
.
scale
(
to
:
1.3
),
.
fade
])
context
[
fromView
]
!.
append
(
contentsOf
:
[
.
scale
(
to
:
0.7
)])
default
:
fatalError
(
"Not implemented"
)
}
...
...
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