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
cc90fb37
Unverified
Commit
cc90fb37
authored
Jul 06, 2018
by
Daniel Dahan
Committed by
GitHub
Jul 06, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1112 from OrkhanAlikhanov/tab-center
Added tab bar centering
parents
04007ca0
6cf49bce
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
3 deletions
+34
-3
Sources/iOS/TabBar.swift
+34
-3
No files found.
Sources/iOS/TabBar.swift
View file @
cc90fb37
...
@@ -199,6 +199,12 @@ public enum TabBarStyle: Int {
...
@@ -199,6 +199,12 @@ public enum TabBarStyle: Int {
case
scrollable
case
scrollable
}
}
public
enum
TabBarCenteringStyle
{
case
never
case
whenNeeded
case
always
}
open
class
TabBar
:
Bar
{
open
class
TabBar
:
Bar
{
/// A dictionary of TabItemLineStates to UIColors for the line.
/// A dictionary of TabItemLineStates to UIColors for the line.
fileprivate
var
lineColorForState
=
[
TabItemLineState
:
UIColor
]()
fileprivate
var
lineColorForState
=
[
TabItemLineState
:
UIColor
]()
...
@@ -230,6 +236,13 @@ open class TabBar: Bar {
...
@@ -230,6 +236,13 @@ open class TabBar: Bar {
}
}
}
}
/// An enum that determines the tab bar centering style.
open
var
tabBarCenteringStyle
=
TabBarCenteringStyle
.
never
{
didSet
{
layoutSubviews
()
}
}
/// A reference to the scroll view when the tab bar style is scrollable.
/// A reference to the scroll view when the tab bar style is scrollable.
open
let
scrollView
=
UIScrollView
()
open
let
scrollView
=
UIScrollView
()
...
@@ -625,9 +638,27 @@ fileprivate extension TabBar {
...
@@ -625,9 +638,27 @@ fileprivate extension TabBar {
return
return
}
}
if
!
scrollView
.
bounds
.
contains
(
v
.
frame
)
{
let
contentOffsetX
:
CGFloat
?
=
{
let
contentOffsetX
=
(
v
.
frame
.
origin
.
x
<
scrollView
.
bounds
.
minX
)
?
v
.
frame
.
origin
.
x
:
v
.
frame
.
maxX
-
scrollView
.
bounds
.
width
let
shouldScroll
=
!
scrollView
.
bounds
.
contains
(
v
.
frame
)
let
normalizedOffsetX
=
min
(
max
(
contentOffsetX
,
0
),
scrollView
.
contentSize
.
width
-
scrollView
.
bounds
.
width
)
switch
tabBarCenteringStyle
{
case
.
whenNeeded
:
guard
shouldScroll
else
{
return
nil
}
fallthrough
case
.
always
:
return
v
.
center
.
x
-
bounds
.
width
/
2
case
.
never
:
guard
shouldScroll
else
{
return
nil
}
return
v
.
frame
.
origin
.
x
<
scrollView
.
bounds
.
minX
?
v
.
frame
.
origin
.
x
:
v
.
frame
.
maxX
-
scrollView
.
bounds
.
width
}
}()
if
let
x
=
contentOffsetX
{
let
normalizedOffsetX
=
min
(
max
(
x
,
0
),
scrollView
.
contentSize
.
width
-
scrollView
.
bounds
.
width
)
scrollView
.
setContentOffset
(
CGPoint
(
x
:
normalizedOffsetX
,
y
:
0
),
animated
:
true
)
scrollView
.
setContentOffset
(
CGPoint
(
x
:
normalizedOffsetX
,
y
:
0
),
animated
:
true
)
}
}
}
}
...
...
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