Revert "Added AxisOrientation property to Scrollbar (#75497)" (#82753)

This reverts commit 4a720313d8.
This commit is contained in:
Zachary Anderson 2021-05-17 14:54:47 -07:00 committed by GitHub
parent 4a720313d8
commit 94f9a2808c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 17 additions and 333 deletions

View file

@ -62,7 +62,6 @@ class CupertinoScrollbar extends RawScrollbar {
Radius radius = defaultRadius,
this.radiusWhileDragging = defaultRadiusWhileDragging,
ScrollNotificationPredicate? notificationPredicate,
ScrollbarOrientation? scrollbarOrientation,
}) : assert(thickness != null),
assert(thickness < double.infinity),
assert(thicknessWhileDragging != null),
@ -80,7 +79,6 @@ class CupertinoScrollbar extends RawScrollbar {
timeToFade: _kScrollbarTimeToFade,
pressDuration: const Duration(milliseconds: 100),
notificationPredicate: notificationPredicate ?? defaultScrollNotificationPredicate,
scrollbarOrientation: scrollbarOrientation,
);
/// Default value for [thickness] if it's not specified in [CupertinoScrollbar].
@ -150,8 +148,7 @@ class _CupertinoScrollbarState extends RawScrollbarState<CupertinoScrollbar> {
..radius = _radius
..padding = MediaQuery.of(context).padding
..minLength = _kScrollbarMinLength
..minOverscrollLength = _kScrollbarMinOverscrollLength
..scrollbarOrientation = widget.scrollbarOrientation;
..minOverscrollLength = _kScrollbarMinOverscrollLength;
}
double _pressStartAxisPosition = 0.0;

View file

@ -117,7 +117,6 @@ class Scrollbar extends StatefulWidget {
this.radius,
this.notificationPredicate,
this.interactive,
this.scrollbarOrientation,
}) : super(key: key);
/// {@macro flutter.widgets.Scrollbar.child}
@ -166,9 +165,6 @@ class Scrollbar extends StatefulWidget {
/// {@macro flutter.widgets.Scrollbar.notificationPredicate}
final ScrollNotificationPredicate? notificationPredicate;
/// {@macro flutter.widgets.Scrollbar.scrollbarOrientation}
final ScrollbarOrientation? scrollbarOrientation;
@override
State<Scrollbar> createState() => _ScrollbarState();
}
@ -187,7 +183,6 @@ class _ScrollbarState extends State<Scrollbar> {
radiusWhileDragging: widget.radius ?? CupertinoScrollbar.defaultRadiusWhileDragging,
controller: widget.controller,
notificationPredicate: widget.notificationPredicate,
scrollbarOrientation: widget.scrollbarOrientation,
child: widget.child,
);
}
@ -200,7 +195,6 @@ class _ScrollbarState extends State<Scrollbar> {
radius: widget.radius,
notificationPredicate: widget.notificationPredicate,
interactive: widget.interactive,
scrollbarOrientation: widget.scrollbarOrientation,
child: widget.child,
);
}
@ -218,7 +212,6 @@ class _MaterialScrollbar extends RawScrollbar {
Radius? radius,
ScrollNotificationPredicate? notificationPredicate,
bool? interactive,
ScrollbarOrientation? scrollbarOrientation,
}) : super(
key: key,
child: child,
@ -231,7 +224,6 @@ class _MaterialScrollbar extends RawScrollbar {
pressDuration: Duration.zero,
notificationPredicate: notificationPredicate ?? defaultScrollNotificationPredicate,
interactive: interactive,
scrollbarOrientation: scrollbarOrientation,
);
final bool? showTrackOnHover;
@ -388,8 +380,7 @@ class _MaterialScrollbarState extends RawScrollbarState<_MaterialScrollbar> {
..crossAxisMargin = _scrollbarTheme.crossAxisMargin ?? (_useAndroidScrollbar ? 0.0 : _kScrollbarMargin)
..mainAxisMargin = _scrollbarTheme.mainAxisMargin ?? 0.0
..minLength = _scrollbarTheme.minThumbLength ?? _kScrollbarMinLength
..padding = MediaQuery.of(context).padding
..scrollbarOrientation = widget.scrollbarOrientation;
..padding = MediaQuery.of(context).padding;
}
@override

View file

@ -29,21 +29,6 @@ const double _kScrollbarThickness = 6.0;
const Duration _kScrollbarFadeDuration = Duration(milliseconds: 300);
const Duration _kScrollbarTimeToFade = Duration(milliseconds: 600);
/// An orientation along either the horizontal or vertical [Axis].
enum ScrollbarOrientation {
/// Place towards the left of the screen.
left,
/// Place towards the right of the screen.
right,
/// Place on top of the screen.
top,
/// Place on the bottom of the screen.
bottom,
}
/// Paints a scrollbar's track and thumb.
///
/// The size of the scrollbar along its scroll direction is typically
@ -87,7 +72,6 @@ class ScrollbarPainter extends ChangeNotifier implements CustomPainter {
Radius? radius,
double minLength = _kMinThumbExtent,
double? minOverscrollLength,
ScrollbarOrientation? scrollbarOrientation,
}) : assert(color != null),
assert(thickness != null),
assert(fadeoutOpacityAnimation != null),
@ -109,7 +93,6 @@ class ScrollbarPainter extends ChangeNotifier implements CustomPainter {
_minLength = minLength,
_trackColor = trackColor,
_trackBorderColor = trackBorderColor,
_scrollbarOrientation = scrollbarOrientation,
_minOverscrollLength = minOverscrollLength ?? minLength {
fadeoutOpacityAnimation.addListener(notifyListeners);
}
@ -287,46 +270,6 @@ class ScrollbarPainter extends ChangeNotifier implements CustomPainter {
notifyListeners();
}
/// {@template flutter.widgets.Scrollbar.scrollbarOrientation}
/// Dictates the orientation of the scrollbar.
///
/// [ScrollbarOrientation.top] places the scrollbar on top of the screen.
/// [ScrollbarOrientation.bottom] places the scrollbar on the bottom of the screen.
/// [ScrollbarOrientation.left] places the scrollbar on the left of the screen.
/// [ScrollbarOrientation.right] places the scrollbar on the right of the screen.
///
/// [ScrollbarOrientation.top] and [ScrollbarOrientation.bottom] can only be
/// used with a vertical scroll.
/// [ScrollbarOrientation.left] and [ScrollbarOrientation.right] can only be
/// used with a horizontal scroll.
///
/// For a vertical scroll the orientation defaults to
/// [ScrollbarOrientation.right] for [TextDirection.ltr] and
/// [ScrollbarOrientation.left] for [TextDirection.rtl].
/// For a horizontal scroll the orientation defaults to [ScrollbarOrientation.bottom].
/// {@endtemplate}
ScrollbarOrientation? get scrollbarOrientation => _scrollbarOrientation;
ScrollbarOrientation? _scrollbarOrientation;
set scrollbarOrientation(ScrollbarOrientation? value) {
if (scrollbarOrientation == value)
return;
_scrollbarOrientation = value;
notifyListeners();
}
void _debugAssertIsValidOrientation(ScrollbarOrientation orientation) {
assert(
(_isVertical && _isVerticalOrientation(orientation)) || (!_isVertical && !_isVerticalOrientation(orientation)),
'The given ScrollbarOrientation: $orientation is incompatible with the current AxisDirection: $_lastAxisDirection.'
);
}
/// Check whether given scrollbar orientation is vertical
bool _isVerticalOrientation(ScrollbarOrientation orientation) =>
orientation == ScrollbarOrientation.left
|| orientation == ScrollbarOrientation.right;
ScrollMetrics? _lastMetrics;
AxisDirection? _lastAxisDirection;
Rect? _thumbRect;
@ -374,48 +317,37 @@ class ScrollbarPainter extends ChangeNotifier implements CustomPainter {
'A TextDirection must be provided before a Scrollbar can be painted.',
);
final ScrollbarOrientation resolvedOrientation;
if (scrollbarOrientation == null) {
if (_isVertical)
resolvedOrientation = textDirection == TextDirection.ltr
? ScrollbarOrientation.right
: ScrollbarOrientation.left;
else
resolvedOrientation = ScrollbarOrientation.bottom;
}
else {
resolvedOrientation = scrollbarOrientation!;
}
final double x, y;
final Size thumbSize, trackSize;
final Offset trackOffset;
_debugAssertIsValidOrientation(resolvedOrientation);
switch(resolvedOrientation) {
case ScrollbarOrientation.left:
switch (direction) {
case AxisDirection.down:
thumbSize = Size(thickness, thumbExtent);
trackSize = Size(thickness + 2 * crossAxisMargin, _trackExtent);
x = crossAxisMargin + padding.left;
x = textDirection == TextDirection.rtl
? crossAxisMargin + padding.left
: size.width - thickness - crossAxisMargin - padding.right;
y = _thumbOffset;
trackOffset = Offset(x - crossAxisMargin, 0.0);
break;
case ScrollbarOrientation.right:
case AxisDirection.up:
thumbSize = Size(thickness, thumbExtent);
trackSize = Size(thickness + 2 * crossAxisMargin, _trackExtent);
x = size.width - thickness - crossAxisMargin - padding.right;
x = textDirection == TextDirection.rtl
? crossAxisMargin + padding.left
: size.width - thickness - crossAxisMargin - padding.right;
y = _thumbOffset;
trackOffset = Offset(x - crossAxisMargin, 0.0);
break;
case ScrollbarOrientation.top:
case AxisDirection.left:
thumbSize = Size(thumbExtent, thickness);
trackSize = Size(_trackExtent, thickness + 2 * crossAxisMargin);
x = _thumbOffset;
y = crossAxisMargin + padding.top;
y = size.height - thickness - crossAxisMargin - padding.bottom;
trackSize = Size(_trackExtent, thickness + 2 * crossAxisMargin);
trackOffset = Offset(0.0, y - crossAxisMargin);
break;
case ScrollbarOrientation.bottom:
case AxisDirection.right:
thumbSize = Size(thumbExtent, thickness);
trackSize = Size(_trackExtent, thickness + 2 * crossAxisMargin);
x = _thumbOffset;
@ -638,8 +570,7 @@ class ScrollbarPainter extends ChangeNotifier implements CustomPainter {
|| radius != old.radius
|| minLength != old.minLength
|| padding != old.padding
|| minOverscrollLength != old.minOverscrollLength
|| scrollbarOrientation != old.scrollbarOrientation;
|| minOverscrollLength != old.minOverscrollLength;
}
@override
@ -724,7 +655,6 @@ class RawScrollbar extends StatefulWidget {
this.pressDuration = Duration.zero,
this.notificationPredicate = defaultScrollNotificationPredicate,
this.interactive,
this.scrollbarOrientation,
}) : assert(child != null),
assert(fadeDuration != null),
assert(timeToFade != null),
@ -936,9 +866,6 @@ class RawScrollbar extends StatefulWidget {
/// {@endtemplate}
final bool? interactive;
/// {@macro flutter.widgets.Scrollbar.scrollbarOrientation}
final ScrollbarOrientation? scrollbarOrientation;
@override
RawScrollbarState<RawScrollbar> createState() => RawScrollbarState<RawScrollbar>();
}
@ -1010,7 +937,6 @@ class RawScrollbarState<T extends RawScrollbar> extends State<T> with TickerProv
color: widget.thumbColor ?? const Color(0x66BCBCBC),
thickness: widget.thickness ?? _kScrollbarThickness,
fadeoutOpacityAnimation: _fadeoutOpacityAnimation,
scrollbarOrientation: widget.scrollbarOrientation,
);
}
@ -1116,8 +1042,7 @@ class RawScrollbarState<T extends RawScrollbar> extends State<T> with TickerProv
..textDirection = Directionality.of(context)
..thickness = widget.thickness ?? _kScrollbarThickness
..radius = widget.radius
..padding = MediaQuery.of(context).padding
..scrollbarOrientation = widget.scrollbarOrientation;
..padding = MediaQuery.of(context).padding;
}
@override

View file

@ -889,43 +889,4 @@ void main() {
),
);
});
testWidgets('CupertinoScrollbar scrollOrientation works correctly', (WidgetTester tester) async {
final ScrollController scrollController = ScrollController();
await tester.pumpWidget(
CupertinoApp(
home: PrimaryScrollController(
controller: scrollController,
child: CupertinoScrollbar(
isAlwaysShown: true,
controller: scrollController,
scrollbarOrientation: ScrollbarOrientation.left,
child: const SingleChildScrollView(
child: SizedBox(width: 4000.0, height: 4000.0),
),
),
),
),
);
await tester.pumpAndSettle();
expect(
find.byType(CupertinoScrollbar),
paints
..rect(
rect: const Rect.fromLTRB(0.0, 0.0, 9.0, 594.0),
)
..line(
p1: const Offset(0.0, 0.0),
p2: const Offset(0.0, 594.0),
strokeWidth: 1.0,
)
..rrect(
rrect: RRect.fromRectAndRadius(const Rect.fromLTRB(3.0, 3.0, 6.0, 92.1), const Radius.circular(1.5)),
color: _kScrollbarColor.color,
),
);
});
}

View file

@ -1492,52 +1492,4 @@ void main() {
);
}
});
testWidgets('Scrollbar scrollOrientation works correctly', (WidgetTester tester) async {
final ScrollController scrollController = ScrollController();
Widget _buildScrollWithOrientation(ScrollbarOrientation orientation) {
return _buildBoilerplate(
child: Theme(
data: ThemeData(
platform: TargetPlatform.android,
),
child: PrimaryScrollController(
controller: scrollController,
child: Scrollbar(
interactive: true,
isAlwaysShown: true,
scrollbarOrientation: orientation,
controller: scrollController,
child: const SingleChildScrollView(
child: SizedBox(width: 4000.0, height: 4000.0)
),
),
),
)
);
}
await tester.pumpWidget(_buildScrollWithOrientation(ScrollbarOrientation.left));
await tester.pumpAndSettle();
expect(
find.byType(Scrollbar),
paints
..rect(
rect: const Rect.fromLTRB(0.0, 0.0, 4.0, 600.0),
color: Colors.transparent,
)
..line(
p1: const Offset(0.0, 0.0),
p2: const Offset(0.0, 600.0),
strokeWidth: 1.0,
color: Colors.transparent,
)
..rect(
rect: const Rect.fromLTRB(0.0, 0.0, 4.0, 90.0),
color: _kAndroidThumbIdleColor,
),
);
});
}

View file

@ -26,7 +26,6 @@ ScrollbarPainter _buildPainter({
Radius? radius,
double minLength = _kMinThumbExtent,
double? minOverscrollLength,
ScrollbarOrientation? scrollbarOrientation,
required ScrollMetrics scrollMetrics,
}) {
return ScrollbarPainter(
@ -40,7 +39,6 @@ ScrollbarPainter _buildPainter({
minLength: minLength,
minOverscrollLength: minOverscrollLength ?? minLength,
fadeoutOpacityAnimation: kAlwaysCompleteAnimation,
scrollbarOrientation: scrollbarOrientation,
)..update(scrollMetrics, scrollMetrics.axisDirection);
}
@ -250,128 +248,6 @@ void main() {
},
);
test('scrollbarOrientation are respected', () {
const double viewportDimension = 23;
const double maxExtent = 100;
final ScrollMetrics startingMetrics = defaultMetrics.copyWith(
maxScrollExtent: maxExtent,
viewportDimension: viewportDimension,
);
const Size size = Size(600, viewportDimension);
const double margin = 0;
for (final ScrollbarOrientation scrollbarOrientation in ScrollbarOrientation.values) {
final AxisDirection axisDirection;
if (scrollbarOrientation == ScrollbarOrientation.left || scrollbarOrientation == ScrollbarOrientation.right)
axisDirection = AxisDirection.down;
else
axisDirection = AxisDirection.right;
painter = _buildPainter(
crossAxisMargin: margin,
scrollMetrics: startingMetrics,
scrollbarOrientation: scrollbarOrientation,
);
painter.update(
startingMetrics.copyWith(axisDirection: axisDirection),
axisDirection
);
painter.paint(testCanvas, size);
final Rect rect = captureRect();
switch (scrollbarOrientation) {
case ScrollbarOrientation.left:
expect(rect.left, 0);
expect(rect.top, 0);
expect(rect.right, _kThickness);
expect(rect.bottom, _kMinThumbExtent);
break;
case ScrollbarOrientation.right:
expect(rect.left, 600 - _kThickness);
expect(rect.top, 0);
expect(rect.right, 600);
expect(rect.bottom, _kMinThumbExtent);
break;
case ScrollbarOrientation.top:
expect(rect.left, 0);
expect(rect.top, 0);
expect(rect.right, _kMinThumbExtent);
expect(rect.bottom, _kThickness);
break;
case ScrollbarOrientation.bottom:
expect(rect.left, 0);
expect(rect.top, 23 - _kThickness);
expect(rect.right, _kMinThumbExtent);
expect(rect.bottom, 23);
break;
}
}
});
test('scrollbarOrientation default values are correct', () {
const double viewportDimension = 23;
const double maxExtent = 100;
final ScrollMetrics startingMetrics = defaultMetrics.copyWith(
maxScrollExtent: maxExtent,
viewportDimension: viewportDimension,
);
const Size size = Size(600, viewportDimension);
const double margin = 0;
Rect rect;
// Vertical scroll with TextDirection.ltr
painter = _buildPainter(
crossAxisMargin: margin,
scrollMetrics: startingMetrics,
textDirection: TextDirection.ltr,
);
painter.update(
startingMetrics.copyWith(axisDirection: AxisDirection.down),
AxisDirection.down
);
painter.paint(testCanvas, size);
rect = captureRect();
expect(rect.left, 600 - _kThickness);
expect(rect.top, 0);
expect(rect.right, 600);
expect(rect.bottom, _kMinThumbExtent);
// Vertical scroll with TextDirection.rtl
painter = _buildPainter(
crossAxisMargin: margin,
scrollMetrics: startingMetrics,
textDirection: TextDirection.rtl,
);
painter.update(
startingMetrics.copyWith(axisDirection: AxisDirection.down),
AxisDirection.down
);
painter.paint(testCanvas, size);
rect = captureRect();
expect(rect.left, 0);
expect(rect.top, 0);
expect(rect.right, _kThickness);
expect(rect.bottom, _kMinThumbExtent);
// Horizontal scroll
painter = _buildPainter(
crossAxisMargin: margin,
scrollMetrics: startingMetrics,
);
painter.update(
startingMetrics.copyWith(axisDirection: AxisDirection.right),
AxisDirection.right,
);
painter.paint(testCanvas, size);
rect = captureRect();
expect(rect.left, 0);
expect(rect.top, 23 - _kThickness);
expect(rect.right, _kMinThumbExtent);
expect(rect.bottom, 23);
});
group('Padding works for all scroll directions', () {
const EdgeInsets padding = EdgeInsets.fromLTRB(1, 2, 3, 4);
const Size size = Size(60, 80);
@ -1338,22 +1214,4 @@ void main() {
),
);
});
testWidgets('ScrollbarPainter asserts if scrollbarOrientation is used with wrong axisDirection', (WidgetTester tester) async {
final ScrollbarPainter painter = ScrollbarPainter(
color: _kScrollbarColor,
fadeoutOpacityAnimation: kAlwaysCompleteAnimation,
textDirection: TextDirection.ltr,
scrollbarOrientation: ScrollbarOrientation.left,
);
const Size size = Size(60, 80);
final ScrollMetrics scrollMetrics = defaultMetrics.copyWith(
maxScrollExtent: 100,
viewportDimension: size.height,
axisDirection: AxisDirection.right,
);
painter.update(scrollMetrics, scrollMetrics.axisDirection);
expect(() => painter.paint(testCanvas, size), throwsA(isA<AssertionError>()));
});
}