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
1faf6a9a
Commit
1faf6a9a
authored
Oct 17, 2019
by
Jaumard
Committed by
Kate Lovett
Oct 17, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
create gesture recognizers on attach and dispose on detach to avoid leaks (#42076)
parent
b194f935
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
81 additions
and
8 deletions
+81
-8
editable.dart
packages/flutter/lib/src/rendering/editable.dart
+6
-5
editable_gesture_test.dart
packages/flutter/test/rendering/editable_gesture_test.dart
+72
-0
editable_test.dart
packages/flutter/test/rendering/editable_test.dart
+3
-3
No files found.
packages/flutter/lib/src/rendering/editable.dart
View file @
1faf6a9a
...
...
@@ -229,11 +229,6 @@ class RenderEditable extends RenderBox with RelayoutWhenSystemFontsChangeMixin {
assert
(
_showCursor
!=
null
);
assert
(!
_showCursor
.
value
||
cursorColor
!=
null
);
this
.
hasFocus
=
hasFocus
??
false
;
_tap
=
TapGestureRecognizer
(
debugOwner:
this
)
..
onTapDown
=
_handleTapDown
..
onTap
=
_handleTap
;
_longPress
=
LongPressGestureRecognizer
(
debugOwner:
this
)
..
onLongPress
=
_handleLongPress
;
}
/// Character used to obscure text if [obscureText] is true.
...
...
@@ -1173,12 +1168,18 @@ class RenderEditable extends RenderBox with RelayoutWhenSystemFontsChangeMixin {
@override
void
attach
(
PipelineOwner
owner
)
{
super
.
attach
(
owner
);
_tap
=
TapGestureRecognizer
(
debugOwner:
this
)
..
onTapDown
=
_handleTapDown
..
onTap
=
_handleTap
;
_longPress
=
LongPressGestureRecognizer
(
debugOwner:
this
)..
onLongPress
=
_handleLongPress
;
_offset
.
addListener
(
markNeedsPaint
);
_showCursor
.
addListener
(
markNeedsPaint
);
}
@override
void
detach
()
{
_tap
.
dispose
();
_longPress
.
dispose
();
_offset
.
removeListener
(
markNeedsPaint
);
_showCursor
.
removeListener
(
markNeedsPaint
);
if
(
_listenerAttached
)
...
...
packages/flutter/test/rendering/editable_gesture_test.dart
0 → 100644
View file @
1faf6a9a
// Copyright 2017 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/gestures.dart'
;
import
'package:flutter/material.dart'
;
import
'package:flutter/rendering.dart'
;
import
'package:flutter/services.dart'
;
import
'package:flutter_test/flutter_test.dart'
;
import
'package:mockito/mockito.dart'
;
void
main
(
)
{
setUp
(()
=>
_GestureBindingSpy
());
test
(
'attach and detach correctly handle gesture'
,
()
{
final
TextSelectionDelegate
delegate
=
FakeEditableTextState
();
final
RenderEditable
editable
=
RenderEditable
(
backgroundCursorColor:
Colors
.
grey
,
selectionColor:
Colors
.
black
,
textDirection:
TextDirection
.
ltr
,
cursorColor:
Colors
.
red
,
offset:
ViewportOffset
.
zero
(),
textSelectionDelegate:
delegate
,
text:
const
TextSpan
(
text:
'test'
,
style:
TextStyle
(
height:
1.0
,
fontSize:
10.0
,
fontFamily:
'Ahem'
,
),
),
startHandleLayerLink:
LayerLink
(),
endHandleLayerLink:
LayerLink
(),
selection:
const
TextSelection
(
baseOffset:
0
,
extentOffset:
3
,
affinity:
TextAffinity
.
upstream
,
),
onSelectionChanged:
(
_
,
__
,
___
)
{
},
);
final
PipelineOwner
owner
=
PipelineOwner
(
onNeedVisualUpdate:
()
{
});
final
_PointerRouterSpy
spy
=
GestureBinding
.
instance
.
pointerRouter
;
editable
.
attach
(
owner
);
// This should register pointer into GestureBinding.instance.pointerRouter.
editable
.
handleEvent
(
const
PointerDownEvent
(),
BoxHitTestEntry
(
editable
,
const
Offset
(
10
,
10
)));
expect
(
spy
.
routeCount
,
greaterThan
(
0
));
editable
.
detach
();
expect
(
spy
.
routeCount
,
0
);
});
}
class
_GestureBindingSpy
extends
AutomatedTestWidgetsFlutterBinding
{
final
PointerRouter
_testPointerRouter
=
_PointerRouterSpy
();
@override
PointerRouter
get
pointerRouter
=>
_testPointerRouter
;
}
class
FakeEditableTextState
extends
TextSelectionDelegate
with
Mock
{
}
class
_PointerRouterSpy
extends
PointerRouter
{
int
routeCount
=
0
;
@override
void
addRoute
(
int
pointer
,
PointerRoute
route
,
[
Matrix4
transform
])
{
super
.
addRoute
(
pointer
,
route
,
transform
);
routeCount
++;
}
@override
void
removeRoute
(
int
pointer
,
PointerRoute
route
)
{
super
.
removeRoute
(
pointer
,
route
);
routeCount
--;
}
}
packages/flutter/test/rendering/editable_test.dart
View file @
1faf6a9a
...
...
@@ -2,11 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'package:flutter/foundation.dart'
;
import
'package:flutter/material.dart'
;
import
'package:flutter/rendering.dart'
;
import
'package:flutter_test/flutter_test.dart'
;
import
'package:flutter/services.dart'
;
import
'package:flutter/material.dart'
;
import
'package:flutter/foundation.dart'
;
import
'package:flutter_test/flutter_test.dart'
;
import
'../rendering/mock_canvas.dart'
;
import
'../rendering/recording_canvas.dart'
;
...
...
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