feat: disable native safari swipe navigation on IOS for gesture back

This commit is contained in:
sBubshait 2025-07-28 11:17:27 +03:00
parent a2abe08d3a
commit c9316b5190
8 changed files with 76 additions and 38 deletions

View File

@ -129,11 +129,8 @@ class _LandingPageState extends State<LandingPage> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return WillPopScope( return PopScope(
onWillPop: () async { canPop: false, // Prevent back navigation from landing page
// Prevent back navigation from landing page
return false;
},
child: Scaffold( child: Scaffold(
body: Stack( body: Stack(
children: [ children: [
@ -379,11 +376,8 @@ class _SignInPageState extends State<SignInPage> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return WillPopScope( return PopScope(
onWillPop: () async { canPop: false, // Prevent back navigation from sign in page
// Prevent back navigation from sign in page
return false;
},
child: Scaffold( child: Scaffold(
body: Container( body: Container(
decoration: BoxDecoration( decoration: BoxDecoration(

View File

@ -70,11 +70,8 @@ class _CreatePostScreenState extends State<CreatePostScreen> {
final remainingChars = _maxCharacters - _bodyController.text.length; final remainingChars = _maxCharacters - _bodyController.text.length;
final isOverLimit = remainingChars < 0; final isOverLimit = remainingChars < 0;
return WillPopScope( return PopScope(
onWillPop: () async { canPop: true, // Allow back navigation to go back to feed page only
// Allow back navigation to go back to feed page only
return true;
},
child: Scaffold( child: Scaffold(
appBar: AppBar( appBar: AppBar(
title: Text('Create Post', style: TextStyle(fontWeight: FontWeight.w600)), title: Text('Create Post', style: TextStyle(fontWeight: FontWeight.w600)),

View File

@ -79,11 +79,8 @@ class _NotificationPermissionScreenState
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return WillPopScope( return PopScope(
onWillPop: () async { canPop: false, // Prevent back navigation from notification permission screen
// Prevent back navigation from notification permission screen
return false;
},
child: Scaffold( child: Scaffold(
body: Container( body: Container(
decoration: BoxDecoration( decoration: BoxDecoration(

View File

@ -14,7 +14,15 @@ class _FeedPageState extends State<FeedPage> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return PopScope(
canPop: false, // Prevent back navigation from feed page
onPopInvoked: (bool didPop) {
// Prevent any pop behavior, including iOS back gesture
if (!didPop) {
// Do nothing - stay on feed page
}
},
child: Scaffold(
appBar: AppBar( appBar: AppBar(
title: Text('Feed', style: TextStyle(fontWeight: FontWeight.w600)), title: Text('Feed', style: TextStyle(fontWeight: FontWeight.w600)),
backgroundColor: Colors.white, backgroundColor: Colors.white,
@ -45,6 +53,7 @@ class _FeedPageState extends State<FeedPage> {
backgroundColor: Color(0xFF6A4C93), backgroundColor: Color(0xFF6A4C93),
child: Icon(Icons.edit, color: Colors.white), child: Icon(Icons.edit, color: Colors.white),
), ),
),
); );
} }

View File

@ -152,11 +152,8 @@ class _InvitationDetailsPageState extends State<InvitationDetailsPage> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return WillPopScope( return PopScope(
onWillPop: () async { canPop: true, // Allow back navigation to go back to invitations page only
// Allow back navigation to go back to invitations page only
return true;
},
child: Scaffold( child: Scaffold(
backgroundColor: Colors.grey[50], backgroundColor: Colors.grey[50],
appBar: AppBar( appBar: AppBar(

View File

@ -528,7 +528,15 @@ class _InvitationsPageState extends State<InvitationsPage>
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return PopScope(
canPop: false, // Prevent back navigation from invitations page
onPopInvoked: (bool didPop) {
// Prevent any pop behavior, including iOS back gesture
if (!didPop) {
// Do nothing - stay on invitations page
}
},
child: Scaffold(
appBar: AppBar( appBar: AppBar(
title: Text( title: Text(
'Invitations', 'Invitations',
@ -593,6 +601,7 @@ class _InvitationsPageState extends State<InvitationsPage>
backgroundColor: Color(0xFF6A4C93), backgroundColor: Color(0xFF6A4C93),
child: Icon(Icons.add, color: Colors.white), child: Icon(Icons.add, color: Colors.white),
), ),
),
); );
} }
} }
@ -734,11 +743,8 @@ class _CreateInvitationPageState extends State<CreateInvitationPage> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return WillPopScope( return PopScope(
onWillPop: () async { canPop: true, // Allow back navigation to go back to invitations page only
// Allow back navigation to go back to invitations page only
return true;
},
child: Scaffold( child: Scaffold(
body: Container( body: Container(
decoration: BoxDecoration( decoration: BoxDecoration(

View File

@ -170,7 +170,15 @@ class _ProfilePageState extends State<ProfilePage> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return PopScope(
canPop: false, // Prevent back navigation from profile page
onPopInvoked: (bool didPop) {
// Prevent any pop behavior, including iOS back gesture
if (!didPop) {
// Do nothing - stay on profile page
}
},
child: Scaffold(
appBar: AppBar( appBar: AppBar(
title: Text('Profile', style: TextStyle(fontWeight: FontWeight.w600)), title: Text('Profile', style: TextStyle(fontWeight: FontWeight.w600)),
backgroundColor: Colors.white, backgroundColor: Colors.white,
@ -318,6 +326,7 @@ class _ProfilePageState extends State<ProfilePage> {
], ],
], ],
), ),
),
), ),
); );
} }
@ -674,11 +683,8 @@ class _SettingsPageState extends State<SettingsPage> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return WillPopScope( return PopScope(
onWillPop: () async { canPop: true, // Allow back navigation to go back to profile page only
// Allow back navigation to go back to profile page only
return true;
},
child: Scaffold( child: Scaffold(
appBar: AppBar( appBar: AppBar(
title: Text('Settings', style: TextStyle(fontWeight: FontWeight.w600)), title: Text('Settings', style: TextStyle(fontWeight: FontWeight.w600)),

View File

@ -32,6 +32,21 @@
<title>Wesal</title> <title>Wesal</title>
<link rel="manifest" href="manifest.json"> <link rel="manifest" href="manifest.json">
<style>
body {
overscroll-behavior-x: none;
-webkit-overflow-scrolling: touch;
}
/* Prevent pull-to-refresh and back gesture */
html,
body {
overflow-x: hidden;
position: fixed;
width: 100%;
height: 100%;
}
</style>
</head> </head>
<body> <body>
@ -50,6 +65,23 @@
}); });
}); });
} }
// Prevent iOS Safari back gesture
window.addEventListener('touchstart', function (e) {
if (e.touches.length > 1) return;
const touch = e.touches[0];
if (touch.clientX < 20) { // Left edge
e.preventDefault();
}
}, { passive: false });
// Override browser back
window.addEventListener('popstate', function (e) {
e.preventDefault();
// Send message to Flutter
window.dispatchEvent(new CustomEvent('browser-back'));
});
</script> </script>
</body> </body>