Add cupertino page routes for all full-screen dialogs

This commit is contained in:
Shawn 2022-12-08 18:50:27 -07:00
parent 4205cc0b00
commit a4f2daffec
6 changed files with 32 additions and 28 deletions

View File

@ -1,6 +1,7 @@
import 'dart:async';
import 'package:desktop_window/desktop_window.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter_displaymode/flutter_displaymode.dart';
import 'package:wonders/common_libs.dart';
import 'package:wonders/logic/common/platform_info.dart';

View File

@ -1,17 +1,21 @@
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
class PageRoutes {
static const Duration kDefaultDuration = Duration(milliseconds: 300);
static Route<T> dialog<T>(Widget child, [Duration duration = kDefaultDuration, bool opaque = false]) {
return PageRouteBuilder<T>(
transitionDuration: duration,
reverseTransitionDuration: duration,
pageBuilder: (context, animation, secondaryAnimation) => child,
opaque: opaque,
fullscreenDialog: true,
transitionsBuilder: (context, animation, secondaryAnimation, child) =>
FadeTransition(opacity: animation, child: child),
);
// Use cupertino routes for all dialogs so we get the 'swipe right to go back' behavior
return CupertinoPageRoute(builder: (_) => child);
// SB: Removed this in favor of Cupertino routes, we could restor with a `useFade` option
// return PageRouteBuilder<T>(
// transitionDuration: duration,
// reverseTransitionDuration: duration,
// pageBuilder: (context, animation, secondaryAnimation) => child,
// opaque: opaque,
// fullscreenDialog: true,
// transitionsBuilder: (context, animation, secondaryAnimation, child) =>
// FadeTransition(opacity: animation, child: child),
// );
}
}

View File

@ -5,8 +5,8 @@ import 'package:wonders/ui/common/controls/app_loading_indicator.dart';
import 'package:wonders/ui/common/gradient_container.dart';
import 'package:wonders/ui/common/modals/fullscreen_url_img_viewer.dart';
part 'widgets/_content.dart';
part 'widgets/_header.dart';
part 'widgets/_info_column.dart';
part 'widgets/_image_btn.dart';
class ArtifactDetailsScreen extends StatefulWidget {
const ArtifactDetailsScreen({Key? key, required this.artifactId}) : super(key: key);
@ -36,8 +36,8 @@ class _ArtifactDetailsScreenState extends State<ArtifactDetailsScreen> {
} else {
content = hzMode
? Row(children: [
Expanded(child: _Header(data: data!)),
Expanded(child: Center(child: SizedBox(width: 600, child: _Content(data: data)))),
Expanded(child: _ImageBtn(data: data!)),
Expanded(child: Center(child: SizedBox(width: 600, child: _InfoColumn(data: data)))),
])
: CustomScrollView(
slivers: [
@ -47,9 +47,9 @@ class _ArtifactDetailsScreenState extends State<ArtifactDetailsScreen> {
leading: SizedBox.shrink(),
expandedHeight: context.heightPx * .5,
collapsedHeight: context.heightPx * .35,
flexibleSpace: _Header(data: data!),
flexibleSpace: _ImageBtn(data: data!),
),
SliverToBoxAdapter(child: _Content(data: data)),
SliverToBoxAdapter(child: _InfoColumn(data: data)),
],
);
}

View File

@ -1,7 +1,7 @@
part of '../artifact_details_screen.dart';
class _Header extends StatelessWidget {
const _Header({Key? key, required this.data}) : super(key: key);
class _ImageBtn extends StatelessWidget {
const _ImageBtn({Key? key, required this.data}) : super(key: key);
final ArtifactData data;
@override

View File

@ -1,7 +1,7 @@
part of '../artifact_details_screen.dart';
class _Content extends StatelessWidget {
const _Content({Key? key, required this.data}) : super(key: key);
class _InfoColumn extends StatelessWidget {
const _InfoColumn({Key? key, required this.data}) : super(key: key);
final ArtifactData data;
@override

View File

@ -107,15 +107,14 @@ class _PhotoGalleryState extends State<PhotoGallery> {
Future<void> _handleImageTapped(int index) async {
if (_index == index) {
int? newIndex = await Navigator.push(
final urls = _photoIds.value.map((e) {
return UnsplashPhotoData.getSelfHostedUrl(e, UnsplashPhotoSize.med);
}).toList();
int? newIndex = await appLogic.showFullscreenDialogRoute(
context,
CupertinoPageRoute(builder: (_) {
final urls = _photoIds.value.map((e) {
return UnsplashPhotoData.getSelfHostedUrl(e, UnsplashPhotoSize.med);
}).toList();
return FullscreenUrlImgViewer(urls: urls, index: _index);
}),
FullscreenUrlImgViewer(urls: urls, index: _index),
);
if (newIndex != null) {
_setIndex(newIndex, skipAnimation: true);
}
@ -148,7 +147,7 @@ class _PhotoGalleryState extends State<PhotoGallery> {
gridOffset += Offset(0, -context.mq.padding.top / 2);
final offsetTweenDuration = _skipNextOffsetTween ? Duration.zero : swipeDuration;
final cutoutTweenDuration = _skipNextOffsetTween ? Duration.zero : swipeDuration * .5;
return _AnimatedCutoutOverlay(
return _AnimatedCutoutOverlay(
animationKey: ValueKey(_index),
cutoutSize: imgSize,
swipeDir: _lastSwipeDir,