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
66bb1e7b
Commit
66bb1e7b
authored
Aug 18, 2016
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
development: improved performance when laying out ControlView controls
parent
a6308b53
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
75 additions
and
90 deletions
+75
-90
Sources/iOS/ControlView.swift
+53
-69
Sources/iOS/Grid.swift
+2
-1
Sources/iOS/NavigationBar.swift
+1
-1
Sources/iOS/TabBar.swift
+1
-1
Sources/iOS/Toolbar.swift
+18
-18
No files found.
Sources/iOS/ControlView.swift
View file @
66bb1e7b
...
...
@@ -33,7 +33,7 @@ import UIKit
open
class
ControlView
:
View
{
/// Will render the view.
open
var
willRenderView
:
Bool
{
return
0
<
width
&&
0
<
height
return
0
<
width
&&
0
<
height
&&
nil
!==
superview
}
/// A preset wrapper around contentInset.
...
...
@@ -89,38 +89,30 @@ open class ControlView: View {
open
private(set)
var
contentView
:
View
!
/// Left side UIControls.
open
var
leftControls
:
[
UIView
]
?
{
open
var
leftControls
:
[
UIView
]
{
didSet
{
if
let
v
=
oldValue
{
for
b
in
v
{
b
.
removeFromSuperview
()
}
}
for
v
in
oldValue
{
v
.
removeFromSuperview
()
}
if
let
v
=
leftControls
{
for
b
in
v
{
addSubview
(
b
)
}
}
for
v
in
leftControls
{
addSubview
(
v
)
}
layoutSubviews
()
}
}
/// Right side UIControls.
open
var
rightControls
:
[
UIView
]
?
{
open
var
rightControls
:
[
UIView
]
{
didSet
{
if
let
v
=
oldValue
{
for
b
in
v
{
b
.
removeFromSuperview
()
}
}
if
let
v
=
rightControls
{
for
b
in
v
{
addSubview
(
b
)
}
}
layoutSubviews
()
for
v
in
oldValue
{
v
.
removeFromSuperview
()
}
for
v
in
rightControls
{
addSubview
(
v
)
}
layoutSubviews
()
}
}
...
...
@@ -129,7 +121,9 @@ open class ControlView: View {
- Parameter aDecoder: A NSCoder instance.
*/
public
required
init
?(
coder
aDecoder
:
NSCoder
)
{
super
.
init
(
coder
:
aDecoder
)
leftControls
=
[]
rightControls
=
[]
super
.
init
(
coder
:
aDecoder
)
}
/**
...
...
@@ -139,13 +133,17 @@ open class ControlView: View {
- Parameter frame: A CGRect instance.
*/
public
override
init
(
frame
:
CGRect
)
{
leftControls
=
[]
rightControls
=
[]
super
.
init
(
frame
:
frame
)
}
/// Basic initializer.
public
init
()
{
leftControls
=
[]
rightControls
=
[]
super
.
init
(
frame
:
CGRect
.
zero
)
frame
.
size
=
intrinsicContentSize
frame
.
size
=
intrinsicContentSize
}
/**
...
...
@@ -154,9 +152,10 @@ open class ControlView: View {
- Parameter rightControls: An Array of UIControls that go on the right side.
*/
public
init
(
leftControls
:
[
UIView
]?
=
nil
,
rightControls
:
[
UIView
]?
=
nil
)
{
super
.
init
(
frame
:
CGRect
.
zero
)
self
.
leftControls
=
leftControls
??
[]
self
.
rightControls
=
rightControls
??
[]
super
.
init
(
frame
:
CGRect
.
zero
)
frame
.
size
=
intrinsicContentSize
prepareProperties
(
leftControls
:
leftControls
,
rightControls
:
rightControls
)
}
open
override
func
layoutSubviews
()
{
...
...
@@ -167,51 +166,46 @@ open class ControlView: View {
let
g
=
Int
(
width
/
gridFactor
)
let
columns
=
g
+
1
grid
.
views
.
removeAll
()
grid
.
views
=
[]
grid
.
axis
.
columns
=
columns
contentView
.
grid
.
columns
=
columns
// leftControls
if
let
v
=
leftControls
{
for
c
in
v
{
let
w
:
CGFloat
=
c
.
intrinsicContentSize
.
width
(
c
as?
UIButton
)?
.
contentEdgeInsets
=
UIEdgeInsets
.
zero
c
.
frame
.
size
.
height
=
frame
.
size
.
height
-
contentInset
.
top
-
contentInset
.
bottom
let
q
:
Int
=
Int
(
w
/
gridFactor
)
c
.
grid
.
columns
=
q
+
1
contentView
.
grid
.
columns
-=
c
.
grid
.
columns
addSubview
(
c
)
grid
.
views
.
append
(
c
)
}
for
c
in
leftControls
{
let
w
:
CGFloat
=
c
.
intrinsicContentSize
.
width
(
c
as?
UIButton
)?
.
contentEdgeInsets
=
UIEdgeInsets
.
zero
c
.
frame
.
size
.
height
=
frame
.
size
.
height
-
contentInset
.
top
-
contentInset
.
bottom
let
q
:
Int
=
Int
(
w
/
gridFactor
)
c
.
grid
.
columns
=
q
+
1
contentView
.
grid
.
columns
-=
c
.
grid
.
columns
addSubview
(
c
)
grid
.
views
.
append
(
c
)
}
addSubview
(
contentView
)
grid
.
views
.
append
(
contentView
)
// rightControls
if
let
v
=
rightControls
{
for
c
in
v
{
let
w
:
CGFloat
=
c
.
intrinsicContentSize
.
width
(
c
as?
UIButton
)?
.
contentEdgeInsets
=
UIEdgeInsets
.
zero
c
.
frame
.
size
.
height
=
frame
.
size
.
height
-
contentInset
.
top
-
contentInset
.
bottom
let
q
:
Int
=
Int
(
w
/
gridFactor
)
c
.
grid
.
columns
=
q
+
1
contentView
.
grid
.
columns
-=
c
.
grid
.
columns
addSubview
(
c
)
grid
.
views
.
append
(
c
)
}
for
c
in
rightControls
{
let
w
=
c
.
intrinsicContentSize
.
width
(
c
as?
UIButton
)?
.
contentEdgeInsets
=
UIEdgeInsets
.
zero
c
.
frame
.
size
.
height
=
frame
.
size
.
height
-
contentInset
.
top
-
contentInset
.
bottom
let
q
:
Int
=
Int
(
w
/
gridFactor
)
c
.
grid
.
columns
=
q
+
1
contentView
.
grid
.
columns
-=
c
.
grid
.
columns
addSubview
(
c
)
grid
.
views
.
append
(
c
)
}
grid
.
contentEdgeInsets
=
contentInset
grid
.
interimSpace
=
interimSpace
grid
.
reload
()
contentView
.
grid
.
reload
()
}
}
...
...
@@ -232,16 +226,6 @@ open class ControlView: View {
prepareContentView
()
}
/**
Used to trigger property changes that initializers avoid.
- Parameter leftControls: An Array of UIControls that go on the left side.
- Parameter rightControls: An Array of UIControls that go on the right side.
*/
internal
func
prepareProperties
(
leftControls
:
[
UIView
]?,
rightControls
:
[
UIView
]?)
{
self
.
leftControls
=
leftControls
self
.
rightControls
=
rightControls
}
/// Prepares the contentView.
private
func
prepareContentView
()
{
contentView
=
View
()
...
...
Sources/iOS/Grid.swift
View file @
66bb1e7b
...
...
@@ -199,8 +199,9 @@ public class Grid {
public
func
reload
()
{
var
n
:
Int
=
0
print
(
"before"
,
views
.
count
)
for
i
in
0
..<
views
.
count
{
print
(
i
,
views
.
count
,
views
)
print
(
"after"
,
i
,
views
.
count
)
let
child
=
views
[
i
]
if
let
parent
=
context
{
...
...
Sources/iOS/NavigationBar.swift
View file @
66bb1e7b
...
...
@@ -70,7 +70,7 @@ public class NavigationBar: UINavigationBar {
/// Will render the view.
public
var
willRenderView
:
Bool
{
return
0
<
width
&&
0
<
height
return
0
<
width
&&
0
<
height
&&
nil
!=
superview
}
/// A preset wrapper around contentInset.
...
...
Sources/iOS/TabBar.swift
View file @
66bb1e7b
...
...
@@ -49,7 +49,7 @@ public class TabBar: View {
/// Will render the view.
public
var
willRenderView
:
Bool
{
return
0
<
width
return
0
<
width
&&
0
<
height
&&
nil
!=
superview
}
/// Buttons.
...
...
Sources/iOS/Toolbar.swift
View file @
66bb1e7b
...
...
@@ -101,39 +101,39 @@ public class Toolbar: BarView {
}
/**
An initializer that initializes the object with a NSCoder object.
- Parameter aDecoder: A NSCoder instance.
*/
An initializer that initializes the object with a NSCoder object.
- Parameter aDecoder: A NSCoder instance.
*/
public
required
init
?(
coder
aDecoder
:
NSCoder
)
{
super
.
init
(
coder
:
aDecoder
)
}
/**
An initializer that initializes the object with a CGRect object.
If AutoLayout is used, it is better to initilize the instance
using the init() initializer.
- Parameter frame: A CGRect instance.
*/
An initializer that initializes the object with a CGRect object.
If AutoLayout is used, it is better to initilize the instance
using the init() initializer.
- Parameter frame: A CGRect instance.
*/
public
override
init
(
frame
:
CGRect
)
{
super
.
init
(
frame
:
frame
)
}
/**
A convenience initializer with parameter settings.
- Parameter leftControls: An Array of UIControls that go on the left side.
- Parameter rightControls: An Array of UIControls that go on the right side.
*/
A convenience initializer with parameter settings.
- Parameter leftControls: An Array of UIControls that go on the left side.
- Parameter rightControls: An Array of UIControls that go on the right side.
*/
public
override
init
(
leftControls
:
[
UIView
]?
=
nil
,
rightControls
:
[
UIView
]?
=
nil
)
{
super
.
init
(
leftControls
:
leftControls
,
rightControls
:
rightControls
)
}
/**
Prepares the view instance when intialized. When subclassing,
it is recommended to override the prepareView method
to initialize property values and other setup operations.
The super.prepareView method should always be called immediately
when subclassing.
*/
Prepares the view instance when intialized. When subclassing,
it is recommended to override the prepareView method
to initialize property values and other setup operations.
The super.prepareView method should always be called immediately
when subclassing.
*/
public
override
func
prepareView
()
{
super
.
prepareView
()
prepareTitleLabel
()
...
...
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