Skip to content

Commit

Permalink
feat: pop scope (#437)
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesblasco authored Nov 18, 2024
1 parent c6718a0 commit a87f82b
Show file tree
Hide file tree
Showing 25 changed files with 260 additions and 189 deletions.
2 changes: 1 addition & 1 deletion modal_bottom_sheet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Why not `showModalBottomSheet`?
Inspired by `showModalBottomSheet`, it completes with some must-need features:

- Support for inside scrollview + dragging down to close (`showModalBottomSheet` won't work correctly with scrollviews.
- Support for `WillPopScope` to prevent closing the dialog.
- Support for `PopScope` and `WillPopScope` to prevent closing the dialog.
- Support for scroll to top when tapping status bar (iOS only)
- Support for top SafeArea (not supported by showModalBottomSheet)
- Cupertino modal bottom sheet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
<key>CFBundleVersion</key>
<string>1.0</string>
<key>MinimumOSVersion</key>
<string>11.0</string>
<string>12.0</string>
</dict>
</plist>
2 changes: 1 addition & 1 deletion modal_bottom_sheet/example/ios/Podfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Uncomment this line to define a global platform for your project
# platform :ios, '11.0'
# platform :ios, '12.0'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'
Expand Down
6 changes: 3 additions & 3 deletions modal_bottom_sheet/example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/url_launcher_ios/ios"

SPEC CHECKSUMS:
Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
url_launcher_ios: 68d46cc9766d0c41dbdc884310529557e3cd7a86

PODFILE CHECKSUM: ef19549a9bc3046e7bb7d2fab4d021637c0c58a3
PODFILE CHECKSUM: c4c93c5f6502fe2754f48404d3594bf779584011

COCOAPODS: 1.14.3
COCOAPODS: 1.15.2
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@
97C146E61CF9000F007C117D /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 1430;
LastUpgradeCheck = 1510;
ORGANIZATIONNAME = "";
TargetAttributes = {
97C146ED1CF9000F007C117D = {
Expand Down Expand Up @@ -342,7 +342,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = iphoneos;
Expand Down Expand Up @@ -420,7 +420,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand Down Expand Up @@ -469,7 +469,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = iphoneos;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1430"
LastUpgradeVersion = "1510"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
5 changes: 2 additions & 3 deletions modal_bottom_sheet/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,7 @@ class _MyHomePageState extends State<MyHomePage> {
builder: (context) => ModalWithNavigator(),
)),
ListTile(
title:
Text('Cupertino Navigator + Scroll + WillPopScope'),
title: Text('Cupertino Navigator + Scroll + PopScope'),
onTap: () => showCupertinoModalBottomSheet(
expand: true,
context: context,
Expand All @@ -218,7 +217,7 @@ class _MyHomePageState extends State<MyHomePage> {
),
),
ListTile(
title: Text('Modal with WillPopScope'),
title: Text('Modal with PopScope'),
onTap: () => showCupertinoModalBottomSheet(
expand: true,
context: context,
Expand Down
52 changes: 27 additions & 25 deletions modal_bottom_sheet/example/lib/modals/modal_complex_all.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,33 @@ class ComplexModal extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Material(
child: WillPopScope(
onWillPop: () async {
bool shouldClose = true;
await showCupertinoDialog(
context: context,
builder: (context) => CupertinoAlertDialog(
title: Text('Should Close?'),
actions: <Widget>[
CupertinoButton(
child: Text('Yes'),
onPressed: () {
shouldClose = true;
Navigator.of(context).pop();
},
),
CupertinoButton(
child: Text('No'),
onPressed: () {
shouldClose = false;
Navigator.of(context).pop();
},
),
],
));
return shouldClose;
child: PopScope(
canPop: false,
onPopInvoked: (didPop) {
if (!didPop) {
final sheetNavigator = Navigator.of(context);

showCupertinoDialog(
context: context,
builder: (context) => CupertinoAlertDialog(
title: Text('Should Close?'),
actions: <Widget>[
CupertinoButton(
child: Text('Yes'),
onPressed: () {
Navigator.of(context).pop();
sheetNavigator.pop();
},
),
CupertinoButton(
child: Text('No'),
onPressed: () {
Navigator.of(context).pop();
},
),
],
));
}
},
child: Navigator(
onGenerateRoute: (_) => MaterialPageRoute(
Expand Down
51 changes: 26 additions & 25 deletions modal_bottom_sheet/example/lib/modals/modal_will_scope.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,32 @@ class ModalWillScope extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Material(
child: WillPopScope(
onWillPop: () async {
bool shouldClose = true;
await showCupertinoDialog(
context: context,
builder: (context) => CupertinoAlertDialog(
title: Text('Should Close?'),
actions: <Widget>[
CupertinoButton(
child: Text('Yes'),
onPressed: () {
shouldClose = true;
Navigator.of(context).pop();
},
),
CupertinoButton(
child: Text('No'),
onPressed: () {
shouldClose = false;
Navigator.of(context).pop();
},
),
],
));
return shouldClose;
child: PopScope(
canPop: false,
onPopInvoked: (didPop) {
if (didPop) return;
final sheetNavigator = Navigator.of(context);
showCupertinoDialog(
context: context,
builder: (context) => CupertinoAlertDialog(
title: Text('Should Close?'),
actions: <Widget>[
CupertinoButton(
child: Text('Yes'),
onPressed: () {
Navigator.of(context).pop();
},
),
CupertinoButton(
child: Text('No'),
onPressed: () {
Navigator.of(context).pop();
sheetNavigator.pop();
},
),
],
),
);
},
child: CupertinoPageScaffold(
navigationBar: CupertinoNavigationBar(
Expand Down
52 changes: 38 additions & 14 deletions modal_bottom_sheet/example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,30 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
leak_tracker:
dependency: transitive
description:
name: leak_tracker
sha256: "78eb209deea09858f5269f5a5b02be4049535f568c07b275096836f01ea323fa"
url: "https://pub.dev"
source: hosted
version: "10.0.0"
leak_tracker_flutter_testing:
dependency: transitive
description:
name: leak_tracker_flutter_testing
sha256: b46c5e37c19120a8a01918cfaf293547f47269f7cb4b0058f21531c2465d6ef0
url: "https://pub.dev"
source: hosted
version: "2.0.1"
leak_tracker_testing:
dependency: transitive
description:
name: leak_tracker_testing
sha256: a597f72a664dbd293f3bfc51f9ba69816f84dcd403cdac7066cb3f6003f3ab47
url: "https://pub.dev"
source: hosted
version: "2.0.1"
lints:
dependency: "direct dev"
description:
Expand All @@ -84,41 +108,41 @@ packages:
dependency: transitive
description:
name: matcher
sha256: "1803e76e6653768d64ed8ff2e1e67bea3ad4b923eb5c56a295c3e634bad5960e"
sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb
url: "https://pub.dev"
source: hosted
version: "0.12.16"
version: "0.12.16+1"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41"
sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a"
url: "https://pub.dev"
source: hosted
version: "0.5.0"
version: "0.8.0"
meta:
dependency: transitive
description:
name: meta
sha256: a6e590c838b18133bb482a2745ad77c5bb7715fb0451209e1a7567d416678b8e
sha256: d584fa6707a52763a52446f02cc621b077888fb63b93bbcb1143a7be5a0c0c04
url: "https://pub.dev"
source: hosted
version: "1.10.0"
version: "1.11.0"
modal_bottom_sheet:
dependency: "direct main"
description:
path: ".."
relative: true
source: path
version: "3.0.1"
version: "3.0.0"
path:
dependency: transitive
description:
name: path
sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917"
sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af"
url: "https://pub.dev"
source: hosted
version: "1.8.3"
version: "1.9.0"
plugin_platform_interface:
dependency: transitive
description:
Expand Down Expand Up @@ -252,14 +276,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.1.4"
web:
vm_service:
dependency: transitive
description:
name: web
sha256: afe077240a270dcfd2aafe77602b4113645af95d0ad31128cc02bce5ac5d5152
name: vm_service
sha256: b3d56ff4341b8f182b96aceb2fa20e3dcb336b9f867bc0eafc0de10f1048e957
url: "https://pub.dev"
source: hosted
version: "0.3.0"
version: "13.0.0"
sdks:
dart: ">=3.2.0-194.0.dev <4.0.0"
dart: ">=3.3.0 <4.0.0"
flutter: ">=3.13.0"
17 changes: 14 additions & 3 deletions modal_bottom_sheet/lib/src/bottom_sheet_route.dart
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,21 @@ class _ModalBottomSheetState<T> extends State<_ModalBottomSheet<T>> {
expanded: widget.route.expanded,
containerBuilder: widget.route.containerBuilder,
animationController: widget.route._animationController!,
shouldClose: widget.route._hasScopedWillPopCallback
shouldClose: widget.route.popDisposition ==
RoutePopDisposition.doNotPop ||
widget.route._hasScopedWillPopCallback
? () async {
// ignore: deprecated_member_use
final willPop = await widget.route.willPop();
return willPop != RoutePopDisposition.doNotPop;
final popDisposition = widget.route.popDisposition;
final shouldClose =
!(willPop == RoutePopDisposition.doNotPop ||
popDisposition == RoutePopDisposition.doNotPop);
popDisposition == RoutePopDisposition.doNotPop;
if (!shouldClose) {
widget.route.onPopInvoked(false);
}
return shouldClose;
}
: null,
onClosing: () {
Expand Down Expand Up @@ -138,7 +149,7 @@ class ModalSheetRoute<T> extends PageRoute<T> {
this.animationCurve,
Duration? duration,
super.settings,
}) : duration = duration ?? _bottomSheetDuration;
}) : duration = duration ?? _bottomSheetDuration;

final double? closeProgressThreshold;
final WidgetWithChildBuilder? containerBuilder;
Expand Down
2 changes: 1 addition & 1 deletion sheet/example/ios/Flutter/AppFrameworkInfo.plist
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
<key>CFBundleVersion</key>
<string>1.0</string>
<key>MinimumOSVersion</key>
<string>11.0</string>
<string>12.0</string>
</dict>
</plist>
8 changes: 4 additions & 4 deletions sheet/example/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
97C146E61CF9000F007C117D /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 1430;
LastUpgradeCheck = 1510;
ORGANIZATIONNAME = "";
TargetAttributes = {
97C146ED1CF9000F007C117D = {
Expand Down Expand Up @@ -275,7 +275,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = iphoneos;
Expand Down Expand Up @@ -361,7 +361,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand Down Expand Up @@ -410,7 +410,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = iphoneos;
Expand Down
Loading

0 comments on commit a87f82b

Please sign in to comment.