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
928ba8cb
Unverified
Commit
928ba8cb
authored
Sep 09, 2016
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
development: updated access rights and renamed ControlView to ContentView
parent
05b19fa0
Show whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
224 additions
and
203 deletions
+224
-203
Material.xcodeproj/project.pbxproj
+18
-10
Sources/iOS/BarView.swift
+1
-1
Sources/iOS/Button.swift
+1
-1
Sources/iOS/Capture.swift
+5
-5
Sources/iOS/CaptureSession.swift
+2
-2
Sources/iOS/CollectionView.swift
+4
-4
Sources/iOS/CollectionViewLayout.swift
+15
-15
Sources/iOS/ContentView.swift
+5
-3
Sources/iOS/Menu.swift
+8
-7
Sources/iOS/NavigationDrawerController.swift
+49
-49
Sources/iOS/SearchBar.swift
+6
-7
Sources/iOS/Switch.swift
+102
-91
Sources/iOS/TextField.swift
+8
-8
No files found.
Material.xcodeproj/project.pbxproj
View file @
928ba8cb
...
...
@@ -32,7 +32,7 @@
96BCB7A41CB40DC500C806FE
/* CaptureSession.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96BCB75B1CB40DC500C806FE
/* CaptureSession.swift */
;
};
96BCB7A51CB40DC500C806FE
/* Capture.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96BCB75C1CB40DC500C806FE
/* Capture.swift */
;
};
96BCB7A61CB40DC500C806FE
/* Card.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96BCB75D1CB40DC500C806FE
/* Card.swift */
;
};
96BCB7A71CB40DC500C806FE
/* Cont
rolView.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96BCB75E1CB40DC500C806FE
/* Control
View.swift */
;
};
96BCB7A71CB40DC500C806FE
/* Cont
entView.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96BCB75E1CB40DC500C806FE
/* Content
View.swift */
;
};
96BCB7A81CB40DC500C806FE
/* FabButton.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96BCB75F1CB40DC500C806FE
/* FabButton.swift */
;
};
96BCB7A91CB40DC500C806FE
/* FlatButton.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96BCB7601CB40DC500C806FE
/* FlatButton.swift */
;
};
96BCB7AA1CB40DC500C806FE
/* Grid.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96BCB7611CB40DC500C806FE
/* Grid.swift */
;
};
...
...
@@ -133,7 +133,7 @@
96BCB8351CB4115200C806FE
/* MaterialTextLayer.swift in Headers */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96BCB78A1CB40DC500C806FE
/* MaterialTextLayer.swift */
;
settings
=
{
ATTRIBUTES
=
(
Public
,
);
};
};
96BCB8361CB4115200C806FE
/* Grid.swift in Headers */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96BCB7611CB40DC500C806FE
/* Grid.swift */
;
settings
=
{
ATTRIBUTES
=
(
Public
,
);
};
};
96BCB8371CB4115200C806FE
/* Layout.swift in Headers */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96BCB7811CB40DC500C806FE
/* Layout.swift */
;
settings
=
{
ATTRIBUTES
=
(
Public
,
);
};
};
96BCB8381CB4115200C806FE
/* Cont
rolView.swift in Headers */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96BCB75E1CB40DC500C806FE
/* Control
View.swift */
;
settings
=
{
ATTRIBUTES
=
(
Public
,
);
};
};
96BCB8381CB4115200C806FE
/* Cont
entView.swift in Headers */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96BCB75E1CB40DC500C806FE
/* Content
View.swift */
;
settings
=
{
ATTRIBUTES
=
(
Public
,
);
};
};
96BCB8391CB4115200C806FE
/* SearchBar.swift in Headers */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96BCB7951CB40DC500C806FE
/* SearchBar.swift */
;
settings
=
{
ATTRIBUTES
=
(
Public
,
);
};
};
96BCB83A1CB4115200C806FE
/* SearchBarController.swift in Headers */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96BCB7961CB40DC500C806FE
/* SearchBarController.swift */
;
settings
=
{
ATTRIBUTES
=
(
Public
,
);
};
};
96BCB83B1CB4115200C806FE
/* NavigationDrawerController.swift in Headers */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96BCB7971CB40DC500C806FE
/* NavigationDrawerController.swift */
;
settings
=
{
ATTRIBUTES
=
(
Public
,
);
};
};
...
...
@@ -225,7 +225,7 @@
96BCB75B1CB40DC500C806FE
/* CaptureSession.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
CaptureSession.swift
;
sourceTree
=
"<group>"
;
};
96BCB75C1CB40DC500C806FE
/* Capture.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
Capture.swift
;
sourceTree
=
"<group>"
;
};
96BCB75D1CB40DC500C806FE
/* Card.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
Card.swift
;
sourceTree
=
"<group>"
;
};
96BCB75E1CB40DC500C806FE
/* Cont
rolView.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
Control
View.swift
;
sourceTree
=
"<group>"
;
};
96BCB75E1CB40DC500C806FE
/* Cont
entView.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
Content
View.swift
;
sourceTree
=
"<group>"
;
};
96BCB75F1CB40DC500C806FE
/* FabButton.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
FabButton.swift
;
sourceTree
=
"<group>"
;
};
96BCB7601CB40DC500C806FE
/* FlatButton.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
FlatButton.swift
;
sourceTree
=
"<group>"
;
};
96BCB7611CB40DC500C806FE
/* Grid.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
Grid.swift
;
sourceTree
=
"<group>"
;
};
...
...
@@ -342,6 +342,14 @@
name
=
Divider
;
sourceTree
=
"<group>"
;
};
96264BE41D833C8400576F37
/* BarView */
=
{
isa
=
PBXGroup
;
children
=
(
96BCB7981CB40DC500C806FE
/* BarView.swift */
,
);
name
=
BarView
;
sourceTree
=
"<group>"
;
};
962864601D5410FD00690B69
/* JSON */
=
{
isa
=
PBXGroup
;
children
=
(
...
...
@@ -448,13 +456,12 @@
name
=
SearchBar
;
sourceTree
=
"<group>"
;
};
963FBF061D669795008F8512
/* Cont
rol
View */
=
{
963FBF061D669795008F8512
/* Cont
ent
View */
=
{
isa
=
PBXGroup
;
children
=
(
96BCB75E1CB40DC500C806FE
/* ControlView.swift */
,
96BCB7981CB40DC500C806FE
/* BarView.swift */
,
96BCB75E1CB40DC500C806FE
/* ContentView.swift */
,
);
name
=
Cont
rol
View
;
name
=
Cont
ent
View
;
sourceTree
=
"<group>"
;
};
9661222C1D3EC414008BB4CB
/* macOS */
=
{
...
...
@@ -509,12 +516,13 @@
isa
=
PBXGroup
;
children
=
(
96BCB8091CB4107700C806FE
/* Animate */
,
96264BE41D833C8400576F37
/* BarView */
,
962DDD081D6FBBD0001C307C
/* BottomTabBar */
,
96BCB8031CB40F4B00C806FE
/* Button */
,
96BCB8021CB40F3B00C806FE
/* Card */
,
96BCB7FF1CB40EF000C806FE
/* Capture */
,
96BCB8051CB40F9C00C806FE
/* Collection */
,
963FBF061D669795008F8512
/* Cont
rol
View */
,
963FBF061D669795008F8512
/* Cont
ent
View */
,
96BCB8001CB40F0300C806FE
/* Color */
,
962A92581D42839100DBAF8E
/* Data */
,
96BCB80B1CB410CC00C806FE
/* Device */
,
...
...
@@ -808,7 +816,7 @@
96BCB8351CB4115200C806FE
/* MaterialTextLayer.swift in Headers */
,
96BCB8361CB4115200C806FE
/* Grid.swift in Headers */
,
96BCB8371CB4115200C806FE
/* Layout.swift in Headers */
,
96BCB8381CB4115200C806FE
/* Cont
rol
View.swift in Headers */
,
96BCB8381CB4115200C806FE
/* Cont
ent
View.swift in Headers */
,
96BCB8391CB4115200C806FE
/* SearchBar.swift in Headers */
,
96BCB83A1CB4115200C806FE
/* SearchBarController.swift in Headers */
,
96BCB83B1CB4115200C806FE
/* NavigationDrawerController.swift in Headers */
,
...
...
@@ -1101,7 +1109,7 @@
96BCB7D21CB40DC500C806FE
/* TableViewCell.swift in Sources */
,
96F1DC881D654FDF0025F925
/* Material+CALayer.swift in Sources */
,
96BCB7B61CB40DC500C806FE
/* Animation.swift in Sources */
,
96BCB7A71CB40DC500C806FE
/* Cont
rol
View.swift in Sources */
,
96BCB7A71CB40DC500C806FE
/* Cont
ent
View.swift in Sources */
,
96BCB7DB1CB40DC500C806FE
/* NavigationItem.swift in Sources */
,
96BCB7E01CB40DC500C806FE
/* NavigationDrawerController.swift in Sources */
,
9628645F1D540AF300690B69
/* DynamicFontType.swift in Sources */
,
...
...
Sources/iOS/BarView.swift
View file @
928ba8cb
...
...
@@ -30,7 +30,7 @@
import
UIKit
open
class
BarView
:
Cont
rol
View
{
open
class
BarView
:
Cont
ent
View
{
/// Divider layer.
open
internal(set)
var
divider
:
Divider
!
...
...
Sources/iOS/Button.swift
View file @
928ba8cb
...
...
@@ -42,7 +42,7 @@ open class Button: UIButton {
open
private(set)
lazy
var
visualLayer
=
CAShapeLayer
()
/// An Array of pulse layers.
public
private(set)
lazy
var
pulseLayers
=
[
CAShapeLayer
]()
open
private(set)
lazy
var
pulseLayers
=
[
CAShapeLayer
]()
/// The opacity value for the pulse animation.
@IBInspectable
...
...
Sources/iOS/Capture.swift
View file @
928ba8cb
...
...
@@ -221,19 +221,19 @@ open class Capture: View, UIGestureRecognizerDelegate {
}
/// A reference to the CapturePreview view.
open
private
(set)
var
previewView
:
CapturePreview
!
open
internal
(set)
var
previewView
:
CapturePreview
!
/// A reference to the CaptureSession.
open
private
(set)
var
captureSession
:
CaptureSession
!
open
internal
(set)
var
captureSession
:
CaptureSession
!
/// A reference to the focus layer used in focus animations.
open
private
(set)
var
focusLayer
:
Layer
?
open
internal
(set)
var
focusLayer
:
Layer
?
/// A reference to the exposure layer used in exposure animations.
open
private
(set)
var
exposureLayer
:
Layer
?
open
internal
(set)
var
exposureLayer
:
Layer
?
/// A reference to the reset layer used in reset animations.
open
private
(set)
var
resetLayer
:
Layer
?
open
internal
(set)
var
resetLayer
:
Layer
?
/// A reference to the cameraButton.
open
var
cameraButton
:
UIButton
?
{
...
...
Sources/iOS/CaptureSession.swift
View file @
928ba8cb
...
...
@@ -192,10 +192,10 @@ open class CaptureSession: NSObject, AVCaptureFileOutputRecordingDelegate {
internal
var
session
:
AVCaptureSession
!
/// A boolean indicating if the session is running.
open
private(set)
var
isRunning
:
Bool
=
false
open
internal(set)
var
isRunning
=
false
/// A boolean indicating if the session is recording.
open
private(set)
var
isRecording
:
Bool
=
false
open
internal(set)
var
isRecording
=
false
/// A reference to the recorded time duration.
open
var
recordedDuration
:
CMTime
{
...
...
Sources/iOS/CollectionView.swift
View file @
928ba8cb
...
...
@@ -35,19 +35,19 @@ open class CollectionView: UICollectionView {
/// A preset wrapper around contentInset.
open
var
contentEdgeInsetsPreset
:
EdgeInsets
{
get
{
return
(
collectionViewLayout
as?
CollectionViewLayout
)
!.
content
Inset
return
(
collectionViewLayout
as?
CollectionViewLayout
)
!.
content
EdgeInsets
}
set
(
value
)
{
(
collectionViewLayout
as?
CollectionViewLayout
)
!.
content
Inset
=
value
(
collectionViewLayout
as?
CollectionViewLayout
)
!.
content
EdgeInsets
=
value
}
}
open
override
var
contentInset
:
UIEdgeInsets
{
get
{
return
(
collectionViewLayout
as?
CollectionViewLayout
)
!.
content
Inset
return
(
collectionViewLayout
as?
CollectionViewLayout
)
!.
content
EdgeInsets
}
set
(
value
)
{
(
collectionViewLayout
as?
CollectionViewLayout
)
!.
content
Inset
=
value
(
collectionViewLayout
as?
CollectionViewLayout
)
!.
content
EdgeInsets
=
value
}
}
...
...
Sources/iOS/CollectionViewLayout.swift
View file @
928ba8cb
...
...
@@ -37,27 +37,27 @@ open class CollectionViewLayout: UICollectionViewLayout {
/// The size of items.
open
var
itemSize
=
CGSize
.
zero
/// A preset wrapper around content
Inset
.
/// A preset wrapper around content
EdgeInsets
.
open
var
contentEdgeInsetsPreset
:
EdgeInsetsPreset
=
.
none
{
didSet
{
content
Inset
=
EdgeInsetsPresetToValue
(
preset
:
contentEdgeInsetsPreset
)
content
EdgeInsets
=
EdgeInsetsPresetToValue
(
preset
:
contentEdgeInsetsPreset
)
}
}
/// A wrapper around grid.content
Inset
.
open
var
content
Inset
=
EdgeInsets
.
zero
/// A wrapper around grid.content
EdgeInsets
.
open
var
content
EdgeInsets
=
EdgeInsets
.
zero
/// Size of the content.
open
private
(set)
var
contentSize
=
CGSize
.
zero
open
internal
(set)
var
contentSize
=
CGSize
.
zero
/// Layout attribute items.
open
private(set)
var
layoutItems
=
[(
UICollectionViewLayoutAttributes
,
NSIndexPath
)]()
open
internal(set)
lazy
var
layoutItems
=
[(
UICollectionViewLayoutAttributes
,
NSIndexPath
)]()
/// Cell data source items.
open
private
(set)
var
dataSourceItems
:
[
DataSourceItem
]?
open
internal
(set)
var
dataSourceItems
:
[
DataSourceItem
]?
/// Scroll direction.
open
var
scrollDirection
:
UICollectionViewScrollDirection
=
.
vertical
open
var
scrollDirection
=
UICollectionViewScrollDirection
.
vertical
/// A preset wrapper around interimSpace.
open
var
interimSpacePreset
=
InterimSpacePreset
.
none
{
...
...
@@ -93,11 +93,11 @@ open class CollectionViewLayout: UICollectionViewLayout {
let
item
:
DataSourceItem
=
dataSourceItems
!
[
indexPath
.
item
]
if
0
<
itemSize
.
width
&&
0
<
itemSize
.
height
{
attributes
.
frame
=
CGRect
(
x
:
offset
.
x
,
y
:
offset
.
y
,
width
:
itemSize
.
width
-
content
Inset
.
left
-
contentInset
.
right
,
height
:
itemSize
.
height
-
contentInset
.
top
-
contentInset
.
bottom
)
attributes
.
frame
=
CGRect
(
x
:
offset
.
x
,
y
:
offset
.
y
,
width
:
itemSize
.
width
-
content
EdgeInsets
.
left
-
contentEdgeInsets
.
right
,
height
:
itemSize
.
height
-
contentEdgeInsets
.
top
-
contentEdgeInsets
.
bottom
)
}
else
if
.
vertical
==
scrollDirection
{
attributes
.
frame
=
CGRect
(
x
:
content
Inset
.
left
,
y
:
offset
.
y
,
width
:
collectionView
!.
bounds
.
width
-
contentInset
.
left
-
contentInset
.
right
,
height
:
item
.
height
??
collectionView
!.
bounds
.
height
)
attributes
.
frame
=
CGRect
(
x
:
content
EdgeInsets
.
left
,
y
:
offset
.
y
,
width
:
collectionView
!.
bounds
.
width
-
contentEdgeInsets
.
left
-
contentEdgeInsets
.
right
,
height
:
item
.
height
??
collectionView
!.
bounds
.
height
)
}
else
{
attributes
.
frame
=
CGRect
(
x
:
offset
.
x
,
y
:
content
Inset
.
top
,
width
:
item
.
width
??
collectionView
!.
bounds
.
width
,
height
:
collectionView
!.
bounds
.
height
-
contentInset
.
top
-
contentInset
.
bottom
)
attributes
.
frame
=
CGRect
(
x
:
offset
.
x
,
y
:
content
EdgeInsets
.
top
,
width
:
item
.
width
??
collectionView
!.
bounds
.
width
,
height
:
collectionView
!.
bounds
.
height
-
contentEdgeInsets
.
top
-
contentEdgeInsets
.
bottom
)
}
return
attributes
...
...
@@ -131,8 +131,8 @@ open class CollectionViewLayout: UICollectionViewLayout {
self
.
dataSourceItems
=
dataSourceItems
layoutItems
.
removeAll
()
offset
.
x
=
content
Inset
.
left
offset
.
y
=
content
Inset
.
top
offset
.
x
=
content
EdgeInsets
.
left
offset
.
y
=
content
EdgeInsets
.
top
for
i
in
0
..<
dataSourceItems
.
count
{
let
item
:
DataSourceItem
=
dataSourceItems
[
i
]
...
...
@@ -146,8 +146,8 @@ open class CollectionViewLayout: UICollectionViewLayout {
offset
.
y
+=
nil
==
item
.
height
?
itemSize
.
height
:
item
.
height
!
}
offset
.
x
+=
content
Inset
.
right
-
interimSpace
offset
.
y
+=
content
Inset
.
bottom
-
interimSpace
offset
.
x
+=
content
EdgeInsets
.
right
-
interimSpace
offset
.
y
+=
content
EdgeInsets
.
bottom
-
interimSpace
if
0
<
itemSize
.
width
&&
0
<
itemSize
.
height
{
contentSize
=
CGSize
(
width
:
offset
.
x
,
height
:
offset
.
y
)
...
...
Sources/iOS/Cont
rol
View.swift
→
Sources/iOS/Cont
ent
View.swift
View file @
928ba8cb
...
...
@@ -36,7 +36,7 @@ public enum ContentViewAlignment: Int {
case
center
}
open
class
Cont
rol
View
:
View
{
open
class
Cont
ent
View
:
View
{
/// Should center the contentView.
open
var
contentViewAlignment
=
ContentViewAlignment
.
any
{
didSet
{
...
...
@@ -93,7 +93,8 @@ open class ControlView: View {
}
/// Grid cell factor.
@IBInspectable
open
var
gridFactor
:
CGFloat
=
24
{
@IBInspectable
open
var
gridFactor
:
CGFloat
=
24
{
didSet
{
assert
(
0
<
gridFactor
,
"[Material Error: gridFactor must be greater than 0.]"
)
layoutSubviews
()
...
...
@@ -101,7 +102,7 @@ open class ControlView: View {
}
/// ContentView that holds the any desired subviews.
open
private(set)
lazy
var
contentView
:
UIView
=
UIView
()
open
private(set)
lazy
var
contentView
=
UIView
()
/// Left side UIControls.
open
var
leftControls
=
[
UIView
]()
{
...
...
@@ -196,6 +197,7 @@ open class ControlView: View {
}
contentView
.
grid
.
begin
()
if
.
center
==
contentViewAlignment
{
if
lc
<
rc
{
contentView
.
grid
.
columns
=
columns
-
2
*
rc
...
...
Sources/iOS/Menu.swift
View file @
928ba8cb
...
...
@@ -46,11 +46,11 @@ public protocol MenuDelegate {
}
open
class
Menu
:
View
{
/// A delegation reference.
open
weak
var
delegate
:
MenuDelegate
?
/// A Boolean that indicates if the menu is open or not.
open
private(set)
var
isOpened
=
false
open
internal(set)
var
isOpened
=
false
/// Enables the animations for the Menu.
open
internal(set)
var
isEnabled
=
true
/// A preset wrapper around interimSpace.
open
var
interimSpacePreset
=
InterimSpacePreset
.
none
{
...
...
@@ -66,9 +66,6 @@ open class Menu: View {
}
}
/// Enables the animations for the Menu.
open
private(set)
var
isEnabled
=
true
/// The direction in which the animation opens the menu.
open
var
direction
=
MenuDirection
.
up
{
didSet
{
...
...
@@ -76,6 +73,9 @@ open class Menu: View {
}
}
/// A delegation reference.
open
weak
var
delegate
:
MenuDelegate
?
/// An Array of UIViews.
open
var
views
=
[
UIView
]()
{
didSet
{
...
...
@@ -86,6 +86,7 @@ open class Menu: View {
for
v
in
views
{
addSubview
(
v
)
}
reload
()
}
}
...
...
Sources/iOS/NavigationDrawerController.swift
View file @
928ba8cb
...
...
@@ -193,16 +193,16 @@ open class NavigationDrawerController: RootController, UIGestureRecognizerDelega
opening and closing. Defaults to true.
*/
@IBInspectable
open
var
e
nabled
:
Bool
{
open
var
isE
nabled
:
Bool
{
get
{
return
enabledLeftView
||
enabledRightView
return
isLeftViewEnabled
||
isRightViewEnabled
}
set
(
value
)
{
if
nil
!=
leftView
{
enabledLeftView
=
value
isLeftViewEnabled
=
value
}
if
nil
!=
rightView
{
enabledRightView
=
value
isRightViewEnabled
=
value
}
}
}
...
...
@@ -212,18 +212,18 @@ open class NavigationDrawerController: RootController, UIGestureRecognizerDelega
opening and closing. Defaults to true.
*/
@IBInspectable
open
var
enabledLeftView
=
false
{
open
var
isLeftViewEnabled
=
false
{
didSet
{
enabledLeftPanGesture
=
enabledLeftView
enabledLeftTapGesture
=
enabledLeftView
isLeftPanGestureEnabled
=
isLeftViewEnabled
isLeftTapGestureEnabled
=
isLeftViewEnabled
}
}
/// Enables the left pan gesture.
@IBInspectable
open
var
enabledLeftPanGesture
=
false
{
open
var
isLeftPanGestureEnabled
=
false
{
didSet
{
if
enabledLeftPanGesture
{
if
isLeftPanGestureEnabled
{
prepareLeftPanGesture
()
}
else
{
removeLeftPanGesture
()
...
...
@@ -233,9 +233,9 @@ open class NavigationDrawerController: RootController, UIGestureRecognizerDelega
/// Enables the left tap gesture.
@IBInspectable
open
var
enabledLeftTapGesture
=
false
{
open
var
isLeftTapGestureEnabled
=
false
{
didSet
{
if
enabledLeftTapGesture
{
if
isLeftTapGestureEnabled
{
prepareLeftTapGesture
()
}
else
{
removeLeftTapGesture
()
...
...
@@ -248,18 +248,18 @@ open class NavigationDrawerController: RootController, UIGestureRecognizerDelega
opening and closing. Defaults to true.
*/
@IBInspectable
open
var
enabledRightView
=
false
{
open
var
isRightViewEnabled
=
false
{
didSet
{
enabledRightPanGesture
=
enabledRightView
enabledRightTapGesture
=
enabledRightView
isRightPanGestureEnabled
=
isRightViewEnabled
isRightTapGestureEnabled
=
isRightViewEnabled
}
}
/// Enables the right pan gesture.
@IBInspectable
open
var
enabledRightPanGesture
=
false
{
open
var
isRightPanGestureEnabled
=
false
{
didSet
{
if
enabledRightPanGesture
{
if
isRightPanGestureEnabled
{
prepareRightPanGesture
()
}
else
{
removeRightPanGesture
()
...
...
@@ -269,9 +269,9 @@ open class NavigationDrawerController: RootController, UIGestureRecognizerDelega
/// Enables the right tap gesture.
@IBInspectable
open
var
enabledRightTapGesture
=
false
{
open
var
isRightTapGestureEnabled
=
false
{
didSet
{
if
enabledRightTapGesture
{
if
isRightTapGestureEnabled
{
prepareRightTapGesture
()
}
else
{
removeRightTapGesture
()
...
...
@@ -284,10 +284,10 @@ open class NavigationDrawerController: RootController, UIGestureRecognizerDelega
when the leftView is opened. Defaults to true.
*/
@IBInspectable
open
var
enableHideStatusBar
=
true
open
var
isHiddenStatusBarEnabled
=
true
/// Sets the statusBar to hidden or not.
open
private
(set)
var
isStatusBarHidden
=
false
open
internal
(set)
var
isStatusBarHidden
=
false
/**
A DepthPreset property that is used to set the depth of the
...
...
@@ -310,12 +310,12 @@ open class NavigationDrawerController: RootController, UIGestureRecognizerDelega
open
private(set)
var
rightView
:
View
?
/// Indicates whether the leftView or rightView is opened.
open
var
o
pened
:
Bool
{
return
openedLeftView
||
openedRightView
open
var
isO
pened
:
Bool
{
return
isLeftViewOpened
||
isRightViewOpened
}
/// indicates if the leftView is opened.
open
var
openedLeftView
:
Bool
{
open
var
isLeftViewOpened
:
Bool
{
guard
nil
!=
leftView
else
{
return
false
}
...
...
@@ -323,7 +323,7 @@ open class NavigationDrawerController: RootController, UIGestureRecognizerDelega
}
/// Indicates if the rightView is opened.
open
var
openedRightView
:
Bool
{
open
var
isRightViewOpened
:
Bool
{
guard
nil
!=
rightView
else
{
return
false
}
...
...
@@ -337,7 +337,7 @@ open class NavigationDrawerController: RootController, UIGestureRecognizerDelega
this, and to add a hidden transition viewController for complex
situations, the contentViewController was added.
*/
open
private(set)
lazy
var
contentViewController
:
UIViewController
=
UIViewController
()
open
private(set)
lazy
var
contentViewController
=
UIViewController
()
/**
A UIViewController property that references the
...
...
@@ -413,7 +413,7 @@ open class NavigationDrawerController: RootController, UIGestureRecognizerDelega
/// Layout subviews.
open
override
func
layoutSubviews
()
{
if
o
pened
{
if
isO
pened
{
hideStatusBar
()
}
else
{
showStatusBar
()
...
...
@@ -446,7 +446,7 @@ open class NavigationDrawerController: RootController, UIGestureRecognizerDelega
super
.
viewWillTransition
(
to
:
size
,
with
:
coordinator
)
// Ensures the view is hidden.
if
let
v
:
View
=
rightView
{
v
.
position
.
x
=
size
.
width
+
(
openedRightView
?
-
v
.
width
:
v
.
width
)
/
2
v
.
position
.
x
=
size
.
width
+
(
isRightViewOpened
?
-
v
.
width
:
v
.
width
)
/
2
}
}
...
...
@@ -466,7 +466,7 @@ open class NavigationDrawerController: RootController, UIGestureRecognizerDelega
var
hide
:
Bool
=
hidden
if
openedRightView
{
if
isRightViewOpened
{
hide
=
true
}
...
...
@@ -540,7 +540,7 @@ open class NavigationDrawerController: RootController, UIGestureRecognizerDelega
var
hide
:
Bool
=
hidden
if
openedLeftView
{
if
isLeftViewOpened
{
hide
=
true
}
...
...
@@ -605,7 +605,7 @@ open class NavigationDrawerController: RootController, UIGestureRecognizerDelega
leftView. Defaults to 0.
*/
open
func
toggleLeftView
(
velocity
:
CGFloat
=
0
)
{
openedLeftView
?
closeLeftView
(
velocity
:
velocity
)
:
openLeftView
(
velocity
:
velocity
)
isLeftViewOpened
?
closeLeftView
(
velocity
:
velocity
)
:
openLeftView
(
velocity
:
velocity
)
}
/**
...
...
@@ -616,7 +616,7 @@ open class NavigationDrawerController: RootController, UIGestureRecognizerDelega
leftView. Defaults to 0.
*/
open
func
toggleRightView
(
velocity
:
CGFloat
=
0
)
{
openedRightView
?
closeRightView
(
velocity
:
velocity
)
:
openRightView
(
velocity
:
velocity
)
isRightViewOpened
?
closeRightView
(
velocity
:
velocity
)
:
openRightView
(
velocity
:
velocity
)
}
/**
...
...
@@ -626,7 +626,7 @@ open class NavigationDrawerController: RootController, UIGestureRecognizerDelega
leftView. Defaults to 0.
*/
open
func
openLeftView
(
velocity
:
CGFloat
=
0
)
{
if
enabledLeftView
{
if
isLeftViewEnabled
{
if
let
v
:
View
=
leftView
{
hideStatusBar
()
showView
(
container
:
v
)
...
...
@@ -652,7 +652,7 @@ open class NavigationDrawerController: RootController, UIGestureRecognizerDelega
leftView. Defaults to 0.
*/
open
func
openRightView
(
velocity
:
CGFloat
=
0
)
{
if
enabledRightView
{
if
isRightViewEnabled
{
if
let
v
:
View
=
rightView
{
hideStatusBar
()
showView
(
container
:
v
)
...
...
@@ -680,7 +680,7 @@ open class NavigationDrawerController: RootController, UIGestureRecognizerDelega
leftView. Defaults to 0.
*/
open
func
closeLeftView
(
velocity
:
CGFloat
=
0
)
{
if
enabledLeftView
{
if
isLeftViewEnabled
{
if
let
v
:
View
=
leftView
{
isUserInteractionEnabled
=
true
delegate
?
.
navigationDrawerWillClose
?(
navigationDrawerController
:
self
,
position
:
.
left
)
...
...
@@ -708,7 +708,7 @@ open class NavigationDrawerController: RootController, UIGestureRecognizerDelega
leftView. Defaults to 0.
*/
open
func
closeRightView
(
velocity
:
CGFloat
=
0
)
{
if
enabledRightView
{
if
isRightViewEnabled
{
if
let
v
:
View
=
rightView
{
isUserInteractionEnabled
=
true
delegate
?
.
navigationDrawerWillClose
?(
navigationDrawerController
:
self
,
position
:
.
right
)
...
...
@@ -736,16 +736,16 @@ open class NavigationDrawerController: RootController, UIGestureRecognizerDelega
- Returns: A Boolean of whether to continue the gesture or not.
*/
open
func
gestureRecognizer
(
_
gestureRecognizer
:
UIGestureRecognizer
,
shouldReceive
touch
:
UITouch
)
->
Bool
{
if
!
openedRightView
&&
gestureRecognizer
==
leftPanGesture
&&
(
openedLeftView
||
isPointContainedWithinLeftThreshold
(
point
:
touch
.
location
(
in
:
view
)))
{
if
!
isRightViewOpened
&&
gestureRecognizer
==
leftPanGesture
&&
(
isLeftViewOpened
||
isPointContainedWithinLeftThreshold
(
point
:
touch
.
location
(
in
:
view
)))
{
return
true
}
if
!
openedLeftView
&&
gestureRecognizer
==
rightPanGesture
&&
(
openedRightView
||
isPointContainedWithinRighThreshold
(
point
:
touch
.
location
(
in
:
view
)))
{
if
!
isLeftViewOpened
&&
gestureRecognizer
==
rightPanGesture
&&
(
isRightViewOpened
||
isPointContainedWithinRighThreshold
(
point
:
touch
.
location
(
in
:
view
)))
{
return
true
}
if
openedLeftView
&&
gestureRecognizer
==
leftTapGesture
{
if
isLeftViewOpened
&&
gestureRecognizer
==
leftTapGesture
{
return
true
}
if
openedRightView
&&
gestureRecognizer
==
rightTapGesture
{
if
isRightViewOpened
&&
gestureRecognizer
==
rightTapGesture
{
return
true
}
return
false
...
...
@@ -759,7 +759,7 @@ open class NavigationDrawerController: RootController, UIGestureRecognizerDelega
*/
@objc
internal
func
handleLeftViewPanGesture
(
recognizer
:
UIPanGestureRecognizer
)
{
if
enabledLeftView
&&
(
openedLeftView
||
!
openedRightView
&&
isPointContainedWithinLeftThreshold
(
point
:
recognizer
.
location
(
in
:
view
)))
{
if
isLeftViewEnabled
&&
(
isLeftViewOpened
||
!
isRightViewOpened
&&
isPointContainedWithinLeftThreshold
(
point
:
recognizer
.
location
(
in
:
view
)))
{
if
let
v
:
View
=
leftView
{
let
point
:
CGPoint
=
recognizer
.
location
(
in
:
view
)
...
...
@@ -808,7 +808,7 @@ open class NavigationDrawerController: RootController, UIGestureRecognizerDelega
*/
@objc
internal
func
handleRightViewPanGesture
(
recognizer
:
UIPanGestureRecognizer
)
{
if
enabledRightView
&&
(
openedRightView
||
!
openedLeftView
&&
isPointContainedWithinRighThreshold
(
point
:
recognizer
.
location
(
in
:
view
)))
{
if
isRightViewEnabled
&&
(
isRightViewOpened
||
!
isLeftViewOpened
&&
isPointContainedWithinRighThreshold
(
point
:
recognizer
.
location
(
in
:
view
)))
{
if
let
v
:
View
=
rightView
{
let
point
:
CGPoint
=
recognizer
.
location
(
in
:
view
)
...
...
@@ -857,10 +857,10 @@ open class NavigationDrawerController: RootController, UIGestureRecognizerDelega
*/
@objc
internal
func
handleLeftViewTapGesture
(
recognizer
:
UITapGestureRecognizer
)
{
if
openedLeftView
{
if
isLeftViewOpened
{
if
let
v
:
View
=
leftView
{
delegate
?
.
navigationDrawerDidTap
?(
navigationDrawerController
:
self
,
point
:
recognizer
.
location
(
in
:
view
),
position
:
.
left
)
if
enabledLeftView
&&
openedLeftView
&&
!
isPointContainedWithinView
(
container
:
v
,
point
:
recognizer
.
location
(
in
:
v
))
{
if
isLeftViewEnabled
&&
isLeftViewOpened
&&
!
isPointContainedWithinView
(
container
:
v
,
point
:
recognizer
.
location
(
in
:
v
))
{
closeLeftView
()
}
}
...
...
@@ -875,10 +875,10 @@ open class NavigationDrawerController: RootController, UIGestureRecognizerDelega
*/
@objc
internal
func
handleRightViewTapGesture
(
recognizer
:
UITapGestureRecognizer
)
{
if
openedRightView
{
if
isRightViewOpened
{
if
let
v
:
View
=
rightView
{
delegate
?
.
navigationDrawerDidTap
?(
navigationDrawerController
:
self
,
point
:
recognizer
.
location
(
in
:
view
),
position
:
.
right
)
if
enabledRightView
&&
openedRightView
&&
!
isPointContainedWithinView
(
container
:
v
,
point
:
recognizer
.
location
(
in
:
v
))
{
if
isRightViewEnabled
&&
isRightViewOpened
&&
!
isPointContainedWithinView
(
container
:
v
,
point
:
recognizer
.
location
(
in
:
v
))
{
closeRightView
()
}
}
...
...
@@ -912,7 +912,7 @@ open class NavigationDrawerController: RootController, UIGestureRecognizerDelega
return
}
enabledLeftView
=
true
isLeftViewEnabled
=
true
leftViewWidth
=
.
phone
==
Device
.
userInterfaceIdiom
?
280
:
320
leftView
=
View
()
...
...
@@ -932,7 +932,7 @@ open class NavigationDrawerController: RootController, UIGestureRecognizerDelega
return
}
enabledRightView
=
true
isRightViewEnabled
=
true
rightViewWidth
=
.
phone
==
Device
.
userInterfaceIdiom
?
280
:
320
rightView
=
View
()
...
...
@@ -1046,7 +1046,7 @@ open class NavigationDrawerController: RootController, UIGestureRecognizerDelega
/// Hides the statusBar.
private
func
hideStatusBar
()
{
if
enableHideStatusBar
{
if
isHiddenStatusBarEnabled
{
if
!
isStatusBarHidden
{
isStatusBarHidden
=
true
DispatchQueue
.
main
.
async
{
[
weak
self
]
in
...
...
@@ -1063,7 +1063,7 @@ open class NavigationDrawerController: RootController, UIGestureRecognizerDelega
/// Toggles the statusBar
private
func
toggleStatusBar
()
{
if
o
pened
||
Device
.
isLandscape
&&
.
phone
==
Device
.
userInterfaceIdiom
{
if
isO
pened
||
Device
.
isLandscape
&&
.
phone
==
Device
.
userInterfaceIdiom
{
hideStatusBar
()
}
else
{
showStatusBar
()
...
...
Sources/iOS/SearchBar.swift
View file @
928ba8cb
...
...
@@ -32,17 +32,17 @@ import UIKit
open
class
SearchBar
:
BarView
{
/// The UITextField for the searchBar.
open
private(set)
var
textField
:
UITextField
!
open
private(set)
lazy
var
textField
=
UITextField
()
/// Reference to the clearButton.
open
private(set)
var
clearButton
:
IconButton
!
/// Handle the clearButton manually.
@IBInspectable
open
var
clearButtonAutoHandleEnabled
:
Bool
=
true
{
open
var
isClearButtonAutoHandleEnabled
=
true
{
didSet
{
clearButton
.
removeTarget
(
self
,
action
:
#selector(
handleClearButton
)
,
for
:
.
touchUpInside
)
if
c
learButtonAutoHandleEnabled
{
if
isC
learButtonAutoHandleEnabled
{
clearButton
.
addTarget
(
self
,
action
:
#selector(
handleClearButton
)
,
for
:
.
touchUpInside
)
}
}
...
...
@@ -82,7 +82,7 @@ open class SearchBar: BarView {
/// Placeholder textColor.
@IBInspectable
open
var
placeholderColor
:
UIColor
=
Color
.
darkText
.
others
{
open
var
placeholderColor
=
Color
.
darkText
.
others
{
didSet
{
if
let
v
:
String
=
placeholder
{
textField
.
attributedPlaceholder
=
NSAttributedString
(
string
:
v
,
attributes
:
[
NSForegroundColorAttributeName
:
placeholderColor
])
...
...
@@ -142,7 +142,7 @@ open class SearchBar: BarView {
/// Layout the clearButton.
open
func
layoutClearButton
()
{
let
h
:
CGFloat
=
textField
.
frame
.
height
let
h
=
textField
.
frame
.
height
clearButton
.
frame
=
CGRect
(
x
:
textField
.
frame
.
width
-
h
,
y
:
0
,
width
:
h
,
height
:
h
)
}
...
...
@@ -154,7 +154,6 @@ open class SearchBar: BarView {
/// Prepares the textField.
private
func
prepareTextField
()
{
textField
=
UITextField
()
textField
.
contentScaleFactor
=
Device
.
scale
textField
.
font
=
RobotoFont
.
regular
(
with
:
17
)
textField
.
backgroundColor
=
Color
.
clear
...
...
@@ -169,7 +168,7 @@ open class SearchBar: BarView {
private
func
prepareClearButton
()
{
clearButton
=
IconButton
(
image
:
Icon
.
cm
.
close
,
tintColor
:
placeholderColor
)
clearButton
.
contentEdgeInsets
=
.
zero
c
learButtonAutoHandleEnabled
=
true
isC
learButtonAutoHandleEnabled
=
true
textField
.
clearButtonMode
=
.
never
textField
.
rightViewMode
=
.
whileEditing
textField
.
rightView
=
clearButton
...
...
Sources/iOS/Switch.swift
View file @
928ba8cb
...
...
@@ -30,39 +30,39 @@
import
UIKit
@objc(SwitchStyle)
public
enum
SwitchStyle
:
Int
{
@objc(Switch
Control
Style)
public
enum
Switch
Control
Style
:
Int
{
case
light
case
dark
}
@objc(SwitchState)
public
enum
SwitchState
:
Int
{
@objc(Switch
Control
State)
public
enum
Switch
Control
State
:
Int
{
case
on
case
off
}
@objc(SwitchSize)
public
enum
SwitchSize
:
Int
{
@objc(Switch
Control
Size)
public
enum
Switch
Control
Size
:
Int
{
case
small
case
medium
case
large
}
@objc(SwitchDelegate)
public
protocol
SwitchDelegate
{
@objc(Switch
Control
Delegate)
public
protocol
Switch
Control
Delegate
{
/**
A Switch delegate method for state changes.
- Parameter control: Switch control.
A Switch
Control
delegate method for state changes.
- Parameter control: Switch
Control
control.
*/
func
switchStateChanged
(
control
:
Switch
)
func
switchStateChanged
(
control
:
Switch
Control
)
}
@objc(Switch)
@objc(Switch
Control
)
@IBDesignable
public
class
Switch
:
UIControl
{
open
class
SwitchControl
:
UIControl
{
/// An internal reference to the switchState public property.
private
var
internalSwitch
State
:
Switch
State
=
.
off
private
var
internalSwitch
ControlState
:
SwitchControl
State
=
.
off
/// Track thickness.
private
var
trackThickness
:
CGFloat
=
0
...
...
@@ -80,66 +80,75 @@ public class Switch: UIControl {
private
var
bounceOffset
:
CGFloat
=
3
/// An Optional delegation method.
open
weak
var
delegate
:
SwitchDelegate
?
open
weak
var
delegate
:
Switch
Control
Delegate
?
/// Indicates if the animation should bounce.
@IBInspectable
public
var
bounceable
:
Bool
=
true
{
@IBInspectable
public
var
bounceable
=
true
{
didSet
{
bounceOffset
=
bounceable
?
3
:
0
}
}
/// Button on color.
@IBInspectable
public
var
buttonOnColor
:
UIColor
=
Color
.
clear
{
@IBInspectable
public
var
buttonOnColor
=
Color
.
clear
{
didSet
{
styleForState
(
state
:
switchState
)
}
}
/// Button off color.
@IBInspectable
public
var
buttonOffColor
:
UIColor
=
Color
.
clear
{
@IBInspectable
public
var
buttonOffColor
=
Color
.
clear
{
didSet
{
styleForState
(
state
:
switchState
)
}
}
/// Track on color.
@IBInspectable
public
var
trackOnColor
:
UIColor
=
Color
.
clear
{
@IBInspectable
public
var
trackOnColor
=
Color
.
clear
{
didSet
{
styleForState
(
state
:
switchState
)
}
}
/// Track off color.
@IBInspectable
public
var
trackOffColor
:
UIColor
=
Color
.
clear
{
@IBInspectable
public
var
trackOffColor
=
Color
.
clear
{
didSet
{
styleForState
(
state
:
switchState
)
}
}
/// Button on disabled color.
@IBInspectable
public
var
buttonOnDisabledColor
:
UIColor
=
Color
.
clear
{
@IBInspectable
public
var
buttonOnDisabledColor
=
Color
.
clear
{
didSet
{
styleForState
(
state
:
switchState
)
}
}
/// Track on disabled color.
@IBInspectable
public
var
trackOnDisabledColor
:
UIColor
=
Color
.
clear
{
@IBInspectable
public
var
trackOnDisabledColor
=
Color
.
clear
{
didSet
{
styleForState
(
state
:
switchState
)
}
}
/// Button off disabled color.
@IBInspectable
public
var
buttonOffDisabledColor
:
UIColor
=
Color
.
clear
{
@IBInspectable
public
var
buttonOffDisabledColor
=
Color
.
clear
{
didSet
{
styleForState
(
state
:
switchState
)
}
}
/// Track off disabled color.
@IBInspectable
public
var
trackOffDisabledColor
:
UIColor
=
Color
.
clear
{
@IBInspectable
public
var
trackOffDisabledColor
=
Color
.
clear
{
didSet
{
styleForState
(
state
:
switchState
)
}
...
...
@@ -159,36 +168,38 @@ public class Switch: UIControl {
}
}
@IBInspectable
public
override
var
isEnabled
:
Bool
{
@IBInspectable
open
override
var
isEnabled
:
Bool
{
didSet
{
styleForState
(
state
:
internalSwitchState
)
styleForState
(
state
:
internalSwitch
Control
State
)
}
}
/// A boolean indicating if the switch is on or not.
@IBInspectable
public
var
on
:
Bool
{
@IBInspectable
public
var
on
:
Bool
{
get
{
return
.
on
==
internalSwitchState
return
.
on
==
internalSwitch
Control
State
}
set
(
value
)
{
setOn
(
on
:
value
,
animated
:
true
)
}
}
/// Switch state.
public
var
switchState
:
SwitchState
{
/// Switch
Control
state.
public
var
switchState
:
Switch
Control
State
{
get
{
return
internalSwitchState
return
internalSwitch
Control
State
}
set
(
value
)
{
if
value
!=
internalSwitchState
{
internalSwitchState
=
value
if
value
!=
internalSwitch
Control
State
{
internalSwitch
Control
State
=
value
}
}
}
/// Switch style.
public
var
switchStyle
:
SwitchStyle
=
.
dark
{
/// Switch
Control
style.
public
var
switchStyle
:
Switch
Control
Style
=
.
dark
{
didSet
{
switch
switchStyle
{
case
.
light
:
...
...
@@ -213,8 +224,8 @@ public class Switch: UIControl {
}
}
/// Switch size.
public
var
switchSize
:
SwitchSize
=
.
medium
{
/// Switch
Control
size.
public
var
switchSize
:
Switch
Control
Size
=
.
medium
{
didSet
{
switch
switchSize
{
case
.
small
:
...
...
@@ -233,19 +244,19 @@ public class Switch: UIControl {
}
}
public
override
var
frame
:
CGRect
{
open
override
var
frame
:
CGRect
{
didSet
{
layoutSwitch
()
layoutSwitch
Control
()
}
}
public
override
var
bounds
:
CGRect
{
open
override
var
bounds
:
CGRect
{
didSet
{
layoutSwitch
()
layoutSwitch
Control
()
}
}
public
override
var
intrinsicContentSize
:
CGSize
{
open
override
var
intrinsicContentSize
:
CGSize
{
switch
switchSize
{
case
.
small
:
return
CGSize
(
width
:
30
,
height
:
25
)
...
...
@@ -266,9 +277,9 @@ public class Switch: UIControl {
super
.
init
(
coder
:
aDecoder
)
prepareTrack
()
prepareButton
()
prepareSwitchSize
(
size
:
.
medium
)
prepareSwitchStyle
(
style
:
.
light
)
prepareSwitchState
(
state
:
.
off
)
prepareSwitch
Control
Size
(
size
:
.
medium
)
prepareSwitch
Control
Style
(
style
:
.
light
)
prepareSwitch
Control
State
(
state
:
.
off
)
}
/**
...
...
@@ -284,39 +295,39 @@ public class Switch: UIControl {
super
.
init
(
frame
:
frame
)
prepareTrack
()
prepareButton
()
prepareSwitchSize
(
size
:
.
medium
)
prepareSwitchStyle
(
style
:
.
light
)
prepareSwitchState
(
state
:
.
off
)
prepareSwitch
Control
Size
(
size
:
.
medium
)
prepareSwitch
Control
Style
(
style
:
.
light
)
prepareSwitch
Control
State
(
state
:
.
off
)
}
/**
An initializer that sets the state, style, and size of the Switch instance.
- Parameter state: A SwitchState value.
- Parameter style: A SwitchStyle value.
- Parameter size: A SwitchSize value.
An initializer that sets the state, style, and size of the Switch
Control
instance.
- Parameter state: A Switch
Control
State value.
- Parameter style: A Switch
Control
Style value.
- Parameter size: A Switch
Control
Size value.
*/
public
init
(
state
:
Switch
State
=
.
off
,
style
:
SwitchStyle
=
.
dark
,
size
:
Switch
Size
=
.
medium
)
{
public
init
(
state
:
Switch
ControlState
=
.
off
,
style
:
SwitchControlStyle
=
.
dark
,
size
:
SwitchControl
Size
=
.
medium
)
{
trackLayer
=
CAShapeLayer
()
button
=
FabButton
()
super
.
init
(
frame
:
CGRect
.
null
)
prepareTrack
()
prepareButton
()
prepareSwitchSize
(
size
:
size
)
prepareSwitchStyle
(
style
:
style
)
prepareSwitchState
(
state
:
state
)
prepareSwitch
Control
Size
(
size
:
size
)
prepareSwitch
Control
Style
(
style
:
style
)
prepareSwitch
Control
State
(
state
:
state
)
}
public
override
func
willMove
(
toSuperview
newSuperview
:
UIView
?)
{
open
override
func
willMove
(
toSuperview
newSuperview
:
UIView
?)
{
super
.
willMove
(
toSuperview
:
newSuperview
)
styleForState
(
state
:
internalSwitchState
)
styleForState
(
state
:
internalSwitch
Control
State
)
}
/**
Toggle the Switch state, if On will be Off, and if Off will be On.
Toggle the Switch
Control
state, if On will be Off, and if Off will be On.
- Parameter completion: An Optional completion block.
*/
public
func
toggle
(
completion
:
((
Switch
)
->
Void
)?
=
nil
)
{
setSwitch
State
(
state
:
.
on
==
internalSwitch
State
?
.
off
:
.
on
,
animated
:
true
,
completion
:
completion
)
public
func
toggle
(
completion
:
((
Switch
Control
)
->
Void
)?
=
nil
)
{
setSwitch
ControlState
(
state
:
.
on
==
internalSwitchControl
State
?
.
off
:
.
on
,
animated
:
true
,
completion
:
completion
)
}
/**
...
...
@@ -324,22 +335,22 @@ public class Switch: UIControl {
- Parameter on: A bool of whether the switch should be in the on state or not.
- Parameter animated: A Boolean indicating to set the animation or not.
*/
public
func
setOn
(
on
:
Bool
,
animated
:
Bool
,
completion
:
((
Switch
)
->
Void
)?
=
nil
)
{
setSwitchState
(
state
:
on
?
.
on
:
.
off
,
animated
:
animated
,
completion
:
completion
)
public
func
setOn
(
on
:
Bool
,
animated
:
Bool
,
completion
:
((
Switch
Control
)
->
Void
)?
=
nil
)
{
setSwitch
Control
State
(
state
:
on
?
.
on
:
.
off
,
animated
:
animated
,
completion
:
completion
)
}
/**
Set the switchState property with an option to animate.
- Parameter state: The SwitchState to set.
- Parameter state: The Switch
Control
State to set.
- Parameter animated: A Boolean indicating to set the animation or not.
- Parameter completion: An Optional completion block.
*/
public
func
setSwitch
State
(
state
:
SwitchState
,
animated
:
Bool
=
true
,
completion
:
((
Switch
)
->
Void
)?
=
nil
)
{
if
isEnabled
&&
internalSwitchState
!=
state
{
internalSwitchState
=
state
public
func
setSwitch
ControlState
(
state
:
SwitchControlState
,
animated
:
Bool
=
true
,
completion
:
((
SwitchControl
)
->
Void
)?
=
nil
)
{
if
isEnabled
&&
internalSwitch
Control
State
!=
state
{
internalSwitch
Control
State
=
state
if
animated
{
animateToState
(
state
:
state
)
{
[
weak
self
]
_
in
if
let
s
:
Switch
=
self
{
if
let
s
:
Switch
Control
=
self
{
s
.
sendActions
(
for
:
.
valueChanged
)
completion
?(
s
)
s
.
delegate
?
.
switchStateChanged
(
control
:
s
)
...
...
@@ -364,7 +375,7 @@ public class Switch: UIControl {
internal
func
handleTouchUpOutsideOrCanceled
(
sender
:
FabButton
,
event
:
UIEvent
)
{
if
let
v
:
UITouch
=
event
.
touches
(
for
:
sender
)?
.
first
{
let
q
:
CGFloat
=
sender
.
x
+
v
.
location
(
in
:
sender
)
.
x
-
v
.
previousLocation
(
in
:
sender
)
.
x
setSwitchState
(
state
:
q
>
(
width
-
button
.
width
)
/
2
?
.
on
:
.
off
,
animated
:
true
)
setSwitch
Control
State
(
state
:
q
>
(
width
-
button
.
width
)
/
2
?
.
on
:
.
off
,
animated
:
true
)
}
}
...
...
@@ -389,9 +400,9 @@ public class Switch: UIControl {
}
}
public
override
func
touchesBegan
(
_
touches
:
Set
<
UITouch
>
,
with
event
:
UIEvent
?)
{
open
override
func
touchesBegan
(
_
touches
:
Set
<
UITouch
>
,
with
event
:
UIEvent
?)
{
if
true
==
trackLayer
.
frame
.
contains
(
layer
.
convert
(
touches
.
first
!.
location
(
in
:
self
),
from
:
layer
))
{
setOn
(
on
:
.
on
!=
internalSwitchState
,
animated
:
true
)
setOn
(
on
:
.
on
!=
internalSwitch
Control
State
,
animated
:
true
)
}
}
...
...
@@ -413,35 +424,35 @@ public class Switch: UIControl {
/**
Prepares the switchState property. This is used mainly to allow
init to set the state value and have an effect.
- Parameter state: The SwitchState to set.
- Parameter state: The Switch
Control
State to set.
*/
private
func
prepareSwitch
State
(
state
:
Switch
State
)
{
setSwitchState
(
state
:
state
,
animated
:
false
)
private
func
prepareSwitch
ControlState
(
state
:
SwitchControl
State
)
{
setSwitch
Control
State
(
state
:
state
,
animated
:
false
)
}
/**
Prepares the switchStyle property. This is used mainly to allow
init to set the state value and have an effect.
- Parameter style: The SwitchStyle to set.
- Parameter style: The Switch
Control
Style to set.
*/
private
func
prepareSwitch
Style
(
style
:
Switch
Style
)
{
private
func
prepareSwitch
ControlStyle
(
style
:
SwitchControl
Style
)
{
switchStyle
=
style
}
/**
Prepares the switchSize property. This is used mainly to allow
init to set the size value and have an effect.
- Parameter size: The SwitchSize to set.
- Parameter size: The Switch
Control
Size to set.
*/
private
func
prepareSwitch
Size
(
size
:
Switch
Size
)
{
private
func
prepareSwitch
ControlSize
(
size
:
SwitchControl
Size
)
{
switchSize
=
size
}
/**
Updates the style based on the state.
- Parameter state: The SwitchState to set the style to.
- Parameter state: The Switch
Control
State to set the style to.
*/
private
func
styleForState
(
state
:
SwitchState
)
{
private
func
styleForState
(
state
:
Switch
Control
State
)
{
if
isEnabled
{
updateColorForState
(
state
:
state
)
}
else
{
...
...
@@ -451,9 +462,9 @@ public class Switch: UIControl {
/**
Updates the coloring for the enabled state.
- Parameter state: SwitchState.
- Parameter state: Switch
Control
State.
*/
private
func
updateColorForState
(
state
:
SwitchState
)
{
private
func
updateColorForState
(
state
:
Switch
Control
State
)
{
if
.
on
==
state
{
button
.
backgroundColor
=
buttonOnColor
trackLayer
.
backgroundColor
=
trackOnColor
.
cgColor
...
...
@@ -465,9 +476,9 @@ public class Switch: UIControl {
/**
Updates the coloring for the disabled state.
- Parameter state: SwitchState.
- Parameter state: Switch
Control
State.
*/
private
func
updateColorForDisabledState
(
state
:
SwitchState
)
{
private
func
updateColorForDisabledState
(
state
:
Switch
Control
State
)
{
if
.
on
==
state
{
button
.
backgroundColor
=
buttonOnDisabledColor
trackLayer
.
backgroundColor
=
trackOnDisabledColor
.
cgColor
...
...
@@ -478,7 +489,7 @@ public class Switch: UIControl {
}
/// Laout the button and track views.
private
func
layoutSwitch
()
{
private
func
layoutSwitch
Control
()
{
var
w
:
CGFloat
=
0
switch
switchSize
{
case
.
small
:
...
...
@@ -498,34 +509,34 @@ public class Switch: UIControl {
onPosition
=
width
-
px
-
buttonDiameter
offPosition
=
px
if
.
on
==
internalSwitchState
{
if
.
on
==
internalSwitch
Control
State
{
button
.
x
=
onPosition
}
}
/**
Set the switchState property with an animate.
- Parameter state: The SwitchState to set.
- Parameter state: The Switch
Control
State to set.
- Parameter completion: An Optional completion block.
*/
private
func
animateToState
(
state
:
Switch
State
,
completion
:
((
Switch
)
->
Void
)?
=
nil
)
{
private
func
animateToState
(
state
:
Switch
ControlState
,
completion
:
((
SwitchControl
)
->
Void
)?
=
nil
)
{
isUserInteractionEnabled
=
false
UIView
.
animate
(
withDuration
:
0.15
,
delay
:
0.05
,
options
:
[
.
curveEaseIn
,
.
curveEaseOut
],
animations
:
{
[
weak
self
]
in
if
let
s
:
Switch
=
self
{
if
let
s
:
Switch
Control
=
self
{
s
.
button
.
x
=
.
on
==
state
?
s
.
onPosition
+
s
.
bounceOffset
:
s
.
offPosition
-
s
.
bounceOffset
s
.
styleForState
(
state
:
state
)
}
})
{
[
weak
self
]
_
in
UIView
.
animate
(
withDuration
:
0.15
,
animations
:
{
[
weak
self
]
in
if
let
s
:
Switch
=
self
{
if
let
s
:
Switch
Control
=
self
{
s
.
button
.
x
=
.
on
==
state
?
s
.
onPosition
:
s
.
offPosition
}
})
{
[
weak
self
]
_
in
if
let
s
:
Switch
=
self
{
if
let
s
:
Switch
Control
=
self
{
s
.
isUserInteractionEnabled
=
true
completion
?(
s
)
}
...
...
Sources/iOS/TextField.swift
View file @
928ba8cb
...
...
@@ -40,7 +40,7 @@ open class TextField: UITextField {
}
/// A Boolean that indicates if the TextField is in an animating state.
open
private(set)
var
a
nimating
=
false
open
internal(set)
var
isA
nimating
=
false
/// A property that accesses the backing layer's backgroundColor.
@IBInspectable
...
...
@@ -199,7 +199,7 @@ open class TextField: UITextField {
/// Enables the clearIconButton.
@IBInspectable
open
var
enableClearIconButton
:
Bool
{
open
var
isClearIconButtonEnable
:
Bool
{
get
{
return
nil
!=
clearIconButton
}
...
...
@@ -234,7 +234,7 @@ open class TextField: UITextField {
/// Enables the visibilityIconButton.
@IBInspectable
open
var
enableVisibilityIconButton
:
Bool
{
open
var
isVisibilityIconButtonEnable
:
Bool
{
get
{
return
nil
!=
visibilityIconButton
}
...
...
@@ -379,7 +379,7 @@ open class TextField: UITextField {
/// Ensures that the components are sized correctly.
open
func
layoutToSize
()
{
if
!
a
nimating
{
if
!
isA
nimating
{
layoutPlaceholderLabel
()
layoutDetailLabel
()
layoutClearIconButton
()
...
...
@@ -461,7 +461,7 @@ open class TextField: UITextField {
/// The animation for the placeholder when editing begins.
open
func
placeholderEditingDidBeginAnimation
()
{
if
placeholderLabel
.
transform
.
isIdentity
{
a
nimating
=
true
isA
nimating
=
true
UIView
.
animate
(
withDuration
:
0.15
,
animations
:
{
[
weak
self
]
in
if
let
s
=
self
{
s
.
placeholderLabel
.
transform
=
CGAffineTransform
(
scaleX
:
0.75
,
y
:
0.75
)
...
...
@@ -476,7 +476,7 @@ open class TextField: UITextField {
s
.
placeholderLabel
.
textColor
=
s
.
placeholderActiveColor
}
})
{
[
weak
self
]
_
in
self
?
.
a
nimating
=
false
self
?
.
isA
nimating
=
false
}
}
else
if
isEditing
{
placeholderLabel
.
textColor
=
placeholderActiveColor
...
...
@@ -486,7 +486,7 @@ open class TextField: UITextField {
/// The animation for the placeholder when editing ends.
open
func
placeholderEditingDidEndAnimation
()
{
if
!
placeholderLabel
.
transform
.
isIdentity
&&
true
==
text
?
.
isEmpty
{
a
nimating
=
true
isA
nimating
=
true
UIView
.
animate
(
withDuration
:
0.15
,
animations
:
{
[
weak
self
]
in
if
let
s
=
self
{
s
.
placeholderLabel
.
transform
=
CGAffineTransform
.
identity
...
...
@@ -495,7 +495,7 @@ open class TextField: UITextField {
s
.
placeholderLabel
.
textColor
=
s
.
placeholderColor
}
})
{
[
weak
self
]
_
in
self
?
.
a
nimating
=
false
self
?
.
isA
nimating
=
false
}
}
else
if
!
isEditing
{
placeholderLabel
.
textColor
=
placeholderColor
...
...
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