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
699fa241
Commit
699fa241
authored
Sep 16, 2015
by
Adam Barth
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1194 from abarth/drawer_gestures
Move Drawer to GestureDetector
parents
cd6c4da3
74f7d9ef
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
35 additions
and
57 deletions
+35
-57
drag.dart
packages/flutter/lib/gestures/drag.dart
+6
-8
dismissable.dart
packages/flutter/lib/src/widgets/dismissable.dart
+6
-6
drawer.dart
packages/flutter/lib/src/widgets/drawer.dart
+12
-38
scrollable.dart
packages/flutter/lib/src/widgets/scrollable.dart
+7
-1
scroll_test.dart
packages/unit/test/gestures/scroll_test.dart
+2
-2
gesture_detector_test.dart
packages/unit/test/widget/gesture_detector_test.dart
+2
-2
No files found.
packages/flutter/lib/gestures/drag.dart
View file @
699fa241
...
...
@@ -15,14 +15,14 @@ enum DragState {
}
typedef
void
GestureDragStartCallback
(
);
typedef
void
GestureDragUpdateCallback
(
double
scrollD
elta
);
typedef
void
GestureDragUpdateCallback
(
double
d
elta
);
typedef
void
GestureDragEndCallback
(
sky
.
Offset
velocity
);
typedef
void
GesturePanStartCallback
(
);
typedef
void
GesturePanUpdateCallback
(
sky
.
Offset
scrollD
elta
);
typedef
void
GesturePanUpdateCallback
(
sky
.
Offset
d
elta
);
typedef
void
GesturePanEndCallback
(
sky
.
Offset
velocity
);
typedef
void
_GesturePolymorphicUpdateCallback
<
T
>(
T
scrollD
elta
);
typedef
void
_GesturePolymorphicUpdateCallback
<
T
>(
T
d
elta
);
int
_eventTime
(
sky
.
PointerEvent
event
)
=>
(
event
.
timeStamp
*
1000.0
).
toInt
();
// microseconds
...
...
@@ -121,8 +121,7 @@ class VerticalDragGestureRecognizer extends _DragGestureRecognizer<double> {
})
:
super
(
router:
router
,
onStart:
onStart
,
onUpdate:
onUpdate
,
onEnd:
onEnd
);
double
get
_initialPendingDragDelta
=>
0.0
;
// Notice that we negate dy because scroll offsets go in the opposite direction.
double
_getDragDelta
(
sky
.
PointerEvent
event
)
=>
-
event
.
dy
;
double
_getDragDelta
(
sky
.
PointerEvent
event
)
=>
event
.
dy
;
bool
get
_hasSufficientPendingDragDeltaToAccept
=>
_pendingDragDelta
.
abs
()
>
kTouchSlop
;
}
...
...
@@ -135,7 +134,7 @@ class HorizontalDragGestureRecognizer extends _DragGestureRecognizer<double> {
})
:
super
(
router:
router
,
onStart:
onStart
,
onUpdate:
onUpdate
,
onEnd:
onEnd
);
double
get
_initialPendingDragDelta
=>
0.0
;
double
_getDragDelta
(
sky
.
PointerEvent
event
)
=>
-
event
.
dx
;
double
_getDragDelta
(
sky
.
PointerEvent
event
)
=>
event
.
dx
;
bool
get
_hasSufficientPendingDragDeltaToAccept
=>
_pendingDragDelta
.
abs
()
>
kTouchSlop
;
}
...
...
@@ -148,8 +147,7 @@ class PanGestureRecognizer extends _DragGestureRecognizer<sky.Offset> {
})
:
super
(
router:
router
,
onStart:
onStart
,
onUpdate:
onUpdate
,
onEnd:
onEnd
);
sky
.
Offset
get
_initialPendingDragDelta
=>
sky
.
Offset
.
zero
;
// Notice that we negate dy because scroll offsets go in the opposite direction.
sky
.
Offset
_getDragDelta
(
sky
.
PointerEvent
event
)
=>
new
sky
.
Offset
(
event
.
dx
,
-
event
.
dy
);
sky
.
Offset
_getDragDelta
(
sky
.
PointerEvent
event
)
=>
new
sky
.
Offset
(
event
.
dx
,
event
.
dy
);
bool
get
_hasSufficientPendingDragDeltaToAccept
{
return
_pendingDragDelta
.
dx
.
abs
()
>
kTouchSlop
||
_pendingDragDelta
.
dy
.
abs
()
>
kTouchSlop
;
}
...
...
packages/flutter/lib/src/widgets/dismissable.dart
View file @
699fa241
...
...
@@ -119,7 +119,7 @@ class Dismissable extends StatefulComponent {
});
}
void
_handleDragUpdate
(
double
scrollOffset
)
{
void
_handleDragUpdate
(
double
delta
)
{
if
(!
_isActive
||
_fadePerformance
.
isAnimating
)
return
;
...
...
@@ -127,19 +127,19 @@ class Dismissable extends StatefulComponent {
switch
(
direction
)
{
case
DismissDirection
.
horizontal
:
case
DismissDirection
.
vertical
:
_dragExtent
-=
scrollOffset
;
_dragExtent
+=
delta
;
break
;
case
DismissDirection
.
up
:
case
DismissDirection
.
left
:
if
(
_dragExtent
-
scrollOffset
<
0
)
_dragExtent
-=
scrollOffset
;
if
(
_dragExtent
+
delta
<
0
)
_dragExtent
+=
delta
;
break
;
case
DismissDirection
.
down
:
case
DismissDirection
.
right
:
if
(
_dragExtent
-
scrollOffset
>
0
)
_dragExtent
-=
scrollOffset
;
if
(
_dragExtent
+
delta
>
0
)
_dragExtent
+=
delta
;
break
;
}
...
...
packages/flutter/lib/src/widgets/drawer.dart
View file @
699fa241
...
...
@@ -109,13 +109,11 @@ class Drawer extends StatefulComponent {
)
);
return
new
Listener
(
child:
new
Stack
([
mask
,
content
]),
onPointerDown:
handlePointerDown
,
onPointerMove:
handlePointerMove
,
onPointerUp:
handlePointerUp
,
onPointerCancel:
handlePointerCancel
,
onGestureFlingStart:
handleFlingStart
return
new
GestureDetector
(
onHorizontalDragStart:
_performance
.
stop
,
onHorizontalDragUpdate:
_handleDragUpdate
,
onHorizontalDragEnd:
_handleDragEnd
,
child:
new
Stack
([
mask
,
content
])
);
}
...
...
@@ -132,41 +130,17 @@ class Drawer extends StatefulComponent {
void
_settle
()
{
_isMostlyClosed
?
_performance
.
reverse
()
:
_performance
.
play
();
}
// TODO(mpcomplete): Figure out how to generalize these handlers on a
// "PannableThingy" interface.
EventDisposition
handlePointerDown
(
_
)
{
_performance
.
stop
();
return
EventDisposition
.
processed
;
}
EventDisposition
handlePointerMove
(
sky
.
PointerEvent
event
)
{
if
(
_performance
.
isAnimating
)
return
EventDisposition
.
ignored
;
_performance
.
progress
+=
event
.
dx
/
_kWidth
;
return
EventDisposition
.
processed
;
void
_handleDragUpdate
(
double
delta
)
{
_performance
.
progress
+=
delta
/
_kWidth
;
}
EventDisposition
handlePointerUp
(
_
)
{
if
(!
_performance
.
isAnimating
)
{
void
_handleDragEnd
(
Offset
velocity
)
{
if
(
velocity
.
dx
.
abs
()
>=
_kMinFlingVelocity
)
{
_performance
.
fling
(
velocity:
velocity
.
dx
*
_kFlingVelocityScale
);
return
;
}
else
{
_settle
();
return
EventDisposition
.
processed
;
}
return
EventDisposition
.
ignored
;
}
EventDisposition
handlePointerCancel
(
_
)
{
if
(!
_performance
.
isAnimating
)
{
_settle
();
return
EventDisposition
.
processed
;
}
return
EventDisposition
.
ignored
;
}
EventDisposition
handleFlingStart
(
event
)
{
if
(
event
.
velocityX
.
abs
()
>=
_kMinFlingVelocity
)
{
_performance
.
fling
(
velocity:
event
.
velocityX
*
_kFlingVelocityScale
);
return
EventDisposition
.
processed
;
}
return
EventDisposition
.
ignored
;
}
}
packages/flutter/lib/src/widgets/scrollable.dart
View file @
699fa241
...
...
@@ -83,7 +83,7 @@ abstract class Scrollable extends StatefulComponent {
GestureDragUpdateCallback
_getDragUpdateHandler
(
ScrollDirection
direction
)
{
if
(
scrollDirection
!=
direction
||
!
scrollBehavior
.
isScrollable
)
return
null
;
return
scrollBy
;
return
_handleDragUpdate
;
}
GestureDragEndCallback
_getDragEndHandler
(
ScrollDirection
direction
)
{
...
...
@@ -181,6 +181,12 @@ abstract class Scrollable extends StatefulComponent {
return
EventDisposition
.
processed
;
}
void
_handleDragUpdate
(
double
delta
)
{
// We negate the delta here because a positive scroll offset moves the
// the content up (or to the left) rather than down (or the right).
scrollBy
(-
delta
);
}
void
_handleDragEnd
(
Offset
velocity
)
{
if
(
velocity
!=
Offset
.
zero
)
{
_startToEndAnimation
(
velocity:
_scrollVelocity
(
velocity
));
...
...
packages/unit/test/gestures/scroll_test.dart
View file @
699fa241
...
...
@@ -53,14 +53,14 @@ void main() {
router
.
route
(
pointer
.
move
(
new
Point
(
20.0
,
20.0
)));
expect
(
didStartPan
,
isTrue
);
didStartPan
=
false
;
expect
(
updatedScrollDelta
,
new
sky
.
Offset
(
10.0
,
-
10.0
));
expect
(
updatedScrollDelta
,
new
sky
.
Offset
(
10.0
,
10.0
));
updatedScrollDelta
=
null
;
expect
(
didEndPan
,
isFalse
);
expect
(
didTap
,
isFalse
);
router
.
route
(
pointer
.
move
(
new
Point
(
20.0
,
25.0
)));
expect
(
didStartPan
,
isFalse
);
expect
(
updatedScrollDelta
,
new
sky
.
Offset
(
0.0
,
-
5.0
));
expect
(
updatedScrollDelta
,
new
sky
.
Offset
(
0.0
,
5.0
));
updatedScrollDelta
=
null
;
expect
(
didEndPan
,
isFalse
);
expect
(
didTap
,
isFalse
);
...
...
packages/unit/test/widget/gesture_detector_test.dart
View file @
699fa241
...
...
@@ -43,7 +43,7 @@ void main() {
Point
secondLocation
=
new
Point
(
10.0
,
9.0
);
tester
.
dispatchEvent
(
pointer
.
move
(
secondLocation
),
firstLocation
);
expect
(
didStartDrag
,
isFalse
);
expect
(
updatedDragDelta
,
1.0
);
expect
(
updatedDragDelta
,
-
1.0
);
updatedDragDelta
=
null
;
expect
(
didEndDrag
,
isFalse
);
...
...
@@ -86,6 +86,6 @@ void main() {
tester
.
dispatchEvent
(
pointer
.
up
(),
downLocation
);
expect
(
gestureCount
,
2
);
expect
(
dragDistance
,
-
20.0
);
expect
(
dragDistance
,
20.0
);
});
}
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