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
b6de5705
Unverified
Commit
b6de5705
authored
Jun 11, 2017
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
reworked DurationPreprocessor
parent
426a8998
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
24 deletions
+41
-24
Sources/Preprocessors/DurationPreprocessor.swift
+41
-24
No files found.
Sources/Preprocessors/DurationPreprocessor.swift
View file @
b6de5705
...
...
@@ -45,32 +45,49 @@ class DurationPreprocessor: MotionPreprocessor {
setDurationForInfiniteDuration
(
views
:
toViews
,
duration
:
maxDuration
)
}
func
optimizedDurationFor
(
view
:
UIView
)
->
TimeInterval
{
let
targetState
=
context
[
view
]
!
return
view
.
optimizedDuration
(
fromPosition
:
context
.
container
.
convert
(
view
.
layer
.
position
,
from
:
view
.
superview
),
toPosition
:
targetState
.
position
,
size
:
targetState
.
size
,
transform
:
targetState
.
transform
)
}
/**
Retrieves the optimized duration for a given UIView.
- Parameter for view: A UIView.
- Returns: A TimeInterval.
*/
func
optimizedDuration
(
for
view
:
UIView
)
->
TimeInterval
{
let
v
=
context
[
view
]
!
return
view
.
optimizedDuration
(
fromPosition
:
context
.
container
.
convert
(
view
.
layer
.
position
,
from
:
view
.
superview
),
toPosition
:
v
.
position
,
size
:
v
.
size
,
transform
:
v
.
transform
)
}
func
applyOptimizedDurationIfNoDuration
(
views
:
[
UIView
])
->
TimeInterval
{
var
maxDuration
:
TimeInterval
=
0
for
view
in
views
where
context
[
view
]
!=
nil
{
if
context
[
view
]?
.
duration
==
nil
{
context
[
view
]
!.
duration
=
optimizedDurationFor
(
view
:
view
)
}
if
context
[
view
]
!.
duration
!
==
.
infinity
{
maxDuration
=
max
(
maxDuration
,
optimizedDurationFor
(
view
:
view
))
}
else
{
maxDuration
=
max
(
maxDuration
,
context
[
view
]
!.
duration
!
)
}
/**
Applies the optimized duration for an Array of UIViews.
- Parameter views: An Array of UIViews.
- Returns: A TimeInterval.
*/
func
applyOptimizedDurationIfNoDuration
(
views
:
[
UIView
])
->
TimeInterval
{
var
d
:
TimeInterval
=
0
for
v
in
views
where
nil
!=
context
[
v
]
{
if
nil
==
context
[
v
]?
.
duration
{
context
[
v
]
!.
duration
=
optimizedDuration
(
for
:
v
)
}
d
=
.
infinity
==
context
[
v
]
!.
duration
!
?
max
(
d
,
optimizedDuration
(
for
:
v
))
:
max
(
d
,
context
[
v
]
!.
duration
!
)
}
return
d
}
return
maxDuration
}
func
setDurationForInfiniteDuration
(
views
:
[
UIView
],
duration
:
TimeInterval
)
{
for
view
in
views
where
context
[
view
]?
.
duration
==
.
infinity
{
context
[
view
]
!.
duration
=
duration
/**
Sets the duration if the duration of a transition is set to `.infinity`.
- Parameter views: An Array of UIViews.
- Parameter duration: A TimeInterval.
*/
func
setDurationForInfiniteDuration
(
views
:
[
UIView
],
duration
:
TimeInterval
)
{
for
v
in
views
where
.
infinity
==
context
[
v
]?
.
duration
{
context
[
v
]
!.
duration
=
duration
}
}
}
}
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