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
7beedd7a
Commit
7beedd7a
authored
Jul 22, 2016
by
Hans Muller
Committed by
GitHub
Jul 22, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Report ScrollNotification depth (#4992)
parent
6cc6c95b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
119 additions
and
10 deletions
+119
-10
overscroll_indicator.dart
packages/flutter/lib/src/material/overscroll_indicator.dart
+2
-0
notification_listener.dart
packages/flutter/lib/src/widgets/notification_listener.dart
+13
-9
scrollable.dart
packages/flutter/lib/src/widgets/scrollable.dart
+18
-1
scroll_notification_test.dart
packages/flutter/test/widget/scroll_notification_test.dart
+86
-0
No files found.
packages/flutter/lib/src/material/overscroll_indicator.dart
View file @
7beedd7a
...
...
@@ -188,6 +188,8 @@ class _OverscrollIndicatorState extends State<OverscrollIndicator> {
}
bool
_handleScrollNotification
(
ScrollNotification
notification
)
{
if
(
notification
.
depth
!=
0
)
return
false
;
if
(
config
.
scrollableKey
==
null
||
config
.
scrollableKey
==
notification
.
scrollable
.
config
.
key
)
{
final
ScrollableState
scrollable
=
notification
.
scrollable
;
switch
(
notification
.
kind
)
{
...
...
packages/flutter/lib/src/widgets/notification_listener.dart
View file @
7beedd7a
...
...
@@ -9,18 +9,22 @@ typedef bool NotificationListenerCallback<T extends Notification>(T notification
/// A notification that can bubble up the widget tree.
abstract
class
Notification
{
/// Applied to each ancestor of the [dispatch] target. Dispatches this
/// Notification to ancestor [NotificationListener] widgets.
bool
visitAncestor
(
Element
element
)
{
if
(
element
is
StatelessElement
&&
element
.
widget
is
NotificationListener
<
Notification
>)
{
final
NotificationListener
<
Notification
>
widget
=
element
.
widget
;
if
(
widget
.
_dispatch
(
this
))
// that function checks the type dynamically
return
false
;
}
return
true
;
}
/// Start bubbling this notification at the given build context.
void
dispatch
(
BuildContext
target
)
{
assert
(
target
!=
null
);
// Only call dispatch if the widget's State is still mounted.
target
.
visitAncestorElements
((
Element
element
)
{
if
(
element
is
StatelessElement
&&
element
.
widget
is
NotificationListener
<
Notification
>)
{
final
NotificationListener
<
Notification
>
widget
=
element
.
widget
;
if
(
widget
.
_dispatch
(
this
))
// that function checks the type dynamically
return
false
;
}
return
true
;
});
target
.
visitAncestorElements
(
visitAncestor
);
}
}
...
...
packages/flutter/lib/src/widgets/scrollable.dart
View file @
7beedd7a
...
...
@@ -710,7 +710,11 @@ enum ScrollNotificationKind {
ended
}
/// Indicates that a descendant scrollable has scrolled.
/// Indicates that a scrollable descendant is scrolling.
///
/// See also:
///
/// * [NotificationListener]
class
ScrollNotification
extends
Notification
{
/// Creates a notification about scrolling.
ScrollNotification
(
this
.
scrollable
,
this
.
kind
);
...
...
@@ -720,6 +724,19 @@ class ScrollNotification extends Notification {
/// The scrollable that scrolled.
final
ScrollableState
scrollable
;
/// The number of scrollable widgets that have already received this
/// notification. Typically listeners only respond to notifications
/// with depth = 0.
int
get
depth
=>
_depth
;
int
_depth
=
0
;
@override
bool
visitAncestor
(
Element
element
)
{
if
(
element
is
StatefulElement
&&
element
.
state
is
ScrollableState
)
_depth
+=
1
;
return
super
.
visitAncestor
(
element
);
}
}
/// A simple scrolling widget that has a single child.
...
...
packages/flutter/test/widget/scroll_notification_test.dart
0 → 100644
View file @
7beedd7a
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'package:flutter_test/flutter_test.dart'
;
import
'package:flutter/widgets.dart'
;
void
main
(
)
{
testWidgets
(
'Scroll notifcation basics'
,
(
WidgetTester
tester
)
async
{
ScrollNotification
notification
;
await
tester
.
pumpWidget
(
new
NotificationListener
<
ScrollNotification
>(
onNotification:
(
ScrollNotification
value
)
{
notification
=
value
;
return
false
;
},
child:
new
ScrollableViewport
(
child:
new
SizedBox
(
height:
1200.0
)
)
));
TestGesture
gesture
=
await
tester
.
startGesture
(
new
Point
(
100.0
,
100.0
));
await
tester
.
pump
(
const
Duration
(
seconds:
1
));
expect
(
notification
.
kind
,
equals
(
ScrollNotificationKind
.
started
));
expect
(
notification
.
depth
,
equals
(
0
));
await
gesture
.
moveBy
(
new
Offset
(-
10.0
,
-
10.0
));
await
tester
.
pump
(
const
Duration
(
seconds:
1
));
expect
(
notification
.
kind
,
equals
(
ScrollNotificationKind
.
updated
));
expect
(
notification
.
depth
,
equals
(
0
));
await
gesture
.
up
();
await
tester
.
pump
(
const
Duration
(
seconds:
1
));
expect
(
notification
.
kind
,
equals
(
ScrollNotificationKind
.
ended
));
expect
(
notification
.
depth
,
equals
(
0
));
});
testWidgets
(
'Scroll notifcation depth'
,
(
WidgetTester
tester
)
async
{
final
List
<
ScrollNotificationKind
>
depth0Kinds
=
<
ScrollNotificationKind
>[];
final
List
<
ScrollNotificationKind
>
depth1Kinds
=
<
ScrollNotificationKind
>[];
final
List
<
int
>
depth0Values
=
<
int
>[];
final
List
<
int
>
depth1Values
=
<
int
>[];
await
tester
.
pumpWidget
(
new
NotificationListener
<
ScrollNotification
>(
onNotification:
(
ScrollNotification
value
)
{
depth1Kinds
.
add
(
value
.
kind
);
depth1Values
.
add
(
value
.
depth
);
return
false
;
},
child:
new
ScrollableViewport
(
child:
new
SizedBox
(
height:
1200.0
,
child:
new
NotificationListener
<
ScrollNotification
>(
onNotification:
(
ScrollNotification
value
)
{
depth0Kinds
.
add
(
value
.
kind
);
depth0Values
.
add
(
value
.
depth
);
return
false
;
},
child:
new
Container
(
padding:
const
EdgeInsets
.
all
(
50.0
),
child:
new
ScrollableViewport
(
child:
new
SizedBox
(
height:
1200.0
))
)
)
)
)
));
TestGesture
gesture
=
await
tester
.
startGesture
(
new
Point
(
100.0
,
100.0
));
await
tester
.
pump
(
const
Duration
(
seconds:
1
));
await
gesture
.
moveBy
(
new
Offset
(-
10.0
,
-
10.0
));
await
tester
.
pump
(
const
Duration
(
seconds:
1
));
await
gesture
.
up
();
await
tester
.
pump
(
const
Duration
(
seconds:
1
));
final
List
<
ScrollNotificationKind
>
kinds
=
<
ScrollNotificationKind
>[
ScrollNotificationKind
.
started
,
ScrollNotificationKind
.
updated
,
ScrollNotificationKind
.
ended
];
expect
(
depth0Kinds
,
equals
(
kinds
));
expect
(
depth1Kinds
,
equals
(
kinds
));
expect
(
depth0Values
,
equals
(<
int
>[
0
,
0
,
0
]));
expect
(
depth1Values
,
equals
(<
int
>[
1
,
1
,
1
]));
});
}
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