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
edfe8046
Commit
edfe8046
authored
Dec 25, 2017
by
Orkhan Alikhanov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Considered disabled state for CheckButton/RadioButton
parent
28ee6886
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
63 additions
and
26 deletions
+63
-26
Sources/iOS/BaseIconLayerButton.swift
+36
-14
Sources/iOS/CheckButton.swift
+13
-5
Sources/iOS/RadioButton.swift
+14
-7
No files found.
Sources/iOS/BaseIconLayerButton.swift
View file @
edfe8046
...
@@ -20,21 +20,35 @@ open class BaseIconLayerButton: Button {
...
@@ -20,21 +20,35 @@ open class BaseIconLayerButton: Button {
}
}
}
}
open
var
normalIconColor
:
UIColor
{
open
override
var
isEnabled
:
Bool
{
get
{
didSet
{
return
iconLayer
.
normalColor
iconLayer
.
isEnabled
=
isEnabled
}
set
{
iconLayer
.
normalColor
=
newValue
}
}
}
}
open
var
selectedIconColor
:
UIColor
{
open
func
setIconColor
(
_
color
:
UIColor
,
for
state
:
UIControlState
)
{
get
{
switch
state
{
return
iconLayer
.
selectedColor
case
.
normal
:
iconLayer
.
normalColor
=
color
case
.
selected
:
iconLayer
.
selectedColor
=
color
case
.
disabled
:
iconLayer
.
disabledColor
=
color
default
:
fatalError
(
"unsupported state"
)
}
}
set
{
}
iconLayer
.
selectedColor
=
newValue
open
func
iconColor
(
for
state
:
UIControlState
)
->
UIColor
{
switch
state
{
case
.
normal
:
return
iconLayer
.
normalColor
case
.
selected
:
return
iconLayer
.
selectedColor
case
.
disabled
:
return
iconLayer
.
disabledColor
default
:
fatalError
(
"unsupported state"
)
}
}
}
}
...
@@ -95,6 +109,7 @@ open class BaseIconLayerButton: Button {
...
@@ -95,6 +109,7 @@ open class BaseIconLayerButton: Button {
internal
class
BaseIconLayer
:
CALayer
{
internal
class
BaseIconLayer
:
CALayer
{
var
selectedColor
=
Color
.
blue
.
base
var
selectedColor
=
Color
.
blue
.
base
var
normalColor
=
Color
.
lightGray
var
normalColor
=
Color
.
lightGray
var
disabledColor
=
Color
.
gray
func
prepareForFirstAnimation
()
{}
func
prepareForFirstAnimation
()
{}
...
@@ -103,8 +118,15 @@ internal class BaseIconLayer: CALayer {
...
@@ -103,8 +118,15 @@ internal class BaseIconLayer: CALayer {
func
prepareForSecondAnimation
()
{}
func
prepareForSecondAnimation
()
{}
func
secondAnimation
()
{}
func
secondAnimation
()
{}
var
isAnimating
=
false
private(set)
var
isAnimating
=
false
var
isSelected
=
false
private(set)
var
isSelected
=
false
var
isEnabled
=
true
{
didSet
{
selectedColor
=
{
selectedColor
}()
normalColor
=
{
normalColor
}()
disabledColor
=
{
disabledColor
}()
}
}
override
init
()
{
override
init
()
{
super
.
init
()
super
.
init
()
...
@@ -187,7 +209,7 @@ internal extension CALayer {
...
@@ -187,7 +209,7 @@ internal extension CALayer {
func
animate
(
_
keyPath
:
String
,
to
:
CGFloat
,
dur
:
TimeInterval
=
0
)
{
func
animate
(
_
keyPath
:
String
,
to
:
CGFloat
,
dur
:
TimeInterval
=
0
)
{
let
animation
=
CABasicAnimation
(
keyPath
:
keyPath
)
let
animation
=
CABasicAnimation
(
keyPath
:
keyPath
)
animation
.
timingFunction
=
.
easeIn
animation
.
timingFunction
=
.
easeIn
animation
.
fromValue
=
self
.
value
(
forKey
:
keyPath
)
// from current value
animation
.
fromValue
=
self
.
value
(
forKey
Path
:
keyPath
)
// from current value
animation
.
duration
=
dur
animation
.
duration
=
dur
setValue
(
to
,
forKeyPath
:
keyPath
)
setValue
(
to
,
forKeyPath
:
keyPath
)
...
...
Sources/iOS/CheckButton.swift
View file @
edfe8046
...
@@ -46,7 +46,7 @@ internal class CheckBoxLayer: BaseIconLayer {
...
@@ -46,7 +46,7 @@ internal class CheckBoxLayer: BaseIconLayer {
override
var
selectedColor
:
UIColor
{
override
var
selectedColor
:
UIColor
{
didSet
{
didSet
{
guard
isSelected
else
{
return
}
guard
isSelected
,
isEnabled
else
{
return
}
borderLayer
.
borderColor
=
selectedColor
.
cgColor
borderLayer
.
borderColor
=
selectedColor
.
cgColor
borderLayer
.
backgroundColor
=
selectedColor
.
cgColor
borderLayer
.
backgroundColor
=
selectedColor
.
cgColor
}
}
...
@@ -54,11 +54,19 @@ internal class CheckBoxLayer: BaseIconLayer {
...
@@ -54,11 +54,19 @@ internal class CheckBoxLayer: BaseIconLayer {
override
var
normalColor
:
UIColor
{
override
var
normalColor
:
UIColor
{
didSet
{
didSet
{
guard
!
isSelected
else
{
return
}
guard
!
isSelected
,
isEnabled
else
{
return
}
borderLayer
.
borderColor
=
normalColor
.
cgColor
borderLayer
.
borderColor
=
normalColor
.
cgColor
}
}
}
}
override
var
disabledColor
:
UIColor
{
didSet
{
guard
!
isEnabled
else
{
return
}
borderLayer
.
borderColor
=
disabledColor
.
cgColor
if
isSelected
{
borderLayer
.
backgroundColor
=
disabledColor
.
cgColor
}
}
}
open
override
func
prepare
()
{
open
override
func
prepare
()
{
super
.
prepare
()
super
.
prepare
()
addSublayer
(
borderLayer
)
addSublayer
(
borderLayer
)
...
@@ -73,11 +81,11 @@ internal class CheckBoxLayer: BaseIconLayer {
...
@@ -73,11 +81,11 @@ internal class CheckBoxLayer: BaseIconLayer {
}
}
override
func
prepareForFirstAnimation
()
{
override
func
prepareForFirstAnimation
()
{
borderLayer
.
borderColor
=
(
is
Selected
?
selectedColor
:
normal
Color
)
.
cgColor
borderLayer
.
borderColor
=
(
is
Enabled
?
(
isSelected
?
selectedColor
:
normalColor
)
:
disabled
Color
)
.
cgColor
if
isSelected
{
if
isSelected
{
borderLayer
.
borderWidth
=
borderLayerNormalBorderWidth
borderLayer
.
borderWidth
=
borderLayerNormalBorderWidth
}
else
{
}
else
{
borderLayer
.
backgroundColor
=
normalColor
.
cgColor
borderLayer
.
backgroundColor
=
(
isEnabled
?
normalColor
:
disabledColor
)
.
cgColor
checkMarkLeftLayer
.
strokeEnd
=
1
checkMarkLeftLayer
.
strokeEnd
=
1
checkMarkRightLayer
.
strokeEnd
=
1
checkMarkRightLayer
.
strokeEnd
=
1
}
}
...
@@ -98,7 +106,7 @@ internal class CheckBoxLayer: BaseIconLayer {
...
@@ -98,7 +106,7 @@ internal class CheckBoxLayer: BaseIconLayer {
}
}
override
func
prepareForSecondAnimation
()
{
override
func
prepareForSecondAnimation
()
{
borderLayer
.
backgroundColor
=
(
isSelected
?
selectedColor
:
.
clear
)
.
cgColor
borderLayer
.
backgroundColor
=
(
isSelected
?
(
isEnabled
?
selectedColor
:
disabledColor
)
:
.
clear
)
.
cgColor
if
isSelected
{
if
isSelected
{
borderLayer
.
borderWidth
=
borderLayerNormalBorderWidth
borderLayer
.
borderWidth
=
borderLayerNormalBorderWidth
...
...
Sources/iOS/RadioButton.swift
View file @
edfe8046
...
@@ -29,7 +29,7 @@ internal class RadioBoxLayer: BaseIconLayer {
...
@@ -29,7 +29,7 @@ internal class RadioBoxLayer: BaseIconLayer {
override
var
selectedColor
:
UIColor
{
override
var
selectedColor
:
UIColor
{
didSet
{
didSet
{
guard
isSelected
else
{
return
}
guard
isSelected
,
isEnabled
else
{
return
}
outerCircle
.
borderColor
=
selectedColor
.
cgColor
outerCircle
.
borderColor
=
selectedColor
.
cgColor
centerDot
.
backgroundColor
=
selectedColor
.
cgColor
centerDot
.
backgroundColor
=
selectedColor
.
cgColor
}
}
...
@@ -37,12 +37,19 @@ internal class RadioBoxLayer: BaseIconLayer {
...
@@ -37,12 +37,19 @@ internal class RadioBoxLayer: BaseIconLayer {
override
var
normalColor
:
UIColor
{
override
var
normalColor
:
UIColor
{
didSet
{
didSet
{
if
!
isSelected
{
guard
!
isSelected
,
isEnabled
else
{
return
}
outerCircle
.
borderColor
=
normalColor
.
cgColor
outerCircle
.
borderColor
=
normalColor
.
cgColor
}
}
}
}
}
override
var
disabledColor
:
UIColor
{
didSet
{
guard
!
isEnabled
else
{
return
}
outerCircle
.
borderColor
=
disabledColor
.
cgColor
if
isSelected
{
centerDot
.
backgroundColor
=
disabledColor
.
cgColor
}
}
}
override
func
prepare
()
{
override
func
prepare
()
{
super
.
prepare
()
super
.
prepare
()
addSublayer
(
centerDot
)
addSublayer
(
centerDot
)
...
@@ -50,9 +57,9 @@ internal class RadioBoxLayer: BaseIconLayer {
...
@@ -50,9 +57,9 @@ internal class RadioBoxLayer: BaseIconLayer {
}
}
override
func
prepareForFirstAnimation
()
{
override
func
prepareForFirstAnimation
()
{
outerCircle
.
borderColor
=
(
is
Selected
?
selectedColor
:
normal
Color
)
.
cgColor
outerCircle
.
borderColor
=
(
is
Enabled
?
(
isSelected
?
selectedColor
:
normalColor
)
:
disabled
Color
)
.
cgColor
if
!
isSelected
{
if
!
isSelected
{
centerDot
.
backgroundColor
=
normalColor
.
cgColor
centerDot
.
backgroundColor
=
(
isEnabled
?
normalColor
:
disabledColor
)
.
cgColor
}
}
outerCircle
.
borderWidth
=
outerCircleBorderWidth
outerCircle
.
borderWidth
=
outerCircleBorderWidth
}
}
...
@@ -68,7 +75,7 @@ internal class RadioBoxLayer: BaseIconLayer {
...
@@ -68,7 +75,7 @@ internal class RadioBoxLayer: BaseIconLayer {
override
func
prepareForSecondAnimation
()
{
override
func
prepareForSecondAnimation
()
{
centerDot
.
transform
=
isSelected
?
centerDotScaleForMeeting
:
.
identity
centerDot
.
transform
=
isSelected
?
centerDotScaleForMeeting
:
.
identity
centerDot
.
backgroundColor
=
(
isSelected
?
selectedColor
:
.
clear
)
.
cgColor
centerDot
.
backgroundColor
=
(
isSelected
?
(
isEnabled
?
selectedColor
:
disabledColor
)
:
.
clear
)
.
cgColor
outerCircle
.
borderWidth
=
isSelected
?
outerCircleBorderWidth
*
percentageOfOuterCircleWidthToStart
:
outerCircleFullBorderWidth
outerCircle
.
borderWidth
=
isSelected
?
outerCircleBorderWidth
*
percentageOfOuterCircleWidthToStart
:
outerCircleFullBorderWidth
}
}
...
...
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