Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
65caad47
Commit
65caad47
authored
Jul 27, 2015
by
Hans Muller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Enable fling scrolling in TabBar
parent
2c09a982
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
59 additions
and
35 deletions
+59
-35
tabs.dart
packages/flutter/example/widgets/tabs.dart
+9
-8
scroll_behavior.dart
packages/flutter/lib/animation/scroll_behavior.dart
+1
-1
tabs.dart
packages/flutter/lib/widgets/tabs.dart
+48
-25
pubspec.yaml
packages/flutter/pubspec.yaml
+1
-1
No files found.
packages/flutter/example/widgets/tabs.dart
View file @
65caad47
...
...
@@ -16,11 +16,12 @@ class TabbedNavigatorApp extends App {
// The index of the selected tab for each of the TabNavigators constructed below.
List
<
int
>
selectedIndices
=
new
List
<
int
>.
filled
(
5
,
0
);
TabNavigator
_buildTabNavigator
(
int
n
,
List
<
TabNavigatorView
>
views
,
{
s
crollable:
false
})
{
TabNavigator
_buildTabNavigator
(
int
n
,
List
<
TabNavigatorView
>
views
,
Key
key
,
{
isS
crollable:
false
})
{
return
new
TabNavigator
(
key:
key
,
views:
views
,
selectedIndex:
selectedIndices
[
n
],
scrollable:
s
crollable
,
isScrollable:
isS
crollable
,
onChanged:
(
tabIndex
)
{
setState
(()
{
selectedIndices
[
n
]
=
tabIndex
;
}
);
}
...
...
@@ -41,7 +42,7 @@ class TabbedNavigatorApp extends App {
builder:
()
=>
_buildContent
(
text
)
);
});
return
_buildTabNavigator
(
n
,
views
.
toList
());
return
_buildTabNavigator
(
n
,
views
.
toList
()
,
new
Key
(
'textLabelsTabNavigator'
)
);
}
TabNavigator
_buildIconLabelsTabNavigator
(
int
n
)
{
...
...
@@ -52,7 +53,7 @@ class TabbedNavigatorApp extends App {
builder:
()
=>
_buildContent
(
icon_name
)
);
});
return
_buildTabNavigator
(
n
,
views
.
toList
());
return
_buildTabNavigator
(
n
,
views
.
toList
()
,
new
Key
(
'iconLabelsTabNavigator'
)
);
}
TabNavigator
_buildTextAndIconLabelsTabNavigator
(
int
n
)
{
...
...
@@ -70,7 +71,7 @@ class TabbedNavigatorApp extends App {
builder:
()
=>
_buildContent
(
"Summary"
)
)
];
return
_buildTabNavigator
(
n
,
views
);
return
_buildTabNavigator
(
n
,
views
,
new
Key
(
'textAndIconLabelsTabNavigator'
)
);
}
TabNavigator
_buildScrollableTabNavigator
(
int
n
)
{
...
...
@@ -92,7 +93,7 @@ class TabbedNavigatorApp extends App {
builder:
()
=>
_buildContent
(
text
)
);
});
return
_buildTabNavigator
(
n
,
views
.
toList
(),
s
crollable:
true
);
return
_buildTabNavigator
(
n
,
views
.
toList
(),
new
Key
(
'scrollableTabNavigator'
),
isS
crollable:
true
);
}
...
...
@@ -124,7 +125,7 @@ class TabbedNavigatorApp extends App {
)
];
TabNavigator
tabNavigator
=
_buildTabNavigator
(
4
,
views
);
TabNavigator
tabNavigator
=
_buildTabNavigator
(
4
,
views
,
new
Key
(
'tabs'
)
);
assert
(
selectedIndices
.
length
==
5
);
ToolBar
toolbar
=
new
ToolBar
(
...
...
packages/flutter/lib/animation/scroll_behavior.dart
View file @
65caad47
...
...
@@ -60,7 +60,7 @@ class FlingBehavior extends BoundedBehavior {
:
super
(
contentsSize:
contentsSize
,
containerSize:
containerSize
);
Simulation
release
(
double
position
,
double
velocity
)
{
return
createDefaultScrollSimulation
(
position
,
0.0
,
minScrollOffset
,
maxScrollOffset
);
return
createDefaultScrollSimulation
(
position
,
velocity
,
minScrollOffset
,
maxScrollOffset
);
}
}
...
...
packages/flutter/lib/widgets/tabs.dart
View file @
65caad47
...
...
@@ -4,6 +4,7 @@
import
'dart:math'
as
math
;
import
'package:newton/newton.dart'
;
import
'package:sky/animation/scroll_behavior.dart'
;
import
'package:sky/painting/text_style.dart'
;
import
'package:sky/rendering/box.dart'
;
...
...
@@ -32,7 +33,7 @@ const double _kRelativeMaxTabWidth = 56.0;
const
EdgeDims
_kTabLabelPadding
=
const
EdgeDims
.
symmetric
(
horizontal:
12.0
);
const
TextStyle
_kTabTextStyle
=
const
TextStyle
(
textAlign:
TextAlign
.
center
);
const
int
_kTabIconSize
=
24
;
const
double
_kTabBarScroll
Friction
=
0.00
5
;
const
double
_kTabBarScroll
Drag
=
0.02
5
;
class
TabBarParentData
extends
BoxParentData
with
ContainerParentDataMixin
<
RenderBox
>
{
}
...
...
@@ -79,11 +80,11 @@ class RenderTabBar extends RenderBox with
}
}
bool
_
s
crollable
;
bool
get
scrollable
=>
_s
crollable
;
void
set
s
crollable
(
bool
value
)
{
if
(
_
s
crollable
!=
value
)
{
_
s
crollable
=
value
;
bool
_
isS
crollable
;
bool
get
isScrollable
=>
_isS
crollable
;
void
set
isS
crollable
(
bool
value
)
{
if
(
_
isS
crollable
!=
value
)
{
_
isS
crollable
=
value
;
markNeedsLayout
();
}
}
...
...
@@ -104,7 +105,7 @@ class RenderTabBar extends RenderBox with
assert
(
child
.
parentData
is
TabBarParentData
);
child
=
child
.
parentData
.
nextSibling
;
}
double
width
=
s
crollable
?
maxWidth
:
maxWidth
*
childCount
;
double
width
=
isS
crollable
?
maxWidth
:
maxWidth
*
childCount
;
return
constraints
.
constrainWidth
(
width
);
}
...
...
@@ -119,7 +120,7 @@ class RenderTabBar extends RenderBox with
assert
(
child
.
parentData
is
TabBarParentData
);
child
=
child
.
parentData
.
nextSibling
;
}
double
width
=
s
crollable
?
maxWidth
:
maxWidth
*
childCount
;
double
width
=
isS
crollable
?
maxWidth
:
maxWidth
*
childCount
;
return
constraints
.
constrainWidth
(
width
);
}
...
...
@@ -172,10 +173,10 @@ class RenderTabBar extends RenderBox with
void
reportLayoutChangedIfNeeded
()
{
assert
(
onLayoutChanged
!=
null
);
List
<
double
>
widths
=
new
List
<
double
>(
childCount
);
if
(!
s
crollable
&&
childCount
>
0
)
{
if
(!
isS
crollable
&&
childCount
>
0
)
{
double
tabWidth
=
size
.
width
/
childCount
;
widths
.
fillRange
(
0
,
widths
.
length
-
1
,
tabWidth
);
}
else
if
(
s
crollable
)
{
}
else
if
(
isS
crollable
)
{
RenderBox
child
=
firstChild
;
int
childIndex
=
0
;
while
(
child
!=
null
)
{
...
...
@@ -200,7 +201,7 @@ class RenderTabBar extends RenderBox with
if
(
childCount
==
0
)
return
;
if
(
s
crollable
)
if
(
isS
crollable
)
layoutScrollableTabs
();
else
layoutFixedWidthTabs
();
...
...
@@ -255,7 +256,7 @@ class TabBarWrapper extends MultiChildRenderObjectWrapper {
this
.
backgroundColor
,
this
.
indicatorColor
,
this
.
textAndIcons
,
this
.
s
crollable
:
false
,
this
.
isS
crollable
:
false
,
this
.
onLayoutChanged
})
:
super
(
key:
key
,
children:
children
);
...
...
@@ -263,7 +264,7 @@ class TabBarWrapper extends MultiChildRenderObjectWrapper {
final
Color
backgroundColor
;
final
Color
indicatorColor
;
final
bool
textAndIcons
;
final
bool
s
crollable
;
final
bool
isS
crollable
;
final
LayoutChanged
onLayoutChanged
;
RenderTabBar
get
root
=>
super
.
root
;
...
...
@@ -275,7 +276,7 @@ class TabBarWrapper extends MultiChildRenderObjectWrapper {
root
.
backgroundColor
=
backgroundColor
;
root
.
indicatorColor
=
indicatorColor
;
root
.
textAndIcons
=
textAndIcons
;
root
.
scrollable
=
s
crollable
;
root
.
isScrollable
=
isS
crollable
;
root
.
onLayoutChanged
=
onLayoutChanged
;
}
}
...
...
@@ -345,32 +346,54 @@ class Tab extends Component {
}
}
class
_TabsScrollBehavior
extends
BoundedBehavior
{
_TabsScrollBehavior
({
double
contentsSize:
0.0
,
double
containerSize:
0.0
})
:
super
(
contentsSize:
contentsSize
,
containerSize:
containerSize
);
bool
isScrollable
=
true
;
Simulation
release
(
double
position
,
double
velocity
)
{
if
(!
isScrollable
)
return
null
;
double
velocityPerSecond
=
velocity
*
1000.0
;
return
new
BoundedFrictionSimulation
(
_kTabBarScrollDrag
,
position
,
velocityPerSecond
,
minScrollOffset
,
maxScrollOffset
);
}
double
applyCurve
(
double
scrollOffset
,
double
scrollDelta
)
{
return
(
isScrollable
)
?
super
.
applyCurve
(
scrollOffset
,
scrollDelta
)
:
0.0
;
}
}
class
TabBar
extends
Scrollable
{
TabBar
({
Key
key
,
this
.
labels
,
this
.
selectedIndex
:
0
,
this
.
onChanged
,
this
.
s
crollable
:
false
this
.
isS
crollable
:
false
})
:
super
(
key:
key
,
direction:
ScrollDirection
.
horizontal
);
Iterable
<
TabLabel
>
labels
;
int
selectedIndex
;
SelectedIndexChanged
onChanged
;
bool
s
crollable
;
bool
isS
crollable
;
void
syncFields
(
TabBar
source
)
{
super
.
syncFields
(
source
);
labels
=
source
.
labels
;
selectedIndex
=
source
.
selectedIndex
;
onChanged
=
source
.
onChanged
;
scrollable
=
source
.
s
crollable
;
if
(!
s
crollable
)
isScrollable
=
source
.
isS
crollable
;
if
(!
isS
crollable
)
scrollTo
(
0.0
);
scrollBehavior
.
isScrollable
=
source
.
isScrollable
;
}
ScrollBehavior
createScrollBehavior
()
=>
new
Fling
Behavior
();
Fling
Behavior
get
scrollBehavior
=>
super
.
scrollBehavior
;
ScrollBehavior
createScrollBehavior
()
=>
new
_TabsScroll
Behavior
();
_TabsScroll
Behavior
get
scrollBehavior
=>
super
.
scrollBehavior
;
void
_handleTap
(
int
tabIndex
)
{
if
(
tabIndex
!=
selectedIndex
&&
onChanged
!=
null
)
...
...
@@ -445,8 +468,8 @@ class TabBar extends Scrollable {
backgroundColor:
backgroundColor
,
indicatorColor:
indicatorColor
,
textAndIcons:
textAndIcons
,
scrollable:
s
crollable
,
onLayoutChanged:
s
crollable
?
_layoutChanged
:
null
isScrollable:
isS
crollable
,
onLayoutChanged:
isS
crollable
?
_layoutChanged
:
null
)
)
)
...
...
@@ -474,13 +497,13 @@ class TabNavigator extends Component {
this
.
views
,
this
.
selectedIndex
:
0
,
this
.
onChanged
,
this
.
s
crollable
:
false
this
.
isS
crollable
:
false
})
:
super
(
key:
key
);
final
List
<
TabNavigatorView
>
views
;
final
int
selectedIndex
;
final
SelectedIndexChanged
onChanged
;
final
bool
s
crollable
;
final
bool
isS
crollable
;
void
_handleSelectedIndexChanged
(
int
tabIndex
)
{
if
(
onChanged
!=
null
)
...
...
@@ -495,7 +518,7 @@ class TabNavigator extends Component {
labels:
views
.
map
((
view
)
=>
view
.
label
),
onChanged:
_handleSelectedIndexChanged
,
selectedIndex:
selectedIndex
,
scrollable:
s
crollable
isScrollable:
isS
crollable
);
Widget
content
=
views
[
selectedIndex
].
buildContent
();
...
...
packages/flutter/pubspec.yaml
View file @
65caad47
...
...
@@ -9,7 +9,7 @@ dependencies:
mojo_services
:
^0.0.15
mojo
:
^0.0.17
mojom
:
^0.0.17
newton
:
^0.1.
0
newton
:
^0.1.
2
sky_engine
:
^0.0.1
sky_services
:
^0.0.1
sky_tools
:
^0.0.4
...
...
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