Skip to content

Commit

Permalink
revert: "feat: improve predictive back (#1487)"
Browse files Browse the repository at this point in the history
This reverts commit 06ff36c.

Signed-off-by: validcube <[email protected]>
  • Loading branch information
validcube committed Dec 11, 2023
1 parent 637641c commit 7f26c5b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 37 deletions.
4 changes: 2 additions & 2 deletions lib/services/manager_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -582,8 +582,8 @@ class ManagerAPI {
return showDialog(
barrierDismissible: false,
context: context,
builder: (context) => PopScope(
canPop: false,
builder: (context) => WillPopScope(
onWillPop: () async => false,
child: AlertDialog(
backgroundColor: Theme.of(context).colorScheme.secondaryContainer,
title: I18nText('warning'),
Expand Down
6 changes: 3 additions & 3 deletions lib/ui/views/installer/installer_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ class InstallerView extends StatelessWidget {
return ViewModelBuilder<InstallerViewModel>.reactive(
onViewModelReady: (model) => model.initialize(context),
viewModelBuilder: () => InstallerViewModel(),
builder: (context, model, child) => PopScope(
onPopInvoked: (bool didPop) => model.onPopInvoked(context, didPop),
builder: (context, model, child) => WillPopScope(
child: SafeArea(
top: false,
bottom: model.isPatching,
Expand Down Expand Up @@ -84,7 +83,7 @@ class InstallerView extends StatelessWidget {
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
onBackButtonPressed: () => model.onBackButtonInvoked(context),
onBackButtonPressed: () => model.onWillPop(context),
bottom: PreferredSize(
preferredSize: const Size(double.infinity, 1.0),
child: GradientProgressIndicator(progress: model.progress),
Expand Down Expand Up @@ -112,6 +111,7 @@ class InstallerView extends StatelessWidget {
),
),
),
onWillPop: () => model.onWillPop(context),
),
);
}
Expand Down
43 changes: 15 additions & 28 deletions lib/ui/views/installer/installer_viewmodel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -489,38 +489,25 @@ class InstallerViewModel extends BaseViewModel {
}
}

bool canPop() {
return !isPatching;
}

void onBackButtonInvoked(BuildContext context) {
if (canPop()) {
onPopInvoked(context, true);
} else {
onPopInvoked(context, false);
}
}

Future<void> onPopInvoked(BuildContext context, bool didPop) async {
if (didPop) {
Future<bool> onWillPop(BuildContext context) async {
if (isPatching) {
if (!cancel) {
cleanPatcher();
cancel = true;
_toast.showBottom('installerView.pressBackAgain');
} else if (!isCanceled) {
await stopPatcher();
} else {
_patcherAPI.cleanPatcher();
_toast.showBottom('installerView.noExit');
}
screenshotCallback.dispose();
Navigator.of(context).pop();
return false;
}
if (!cancel) {
cleanPatcher();
} else {
if (isPatching) {
if (!cancel) {
cancel = true;
_toast.showBottom('installerView.pressBackAgain');
} else if (!isCanceled) {
await stopPatcher();
} else {
_toast.showBottom('installerView.noExit');
}
}
_patcherAPI.cleanPatcher();
}
screenshotCallback.dispose();
Navigator.of(context).pop();
return true;
}
}
10 changes: 6 additions & 4 deletions lib/ui/views/navigation/navigation_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ class NavigationView extends StatelessWidget {
return ViewModelBuilder<NavigationViewModel>.reactive(
onViewModelReady: (model) => model.initialize(context),
viewModelBuilder: () => locator<NavigationViewModel>(),
builder: (context, model, child) => PopScope(
canPop: model.currentIndex == 0,
onPopInvoked: (bool didPop) {
if (!didPop) {
builder: (context, model, child) => WillPopScope(
onWillPop: () async {
if (model.currentIndex == 0) {
return true;
} else {
model.setIndex(0);
return false;
}
},
child: Scaffold(
Expand Down

0 comments on commit 7f26c5b

Please sign in to comment.