mirror of
https://github.com/revanced/revanced-manager.git
synced 2025-04-30 05:54:26 +02:00
refactor: PopScope Migration (#1674)
Co-authored-by: Benjamin Halko <benjaminhalko@hotmail.com>
This commit is contained in:
parent
f5ba84d81e
commit
3b58d229da
@ -619,8 +619,8 @@ class ManagerAPI {
|
|||||||
return showDialog(
|
return showDialog(
|
||||||
barrierDismissible: false,
|
barrierDismissible: false,
|
||||||
context: context,
|
context: context,
|
||||||
builder: (context) => WillPopScope(
|
builder: (context) => PopScope(
|
||||||
onWillPop: () async => false,
|
canPop: false,
|
||||||
child: AlertDialog(
|
child: AlertDialog(
|
||||||
title: Text(t.warning),
|
title: Text(t.warning),
|
||||||
content: ValueListenableBuilder(
|
content: ValueListenableBuilder(
|
||||||
|
@ -16,12 +16,15 @@ class InstallerView extends StatelessWidget {
|
|||||||
return ViewModelBuilder<InstallerViewModel>.reactive(
|
return ViewModelBuilder<InstallerViewModel>.reactive(
|
||||||
onViewModelReady: (model) => model.initialize(context),
|
onViewModelReady: (model) => model.initialize(context),
|
||||||
viewModelBuilder: () => InstallerViewModel(),
|
viewModelBuilder: () => InstallerViewModel(),
|
||||||
builder: (context, model, child) => WillPopScope(
|
builder: (context, model, child) => PopScope(
|
||||||
/*
|
canPop: !model.isPatching,
|
||||||
TODO(any): migrate to [PopScope],
|
onPopInvoked: (bool didPop) {
|
||||||
we've tried to migrate it two times but
|
if (didPop) {
|
||||||
reverted it because we couldn't exit out of the screen.
|
model.onPop();
|
||||||
*/
|
} else {
|
||||||
|
model.onPopAttempt(context);
|
||||||
|
}
|
||||||
|
},
|
||||||
child: SafeArea(
|
child: SafeArea(
|
||||||
top: false,
|
top: false,
|
||||||
bottom: model.isPatching,
|
bottom: model.isPatching,
|
||||||
@ -83,7 +86,7 @@ class InstallerView extends StatelessWidget {
|
|||||||
maxLines: 1,
|
maxLines: 1,
|
||||||
overflow: TextOverflow.ellipsis,
|
overflow: TextOverflow.ellipsis,
|
||||||
),
|
),
|
||||||
onBackButtonPressed: () => model.onWillPop(context),
|
onBackButtonPressed: () => Navigator.maybePop(context),
|
||||||
bottom: PreferredSize(
|
bottom: PreferredSize(
|
||||||
preferredSize: const Size(double.infinity, 1.0),
|
preferredSize: const Size(double.infinity, 1.0),
|
||||||
child: GradientProgressIndicator(progress: model.progress),
|
child: GradientProgressIndicator(progress: model.progress),
|
||||||
@ -111,7 +114,6 @@ class InstallerView extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
onWillPop: () => model.onWillPop(context),
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -526,25 +526,23 @@ class InstallerViewModel extends BaseViewModel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<bool> onWillPop(BuildContext context) async {
|
Future<void> onPopAttempt(BuildContext context) async {
|
||||||
if (isPatching) {
|
if (!cancel) {
|
||||||
if (!cancel) {
|
cancel = true;
|
||||||
cancel = true;
|
_toast.showBottom(t.installerView.pressBackAgain);
|
||||||
_toast.showBottom(t.installerView.pressBackAgain);
|
} else if (!isCanceled) {
|
||||||
} else if (!isCanceled) {
|
await stopPatcher();
|
||||||
await stopPatcher();
|
} else {
|
||||||
} else {
|
_toast.showBottom(t.installerView.noExit);
|
||||||
_toast.showBottom(t.installerView.noExit);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void onPop() {
|
||||||
if (!cancel) {
|
if (!cancel) {
|
||||||
cleanPatcher();
|
cleanPatcher();
|
||||||
} else {
|
} else {
|
||||||
_patcherAPI.cleanPatcher();
|
_patcherAPI.cleanPatcher();
|
||||||
}
|
}
|
||||||
screenshotCallback.dispose();
|
ScreenshotCallback().dispose();
|
||||||
Navigator.of(context).pop();
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,13 +13,11 @@ class NavigationView extends StatelessWidget {
|
|||||||
return ViewModelBuilder<NavigationViewModel>.reactive(
|
return ViewModelBuilder<NavigationViewModel>.reactive(
|
||||||
onViewModelReady: (model) => model.initialize(context),
|
onViewModelReady: (model) => model.initialize(context),
|
||||||
viewModelBuilder: () => locator<NavigationViewModel>(),
|
viewModelBuilder: () => locator<NavigationViewModel>(),
|
||||||
builder: (context, model, child) => WillPopScope(
|
builder: (context, model, child) => PopScope(
|
||||||
onWillPop: () async {
|
canPop: model.currentIndex == 0,
|
||||||
if (model.currentIndex == 0) {
|
onPopInvoked: (bool didPop) {
|
||||||
return true;
|
if (!didPop) {
|
||||||
} else {
|
|
||||||
model.setIndex(0);
|
model.setIndex(0);
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
child: Scaffold(
|
child: Scaffold(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user