Skip to content

Commit e4fb4fe

Browse files
authored
Revert "Teach drag start behaviors to DragGestureRecognizer (flutter#23424)" (flutter#26209)
This reverts commit 08538f9.
1 parent cccddf8 commit e4fb4fe

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+95
-844
lines changed

examples/flutter_gallery/lib/demo/material/drawer_demo.dart

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// found in the LICENSE file.
44

55
import 'package:flutter/material.dart';
6-
import 'package:flutter/gestures.dart' show DragStartBehavior;
76

87
import '../../gallery/demo.dart';
98

@@ -80,7 +79,6 @@ class _DrawerDemoState extends State<DrawerDemo> with TickerProviderStateMixin {
8079
@override
8180
Widget build(BuildContext context) {
8281
return Scaffold(
83-
drawerDragStartBehavior: DragStartBehavior.down,
8482
key: _scaffoldKey,
8583
appBar: AppBar(
8684
leading: IconButton(
@@ -108,7 +106,6 @@ class _DrawerDemoState extends State<DrawerDemo> with TickerProviderStateMixin {
108106
),
109107
otherAccountsPictures: <Widget>[
110108
GestureDetector(
111-
dragStartBehavior: DragStartBehavior.down,
112109
onTap: () {
113110
_onOtherAccountsTap(context);
114111
},
@@ -123,7 +120,6 @@ class _DrawerDemoState extends State<DrawerDemo> with TickerProviderStateMixin {
123120
),
124121
),
125122
GestureDetector(
126-
dragStartBehavior: DragStartBehavior.down,
127123
onTap: () {
128124
_onOtherAccountsTap(context);
129125
},
@@ -153,7 +149,6 @@ class _DrawerDemoState extends State<DrawerDemo> with TickerProviderStateMixin {
153149
removeTop: true,
154150
child: Expanded(
155151
child: ListView(
156-
dragStartBehavior: DragStartBehavior.down,
157152
padding: const EdgeInsets.only(top: 8.0),
158153
children: <Widget>[
159154
Stack(

examples/flutter_gallery/lib/demo/material/text_form_field_demo.dart

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import 'dart:async';
66

77
import 'package:flutter/material.dart';
88
import 'package:flutter/services.dart';
9-
import 'package:flutter/gestures.dart' show DragStartBehavior;
109

1110
import '../../gallery/demo.dart';
1211

@@ -68,7 +67,6 @@ class _PasswordFieldState extends State<PasswordField> {
6867
labelText: widget.labelText,
6968
helperText: widget.helperText,
7069
suffixIcon: GestureDetector(
71-
dragStartBehavior: DragStartBehavior.down,
7270
onTap: () {
7371
setState(() {
7472
_obscureText = !_obscureText;
@@ -169,7 +167,6 @@ class TextFormFieldDemoState extends State<TextFormFieldDemo> {
169167
@override
170168
Widget build(BuildContext context) {
171169
return Scaffold(
172-
drawerDragStartBehavior: DragStartBehavior.down,
173170
key: _scaffoldKey,
174171
appBar: AppBar(
175172
title: const Text('Text fields'),
@@ -183,7 +180,6 @@ class TextFormFieldDemoState extends State<TextFormFieldDemo> {
183180
autovalidate: _autovalidate,
184181
onWillPop: _warnUserAboutInvalidData,
185182
child: SingleChildScrollView(
186-
dragStartBehavior: DragStartBehavior.down,
187183
padding: const EdgeInsets.symmetric(horizontal: 16.0),
188184
child: Column(
189185
crossAxisAlignment: CrossAxisAlignment.stretch,

examples/stocks/lib/stock_home.dart

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import 'package:flutter/material.dart';
66
import 'package:flutter/rendering.dart' show debugDumpRenderTree, debugDumpLayerTree, debugDumpSemanticsTree, DebugSemanticsDumpOrder;
77
import 'package:flutter/scheduler.dart' show timeDilation;
8-
import 'package:flutter/gestures.dart' show DragStartBehavior;
98
import 'stock_data.dart';
109
import 'stock_list.dart';
1110
import 'stock_strings.dart';
@@ -111,7 +110,6 @@ class StockHomeState extends State<StockHome> {
111110
Widget _buildDrawer(BuildContext context) {
112111
return Drawer(
113112
child: ListView(
114-
dragStartBehavior: DragStartBehavior.down,
115113
children: <Widget>[
116114
const DrawerHeader(child: Center(child: Text('Stocks'))),
117115
const ListTile(
@@ -319,13 +317,11 @@ class StockHomeState extends State<StockHome> {
319317
return DefaultTabController(
320318
length: 2,
321319
child: Scaffold(
322-
drawerDragStartBehavior: DragStartBehavior.down,
323320
key: _scaffoldKey,
324321
appBar: _isSearching ? buildSearchBar() : buildAppBar(),
325322
floatingActionButton: buildFloatingActionButton(),
326323
drawer: _buildDrawer(context),
327324
body: TabBarView(
328-
dragStartBehavior: DragStartBehavior.down,
329325
children: <Widget>[
330326
_buildStockTab(context, StockHomeTab.market, widget.stocks.allSymbols),
331327
_buildStockTab(context, StockHomeTab.portfolio, portfolioSymbols),

packages/flutter/lib/src/cupertino/switch.dart

Lines changed: 3 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,12 @@ import 'thumb_painter.dart';
5252
/// * <https://developer.apple.com/ios/human-interface-guidelines/controls/switches/>
5353
class CupertinoSwitch extends StatefulWidget {
5454
/// Creates an iOS-style switch.
55-
///
56-
/// [dragStartBehavior] must not be null.
5755
const CupertinoSwitch({
5856
Key key,
5957
@required this.value,
6058
@required this.onChanged,
6159
this.activeColor,
62-
this.dragStartBehavior = DragStartBehavior.start,
63-
}) : assert(dragStartBehavior != null),
64-
super(key: key);
60+
}) : super(key: key);
6561

6662
/// Whether this switch is on or off.
6763
final bool value;
@@ -96,26 +92,6 @@ class CupertinoSwitch extends StatefulWidget {
9692
/// [CupertinoTheme] in accordance to native iOS behavior.
9793
final Color activeColor;
9894

99-
/// {@template flutter.cupertino.switch.dragStartBehavior}
100-
/// Determines the way that drag start behavior is handled.
101-
///
102-
/// If set to [DragStartBehavior.start], the drag behavior used to move the
103-
/// switch from on to off will begin upon the detection of a drag gesture. If
104-
/// set to [DragStartBehavior.down] it will begin when a down event is first
105-
/// detected.
106-
///
107-
/// In general, setting this to [DragStartBehavior.start] will make drag
108-
/// animation smoother and setting it to [DragStartBehavior.down] will make
109-
/// drag behavior feel slightly more reactive.
110-
///
111-
/// By default, the drag start behavior is [DragStartBehavior.start].
112-
///
113-
/// See also:
114-
///
115-
/// * [DragGestureRecognizer.dragStartBehavior], which gives an example for the different behaviors.
116-
/// {@endtemplate}
117-
final DragStartBehavior dragStartBehavior;
118-
11995
@override
12096
_CupertinoSwitchState createState() => _CupertinoSwitchState();
12197

@@ -135,7 +111,6 @@ class _CupertinoSwitchState extends State<CupertinoSwitch> with TickerProviderSt
135111
activeColor: widget.activeColor ?? CupertinoColors.activeGreen,
136112
onChanged: widget.onChanged,
137113
vsync: this,
138-
dragStartBehavior: widget.dragStartBehavior,
139114
);
140115
}
141116
}
@@ -147,14 +122,12 @@ class _CupertinoSwitchRenderObjectWidget extends LeafRenderObjectWidget {
147122
this.activeColor,
148123
this.onChanged,
149124
this.vsync,
150-
this.dragStartBehavior = DragStartBehavior.start,
151125
}) : super(key: key);
152126

153127
final bool value;
154128
final Color activeColor;
155129
final ValueChanged<bool> onChanged;
156130
final TickerProvider vsync;
157-
final DragStartBehavior dragStartBehavior;
158131

159132
@override
160133
_RenderCupertinoSwitch createRenderObject(BuildContext context) {
@@ -164,7 +137,6 @@ class _CupertinoSwitchRenderObjectWidget extends LeafRenderObjectWidget {
164137
onChanged: onChanged,
165138
textDirection: Directionality.of(context),
166139
vsync: vsync,
167-
dragStartBehavior: dragStartBehavior
168140
);
169141
}
170142

@@ -175,8 +147,7 @@ class _CupertinoSwitchRenderObjectWidget extends LeafRenderObjectWidget {
175147
..activeColor = activeColor
176148
..onChanged = onChanged
177149
..textDirection = Directionality.of(context)
178-
..vsync = vsync
179-
..dragStartBehavior = dragStartBehavior;
150+
..vsync = vsync;
180151
}
181152
}
182153

@@ -200,7 +171,6 @@ class _RenderCupertinoSwitch extends RenderConstrainedBox {
200171
ValueChanged<bool> onChanged,
201172
@required TextDirection textDirection,
202173
@required TickerProvider vsync,
203-
DragStartBehavior dragStartBehavior = DragStartBehavior.start,
204174
}) : assert(value != null),
205175
assert(activeColor != null),
206176
assert(vsync != null),
@@ -218,8 +188,7 @@ class _RenderCupertinoSwitch extends RenderConstrainedBox {
218188
_drag = HorizontalDragGestureRecognizer()
219189
..onStart = _handleDragStart
220190
..onUpdate = _handleDragUpdate
221-
..onEnd = _handleDragEnd
222-
..dragStartBehavior = dragStartBehavior;
191+
..onEnd = _handleDragEnd;
223192
_positionController = AnimationController(
224193
duration: _kToggleDuration,
225194
value: value ? 1.0 : 0.0,
@@ -307,14 +276,6 @@ class _RenderCupertinoSwitch extends RenderConstrainedBox {
307276
markNeedsPaint();
308277
}
309278

310-
DragStartBehavior get dragStartBehavior => _drag.dragStartBehavior;
311-
set dragStartBehavior(DragStartBehavior value) {
312-
assert(value != null);
313-
if (_drag.dragStartBehavior == value)
314-
return;
315-
_drag.dragStartBehavior = value;
316-
}
317-
318279
bool get isInteractive => onChanged != null;
319280

320281
TapGestureRecognizer _tap;

packages/flutter/lib/src/gestures/monodrag.dart

Lines changed: 7 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
import 'package:flutter/foundation.dart';
6-
75
import 'arena.dart';
86
import 'constants.dart';
97
import 'drag_details.dart';
@@ -50,36 +48,7 @@ typedef GestureDragCancelCallback = void Function();
5048
/// * [PanGestureRecognizer], for drags that are not locked to a single axis.
5149
abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer {
5250
/// Initialize the object.
53-
///
54-
/// [dragStartBehavior] must not be null.
55-
DragGestureRecognizer({
56-
Object debugOwner,
57-
this.dragStartBehavior = DragStartBehavior.start,
58-
}) : assert(dragStartBehavior != null),
59-
super(debugOwner: debugOwner);
60-
61-
/// Configure the behavior of offsets sent to [onStart].
62-
///
63-
/// If set to [DragStartBehavior.start], the [onStart] callback will be called at the time and
64-
/// position when the gesture detector wins the arena. If [DragStartBehavior.down],
65-
/// [onStart] will be called at the time and position when a down event was
66-
/// first detected.
67-
///
68-
/// For more information about the gesture arena:
69-
/// https://flutter.io/docs/development/ui/advanced/gestures#gesture-disambiguation
70-
///
71-
/// By default, the drag start behavior is [DragStartBehavior.start].
72-
///
73-
/// ## Example:
74-
///
75-
/// A finger presses down on the screen with offset (500.0, 500.0),
76-
/// and then moves to position (510.0, 500.0) before winning the arena.
77-
/// With [dragStartBehavior] set to [DragStartBehavior.down], the [onStart]
78-
/// callback will be called at the time corresponding to the touch's position
79-
/// at (500.0, 500.0). If it is instead set to [DragStartBehavior.start],
80-
/// [onStart] will be called at the time corresponding to the touch's position
81-
/// at (510.0, 500.0).
82-
DragStartBehavior dragStartBehavior;
51+
DragGestureRecognizer({ Object debugOwner }) : super(debugOwner: debugOwner);
8352

8453
/// A pointer has contacted the screen and might begin to move.
8554
///
@@ -91,11 +60,6 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer {
9160
///
9261
/// The position of the pointer is provided in the callback's `details`
9362
/// argument, which is a [DragStartDetails] object.
94-
///
95-
/// Depending on the value of [dragStartBehavior], this function will be
96-
/// called on the initial touch down, if set to [DragStartBehavior.down] or
97-
/// when the drag gesture is first detected, if set to
98-
/// [DragStartBehavior.start].
9963
GestureDragStartCallback onStart;
10064

10165
/// A pointer that is in contact with the screen and moving has moved again.
@@ -199,16 +163,6 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer {
199163
_state = _DragState.accepted;
200164
final Offset delta = _pendingDragOffset;
201165
final Duration timestamp = _lastPendingEventTimestamp;
202-
Offset updateDelta;
203-
switch (dragStartBehavior) {
204-
case DragStartBehavior.start:
205-
_initialPosition = _initialPosition + delta;
206-
updateDelta = Offset.zero;
207-
break;
208-
case DragStartBehavior.down:
209-
updateDelta = _getDeltaForDetails(delta);
210-
break;
211-
}
212166
_pendingDragOffset = Offset.zero;
213167
_lastPendingEventTimestamp = null;
214168
if (onStart != null) {
@@ -217,12 +171,13 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer {
217171
globalPosition: _initialPosition,
218172
)));
219173
}
220-
if (updateDelta != Offset.zero && onUpdate != null) {
174+
if (delta != Offset.zero && onUpdate != null) {
175+
final Offset deltaForDetails = _getDeltaForDetails(delta);
221176
invokeCallback<void>('onUpdate', () => onUpdate(DragUpdateDetails(
222177
sourceTimeStamp: timestamp,
223-
delta: updateDelta,
224-
primaryDelta: _getPrimaryValueFromOffset(updateDelta),
225-
globalPosition: _initialPosition + updateDelta, // Only adds delta for down behaviour
178+
delta: deltaForDetails,
179+
primaryDelta: _getPrimaryValueFromOffset(delta),
180+
globalPosition: _initialPosition + deltaForDetails,
226181
)));
227182
}
228183
}
@@ -277,11 +232,6 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer {
277232
_velocityTrackers.clear();
278233
super.dispose();
279234
}
280-
@override
281-
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
282-
super.debugFillProperties(properties);
283-
properties.add(EnumProperty<DragStartBehavior>('Start Behavior', dragStartBehavior));
284-
}
285235
}
286236

287237
/// Recognizes movement in the vertical direction.
@@ -330,8 +280,7 @@ class VerticalDragGestureRecognizer extends DragGestureRecognizer {
330280
/// track each touch point independently.
331281
class HorizontalDragGestureRecognizer extends DragGestureRecognizer {
332282
/// Create a gesture recognizer for interactions in the horizontal axis.
333-
HorizontalDragGestureRecognizer({ Object debugOwner }) :
334-
super(debugOwner: debugOwner);
283+
HorizontalDragGestureRecognizer({ Object debugOwner }) : super(debugOwner: debugOwner);
335284

336285
@override
337286
bool _isFlingGesture(VelocityEstimate estimate) {

packages/flutter/lib/src/gestures/recognizer.dart

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,6 @@ export 'pointer_router.dart' show PointerRouter;
2424
/// anonymous functions that return objects of particular types.
2525
typedef RecognizerCallback<T> = T Function();
2626

27-
/// Configuration of offset passed to [DragStartDetails].
28-
///
29-
/// The settings determines when a drag formally starts when the user
30-
/// initiates a drag.
31-
///
32-
/// See also:
33-
///
34-
/// * [DragGestureRecognizer.dragStartBehavior], which gives an example for the different behaviors.
35-
enum DragStartBehavior {
36-
/// Set the initial offset, at the position where the first down even was
37-
/// detected.
38-
down,
39-
40-
/// Set the initial position at the position where the drag start event was
41-
/// detected.
42-
start,
43-
}
44-
4527
/// The base class that all gesture recognizers inherit from.
4628
///
4729
/// Provides a basic API that can be used by classes that work with

0 commit comments

Comments
 (0)