Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove custom scroll behavior, allow scroll physics customization, fix double scroll effects and double scroll bars #103

Merged
merged 4 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions coffee_maker/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class _DemoAppState extends State<DemoApp> {
@override
Widget build(BuildContext context) {
return MaterialApp(
scrollBehavior: const CustomScrollBehavior(),
theme: ThemeData(
primaryColor: DemoAppColors.blue,
useMaterial3: true,
Expand Down Expand Up @@ -113,14 +114,11 @@ class _DemoAppState extends State<DemoApp> {
),
),
debugShowCheckedModeBanner: false,
home: ScrollConfiguration(
behavior: const DragScrollBehavior(),
child: HomeScreen(
groupedCoffeeOrders:
GroupedCoffeeOrders.fromCoffeeOrders(mockCoffeeOrders),
isStoreOnline: true,
isGridOverlayVisible: false,
),
home: HomeScreen(
groupedCoffeeOrders:
GroupedCoffeeOrders.fromCoffeeOrders(mockCoffeeOrders),
isStoreOnline: true,
isGridOverlayVisible: false,
),
);
}
Expand Down
2 changes: 1 addition & 1 deletion demo_ui_components/lib/demo_ui_components.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ export 'src/text/modal_sheet_content_text.dart';
export 'src/text/modal_sheet_subtitle.dart';
export 'src/text/modal_sheet_title.dart';
export 'src/text/modal_sheet_top_bar_title.dart';
export 'src/utils/drag_scroll_behavior.dart';
export 'src/utils/custom_scroll_behavior.dart';
48 changes: 48 additions & 0 deletions demo_ui_components/lib/src/utils/custom_scroll_behavior.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import 'dart:ui';

import 'package:flutter/material.dart';

class CustomScrollBehavior extends ScrollBehavior {
const CustomScrollBehavior({this.androidSdkVersion}) : super();
final int? androidSdkVersion;

// Override behavior methods and getters like dragDevices
@override
Set<PointerDeviceKind> get dragDevices => <PointerDeviceKind>{
PointerDeviceKind.touch,
PointerDeviceKind.mouse,
PointerDeviceKind.trackpad,
PointerDeviceKind.stylus,
};

@override
Widget buildOverscrollIndicator(
BuildContext context,
Widget child,
ScrollableDetails details,
) {
final glowingOverscrollIndicator = GlowingOverscrollIndicator(
axisDirection: details.direction,
color: Theme.of(context).colorScheme.primary,
child: child,
);
final androidSdkVersion = this.androidSdkVersion;
switch (getPlatform(context)) {
case TargetPlatform.iOS:
case TargetPlatform.linux:
case TargetPlatform.macOS:
case TargetPlatform.windows:
return child;
case TargetPlatform.android:
if (androidSdkVersion != null && androidSdkVersion > 30) {
return StretchingOverscrollIndicator(
axisDirection: details.direction,
child: child,
);
}
return glowingOverscrollIndicator;
case TargetPlatform.fuchsia:
return glowingOverscrollIndicator;
}
}
}
74 changes: 0 additions & 74 deletions demo_ui_components/lib/src/utils/drag_scroll_behavior.dart

This file was deleted.

2 changes: 2 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ Pagination involves a sequence of screens the user navigates sequentially. We ch
heroImageHeight: _heroImageHeight,
topBarShadowColor: _lightThemeShadowColor,
modalBarrierColor: Colors.black54,
mainContentScrollPhysics: ClampingScrollPhysics(),
),
],
),
Expand All @@ -169,6 +170,7 @@ Pagination involves a sequence of screens the user navigates sequentially. We ch
sabGradientColor: _darkSabGradientColor,
dialogShape: BeveledRectangleBorder(),
bottomSheetShape: BeveledRectangleBorder(),
mainContentScrollPhysics: ClampingScrollPhysics(),
),
],
),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'package:flutter/material.dart';
import 'package:wolt_modal_sheet/src/content/components/main_content/wolt_modal_sheet_hero_image.dart';
import 'package:wolt_modal_sheet/src/theme/wolt_modal_sheet_default_theme_data.dart';
import 'package:wolt_modal_sheet/src/utils/drag_scroll_behavior.dart';
import 'package:wolt_modal_sheet/wolt_modal_sheet.dart';

/// The main content widget within the scrollable modal sheet.
Expand All @@ -23,8 +22,7 @@ class WoltModalSheetMainContent extends StatefulWidget {
}) : super(key: key);

@override
State<WoltModalSheetMainContent> createState() =>
_WoltModalSheetMainContentState();
State<WoltModalSheetMainContent> createState() => _WoltModalSheetMainContentState();
}

class _WoltModalSheetMainContentState extends State<WoltModalSheetMainContent> {
Expand All @@ -34,8 +32,7 @@ class _WoltModalSheetMainContentState extends State<WoltModalSheetMainContent> {
void initState() {
super.initState();
scrollController = widget.page.scrollController ??
ScrollController(
initialScrollOffset: widget.currentScrollPosition.value);
ScrollController(initialScrollOffset: widget.currentScrollPosition.value);
}

@override
Expand All @@ -45,24 +42,18 @@ class _WoltModalSheetMainContentState extends State<WoltModalSheetMainContent> {
final page = widget.page;
final heroImageHeight = page.heroImage == null
? 0.0
: (page.heroImageHeight ??
themeData?.heroImageHeight ??
defaultThemeData.heroImageHeight);
final pageHasTopBarLayer = page.hasTopBarLayer ??
themeData?.hasTopBarLayer ??
defaultThemeData.hasTopBarLayer;
final navBarHeight = page.navBarHeight ??
themeData?.navBarHeight ??
defaultThemeData.navBarHeight;
final topBarHeight = pageHasTopBarLayer ||
page.leadingNavBarWidget != null ||
page.trailingNavBarWidget != null
? navBarHeight
: 0.0;
: (page.heroImageHeight ?? themeData?.heroImageHeight ?? defaultThemeData.heroImageHeight);
final pageHasTopBarLayer =
page.hasTopBarLayer ?? themeData?.hasTopBarLayer ?? defaultThemeData.hasTopBarLayer;
final navBarHeight =
page.navBarHeight ?? themeData?.navBarHeight ?? defaultThemeData.navBarHeight;
final topBarHeight =
pageHasTopBarLayer || page.leadingNavBarWidget != null || page.trailingNavBarWidget != null
? navBarHeight
: 0.0;
final scrollView = CustomScrollView(
scrollBehavior: const DragScrollBehavior(),
shrinkWrap: true,
physics: const ClampingScrollPhysics(),
physics: themeData?.mainContentScrollPhysics ?? defaultThemeData.mainContentScrollPhysics,
controller: scrollController,
slivers: [
SliverList(
Expand Down Expand Up @@ -98,12 +89,10 @@ class _WoltModalSheetMainContentState extends State<WoltModalSheetMainContent> {
);
return NotificationListener<ScrollNotification>(
onNotification: (scrollNotification) {
final isVerticalScrollNotification =
scrollNotification is ScrollUpdateNotification &&
scrollNotification.metrics.axis == Axis.vertical;
final isVerticalScrollNotification = scrollNotification is ScrollUpdateNotification &&
scrollNotification.metrics.axis == Axis.vertical;
if (isVerticalScrollNotification) {
widget.currentScrollPosition.value =
scrollNotification.metrics.pixels;
widget.currentScrollPosition.value = scrollNotification.metrics.pixels;
}
return false;
},
Expand Down
3 changes: 3 additions & 0 deletions lib/src/theme/wolt_modal_sheet_default_theme_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,7 @@ class WoltModalSheetDefaultThemeData extends WoltModalSheetThemeData {
/// If null, [WoltModalSheet] uses [Clip.none].
@override
Clip get clipBehavior => Clip.antiAlias;

@override
ScrollPhysics? get mainContentScrollPhysics => null;
}
7 changes: 7 additions & 0 deletions lib/src/theme/wolt_modal_sheet_theme_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class WoltModalSheetThemeData extends ThemeExtension<WoltModalSheetThemeData> {
this.surfaceTintColor,
this.clipBehavior,
this.shadowColor,
this.mainContentScrollPhysics,
});

/// Overrides the default value for surfaceTintColor.
Expand Down Expand Up @@ -128,6 +129,9 @@ class WoltModalSheetThemeData extends ThemeExtension<WoltModalSheetThemeData> {
/// If null, [WoltModalSheet] uses [Clip.antiAlias].
final Clip? clipBehavior;

/// The default value for [WoltModalSheet] scrollPhysics in the main content.
final ScrollPhysics? mainContentScrollPhysics;

@override
WoltModalSheetThemeData copyWith({
Color? backgroundColor,
Expand All @@ -153,6 +157,7 @@ class WoltModalSheetThemeData extends ThemeExtension<WoltModalSheetThemeData> {
Color? surfaceTintColor,
Color? shadowColor,
Clip? clipBehavior,
ScrollPhysics? mainContentScrollPhysics,
}) {
return WoltModalSheetThemeData(
backgroundColor: backgroundColor ?? this.backgroundColor,
Expand All @@ -179,6 +184,7 @@ class WoltModalSheetThemeData extends ThemeExtension<WoltModalSheetThemeData> {
surfaceTintColor: surfaceTintColor ?? this.surfaceTintColor,
shadowColor: shadowColor ?? this.shadowColor,
clipBehavior: clipBehavior ?? this.clipBehavior,
mainContentScrollPhysics: mainContentScrollPhysics ?? this.mainContentScrollPhysics,
);
}

Expand Down Expand Up @@ -216,6 +222,7 @@ class WoltModalSheetThemeData extends ThemeExtension<WoltModalSheetThemeData> {
surfaceTintColor: Color.lerp(surfaceTintColor, other.surfaceTintColor, t),
shadowColor: Color.lerp(shadowColor, other.shadowColor, t),
clipBehavior: t < 0.5 ? clipBehavior : other.clipBehavior,
mainContentScrollPhysics: t < 0.5 ? mainContentScrollPhysics : other.mainContentScrollPhysics,
);
}
}
74 changes: 0 additions & 74 deletions lib/src/utils/drag_scroll_behavior.dart

This file was deleted.

4 changes: 4 additions & 0 deletions melos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,9 @@ command:
scripts:
analyze:
exec: dart analyze .
# Uncomment to use with FVM :
# exec: fvm flutter analyze .
format:
exec: dart format --set-exit-if-changed .
# Uncomment to use with FVM :
# exec: fvm dart format --set-exit-if-changed .
2 changes: 1 addition & 1 deletion playground/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ android {
applicationId "com.wolt_modal_sheet.playground.playground"
// You can update the following values to match your application needs.
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
minSdkVersion flutter.minSdkVersion
minSdkVersion 19
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
Expand Down
1 change: 1 addition & 0 deletions playground/ios/Flutter/Debug.xcconfig
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
#include "Generated.xcconfig"
Loading