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
e8a0ea35
Commit
e8a0ea35
authored
Oct 15, 2015
by
Kris Giesing
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add release semantics, add test
parent
14c9a2c7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
189 additions
and
2 deletions
+189
-2
arena.dart
packages/flutter/lib/src/gestures/arena.dart
+17
-2
arena_test.dart
packages/unit/test/gestures/arena_test.dart
+172
-0
No files found.
packages/flutter/lib/src/gestures/arena.dart
View file @
e8a0ea35
...
...
@@ -46,6 +46,7 @@ class _GestureArenaState {
final
List
<
GestureArenaMember
>
members
=
new
List
<
GestureArenaMember
>();
bool
isOpen
=
true
;
bool
isHeld
=
false
;
bool
hasPendingSweep
=
false
;
void
add
(
GestureArenaMember
member
)
{
assert
(
isOpen
);
...
...
@@ -79,8 +80,11 @@ class GestureArena {
if
(
state
==
null
)
return
;
// This arena either never existed or has been resolved.
assert
(!
state
.
isOpen
);
if
(
state
.
isHeld
)
if
(
state
.
isHeld
)
{
state
.
hasPendingSweep
=
true
;
return
;
// This arena is being held for a long-lived member
}
_arenas
.
remove
(
key
);
if
(!
state
.
members
.
isEmpty
)
{
// First member wins
state
.
members
.
first
.
acceptGesture
(
key
);
...
...
@@ -88,7 +92,6 @@ class GestureArena {
for
(
int
i
=
1
;
i
<
state
.
members
.
length
;
i
++)
state
.
members
[
i
].
rejectGesture
(
key
);
}
_arenas
.
remove
(
key
);
}
/// Prevent the arena from being swept
...
...
@@ -99,6 +102,18 @@ class GestureArena {
state
.
isHeld
=
true
;
}
/// Release a hold, allowing the arena to be swept
/// If a sweep was attempted on a held arena, the sweep will be done
/// on release
void
release
(
Object
key
)
{
_GestureArenaState
state
=
_arenas
[
key
];
if
(
state
==
null
)
return
;
// This arena either never existed or has been resolved.
state
.
isHeld
=
false
;
if
(
state
.
hasPendingSweep
)
sweep
(
key
);
}
void
_tryToResolveArena
(
Object
key
,
_GestureArenaState
state
)
{
assert
(
_arenas
[
key
]
==
state
);
assert
(!
state
.
isOpen
);
...
...
packages/unit/test/gestures/arena_test.dart
View file @
e8a0ea35
...
...
@@ -66,4 +66,176 @@ void main() {
expect
(
secondAcceptRan
,
isFalse
);
expect
(
secondRejectRan
,
isTrue
);
});
test
(
'Should win by sweep'
,
()
{
GestureArena
arena
=
new
GestureArena
();
int
primaryKey
=
4
;
bool
firstAcceptRan
=
false
;
bool
firstRejectRan
=
false
;
bool
secondAcceptRan
=
false
;
bool
secondRejectRan
=
false
;
TestGestureArenaMember
first
=
new
TestGestureArenaMember
(
onAcceptGesture:
(
int
key
)
{
expect
(
key
,
equals
(
primaryKey
));
firstAcceptRan
=
true
;
},
onRejectGesture:
(
int
key
)
{
expect
(
key
,
equals
(
primaryKey
));
firstRejectRan
=
true
;
}
);
TestGestureArenaMember
second
=
new
TestGestureArenaMember
(
onAcceptGesture:
(
int
key
)
{
expect
(
key
,
equals
(
primaryKey
));
secondAcceptRan
=
true
;
},
onRejectGesture:
(
int
key
)
{
expect
(
key
,
equals
(
primaryKey
));
secondRejectRan
=
true
;
}
);
arena
.
add
(
primaryKey
,
first
);
arena
.
add
(
primaryKey
,
second
);
arena
.
close
(
primaryKey
);
expect
(
firstAcceptRan
,
isFalse
);
expect
(
firstRejectRan
,
isFalse
);
expect
(
secondAcceptRan
,
isFalse
);
expect
(
secondRejectRan
,
isFalse
);
arena
.
sweep
(
primaryKey
);
expect
(
firstAcceptRan
,
isTrue
);
expect
(
firstRejectRan
,
isFalse
);
expect
(
secondAcceptRan
,
isFalse
);
expect
(
secondRejectRan
,
isTrue
);
});
test
(
'Should win on release after hold sweep release'
,
()
{
GestureArena
arena
=
new
GestureArena
();
int
primaryKey
=
4
;
bool
firstAcceptRan
=
false
;
bool
firstRejectRan
=
false
;
bool
secondAcceptRan
=
false
;
bool
secondRejectRan
=
false
;
TestGestureArenaMember
first
=
new
TestGestureArenaMember
(
onAcceptGesture:
(
int
key
)
{
expect
(
key
,
equals
(
primaryKey
));
firstAcceptRan
=
true
;
},
onRejectGesture:
(
int
key
)
{
expect
(
key
,
equals
(
primaryKey
));
firstRejectRan
=
true
;
}
);
TestGestureArenaMember
second
=
new
TestGestureArenaMember
(
onAcceptGesture:
(
int
key
)
{
expect
(
key
,
equals
(
primaryKey
));
secondAcceptRan
=
true
;
},
onRejectGesture:
(
int
key
)
{
expect
(
key
,
equals
(
primaryKey
));
secondRejectRan
=
true
;
}
);
arena
.
add
(
primaryKey
,
first
);
arena
.
add
(
primaryKey
,
second
);
arena
.
close
(
primaryKey
);
expect
(
firstAcceptRan
,
isFalse
);
expect
(
firstRejectRan
,
isFalse
);
expect
(
secondAcceptRan
,
isFalse
);
expect
(
secondRejectRan
,
isFalse
);
arena
.
hold
(
primaryKey
);
expect
(
firstAcceptRan
,
isFalse
);
expect
(
firstRejectRan
,
isFalse
);
expect
(
secondAcceptRan
,
isFalse
);
expect
(
secondRejectRan
,
isFalse
);
arena
.
sweep
(
primaryKey
);
expect
(
firstAcceptRan
,
isFalse
);
expect
(
firstRejectRan
,
isFalse
);
expect
(
secondAcceptRan
,
isFalse
);
expect
(
secondRejectRan
,
isFalse
);
arena
.
release
(
primaryKey
);
expect
(
firstAcceptRan
,
isTrue
);
expect
(
firstRejectRan
,
isFalse
);
expect
(
secondAcceptRan
,
isFalse
);
expect
(
secondRejectRan
,
isTrue
);
});
test
(
'Should win on sweep after hold release sweep'
,
()
{
GestureArena
arena
=
new
GestureArena
();
int
primaryKey
=
4
;
bool
firstAcceptRan
=
false
;
bool
firstRejectRan
=
false
;
bool
secondAcceptRan
=
false
;
bool
secondRejectRan
=
false
;
TestGestureArenaMember
first
=
new
TestGestureArenaMember
(
onAcceptGesture:
(
int
key
)
{
expect
(
key
,
equals
(
primaryKey
));
firstAcceptRan
=
true
;
},
onRejectGesture:
(
int
key
)
{
expect
(
key
,
equals
(
primaryKey
));
firstRejectRan
=
true
;
}
);
TestGestureArenaMember
second
=
new
TestGestureArenaMember
(
onAcceptGesture:
(
int
key
)
{
expect
(
key
,
equals
(
primaryKey
));
secondAcceptRan
=
true
;
},
onRejectGesture:
(
int
key
)
{
expect
(
key
,
equals
(
primaryKey
));
secondRejectRan
=
true
;
}
);
arena
.
add
(
primaryKey
,
first
);
arena
.
add
(
primaryKey
,
second
);
arena
.
close
(
primaryKey
);
expect
(
firstAcceptRan
,
isFalse
);
expect
(
firstRejectRan
,
isFalse
);
expect
(
secondAcceptRan
,
isFalse
);
expect
(
secondRejectRan
,
isFalse
);
arena
.
hold
(
primaryKey
);
expect
(
firstAcceptRan
,
isFalse
);
expect
(
firstRejectRan
,
isFalse
);
expect
(
secondAcceptRan
,
isFalse
);
expect
(
secondRejectRan
,
isFalse
);
arena
.
release
(
primaryKey
);
expect
(
firstAcceptRan
,
isFalse
);
expect
(
firstRejectRan
,
isFalse
);
expect
(
secondAcceptRan
,
isFalse
);
expect
(
secondRejectRan
,
isFalse
);
arena
.
sweep
(
primaryKey
);
expect
(
firstAcceptRan
,
isTrue
);
expect
(
firstRejectRan
,
isFalse
);
expect
(
secondAcceptRan
,
isFalse
);
expect
(
secondRejectRan
,
isTrue
);
});
}
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