fix(mobile): Fixes immersive mode not ending for memory lane (#7767)

Fixes immersive mode not ending for memory lane
pull/7871/head
martyfuhry 2024-03-11 23:02:28 +07:00 committed by GitHub
parent b7e5407822
commit de28f83d0d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 109 additions and 113 deletions

@ -39,11 +39,13 @@ class MemoryPage extends HookConsumerWidget {
/// The main vertically scrolling page controller with each list of memories /// The main vertically scrolling page controller with each list of memories
final memoryPageController = usePageController(initialPage: memoryIndex); final memoryPageController = usePageController(initialPage: memoryIndex);
// The Page Controller that scrolls horizontally with all of the assets
useEffect(() { useEffect(() {
// Memories is an immersive activity // Memories is an immersive activity
SystemChrome.setEnabledSystemUIMode(SystemUiMode.immersive); SystemChrome.setEnabledSystemUIMode(SystemUiMode.immersive);
return null; return () {
// Clean up to normal edge to edge when we are done
SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
};
}); });
toNextMemory() { toNextMemory() {
@ -159,127 +161,121 @@ class MemoryPage extends HookConsumerWidget {
}, },
child: Scaffold( child: Scaffold(
backgroundColor: bgColor, backgroundColor: bgColor,
body: PopScope( body: SafeArea(
onPopInvoked: (didPop) { child: PageView.builder(
// Remove immersive mode and go back to normal mode physics: const BouncingScrollPhysics(
SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge); parent: AlwaysScrollableScrollPhysics(),
}, ),
child: SafeArea( scrollDirection: Axis.vertical,
child: PageView.builder( controller: memoryPageController,
physics: const BouncingScrollPhysics( onPageChanged: (pageNumber) {
parent: AlwaysScrollableScrollPhysics(), HapticFeedback.mediumImpact();
), if (pageNumber < memories.length) {
scrollDirection: Axis.vertical, currentMemoryIndex.value = pageNumber;
controller: memoryPageController, currentMemory.value = memories[pageNumber];
onPageChanged: (pageNumber) { }
HapticFeedback.mediumImpact();
if (pageNumber < memories.length) {
currentMemoryIndex.value = pageNumber;
currentMemory.value = memories[pageNumber];
}
currentAssetPage.value = 0; currentAssetPage.value = 0;
updateProgressText(); updateProgressText();
}, },
itemCount: memories.length + 1, itemCount: memories.length + 1,
itemBuilder: (context, mIndex) { itemBuilder: (context, mIndex) {
// Build last page // Build last page
if (mIndex == memories.length) { if (mIndex == memories.length) {
return MemoryEpilogue( return MemoryEpilogue(
onStartOver: () => memoryPageController.animateToPage( onStartOver: () => memoryPageController.animateToPage(
0, 0,
duration: const Duration(seconds: 1), duration: const Duration(seconds: 1),
curve: Curves.easeInOut, curve: Curves.easeInOut,
),
);
}
// Build horizontal page
final assetController = memoryAssetPageControllers[mIndex];
return Column(
children: [
Padding(
padding: const EdgeInsets.only(
left: 24.0,
right: 24.0,
top: 8.0,
bottom: 2.0,
), ),
); child: AnimatedBuilder(
} animation: assetController,
// Build horizontal page builder: (context, child) {
final assetController = memoryAssetPageControllers[mIndex]; double value = 0.0;
return Column( if (assetController.hasClients) {
children: [ // We can only access [page] if this has clients
Padding( value = assetController.page ?? 0;
padding: const EdgeInsets.only( }
left: 24.0, return MemoryProgressIndicator(
right: 24.0, ticks: memories[mIndex].assets.length,
top: 8.0, value: (value + 1) / memories[mIndex].assets.length,
bottom: 2.0, );
), },
child: AnimatedBuilder(
animation: assetController,
builder: (context, child) {
double value = 0.0;
if (assetController.hasClients) {
// We can only access [page] if this has clients
value = assetController.page ?? 0;
}
return MemoryProgressIndicator(
ticks: memories[mIndex].assets.length,
value: (value + 1) / memories[mIndex].assets.length,
);
},
),
), ),
Expanded( ),
child: Stack( Expanded(
children: [ child: Stack(
PageView.builder( children: [
physics: const BouncingScrollPhysics( PageView.builder(
parent: AlwaysScrollableScrollPhysics(), physics: const BouncingScrollPhysics(
), parent: AlwaysScrollableScrollPhysics(),
controller: assetController,
onPageChanged: onAssetChanged,
scrollDirection: Axis.horizontal,
itemCount: memories[mIndex].assets.length,
itemBuilder: (context, index) {
final asset = memories[mIndex].assets[index];
return GestureDetector(
behavior: HitTestBehavior.translucent,
onTap: () {
toNextAsset(index);
},
child: Container(
color: Colors.black,
child: MemoryCard(
asset: asset,
title: memories[mIndex].title,
showTitle: index == 0,
),
),
);
},
), ),
Positioned( controller: assetController,
top: 8, onPageChanged: onAssetChanged,
left: 8, scrollDirection: Axis.horizontal,
child: MaterialButton( itemCount: memories[mIndex].assets.length,
minWidth: 0, itemBuilder: (context, index) {
onPressed: () { final asset = memories[mIndex].assets[index];
// auto_route doesn't invoke pop scope, so return GestureDetector(
// turn off full screen mode here behavior: HitTestBehavior.translucent,
// https://github.com/Milad-Akarie/auto_route_library/issues/1799 onTap: () {
context.popRoute(); toNextAsset(index);
SystemChrome.setEnabledSystemUIMode(
SystemUiMode.edgeToEdge,
);
}, },
shape: const CircleBorder(), child: Container(
color: Colors.white.withOpacity(0.2), color: Colors.black,
elevation: 0, child: MemoryCard(
child: const Icon( asset: asset,
Icons.close_rounded, title: memories[mIndex].title,
color: Colors.white, showTitle: index == 0,
),
), ),
);
},
),
Positioned(
top: 8,
left: 8,
child: MaterialButton(
minWidth: 0,
onPressed: () {
// auto_route doesn't invoke pop scope, so
// turn off full screen mode here
// https://github.com/Milad-Akarie/auto_route_library/issues/1799
context.popRoute();
SystemChrome.setEnabledSystemUIMode(
SystemUiMode.edgeToEdge,
);
},
shape: const CircleBorder(),
color: Colors.white.withOpacity(0.2),
elevation: 0,
child: const Icon(
Icons.close_rounded,
color: Colors.white,
), ),
), ),
], ),
), ],
), ),
MemoryBottomInfo(memory: memories[mIndex]), ),
], MemoryBottomInfo(memory: memories[mIndex]),
); ],
}, );
), },
), ),
), ),
), ),