-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathStepCollectionViewFlowLayout.pas
More file actions
100 lines (70 loc) · 2.91 KB
/
StepCollectionViewFlowLayout.pas
File metadata and controls
100 lines (70 loc) · 2.91 KB
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
94
95
96
97
98
99
100
namespace Moshine.UI.UIKit;
uses
UIKit;
type
StepCollectionViewFlowLayout = public class(UICollectionViewFlowLayout)
private
protected
public
method snapStep:CGFloat;
begin
exit self.itemSize.width + self.minimumLineSpacing;
end;
method isValidOffset(offset: CGFloat):Boolean;
begin
exit ((offset >= CGFloat(self.minContentOffset())) and (offset <= CGFloat(self.maxContentOffset())));
end;
method minContentOffset: CGFloat;
begin
exit -CGFloat(self.collectionView.contentInset.left);
end;
method maxContentOffset:CGFloat;
begin
exit CGFloat(self.minContentOffset() + self.collectionView.contentSize.width - self.itemSize.width);
end;
method targetContentOffsetForProposedContentOffset(proposedContentOffset: CGPoint) withScrollingVelocity(velocity: CGPoint): CGPoint; override;
begin
{$IFDEF TOFFEE}
var _proposedContentOffset := CGPointMake(proposedContentOffset.x, proposedContentOffset.y);
var offSetAdjustment: CGFloat := CGFLOAT_MAX; // CGFloat.greatestFiniteMagnitude;
var horizontalCenter:CGFloat := proposedContentOffset.x + (self.collectionView.bounds.size.width / 2.0);
var targetRect := CGRectMake(proposedContentOffset.x,0.0,self.collectionView.bounds.size.width,self.collectionView.bounds.size.height);
//var attrArray:UICollectionViewLayoutAttributes :=
var attrArray :=self.layoutAttributesForElementsInRect(targetRect);
for each layoutAttributes:UICollectionViewLayoutAttributes in attrArray do
begin
if layoutAttributes.representedElementCategory = UICollectionElementCategory.Cell then
begin
var itemHorizontalCenter:CGFloat := layoutAttributes.center.x;
if RemObjects.Elements.System.abs(itemHorizontalCenter - horizontalCenter) < RemObjects.Elements.System.abs(offSetAdjustment) then
begin
offSetAdjustment := itemHorizontalCenter - horizontalCenter;
end;
end;
end;
var nextOffset: CGFloat := proposedContentOffset.x + offSetAdjustment;
repeat
begin
_proposedContentOffset.x := nextOffset;
var deltaX := proposedContentOffset.x - self.collectionView.contentOffset.x;
var velX := velocity.x;
if (deltaX = 0.0) or (velX = 0) or ((velX > 0.0) and (deltaX > 0.0)) or ((velX < 0.0) and (deltaX < 0.0)) then
begin
break;
end;
if velocity.x > 0.0 then
begin
nextOffset := nextOffset + self.snapStep();
end
else if velocity.x < 0.0 then
begin
nextOffset := nextOffset - self.snapStep();
end;
end
until (not self.isValidOffset(nextOffset));
_proposedContentOffset.y := 0.0;
exit _proposedContentOffset;
{$ENDIF}
end;
end;
end.