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
eae3cc12
Commit
eae3cc12
authored
Oct 11, 2018
by
Orkhan Alikhanov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reworked toolbar theming
parent
28835e94
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
64 additions
and
33 deletions
+64
-33
Sources/iOS/IconButton.swift
+17
-0
Sources/iOS/NavigationBar.swift
+1
-14
Sources/iOS/Toolbar.swift
+46
-1
Sources/iOS/ToolbarController.swift
+0
-18
No files found.
Sources/iOS/IconButton.swift
View file @
eae3cc12
...
@@ -30,7 +30,18 @@
...
@@ -30,7 +30,18 @@
import
UIKit
import
UIKit
public
enum
IconButtonThemingStyle
{
/// Theming when background content is in background color.
case
onBackground
/// Theming when background content is in primary color.
case
onPrimary
}
open
class
IconButton
:
Button
{
open
class
IconButton
:
Button
{
/// A reference to IconButtonThemingStyle.
open
var
themingStyle
=
IconButtonThemingStyle
.
onBackground
open
override
func
prepare
()
{
open
override
func
prepare
()
{
super
.
prepare
()
super
.
prepare
()
pulseAnimation
=
.
center
pulseAnimation
=
.
center
...
@@ -39,7 +50,13 @@ open class IconButton: Button {
...
@@ -39,7 +50,13 @@ open class IconButton: Button {
open
override
func
apply
(
theme
:
Theme
)
{
open
override
func
apply
(
theme
:
Theme
)
{
super
.
apply
(
theme
:
theme
)
super
.
apply
(
theme
:
theme
)
switch
themingStyle
{
case
.
onBackground
:
tintColor
=
theme
.
secondary
tintColor
=
theme
.
secondary
pulseColor
=
theme
.
secondary
pulseColor
=
theme
.
secondary
case
.
onPrimary
:
tintColor
=
theme
.
onPrimary
pulseColor
=
theme
.
onPrimary
}
}
}
}
}
Sources/iOS/NavigationBar.swift
View file @
eae3cc12
...
@@ -179,21 +179,8 @@ open class NavigationBar: UINavigationBar, Themeable {
...
@@ -179,21 +179,8 @@ open class NavigationBar: UINavigationBar, Themeable {
}
}
private
func
apply
(
theme
:
Theme
,
to
item
:
UINavigationItem
)
{
private
func
apply
(
theme
:
Theme
,
to
item
:
UINavigationItem
)
{
Theme
.
apply
(
theme
:
theme
,
to
:
item
.
toolbar
)
item
.
toolbar
.
backgroundColor
=
.
clear
item
.
toolbar
.
backgroundColor
=
.
clear
(
item
.
toolbar
.
leftViews
+
item
.
toolbar
.
rightViews
+
item
.
toolbar
.
centerViews
)
.
compactMap
{
$0
as?
IconButton
}
.
filter
{
$0
.
isThemingEnabled
}
.
forEach
{
$0
.
tintColor
=
theme
.
onPrimary
$0
.
pulseColor
=
theme
.
onPrimary
}
if
!
((
item
.
titleLabel
as?
Themeable
)?
.
isThemingEnabled
==
false
)
{
item
.
titleLabel
.
textColor
=
theme
.
onPrimary
}
if
!
((
item
.
detailLabel
as?
Themeable
)?
.
isThemingEnabled
==
false
)
{
item
.
detailLabel
.
textColor
=
theme
.
onPrimary
}
}
}
}
}
...
...
Sources/iOS/Toolbar.swift
View file @
eae3cc12
...
@@ -30,7 +30,7 @@
...
@@ -30,7 +30,7 @@
import
UIKit
import
UIKit
open
class
Toolbar
:
Bar
{
open
class
Toolbar
:
Bar
,
Themeable
{
/// A convenience property to set the titleLabel.text.
/// A convenience property to set the titleLabel.text.
@IBInspectable
@IBInspectable
open
var
title
:
String
?
{
open
var
title
:
String
?
{
...
@@ -63,6 +63,24 @@ open class Toolbar: Bar {
...
@@ -63,6 +63,24 @@ open class Toolbar: Bar {
@IBInspectable
@IBInspectable
public
let
detailLabel
=
UILabel
()
public
let
detailLabel
=
UILabel
()
open
override
var
leftViews
:
[
UIView
]
{
didSet
{
prepareIconButtons
(
leftViews
)
}
}
open
override
var
centerViews
:
[
UIView
]
{
didSet
{
prepareIconButtons
(
centerViews
)
}
}
open
override
var
rightViews
:
[
UIView
]
{
didSet
{
prepareIconButtons
(
rightViews
)
}
}
/**
/**
An initializer that initializes the object with a NSCoder object.
An initializer that initializes the object with a NSCoder object.
- Parameter aDecoder: A NSCoder instance.
- Parameter aDecoder: A NSCoder instance.
...
@@ -129,6 +147,25 @@ open class Toolbar: Bar {
...
@@ -129,6 +147,25 @@ open class Toolbar: Bar {
prepareDetailLabel
()
prepareDetailLabel
()
}
}
open
func
apply
(
theme
:
Theme
)
{
backgroundColor
=
theme
.
primary
(
leftViews
+
rightViews
+
centerViews
)
.
forEach
{
guard
let
v
=
$0
as?
IconButton
,
v
.
isThemingEnabled
else
{
return
}
v
.
apply
(
theme
:
theme
)
}
if
!
((
titleLabel
as?
Themeable
)?
.
isThemingEnabled
==
false
)
{
titleLabel
.
textColor
=
theme
.
onPrimary
}
if
!
((
detailLabel
as?
Themeable
)?
.
isThemingEnabled
==
false
)
{
detailLabel
.
textColor
=
theme
.
onPrimary
}
}
/// A reference to titleLabel.textAlignment observation.
/// A reference to titleLabel.textAlignment observation.
private
var
titleLabelTextAlignmentObserver
:
NSKeyValueObservation
!
private
var
titleLabelTextAlignmentObserver
:
NSKeyValueObservation
!
}
}
...
@@ -152,4 +189,12 @@ private extension Toolbar {
...
@@ -152,4 +189,12 @@ private extension Toolbar {
detailLabel
.
font
=
RobotoFont
.
regular
(
with
:
12
)
detailLabel
.
font
=
RobotoFont
.
regular
(
with
:
12
)
detailLabel
.
textColor
=
Color
.
darkText
.
secondary
detailLabel
.
textColor
=
Color
.
darkText
.
secondary
}
}
func
prepareIconButtons
(
_
views
:
[
UIView
])
{
views
.
forEach
{
(
$0
as?
IconButton
)?
.
themingStyle
=
.
onPrimary
}
applyCurrentTheme
()
}
}
}
Sources/iOS/ToolbarController.swift
View file @
eae3cc12
...
@@ -73,24 +73,6 @@ open class ToolbarController: StatusBarController {
...
@@ -73,24 +73,6 @@ open class ToolbarController: StatusBarController {
prepareToolbar
()
prepareToolbar
()
}
}
open
override
func
apply
(
theme
:
Theme
)
{
super
.
apply
(
theme
:
theme
)
toolbar
.
backgroundColor
=
theme
.
primary
toolbar
.
titleLabel
.
textColor
=
theme
.
onPrimary
toolbar
.
detailLabel
.
textColor
=
theme
.
onPrimary
(
toolbar
.
leftViews
+
toolbar
.
rightViews
+
toolbar
.
centerViews
)
.
compactMap
{
$0
as?
IconButton
}
.
filter
{
$0
.
isThemingEnabled
}
.
forEach
{
$0
.
tintColor
=
theme
.
onPrimary
$0
.
titleColor
=
theme
.
onPrimary
$0
.
pulseColor
=
theme
.
onPrimary
}
}
}
}
fileprivate
extension
ToolbarController
{
fileprivate
extension
ToolbarController
{
...
...
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