Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
Material
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
Material
Commits
cf6e12ec
Commit
cf6e12ec
authored
Feb 25, 2016
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added MaterialCollectionViewCell
parent
f8d7781b
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
94 additions
and
45 deletions
+94
-45
Examples/Programmatic/App/App/AppNavigationBarViewController.swift
+0
-1
Material.xcodeproj/project.pbxproj
+4
-4
Sources/ControlView.swift
+11
-10
Sources/MaterialCollectionView.swift
+0
-1
Sources/MaterialCollectionViewCell.swift
+30
-0
Sources/MaterialCollectionViewDataSource.swift
+3
-2
Sources/MaterialCollectionViewLayout.swift
+39
-23
Sources/MaterialDataSourceItem.swift
+7
-4
No files found.
Examples/Programmatic/App/App/AppNavigationBarViewController.swift
View file @
cf6e12ec
...
...
@@ -79,7 +79,6 @@ class AppNavigationBarViewController: NavigationBarViewController {
titleLabel
.
text
=
"Feed"
titleLabel
.
textAlignment
=
.
Left
titleLabel
.
textColor
=
MaterialColor
.
white
titleLabel
.
font
=
RobotoFont
.
regular
var
image
=
UIImage
(
named
:
"ic_menu_white"
)
...
...
Material.xcodeproj/project.pbxproj
View file @
cf6e12ec
...
...
@@ -62,7 +62,7 @@
96CC08581C7E11430034FF84
/* MaterialCollectionView.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96CC08571C7E11430034FF84
/* MaterialCollectionView.swift */
;
};
96CC085A1C7E16BD0034FF84
/* MaterialCollectionViewDataSource.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96CC08591C7E16BD0034FF84
/* MaterialCollectionViewDataSource.swift */
;
};
96CC085C1C7E16F20034FF84
/* MaterialCollectionViewDelegate.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96CC085B1C7E16F20034FF84
/* MaterialCollectionViewDelegate.swift */
;
};
96CC085E1C7E1D550034FF84
/* Material
CollectionViewDataSourceItem.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96CC085D1C7E1D550034FF84
/* MaterialCollectionView
DataSourceItem.swift */
;
};
96CC085E1C7E1D550034FF84
/* Material
DataSourceItem.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96CC085D1C7E1D550034FF84
/* Material
DataSourceItem.swift */
;
};
96D88C1E1C1328D800B91418
/* CaptureView.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96D88BF51C1328D800B91418
/* CaptureView.swift */
;
};
96D88C1F1C1328D800B91418
/* CardView.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96D88BF61C1328D800B91418
/* CardView.swift */
;
};
96D88C201C1328D800B91418
/* CapturePreviewView.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96D88BF71C1328D800B91418
/* CapturePreviewView.swift */
;
};
...
...
@@ -175,7 +175,7 @@
96CC08571C7E11430034FF84
/* MaterialCollectionView.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
MaterialCollectionView.swift
;
sourceTree
=
"<group>"
;
};
96CC08591C7E16BD0034FF84
/* MaterialCollectionViewDataSource.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
MaterialCollectionViewDataSource.swift
;
sourceTree
=
"<group>"
;
};
96CC085B1C7E16F20034FF84
/* MaterialCollectionViewDelegate.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
MaterialCollectionViewDelegate.swift
;
sourceTree
=
"<group>"
;
};
96CC085D1C7E1D550034FF84
/* Material
CollectionViewDataSourceItem.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
MaterialCollectionView
DataSourceItem.swift
;
sourceTree
=
"<group>"
;
};
96CC085D1C7E1D550034FF84
/* Material
DataSourceItem.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
Material
DataSourceItem.swift
;
sourceTree
=
"<group>"
;
};
96D88BF51C1328D800B91418
/* CaptureView.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
CaptureView.swift
;
sourceTree
=
"<group>"
;
};
96D88BF61C1328D800B91418
/* CardView.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
CardView.swift
;
sourceTree
=
"<group>"
;
};
96D88BF71C1328D800B91418
/* CapturePreviewView.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
CapturePreviewView.swift
;
sourceTree
=
"<group>"
;
};
...
...
@@ -341,7 +341,7 @@
96CC08571C7E11430034FF84
/* MaterialCollectionView.swift */
,
96CC08591C7E16BD0034FF84
/* MaterialCollectionViewDataSource.swift */
,
96CC085B1C7E16F20034FF84
/* MaterialCollectionViewDelegate.swift */
,
96CC085D1C7E1D550034FF84
/* Material
CollectionView
DataSourceItem.swift */
,
96CC085D1C7E1D550034FF84
/* MaterialDataSourceItem.swift */
,
);
name
=
CollectionView
;
sourceTree
=
"<group>"
;
...
...
@@ -739,7 +739,7 @@
96D88C331C1328D800B91418
/* MaterialLabel.swift in Sources */
,
96D88C281C1328D800B91418
/* MaterialAnimation.swift in Sources */
,
96A71F301C72E41100C0C4AE
/* NavigationBarViewController.swift in Sources */
,
96CC085E1C7E1D550034FF84
/* Material
CollectionView
DataSourceItem.swift in Sources */
,
96CC085E1C7E1D550034FF84
/* MaterialDataSourceItem.swift in Sources */
,
960B232E1C383EAA00E96216
/* Material+UIImage.swift in Sources */
,
96D88C451C1328D800B91418
/* RobotoFont.swift in Sources */
,
96D88C1F1C1328D800B91418
/* CardView.swift in Sources */
,
...
...
Sources/ControlView.swift
View file @
cf6e12ec
...
...
@@ -31,13 +31,13 @@
import
UIKit
public
class
ControlView
:
MaterialView
{
/// ContentView that holds the any desired subviews.
public
private(set)
lazy
var
contentView
:
MaterialView
=
MaterialView
()
/// A preset wrapper around contentInset.
public
var
contentInsetPreset
:
MaterialEdgeInset
=
.
None
{
didSet
{
contentInset
=
MaterialEdgeInsetToValue
(
contentInsetPreset
)
public
var
contentInsetPreset
:
MaterialEdgeInset
{
get
{
return
grid
.
contentInsetPreset
}
set
(
value
)
{
grid
.
contentInsetPreset
=
value
}
}
...
...
@@ -47,8 +47,7 @@ public class ControlView : MaterialView {
return
grid
.
contentInset
}
set
(
value
)
{
grid
.
contentInset
=
contentInset
reloadView
()
grid
.
contentInset
=
value
}
}
...
...
@@ -58,11 +57,13 @@ public class ControlView : MaterialView {
return
grid
.
spacing
}
set
(
value
)
{
grid
.
spacing
=
spacing
reloadView
()
grid
.
spacing
=
value
}
}
/// ContentView that holds the any desired subviews.
public
private(set)
lazy
var
contentView
:
MaterialView
=
MaterialView
()
/// Left side UIControls.
public
var
leftControls
:
Array
<
UIControl
>
?
{
didSet
{
...
...
Sources/MaterialCollectionView.swift
View file @
cf6e12ec
...
...
@@ -66,7 +66,6 @@ public class MaterialCollectionView : UICollectionView {
when subclassing.
*/
public
func
prepareView
()
{
registerClass
(
MaterialCollectionViewCell
.
self
,
forCellWithReuseIdentifier
:
"Cell"
)
backgroundColor
=
MaterialColor
.
clear
contentInset
=
UIEdgeInsetsZero
}
...
...
Sources/MaterialCollectionViewCell.swift
View file @
cf6e12ec
...
...
@@ -32,6 +32,36 @@ import UIKit
@objc(MaterialCollectionViewCell)
public
class
MaterialCollectionViewCell
:
UICollectionViewCell
{
/// A preset wrapper around contentInset.
public
var
contentInsetPreset
:
MaterialEdgeInset
{
get
{
return
contentView
.
grid
.
contentInsetPreset
}
set
(
value
)
{
contentView
.
grid
.
contentInsetPreset
=
value
}
}
/// A wrapper around grid.contentInset.
public
var
contentInset
:
UIEdgeInsets
{
get
{
return
contentView
.
grid
.
contentInset
}
set
(
value
)
{
contentView
.
grid
.
contentInset
=
value
}
}
/// A wrapper around grid.spacing.
public
var
spacing
:
CGFloat
{
get
{
return
contentView
.
grid
.
spacing
}
set
(
value
)
{
contentView
.
grid
.
spacing
=
value
}
}
/**
A CAShapeLayer used to manage elements that would be affected by
the clipToBounds property of the backing layer. For example, this
...
...
Sources/MaterialCollectionViewDataSource.swift
View file @
cf6e12ec
...
...
@@ -31,7 +31,7 @@
public
protocol
MaterialCollectionViewDataSource
:
MaterialDelegate
,
UICollectionViewDataSource
{
/**
/// Retrieves the items for the collectionView.
- Returns: An Array of Arrays of Material
CollectionView
DataSourceItem objects.
- Returns: An Array of Arrays of MaterialDataSourceItem objects.
*/
func
items
()
->
Array
<
Array
<
Material
CollectionView
DataSourceItem
>>
func
items
()
->
Array
<
Array
<
MaterialDataSourceItem
>>
}
\ No newline at end of file
Sources/MaterialCollectionViewLayout.swift
View file @
cf6e12ec
...
...
@@ -30,12 +30,17 @@
import
UIKit
public
enum
MaterialCollectionViewLayoutScrollDirection
{
case
Vertical
case
Horizontal
}
public
class
MaterialCollectionViewLayout
:
UICollectionViewLayout
{
/// A preset wrapper around contentInset.
public
var
contentInsetPreset
:
MaterialEdgeInset
=
.
None
{
didSet
{
contentInset
=
MaterialEdgeInsetToValue
(
contentInsetPreset
)
}
}
/// A wrapper around grid.contentInset.
public
var
contentInset
:
UIEdgeInsets
=
UIEdgeInsetsZero
/// Size of the content.
private
var
contentSize
:
CGSize
=
CGSizeZero
...
...
@@ -43,17 +48,20 @@ public class MaterialCollectionViewLayout : UICollectionViewLayout {
private
var
layoutItems
:
Array
<
(
UICollectionViewLayoutAttributes
,
NSIndexPath
)
>
=
Array
<
(
UICollectionViewLayoutAttributes
,
NSIndexPath
)
>
()
/// Used to calculate the dimensions of the cells.
private
var
offset
:
CG
Float
=
0
private
var
offset
:
CG
Point
=
CGPointZero
/// Cell items.
private
var
items
:
Array
<
Array
<
Material
CollectionView
DataSourceItem
>>
?
private
var
items
:
Array
<
Array
<
MaterialDataSourceItem
>>
?
/// Scroll direction.
public
var
scrollDirection
:
MaterialCollectionViewLayout
ScrollDirection
=
.
Vertical
public
var
scrollDirection
:
UICollectionView
ScrollDirection
=
.
Vertical
/// Scale of the screen.
public
var
scale
:
CGFloat
=
2
/// Spacing between items.
public
var
spacing
:
CGFloat
=
0
/**
Retrieves the index paths for the items within the passed in CGRect.
- Parameter rect: A CGRect that acts as the bounds to find the items within.
...
...
@@ -71,14 +79,13 @@ public class MaterialCollectionViewLayout : UICollectionViewLayout {
public
override
func
layoutAttributesForItemAtIndexPath
(
indexPath
:
NSIndexPath
)
->
UICollectionViewLayoutAttributes
?
{
let
attributes
:
UICollectionViewLayoutAttributes
=
UICollectionViewLayoutAttributes
(
forCellWithIndexPath
:
indexPath
)
let
item
:
Material
CollectionView
DataSourceItem
=
items
!
[
indexPath
.
section
][
indexPath
.
item
]
let
item
:
MaterialDataSourceItem
=
items
!
[
indexPath
.
section
][
indexPath
.
item
]
if
.
Vertical
==
scrollDirection
{
attributes
.
frame
=
CGRectMake
(
0
,
offset
/
scale
,
collectionView
!.
bounds
.
width
,
item
.
size
.
height
)
offset
+=
item
.
size
.
height
}
else
{
attributes
.
frame
=
CGRectMake
(
offset
/
scale
,
0
,
item
.
size
.
width
,
collectionView
!.
bounds
.
height
)
offset
+=
item
.
size
.
width
switch
scrollDirection
{
case
.
Vertical
:
attributes
.
frame
=
CGRectMake
(
contentInset
.
left
,
offset
.
y
,
collectionView
!.
bounds
.
width
-
contentInset
.
left
-
contentInset
.
right
,
nil
==
item
.
size
?
.
height
?
collectionView
!.
bounds
.
height
:
item
.
size
!.
height
)
case
.
Horizontal
:
attributes
.
frame
=
CGRectMake
(
offset
.
x
,
contentInset
.
top
,
nil
==
item
.
size
?
.
width
?
collectionView
!.
bounds
.
width
:
item
.
size
!.
width
,
collectionView
!.
bounds
.
height
-
contentInset
.
top
-
contentInset
.
bottom
)
}
return
attributes
...
...
@@ -107,22 +114,31 @@ public class MaterialCollectionViewLayout : UICollectionViewLayout {
items
=
dataSource
.
items
()
layoutItems
.
removeAll
()
offset
=
0
offset
.
x
=
contentInset
.
left
offset
.
y
=
contentInset
.
top
var
indexPath
:
NSIndexPath
?
for
var
i
:
Int
=
0
,
l
:
Int
=
items
!.
count
;
i
<
l
;
++
i
{
let
v
:
Array
<
Material
CollectionView
DataSourceItem
>
=
items
!
[
i
]
for
var
j
:
Int
=
0
,
k
:
Int
=
v
.
count
;
j
<
k
;
++
j
{
let
item
:
Material
CollectionView
DataSourceItem
=
v
[
j
]
for
var
i
:
Int
=
0
,
l
:
Int
=
items
!.
count
-
1
;
i
<=
l
;
++
i
{
let
v
:
Array
<
MaterialDataSourceItem
>
=
items
!
[
i
]
for
var
j
:
Int
=
0
,
k
:
Int
=
v
.
count
-
1
;
j
<=
k
;
++
j
{
let
item
:
MaterialDataSourceItem
=
v
[
j
]
indexPath
=
NSIndexPath
(
forItem
:
j
,
inSection
:
i
)
layoutItems
.
append
((
layoutAttributesForItemAtIndexPath
(
indexPath
!
)
!
,
indexPath
!
))
offset
+=
.
Vertical
==
scrollDirection
?
item
.
size
.
height
:
item
.
size
.
width
offset
.
x
+=
spacing
offset
.
x
+=
nil
==
item
.
size
?
.
width
?
0
:
item
.
size
!.
width
offset
.
y
+=
spacing
offset
.
y
+=
nil
==
item
.
size
?
.
height
?
0
:
item
.
size
!.
height
}
}
contentSize
=
.
Vertical
==
scrollDirection
?
CGSizeMake
(
collectionView
!.
bounds
.
width
,
offset
/
scale
)
:
CGSizeMake
(
offset
/
scale
,
collectionView
!.
bounds
.
height
)
offset
=
0
offset
.
x
+=
contentInset
.
right
-
spacing
offset
.
y
+=
contentInset
.
bottom
-
spacing
contentSize
=
.
Vertical
==
scrollDirection
?
CGSizeMake
(
collectionView
!.
bounds
.
width
,
offset
.
y
)
:
CGSizeMake
(
offset
.
x
,
collectionView
!.
bounds
.
height
)
}
public
override
func
targetContentOffsetForProposedContentOffset
(
proposedContentOffset
:
CGPoint
)
->
CGPoint
{
...
...
Sources/Material
CollectionView
DataSourceItem.swift
→
Sources/MaterialDataSourceItem.swift
View file @
cf6e12ec
...
...
@@ -28,12 +28,14 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
public
struct
MaterialCollectionViewDataSourceItem
{
var
data
:
AnyObject
var
size
:
CGSize
public
struct
MaterialDataSourceItem
{
public
var
data
:
AnyObject
?
public
var
size
:
CGSize
?
public
var
origin
:
CGPoint
?
public
init
(
data
:
AnyObject
,
size
:
CGSize
)
{
public
init
(
data
:
AnyObject
?
=
nil
,
size
:
CGSize
?
=
nil
,
origin
:
CGPoint
?
=
nil
)
{
self
.
data
=
data
self
.
size
=
size
self
.
origin
=
origin
}
}
\ No newline at end of file
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