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
1bdde898
Unverified
Commit
1bdde898
authored
Dec 28, 2016
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
development: added Menu with internal CollectionView
parent
994062aa
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
85 additions
and
49 deletions
+85
-49
Sources/iOS/Bar.swift
+1
-2
Sources/iOS/Menu.swift
+84
-47
No files found.
Sources/iOS/Bar.swift
View file @
1bdde898
...
...
@@ -36,7 +36,7 @@ public enum ContentViewAlignment: Int {
case
center
}
open
class
Bar
:
Pulse
View
{
open
class
Bar
:
View
{
/// Will layout the view.
open
var
willLayout
:
Bool
{
return
0
<
width
&&
0
<
height
&&
nil
!=
superview
...
...
@@ -275,7 +275,6 @@ open class Bar: PulseView {
open
override
func
prepare
()
{
super
.
prepare
()
heightPreset
=
.
normal
pulseAnimation
=
.
none
autoresizingMask
=
.
flexibleWidth
interimSpacePreset
=
.
interimSpace3
contentEdgeInsetsPreset
=
.
square1
...
...
Sources/iOS/Menu.swift
View file @
1bdde898
...
...
@@ -42,13 +42,21 @@ open class MenuItem: Toolbar {
open
override
func
prepare
()
{
super
.
prepare
()
heightPreset
=
.
normal
pulseAnimation
=
.
pointWithBacking
titleLabel
.
textAlignment
=
.
left
detailLabel
.
textAlignment
=
.
left
}
}
open
class
MenuCard
:
Card
{}
class
MenuCollectionViewCell
:
CollectionViewCell
{
open
var
menuItem
:
MenuItem
?
{
didSet
{
oldValue
?
.
removeFromSuperview
()
if
let
v
=
menuItem
{
contentView
.
addSubview
(
v
)
}
}
}
}
@objc(MenuDelegate)
public
protocol
MenuDelegate
{
...
...
@@ -92,7 +100,7 @@ public protocol MenuDelegate {
optional
func
menu
(
menu
:
Menu
,
tappedAt
point
:
CGPoint
,
isOutside
:
Bool
)
@objc
optional
func
menu
(
menu
:
Menu
,
didSelect
menuItem
:
MenuItem
)
optional
func
menu
(
menu
:
Menu
,
didSelect
menuItem
:
MenuItem
,
at
indexPath
:
IndexPath
)
}
...
...
@@ -105,27 +113,28 @@ open class Menu: Button {
}
}
/// A reference to the
card
.
open
let
card
=
MenuCard
()
/// A reference to the
dataSourceItems
.
open
fileprivate
(
set
)
var
dataSourceItems
=
[
DataSourceItem
]
()
/// A preset wrapper around cardEdgeInsets.
open
var
cardEdgeInsetsPreset
=
EdgeInsetsPreset
.
none
{
didSet
{
cardEdgeInsets
=
EdgeInsetsPresetToValue
(
preset
:
cardEdgeInsetsPreset
)
}
}
/// An index of IndexPath to MenuItem.
open
fileprivate
(
set
)
var
indexForDataSourceItems
=
[
IndexPath
:
MenuItem
]()
/// A reference to cardEdgeInsets.
@IBInspectable
open
var
cardEdgeInsets
=
EdgeInsets
.
zero
{
didSet
{
layoutSubviews
()
}
}
/// A reference to the collectionView.
open
let
collectionView
=
CollectionView
()
/// A reference to the card.
open
let
card
=
Card
()
/// A reference to the MenuItems.
open
var
items
=
[
MenuItem
]()
{
didSet
{
dataSourceItems
.
removeAll
()
indexForDataSourceItems
.
removeAll
()
for
item
in
items
{
dataSourceItems
.
append
(
DataSourceItem
(
data
:
item
,
width
:
item
.
width
,
height
:
item
.
height
))
}
layoutSubviews
()
}
}
...
...
@@ -143,37 +152,40 @@ open class Menu: Button {
open
override
func
prepare
()
{
super
.
prepare
()
prepareCollectionView
()
prepareCard
()
prepareHandler
()
}
open
func
reload
()
{
let
screen
=
Screen
.
bounds
card
.
width
=
screen
.
width
-
cardEdgeInsets
.
left
-
cardEdgeInsets
.
right
guard
let
contentView
=
card
.
contentView
else
{
return
if
0
==
card
.
width
{
card
.
width
=
Screen
.
bounds
.
width
}
contentView
.
grid
.
begin
()
contentView
.
grid
.
axis
.
rows
=
items
.
count
contentView
.
grid
.
axis
.
direction
=
.
vertical
var
h
:
CGFloat
=
0
for
v
in
items
{
h
+=
v
.
height
if
0
==
collectionView
.
height
{
var
h
:
CGFloat
=
0
for
dataSourceItem
in
dataSourceItems
{
h
+=
dataSourceItem
.
height
??
0
}
collectionView
.
height
=
h
}
contentView
.
height
=
h
contentView
.
grid
.
views
=
items
contentView
.
grid
.
commit
()
collectionView
.
reloadData
()
}
}
extension
Menu
{
/// Prepares the collectionView.
fileprivate
func
prepareCollectionView
()
{
collectionView
.
delegate
=
self
collectionView
.
dataSource
=
self
collectionView
.
interimSpacePreset
=
.
none
collectionView
.
register
(
MenuCollectionViewCell
.
self
,
forCellWithReuseIdentifier
:
"MenuCollectionViewCell"
)
}
/// Prepares the card.
fileprivate
func
prepareCard
()
{
card
.
contentView
=
UIView
()
card
.
contentView
=
collectionView
}
/// Prepares the handler.
...
...
@@ -194,19 +206,6 @@ extension Menu {
return
super
.
hitTest
(
point
,
with
:
event
)
}
guard
let
contentView
=
card
.
contentView
else
{
return
nil
}
for
v
in
contentView
.
subviews
{
let
p
=
v
.
convert
(
point
,
from
:
self
)
if
v
.
bounds
.
contains
(
p
)
{
if
let
item
=
v
as?
MenuItem
{
delegate
?
.
menu
?(
menu
:
self
,
didSelect
:
item
)
}
}
}
for
v
in
subviews
{
let
p
=
v
.
convert
(
point
,
from
:
self
)
if
v
.
bounds
.
contains
(
p
)
{
...
...
@@ -276,3 +275,41 @@ extension Menu {
close
()
}
}
extension
Menu
:
CollectionViewDelegate
{
open
func
collectionView
(
_
collectionView
:
UICollectionView
,
didSelectItemAt
indexPath
:
IndexPath
)
{
guard
let
menuItem
=
indexForDataSourceItems
[
indexPath
]
else
{
return
}
delegate
?
.
menu
?(
menu
:
self
,
didSelect
:
menuItem
,
at
:
indexPath
)
}
}
extension
Menu
:
CollectionViewDataSource
{
@objc
open
func
numberOfSections
(
in
collectionView
:
UICollectionView
)
->
Int
{
return
1
}
@objc
open
func
collectionView
(
_
collectionView
:
UICollectionView
,
numberOfItemsInSection
section
:
Int
)
->
Int
{
return
dataSourceItems
.
count
}
@objc
open
func
collectionView
(
_
collectionView
:
UICollectionView
,
cellForItemAt
indexPath
:
IndexPath
)
->
UICollectionViewCell
{
let
cell
=
collectionView
.
dequeueReusableCell
(
withReuseIdentifier
:
"MenuCollectionViewCell"
,
for
:
indexPath
)
as!
MenuCollectionViewCell
guard
let
menuItem
=
dataSourceItems
[
indexPath
.
item
]
.
data
as?
MenuItem
else
{
return
cell
}
indexForDataSourceItems
[
indexPath
]
=
menuItem
cell
.
menuItem
=
menuItem
cell
.
menuItem
?
.
width
=
cell
.
width
return
cell
}
}
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