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
7d3ade62
Unverified
Commit
7d3ade62
authored
Dec 28, 2016
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
development: handling dynamic sizing for collectionViewCard
parent
adc1b827
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
48 additions
and
18 deletions
+48
-18
Sources/iOS/Menu.swift
+48
-18
No files found.
Sources/iOS/Menu.swift
View file @
7d3ade62
...
...
@@ -34,8 +34,10 @@ import UIKit
public
enum
MenuDirection
:
Int
{
case
up
case
down
case
left
case
right
case
topLeft
case
topRight
case
bottomLeft
case
bottomRight
}
open
class
MenuItem
:
Toolbar
{
...
...
@@ -44,10 +46,12 @@ open class MenuItem: Toolbar {
heightPreset
=
.
normal
titleLabel
.
textAlignment
=
.
left
detailLabel
.
textAlignment
=
.
left
contentViewAlignment
=
.
center
}
}
class
MenuCollectionViewCell
:
CollectionViewCell
{
/// A reference to the MenuItem.
open
var
menuItem
:
MenuItem
?
{
didSet
{
oldValue
?
.
removeFromSuperview
()
...
...
@@ -113,19 +117,35 @@ open class Menu: Button {
}
}
/// A reference to the collectionView.
open
let
card
=
CollectionViewCard
()
/// A reference to the collectionViewCard.
@IBInspectable
open
let
collectionViewCard
=
CollectionViewCard
()
/// A preset wrapper around collectionViewCardEdgeInsets.
open
var
collectionViewCardEdgeInsetsPreset
=
EdgeInsetsPreset
.
none
{
didSet
{
collectionViewCardEdgeInsets
=
EdgeInsetsPresetToValue
(
preset
:
collectionViewCardEdgeInsetsPreset
)
}
}
/// A reference to collectionViewCardEdgeInsets.
@IBInspectable
open
var
collectionViewCardEdgeInsets
=
EdgeInsets
.
zero
{
didSet
{
layoutSubviews
()
}
}
/**
Retrieves the data source items for the collectionView.
- Returns: An Array of DataSourceItem objects.
*/
open
var
dataSourceItems
:
[
DataSourceItem
]
{
open
fileprivate
(
set
)
var
dataSourceItems
:
[
DataSourceItem
]
{
get
{
return
card
.
dataSourceItems
return
c
ollectionViewC
ard
.
dataSourceItems
}
set
(
value
)
{
card
.
dataSourceItems
=
value
c
ollectionViewC
ard
.
dataSourceItems
=
value
}
}
...
...
@@ -160,8 +180,8 @@ open class Menu: Button {
}
open
func
reload
()
{
if
0
==
card
.
width
{
c
ard
.
width
=
Screen
.
bounds
.
width
if
0
==
c
ollectionViewC
ard
.
width
{
c
ollectionViewCard
.
width
=
Screen
.
bounds
.
width
-
collectionViewCardEdgeInsets
.
left
-
collectionViewCardEdgeInsets
.
right
}
}
}
...
...
@@ -169,9 +189,9 @@ open class Menu: Button {
extension
Menu
{
/// Prepares the card.
fileprivate
func
prepareCard
()
{
card
.
collectionView
.
delegate
=
self
card
.
collectionView
.
dataSource
=
self
card
.
collectionView
.
register
(
MenuCollectionViewCell
.
self
,
forCellWithReuseIdentifier
:
"MenuCollectionViewCell"
)
c
ollectionViewC
ard
.
collectionView
.
delegate
=
self
c
ollectionViewC
ard
.
collectionView
.
dataSource
=
self
c
ollectionViewC
ard
.
collectionView
.
register
(
MenuCollectionViewCell
.
self
,
forCellWithReuseIdentifier
:
"MenuCollectionViewCell"
)
}
/// Prepares the handler.
...
...
@@ -215,15 +235,25 @@ extension Menu {
return
}
guard
nil
==
card
.
superview
else
{
guard
nil
==
c
ollectionViewC
ard
.
superview
else
{
return
}
delegate
?
.
menuWillOpen
?(
menu
:
self
)
switch
direction
{
case
.
up
,
.
down
,
.
left
,
.
right
:
layout
(
card
)
.
bottom
()
.
centerHorizontally
()
case
.
up
:
layout
(
collectionViewCard
)
.
bottom
()
.
centerHorizontally
()
case
.
down
:
layout
(
collectionViewCard
)
.
top
()
.
centerHorizontally
()
case
.
topLeft
:
layout
(
collectionViewCard
)
.
topLeft
()
case
.
topRight
:
layout
(
collectionViewCard
)
.
topRight
()
case
.
bottomLeft
:
layout
(
collectionViewCard
)
.
bottomLeft
()
case
.
bottomRight
:
layout
(
collectionViewCard
)
.
bottomRight
()
}
isOpened
=
true
...
...
@@ -238,7 +268,7 @@ extension Menu {
delegate
?
.
menuWillClose
?(
menu
:
self
)
card
.
removeFromSuperview
()
c
ollectionViewC
ard
.
removeFromSuperview
()
isOpened
=
false
...
...
@@ -264,7 +294,7 @@ extension Menu {
extension
Menu
:
CollectionViewDelegate
{
open
func
collectionView
(
_
collectionView
:
UICollectionView
,
didSelectItemAt
indexPath
:
IndexPath
)
{
guard
let
menuItem
=
card
.
indexForDataSourceItems
[
indexPath
]
as?
MenuItem
else
{
guard
let
menuItem
=
c
ollectionViewC
ard
.
indexForDataSourceItems
[
indexPath
]
as?
MenuItem
else
{
return
}
...
...
@@ -291,7 +321,7 @@ extension Menu: CollectionViewDataSource {
return
cell
}
card
.
indexForDataSourceItems
[
indexPath
]
=
menuItem
c
ollectionViewC
ard
.
indexForDataSourceItems
[
indexPath
]
=
menuItem
cell
.
menuItem
=
menuItem
cell
.
menuItem
?
.
width
=
cell
.
width
...
...
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