FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
AsyncDisplayKit/AsyncDisplayKit/ASPagerFlowLayout.m at master · SummerXZX/AsyncDisplayKit · GitHub
SummerXZX
/
AsyncDisplayKit
Public
forked from
facebookarchive/AsyncDisplayKit
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
AsyncDisplayKit
/
AsyncDisplayKit
/
ASPagerFlowLayout.m
Copy path
More file actions
More file actions
Latest commit
History
History
History
93 lines (75 loc) · 3.5 KB
Breadcrumbs
AsyncDisplayKit
/
AsyncDisplayKit
/
ASPagerFlowLayout.m
Copy path
File metadata and controls
93 lines (75 loc) · 3.5 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
//
//
ASPagerFlowLayout.m
//
AsyncDisplayKit
//
//
Created by Levi McCallum on 2/12/16.
//
//
Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
//
This source code is licensed under the BSD-style license found in the
//
LICENSE file in the root directory of this source tree. An additional grant
//
of patent rights can be found in the PATENTS file in the same directory.
//
#
import
"
ASPagerFlowLayout.h
"
@interface
ASPagerFlowLayout
() {
BOOL
_didRotate;
CGRect _cachedCollectionViewBounds;
NSIndexPath
*_currentIndexPath;
}
@end
@implementation
ASPagerFlowLayout
- (CGPoint)
targetContentOffsetForProposedContentOffset
:
(CGPoint)
proposedContentOffset
withScrollingVelocity
:
(CGPoint)
velocity
{
NSInteger
currentPage =
ceil
(proposedContentOffset.
x
/ self.
collectionView
.
bounds
.
size
.
width
);
_currentIndexPath = [
NSIndexPath
indexPathForItem:
currentPage
inSection:
0
];
return
[
super
targetContentOffsetForProposedContentOffset:
proposedContentOffset
withScrollingVelocity:
velocity];
}
- (
void
)
prepareForAnimatedBoundsChange
:
(CGRect)
oldBounds
{
//
Cache the current page if a rotation did happen. This happens before the rotation animation
//
is occuring and the bounds changed so we use this as an opportunity to cache the current index path
if
(_cachedCollectionViewBounds.
size
.
width
!= self.
collectionView
.
bounds
.
size
.
width
) {
_cachedCollectionViewBounds = self.
collectionView
.
bounds
;
//
Figurring out current page based on the old bounds visible space
CGRect visibleRect = oldBounds;
CGFloat visibleXCenter =
CGRectGetMidX
(visibleRect);
NSArray
<UICollectionViewLayoutAttributes *> *layoutAttributes = [
self
layoutAttributesForElementsInRect:
visibleRect];
for
(UICollectionViewLayoutAttributes *attributes in layoutAttributes) {
if
([attributes
representedElementCategory
] == UICollectionElementCategoryCell && attributes.
center
.
x
== visibleXCenter) {
_currentIndexPath = attributes.
indexPath
;
break
;
}
}
_didRotate =
YES
;
}
[
super
prepareForAnimatedBoundsChange:
oldBounds];
}
- (CGPoint)
targetContentOffsetForProposedContentOffset
:
(CGPoint)
proposedContentOffset
{
//
Don't mess around if the user is interacting with the page node. Although if just a rotation happened we should
//
try to use the current index path to not end up setting the target content offset to something in between pages
if
(_didRotate || (!self.
collectionView
.
isDecelerating
&& !self.
collectionView
.
isTracking
)) {
_didRotate =
NO
;
if
(_currentIndexPath) {
return
[
self
_targetContentOffsetForItemAtIndexPath:
_currentIndexPath
proposedContentOffset:
proposedContentOffset];
}
}
return
[
super
targetContentOffsetForProposedContentOffset:
proposedContentOffset];
}
- (CGPoint)
_targetContentOffsetForItemAtIndexPath
:
(
NSIndexPath
*)
indexPath
proposedContentOffset
:
(CGPoint)
proposedContentOffset
{
if
([
self
_dataSourceIsEmpty
]) {
return
proposedContentOffset;
}
UICollectionViewLayoutAttributes *attributes = [
self
layoutAttributesForItemAtIndexPath:
_currentIndexPath];
if
(attributes ==
nil
) {
return
proposedContentOffset;
}
CGFloat xOffset = (
CGRectGetWidth
(self.
collectionView
.
bounds
) -
CGRectGetWidth
(attributes.
frame
)) /
2.0
;
return
CGPointMake
(attributes.
frame
.
origin
.
x
- xOffset, proposedContentOffset.
y
);
}
- (
BOOL
)
_dataSourceIsEmpty
{
return
([
self
.collectionView
numberOfSections
] ==
0
||
[
self
.collectionView
numberOfItemsInSection:
0
] ==
0
);
}
@end
Back
|
FazBrowse Home
|
New Git URL