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 {
...
@@ -36,7 +36,7 @@ public enum ContentViewAlignment: Int {
case
center
case
center
}
}
open
class
Bar
:
Pulse
View
{
open
class
Bar
:
View
{
/// Will layout the view.
/// Will layout the view.
open
var
willLayout
:
Bool
{
open
var
willLayout
:
Bool
{
return
0
<
width
&&
0
<
height
&&
nil
!=
superview
return
0
<
width
&&
0
<
height
&&
nil
!=
superview
...
@@ -275,7 +275,6 @@ open class Bar: PulseView {
...
@@ -275,7 +275,6 @@ open class Bar: PulseView {
open
override
func
prepare
()
{
open
override
func
prepare
()
{
super
.
prepare
()
super
.
prepare
()
heightPreset
=
.
normal
heightPreset
=
.
normal
pulseAnimation
=
.
none
autoresizingMask
=
.
flexibleWidth
autoresizingMask
=
.
flexibleWidth
interimSpacePreset
=
.
interimSpace3
interimSpacePreset
=
.
interimSpace3
contentEdgeInsetsPreset
=
.
square1
contentEdgeInsetsPreset
=
.
square1
...
...
Sources/iOS/Menu.swift
View file @
1bdde898
...
@@ -42,13 +42,21 @@ open class MenuItem: Toolbar {
...
@@ -42,13 +42,21 @@ open class MenuItem: Toolbar {
open
override
func
prepare
()
{
open
override
func
prepare
()
{
super
.
prepare
()
super
.
prepare
()
heightPreset
=
.
normal
heightPreset
=
.
normal
pulseAnimation
=
.
pointWithBacking
titleLabel
.
textAlignment
=
.
left
titleLabel
.
textAlignment
=
.
left
detailLabel
.
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)
@objc(MenuDelegate)
public
protocol
MenuDelegate
{
public
protocol
MenuDelegate
{
...
@@ -92,7 +100,7 @@ public protocol MenuDelegate {
...
@@ -92,7 +100,7 @@ public protocol MenuDelegate {
optional
func
menu
(
menu
:
Menu
,
tappedAt
point
:
CGPoint
,
isOutside
:
Bool
)
optional
func
menu
(
menu
:
Menu
,
tappedAt
point
:
CGPoint
,
isOutside
:
Bool
)
@objc
@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 {
...
@@ -105,27 +113,28 @@ open class Menu: Button {
}
}
}
}
/// A reference to the
card
.
/// A reference to the
dataSourceItems
.
open
let
card
=
MenuCard
()
open
fileprivate
(
set
)
var
dataSourceItems
=
[
DataSourceItem
]
()
/// A preset wrapper around cardEdgeInsets.
/// An index of IndexPath to MenuItem.
open
var
cardEdgeInsetsPreset
=
EdgeInsetsPreset
.
none
{
open
fileprivate
(
set
)
var
indexForDataSourceItems
=
[
IndexPath
:
MenuItem
]()
didSet
{
cardEdgeInsets
=
EdgeInsetsPresetToValue
(
preset
:
cardEdgeInsetsPreset
)
}
}
/// A reference to cardEdgeInsets.
/// A reference to the collectionView.
@IBInspectable
open
let
collectionView
=
CollectionView
()
open
var
cardEdgeInsets
=
EdgeInsets
.
zero
{
didSet
{
/// A reference to the card.
layoutSubviews
()
open
let
card
=
Card
()
}
}
/// A reference to the MenuItems.
/// A reference to the MenuItems.
open
var
items
=
[
MenuItem
]()
{
open
var
items
=
[
MenuItem
]()
{
didSet
{
didSet
{
dataSourceItems
.
removeAll
()
indexForDataSourceItems
.
removeAll
()
for
item
in
items
{
dataSourceItems
.
append
(
DataSourceItem
(
data
:
item
,
width
:
item
.
width
,
height
:
item
.
height
))
}
layoutSubviews
()
layoutSubviews
()
}
}
}
}
...
@@ -143,37 +152,40 @@ open class Menu: Button {
...
@@ -143,37 +152,40 @@ open class Menu: Button {
open
override
func
prepare
()
{
open
override
func
prepare
()
{
super
.
prepare
()
super
.
prepare
()
prepareCollectionView
()
prepareCard
()
prepareCard
()
prepareHandler
()
prepareHandler
()
}
}
open
func
reload
()
{
open
func
reload
()
{
let
screen
=
Screen
.
bounds
if
0
==
card
.
width
{
card
.
width
=
screen
.
width
-
cardEdgeInsets
.
left
-
cardEdgeInsets
.
right
card
.
width
=
Screen
.
bounds
.
width
guard
let
contentView
=
card
.
contentView
else
{
return
}
}
contentView
.
grid
.
begin
()
if
0
==
collectionView
.
height
{
contentView
.
grid
.
axis
.
rows
=
items
.
count
var
h
:
CGFloat
=
0
contentView
.
grid
.
axis
.
direction
=
.
vertical
for
dataSourceItem
in
dataSourceItems
{
h
+=
dataSourceItem
.
height
??
0
var
h
:
CGFloat
=
0
}
for
v
in
items
{
collectionView
.
height
=
h
h
+=
v
.
height
}
}
contentView
.
height
=
h
collectionView
.
reloadData
()
contentView
.
grid
.
views
=
items
contentView
.
grid
.
commit
()
}
}
}
}
extension
Menu
{
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.
/// Prepares the card.
fileprivate
func
prepareCard
()
{
fileprivate
func
prepareCard
()
{
card
.
contentView
=
UIView
()
card
.
contentView
=
collectionView
}
}
/// Prepares the handler.
/// Prepares the handler.
...
@@ -194,19 +206,6 @@ extension Menu {
...
@@ -194,19 +206,6 @@ extension Menu {
return
super
.
hitTest
(
point
,
with
:
event
)
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
{
for
v
in
subviews
{
let
p
=
v
.
convert
(
point
,
from
:
self
)
let
p
=
v
.
convert
(
point
,
from
:
self
)
if
v
.
bounds
.
contains
(
p
)
{
if
v
.
bounds
.
contains
(
p
)
{
...
@@ -276,3 +275,41 @@ extension Menu {
...
@@ -276,3 +275,41 @@ extension Menu {
close
()
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