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
6c3b20be
Commit
6c3b20be
authored
Sep 25, 2015
by
Adam Barth
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1354 from abarth/fn3_ensure_widgets_is_visible
Add ensureWidgetIsVisible to fn3
parents
55dc7108
3387bbaa
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
64 additions
and
2 deletions
+64
-2
framework.dart
packages/flutter/lib/src/fn3/framework.dart
+8
-0
scrollable.dart
packages/flutter/lib/src/fn3/scrollable.dart
+56
-2
No files found.
packages/flutter/lib/src/fn3/framework.dart
View file @
6c3b20be
...
...
@@ -396,6 +396,8 @@ typedef void ElementVisitor(Element element);
abstract
class
BuildContext
{
InheritedWidget
inheritedWidgetOfType
(
Type
targetType
);
RenderObject
findRenderObject
();
void
visitAncestorElements
(
bool
visitor
(
Element
element
));
}
/// Elements are the instantiations of Widget configurations.
...
...
@@ -607,6 +609,12 @@ abstract class Element<T extends Widget> implements BuildContext {
RenderObject
findRenderObject
()
=>
renderObject
;
void
visitAncestorElements
(
bool
visitor
(
Element
element
))
{
Element
ancestor
=
_parent
;
while
(
ancestor
!=
null
&&
visitor
(
ancestor
))
ancestor
=
ancestor
.
_parent
;
}
void
dependenciesChanged
()
{
assert
(
false
);
}
...
...
packages/flutter/lib/src/fn3/scrollable.dart
View file @
6c3b20be
...
...
@@ -207,8 +207,62 @@ abstract class ScrollableState<T extends Scrollable> extends State<T> {
}
}
// TODO(abarth): findScrollableAncestor
// TODO(abarth): ensureWidgetIsVisible
ScrollableState
findScrollableAncestor
(
BuildContext
context
)
{
ScrollableState
result
;
context
.
visitAncestorElements
((
Element
element
)
{
if
(
element
is
StatefulComponentElement
)
{
if
(
element
.
state
is
ScrollableState
)
{
result
=
element
.
state
;
return
false
;
}
}
return
true
;
});
return
result
;
}
Future
ensureWidgetIsVisible
(
BuildContext
context
,
{
Duration
duration
,
Curve
curve
})
{
assert
(
context
.
findRenderObject
()
is
RenderBox
);
// TODO(abarth): This function doesn't handle nested scrollable widgets.
ScrollableState
scrollable
=
findScrollableAncestor
(
context
);
if
(
scrollable
==
null
)
return
new
Future
.
value
();
RenderBox
targetBox
=
context
.
findRenderObject
();
assert
(
targetBox
.
attached
);
Size
targetSize
=
targetBox
.
size
;
RenderBox
scrollableBox
=
scrollable
.
context
.
findRenderObject
();
assert
(
scrollableBox
.
attached
);
Size
scrollableSize
=
scrollableBox
.
size
;
double
scrollOffsetDelta
;
switch
(
scrollable
.
config
.
scrollDirection
)
{
case
ScrollDirection
.
vertical
:
Point
targetCenter
=
targetBox
.
localToGlobal
(
new
Point
(
0.0
,
targetSize
.
height
/
2.0
));
Point
scrollableCenter
=
scrollableBox
.
localToGlobal
(
new
Point
(
0.0
,
scrollableSize
.
height
/
2.0
));
scrollOffsetDelta
=
targetCenter
.
y
-
scrollableCenter
.
y
;
break
;
case
ScrollDirection
.
horizontal
:
Point
targetCenter
=
targetBox
.
localToGlobal
(
new
Point
(
targetSize
.
width
/
2.0
,
0.0
));
Point
scrollableCenter
=
scrollableBox
.
localToGlobal
(
new
Point
(
scrollableSize
.
width
/
2.0
,
0.0
));
scrollOffsetDelta
=
targetCenter
.
x
-
scrollableCenter
.
x
;
break
;
case
ScrollDirection
.
both
:
assert
(
false
);
// See https://github.com/flutter/engine/issues/888
break
;
}
ExtentScrollBehavior
scrollBehavior
=
scrollable
.
scrollBehavior
;
double
scrollOffset
=
(
scrollable
.
scrollOffset
+
scrollOffsetDelta
)
.
clamp
(
scrollBehavior
.
minScrollOffset
,
scrollBehavior
.
maxScrollOffset
);
if
(
scrollOffset
!=
scrollable
.
scrollOffset
)
return
scrollable
.
scrollTo
(
scrollOffset
,
duration:
duration
,
curve:
curve
);
return
new
Future
.
value
();
}
/// A simple scrollable widget that has a single child. Use this component if
/// you are not worried about offscreen widgets consuming resources.
...
...
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