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
51a7d750
Unverified
Commit
51a7d750
authored
Aug 28, 2016
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
development: updated ControlView and NavigationBar grid layouts
parent
9efac5ec
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
135 additions
and
144 deletions
+135
-144
Sources/iOS/ControlView.swift
+28
-29
Sources/iOS/NavigationBar.swift
+37
-36
Sources/iOS/NavigationController.swift
+57
-54
Sources/iOS/NavigationItem.swift
+4
-4
Sources/iOS/Snackbar.swift
+5
-19
Sources/iOS/SnackbarController.swift
+2
-0
Sources/iOS/Toolbar.swift
+2
-2
No files found.
Sources/iOS/ControlView.swift
View file @
51a7d750
...
...
@@ -48,7 +48,7 @@ open class ControlView: View {
/// A wrapper around grid.contentInset.
@IBInspectable
open
var
content
Inset
:
EdgeInsets
{
open
var
content
EdgeInsets
:
EdgeInsets
{
get
{
return
grid
.
contentEdgeInsets
}
...
...
@@ -151,49 +151,48 @@ open class ControlView: View {
if
willRenderView
{
layoutIfNeeded
()
let
g
=
Int
(
width
/
gridFactor
)
let
columns
=
g
+
1
let
l
=
(
CGFloat
(
leftControls
.
count
)
*
interimSpace
)
let
r
=
(
CGFloat
(
rightControls
.
count
)
*
interimSpace
)
let
p
=
width
-
l
-
r
-
contentEdgeInsets
.
left
-
contentEdgeInsets
.
right
let
columns
=
Int
(
p
/
gridFactor
)
grid
.
views
=
[]
grid
.
views
.
removeAll
()
grid
.
axis
.
columns
=
columns
contentView
.
grid
.
columns
=
columns
// leftControls
for
c
in
leftControls
{
let
w
:
CGFloat
=
c
.
intrinsicContentSize
.
width
(
c
as?
UIButton
)?
.
contentEdgeInsets
=
.
zero
c
.
height
=
frame
.
size
.
height
-
contentInset
.
top
-
contentInset
.
bottom
for
v
in
leftControls
{
var
w
:
CGFloat
=
0
if
let
b
=
v
as?
UIButton
{
b
.
contentEdgeInsets
=
.
zero
b
.
sizeToFit
()
w
=
b
.
width
}
v
.
height
=
frame
.
size
.
height
-
contentEdgeInsets
.
top
-
contentEdgeInsets
.
bottom
v
.
grid
.
columns
=
Int
(
ceil
(
w
/
gridFactor
))
+
1
let
q
:
Int
=
Int
(
w
/
gridFactor
)
c
.
grid
.
columns
=
q
+
1
contentView
.
grid
.
columns
-=
v
.
grid
.
columns
contentView
.
grid
.
columns
-=
c
.
grid
.
columns
addSubview
(
c
)
grid
.
views
.
append
(
c
)
grid
.
views
.
append
(
v
)
}
addSubview
(
contentView
)
grid
.
views
.
append
(
contentView
)
// rightControls
for
c
in
rightControls
{
let
w
=
c
.
intrinsicContentSize
.
width
(
c
as?
UIButton
)?
.
contentEdgeInsets
=
.
zero
c
.
height
=
frame
.
size
.
height
-
contentInset
.
top
-
contentInset
.
bottom
let
q
:
Int
=
Int
(
w
/
gridFactor
)
c
.
grid
.
columns
=
q
+
1
for
v
in
rightControls
{
var
w
:
CGFloat
=
0
if
let
b
=
v
as?
UIButton
{
b
.
contentEdgeInsets
=
.
zero
b
.
sizeToFit
()
w
=
b
.
width
}
v
.
height
=
frame
.
size
.
height
-
contentEdgeInsets
.
top
-
contentEdgeInsets
.
bottom
v
.
grid
.
columns
=
Int
(
ceil
(
w
/
gridFactor
))
+
1
contentView
.
grid
.
columns
-=
c
.
grid
.
columns
contentView
.
grid
.
columns
-=
v
.
grid
.
columns
addSubview
(
c
)
grid
.
views
.
append
(
c
)
grid
.
views
.
append
(
v
)
}
grid
.
contentEdgeInsets
=
contentInset
grid
.
interimSpace
=
interimSpace
contentView
.
grid
.
reload
()
}
}
...
...
Sources/iOS/NavigationBar.swift
View file @
51a7d750
...
...
@@ -61,19 +61,19 @@ open class NavigationBar: UINavigationBar {
/// Will render the view.
open
var
willRenderView
:
Bool
{
return
0
<
width
&&
0
<
height
&&
nil
!=
superview
return
0
<
width
&&
0
<
height
}
/// A preset wrapper around contentInset.
open
var
contentEdgeInsetsPreset
=
EdgeInsetsPreset
.
none
{
didSet
{
content
Inset
=
EdgeInsetsPresetToValue
(
preset
:
contentEdgeInsetsPreset
)
content
EdgeInsets
=
EdgeInsetsPresetToValue
(
preset
:
contentEdgeInsetsPreset
)
}
}
/// A wrapper around grid.contentInset.
@IBInspectable
open
var
content
Inset
=
EdgeInsets
.
zero
{
open
var
content
EdgeInsets
=
EdgeInsets
.
zero
{
didSet
{
layoutSubviews
()
}
...
...
@@ -175,7 +175,9 @@ open class NavigationBar: UINavigationBar {
layoutNavigationItem
(
item
:
v
)
}
divider
?
.
reload
()
if
let
v
=
divider
{
v
.
reload
()
}
}
open
override
func
pushItem
(
_
item
:
UINavigationItem
,
animated
:
Bool
)
{
...
...
@@ -194,52 +196,51 @@ open class NavigationBar: UINavigationBar {
let
titleView
=
prepareTitleView
(
item
:
item
)
let
contentView
=
prepareContentView
(
item
:
item
)
let
g
=
Int
(
width
/
gridFactor
)
let
columns
=
g
+
1
let
l
=
(
CGFloat
(
item
.
leftControls
.
count
)
*
interimSpace
)
let
r
=
(
CGFloat
(
item
.
rightControls
.
count
)
*
interimSpace
)
let
p
=
width
-
l
-
r
-
contentEdgeInsets
.
left
-
contentEdgeInsets
.
right
let
columns
=
Int
(
p
/
gridFactor
)
titleView
.
frame
.
origin
=
.
zero
titleView
.
frame
.
size
=
intrinsicContentSize
titleView
.
grid
.
views
=
[]
titleView
.
grid
.
views
.
removeAll
()
titleView
.
grid
.
axis
.
columns
=
columns
contentView
.
grid
.
columns
=
columns
// leftControls
if
let
v
=
item
.
leftControls
{
for
c
in
v
{
let
w
=
c
.
intrinsicContentSize
.
width
(
c
as?
UIButton
)?
.
contentEdgeInsets
=
.
zero
c
.
height
=
titleView
.
height
-
contentInset
.
top
-
contentInset
.
bottom
c
.
grid
.
columns
=
Int
(
w
/
gridFactor
)
+
1
contentView
.
grid
.
columns
-=
c
.
grid
.
columns
titleView
.
addSubview
(
c
)
titleView
.
grid
.
views
.
append
(
c
)
for
v
in
item
.
leftControls
{
var
w
:
CGFloat
=
0
if
let
b
=
v
as?
UIButton
{
b
.
contentEdgeInsets
=
.
zero
b
.
sizeToFit
()
w
=
b
.
width
}
v
.
height
=
frame
.
size
.
height
-
contentEdgeInsets
.
top
-
contentEdgeInsets
.
bottom
v
.
grid
.
columns
=
Int
(
ceil
(
w
/
gridFactor
))
+
1
contentView
.
grid
.
columns
-=
v
.
grid
.
columns
titleView
.
grid
.
views
.
append
(
v
)
}
titleView
.
addSubview
(
contentView
)
titleView
.
grid
.
views
.
append
(
contentView
)
// rightControls
if
let
v
=
item
.
rightControls
{
for
c
in
v
{
let
w
=
c
.
intrinsicContentSize
.
width
(
c
as?
UIButton
)?
.
contentEdgeInsets
=
.
zero
c
.
height
=
titleView
.
height
-
contentInset
.
top
-
contentInset
.
bottom
c
.
grid
.
columns
=
Int
(
w
/
gridFactor
)
+
1
contentView
.
grid
.
columns
-=
c
.
grid
.
columns
titleView
.
addSubview
(
c
)
titleView
.
grid
.
views
.
append
(
c
)
for
v
in
item
.
rightControls
{
var
w
:
CGFloat
=
0
if
let
b
=
v
as?
UIButton
{
b
.
contentEdgeInsets
=
.
zero
b
.
sizeToFit
()
w
=
b
.
width
}
v
.
height
=
frame
.
size
.
height
-
contentEdgeInsets
.
top
-
contentEdgeInsets
.
bottom
v
.
grid
.
columns
=
Int
(
ceil
(
w
/
gridFactor
))
+
1
contentView
.
grid
.
columns
-=
v
.
grid
.
columns
titleView
.
grid
.
views
.
append
(
v
)
}
titleView
.
grid
.
contentEdgeInsets
=
content
Inset
titleView
.
grid
.
contentEdgeInsets
=
content
EdgeInsets
titleView
.
grid
.
interimSpace
=
interimSpace
titleView
.
grid
.
reload
()
...
...
Sources/iOS/NavigationController.swift
View file @
51a7d750
...
...
@@ -43,7 +43,7 @@ extension UINavigationController {
}
@IBDesignable
open
class
NavigationController
:
UINavigationController
,
UIGestureRecognizerDelegate
{
open
class
NavigationController
:
UINavigationController
{
/**
An initializer that initializes the object with a NSCoder object.
- Parameter aDecoder: A NSCoder instance.
...
...
@@ -72,15 +72,20 @@ open class NavigationController: UINavigationController, UIGestureRecognizerDele
open
override
func
viewWillAppear
(
_
animated
:
Bool
)
{
super
.
viewWillAppear
(
animated
)
if
let
v
=
interactivePopGestureRecognizer
{
if
let
x
=
navigationDrawerController
{
if
let
l
=
x
.
leftPanGesture
{
l
.
require
(
toFail
:
v
)
}
if
let
r
=
x
.
rightPanGesture
{
r
.
require
(
toFail
:
v
)
}
}
guard
let
v
=
interactivePopGestureRecognizer
else
{
return
}
guard
let
x
=
navigationDrawerController
else
{
return
}
if
let
l
=
x
.
leftPanGesture
{
l
.
require
(
toFail
:
v
)
}
if
let
r
=
x
.
rightPanGesture
{
r
.
require
(
toFail
:
v
)
}
}
...
...
@@ -100,49 +105,6 @@ open class NavigationController: UINavigationController, UIGestureRecognizerDele
}
/**
Detects the gesture recognizer being used. This is necessary when using
NavigationDrawerController. It eliminates the conflict in panning.
- Parameter gestureRecognizer: A UIGestureRecognizer to detect.
- Parameter touch: The UITouch event.
- Returns: A Boolean of whether to continue the gesture or not, true yes, false no.
*/
open
func
gestureRecognizer
(
_
gestureRecognizer
:
UIGestureRecognizer
,
shouldReceive
touch
:
UITouch
)
->
Bool
{
return
interactivePopGestureRecognizer
==
gestureRecognizer
&&
nil
!=
navigationBar
.
backItem
}
/**
Delegation method that is called when a new UINavigationItem is about to be pushed.
This is used to prepare the transitions between UIViewControllers on the stack.
- Parameter navigationBar: A UINavigationBar that is used in the NavigationController.
- Parameter item: The UINavigationItem that will be pushed on the stack.
- Returns: A Boolean value that indicates whether to push the item on to the stack or not.
True is yes, false is no.
*/
open
func
navigationBar
(
navigationBar
:
UINavigationBar
,
shouldPushItem
item
:
UINavigationItem
)
->
Bool
{
if
let
v
=
navigationBar
as?
NavigationBar
{
let
backButton
=
IconButton
(
image
:
v
.
backButtonImage
)
backButton
.
pulseColor
=
Color
.
white
backButton
.
addTarget
(
self
,
action
:
#selector(
handleBackButton
)
,
for
:
.
touchUpInside
)
if
var
c
=
item
.
leftControls
{
c
.
append
(
backButton
)
item
.
leftControls
=
c
}
else
{
item
.
leftControls
=
[
backButton
]
}
item
.
backButton
=
backButton
v
.
layoutNavigationItem
(
item
:
item
)
}
return
true
}
/// Handler for the back button.
internal
func
handleBackButton
()
{
popViewController
(
animated
:
true
)
}
/**
Prepares the view instance when intialized. When subclassing,
it is recommended to override the prepareView method
to initialize property values and other setup operations.
...
...
@@ -153,10 +115,51 @@ open class NavigationController: UINavigationController, UIGestureRecognizerDele
view
.
clipsToBounds
=
true
view
.
contentScaleFactor
=
Device
.
scale
// This ensures the panning gesture is available when going back between views.
// This ensures the panning gesture is available when going back between views.
if
let
v
=
interactivePopGestureRecognizer
{
v
.
isEnabled
=
true
v
.
delegate
=
self
}
}
}
extension
NavigationController
:
UINavigationBarDelegate
{
/**
Delegation method that is called when a new UINavigationItem is about to be pushed.
This is used to prepare the transitions between UIViewControllers on the stack.
- Parameter navigationBar: A UINavigationBar that is used in the NavigationController.
- Parameter item: The UINavigationItem that will be pushed on the stack.
- Returns: A Boolean value that indicates whether to push the item on to the stack or not.
True is yes, false is no.
*/
public
func
navigationBar
(
_
navigationBar
:
UINavigationBar
,
shouldPush
item
:
UINavigationItem
)
->
Bool
{
if
let
v
=
navigationBar
as?
NavigationBar
{
let
backButton
=
IconButton
(
image
:
v
.
backButtonImage
,
tintColor
:
Color
.
blue
.
base
)
backButton
.
pulseColor
=
Color
.
white
backButton
.
addTarget
(
self
,
action
:
#selector(
handleBackButton
)
,
for
:
.
touchUpInside
)
item
.
leftControls
.
append
(
backButton
)
item
.
backButton
=
backButton
v
.
layoutNavigationItem
(
item
:
item
)
}
return
true
}
/// Handler for the back button.
internal
func
handleBackButton
()
{
popViewController
(
animated
:
true
)
}
}
extension
NavigationController
:
UIGestureRecognizerDelegate
{
/**
Detects the gesture recognizer being used. This is necessary when using
NavigationDrawerController. It eliminates the conflict in panning.
- Parameter gestureRecognizer: A UIGestureRecognizer to detect.
- Parameter touch: The UITouch event.
- Returns: A Boolean of whether to continue the gesture or not, true yes, false no.
*/
public
func
gestureRecognizer
(
_
gestureRecognizer
:
UIGestureRecognizer
,
shouldReceive
touch
:
UITouch
)
->
Bool
{
return
interactivePopGestureRecognizer
==
gestureRecognizer
&&
nil
!=
navigationBar
.
backItem
}
}
Sources/iOS/NavigationItem.swift
View file @
51a7d750
...
...
@@ -53,10 +53,10 @@ public class NavigationItem {
public
private(set)
var
detailLabel
:
UILabel
!
/// Left controls.
public
var
leftControls
:
[
UIView
]?
public
var
leftControls
=
[
UIView
]()
/// Right controls.
public
var
rightControls
:
[
UIView
]?
public
var
rightControls
=
[
UIView
]()
/// Initializer.
public
init
()
{
...
...
@@ -153,7 +153,7 @@ extension UINavigationItem {
}
/// Left side UIViews.
public
var
leftControls
:
[
UIView
]
?
{
public
var
leftControls
:
[
UIView
]
{
get
{
return
navigationItem
.
leftControls
}
...
...
@@ -163,7 +163,7 @@ extension UINavigationItem {
}
/// Right side UIViews.
public
var
rightControls
:
[
UIView
]
?
{
public
var
rightControls
:
[
UIView
]
{
get
{
return
navigationItem
.
rightControls
}
...
...
Sources/iOS/Snackbar.swift
View file @
51a7d750
...
...
@@ -49,7 +49,7 @@ open class Snackbar: BarView {
}
/// Text label.
public
private
(set)
var
textLabel
:
UILabel
!
public
internal
(set)
var
textLabel
:
UILabel
!
open
override
var
intrinsicContentSize
:
CGSize
{
return
CGSize
(
width
:
width
,
height
:
49
)
...
...
@@ -58,22 +58,6 @@ open class Snackbar: BarView {
/// The status of the snackbar.
open
internal(set)
var
status
=
SnackbarStatus
.
notVisible
open
override
func
layoutSubviews
()
{
super
.
layoutSubviews
()
if
willRenderView
{
if
nil
!=
text
&&
""
!=
text
{
if
nil
==
textLabel
.
superview
{
contentView
.
addSubview
(
textLabel
)
}
textLabel
.
frame
=
contentView
.
bounds
}
else
{
textLabel
.
removeFromSuperview
()
}
contentView
.
grid
.
reload
()
}
}
/**
Prepares the view instance when intialized. When subclassing,
it is recommended to override the prepareView method
...
...
@@ -83,9 +67,10 @@ open class Snackbar: BarView {
*/
open
override
func
prepareView
()
{
super
.
prepareView
()
interimSpace
=
24
contentEdgeInsets
.
left
=
interimSpace
contentEdgeInsets
.
right
=
interimSpace
backgroundColor
=
Color
.
grey
.
darken3
grid
.
contentEdgeInsets
=
EdgeInsets
(
top
:
0
,
left
:
24
,
bottom
:
0
,
right
:
24
)
grid
.
interimSpace
=
24
prepareTextLabel
()
}
...
...
@@ -96,5 +81,6 @@ open class Snackbar: BarView {
textLabel
.
font
=
RobotoFont
.
medium
(
with
:
14
)
textLabel
.
textAlignment
=
.
left
textLabel
.
textColor
=
Color
.
white
contentView
.
grid
.
views
.
append
(
textLabel
)
}
}
Sources/iOS/SnackbarController.swift
View file @
51a7d750
...
...
@@ -92,6 +92,7 @@ open class SnackbarController: RootController {
*/
open
func
animate
(
snackbar
status
:
SnackbarStatus
,
animations
:
(
@escaping
(
Snackbar
)
->
Void
)?
=
nil
,
completion
:
(
@escaping
(
Snackbar
)
->
Void
)?
=
nil
)
{
isAnimating
=
true
isUserInteractionEnabled
=
false
UIView
.
animate
(
withDuration
:
0.25
,
animations
:
{
[
weak
self
,
status
=
status
,
animations
=
animations
]
in
guard
let
s
=
self
else
{
return
...
...
@@ -105,6 +106,7 @@ open class SnackbarController: RootController {
}
s
.
isAnimating
=
false
s
.
isUserInteractionEnabled
=
true
s
.
snackbar
.
status
=
status
completion
?(
s
.
snackbar
)
}
...
...
Sources/iOS/Toolbar.swift
View file @
51a7d750
...
...
@@ -43,7 +43,7 @@ open class Toolbar: BarView {
}
/// Title label.
open
private
(set)
var
titleLabel
:
UILabel
!
open
internal
(set)
var
titleLabel
:
UILabel
!
/// A convenience property to set the detailLabel text.
open
var
detail
:
String
?
{
...
...
@@ -57,7 +57,7 @@ open class Toolbar: BarView {
}
/// Detail label.
open
private
(set)
var
detailLabel
:
UILabel
!
open
internal
(set)
var
detailLabel
:
UILabel
!
open
override
func
layoutSubviews
()
{
super
.
layoutSubviews
()
...
...
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