mirror of
https://github.com/flutter/holobooth.git
synced 2025-07-01 20:17:30 +08:00
chore: dont display portal animation on mobile (#397)
* chore: dont display portal animation on mobile * chore: tests * chore: fix
This commit is contained in:
2
.vscode/tasks.json
vendored
2
.vscode/tasks.json
vendored
@ -24,7 +24,7 @@
|
||||
{
|
||||
"label": "flutter: Run coverage",
|
||||
"type": "shell",
|
||||
"command": "cd ${input:flutterFolder} && very_good test --test-randomize-ordering-seed random --coverage && genhtml ./coverage/lcov.info -o coverage && open ./coverage/index.html",
|
||||
"command": "cd ${input:flutterFolder} && very_good test --no-optimization --test-randomize-ordering-seed random --coverage && genhtml ./coverage/lcov.info -o coverage && open ./coverage/index.html",
|
||||
"problemMatcher": []
|
||||
},
|
||||
{
|
||||
|
@ -46,7 +46,7 @@ class ShareView extends StatelessWidget {
|
||||
Positioned.fill(
|
||||
child: Column(
|
||||
children: [
|
||||
const Expanded(child: ShareBody()),
|
||||
Expanded(child: ShareBody()),
|
||||
FullFooter(),
|
||||
],
|
||||
),
|
||||
|
@ -5,9 +5,15 @@ import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:holobooth/convert/convert.dart';
|
||||
import 'package:holobooth/share/share.dart';
|
||||
import 'package:holobooth_ui/holobooth_ui.dart';
|
||||
import 'package:platform_helper/platform_helper.dart';
|
||||
|
||||
class ShareBody extends StatelessWidget {
|
||||
const ShareBody({super.key});
|
||||
ShareBody({
|
||||
super.key,
|
||||
PlatformHelper? platformHelper,
|
||||
}) : _platformHelper = platformHelper ?? PlatformHelper();
|
||||
|
||||
final PlatformHelper _platformHelper;
|
||||
|
||||
@visibleForTesting
|
||||
static const portalVideoButtonKey = Key(
|
||||
@ -16,11 +22,12 @@ class ShareBody extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final isMobile = _platformHelper.isMobile;
|
||||
return Align(
|
||||
child: SingleChildScrollView(
|
||||
child: ResponsiveLayoutBuilder(
|
||||
small: (context, _) => const SmallShareBody(),
|
||||
large: (context, _) => const LargeShareBody(),
|
||||
small: (context, _) => SmallShareBody(isMobile: isMobile),
|
||||
large: (context, _) => LargeShareBody(isMobile: isMobile),
|
||||
),
|
||||
),
|
||||
);
|
||||
@ -29,17 +36,19 @@ class ShareBody extends StatelessWidget {
|
||||
|
||||
@visibleForTesting
|
||||
class SmallShareBody extends StatelessWidget {
|
||||
const SmallShareBody({super.key});
|
||||
const SmallShareBody({super.key, required this.isMobile});
|
||||
|
||||
final bool isMobile;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final thumbnail = context.read<ConvertBloc>().state.firstFrameProcessed;
|
||||
return Column(
|
||||
children: [
|
||||
if (thumbnail != null)
|
||||
if (thumbnail != null && !isMobile)
|
||||
SizedBox(
|
||||
height: 450,
|
||||
child: _PortalAnimation(
|
||||
child: PortalAnimationView(
|
||||
thumbnail: thumbnail,
|
||||
mode: PortalMode.portrait,
|
||||
),
|
||||
@ -53,7 +62,9 @@ class SmallShareBody extends StatelessWidget {
|
||||
|
||||
@visibleForTesting
|
||||
class LargeShareBody extends StatelessWidget {
|
||||
const LargeShareBody({super.key});
|
||||
const LargeShareBody({super.key, required this.isMobile});
|
||||
|
||||
final bool isMobile;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@ -65,12 +76,12 @@ class LargeShareBody extends StatelessWidget {
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Expanded(
|
||||
child: thumbnail != null
|
||||
child: thumbnail != null && !isMobile
|
||||
? SizedBox(
|
||||
width: 450,
|
||||
height: 450,
|
||||
child: Align(
|
||||
child: _PortalAnimation(
|
||||
child: PortalAnimationView(
|
||||
thumbnail: thumbnail,
|
||||
mode: PortalMode.landscape,
|
||||
),
|
||||
@ -87,8 +98,10 @@ class LargeShareBody extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
class _PortalAnimation extends StatefulWidget {
|
||||
const _PortalAnimation({
|
||||
@visibleForTesting
|
||||
class PortalAnimationView extends StatefulWidget {
|
||||
const PortalAnimationView({
|
||||
super.key,
|
||||
required this.thumbnail,
|
||||
required this.mode,
|
||||
});
|
||||
@ -97,10 +110,10 @@ class _PortalAnimation extends StatefulWidget {
|
||||
final PortalMode mode;
|
||||
|
||||
@override
|
||||
State<_PortalAnimation> createState() => _PortalAnimationState();
|
||||
State<PortalAnimationView> createState() => _PortalAnimationViewState();
|
||||
}
|
||||
|
||||
class _PortalAnimationState extends State<_PortalAnimation> {
|
||||
class _PortalAnimationViewState extends State<PortalAnimationView> {
|
||||
var _completed = false;
|
||||
final _key = GlobalKey();
|
||||
|
||||
|
@ -9,6 +9,7 @@ import 'package:holobooth/convert/convert.dart';
|
||||
import 'package:holobooth/photo_booth/photo_booth.dart';
|
||||
import 'package:holobooth/share/share.dart';
|
||||
import 'package:mocktail/mocktail.dart';
|
||||
import 'package:platform_helper/platform_helper.dart';
|
||||
|
||||
import '../../helpers/helpers.dart';
|
||||
|
||||
@ -18,11 +19,14 @@ class _MockConvertBloc extends MockBloc<ConvertEvent, ConvertState>
|
||||
class _MockDownloadBloc extends MockBloc<DownloadEvent, DownloadState>
|
||||
implements DownloadBloc {}
|
||||
|
||||
class _MockPlatformHelper extends Mock implements PlatformHelper {}
|
||||
|
||||
void main() {
|
||||
group('ShareBody', () {
|
||||
late ConvertBloc convertBloc;
|
||||
late DownloadBloc downloadBloc;
|
||||
late Uint8List thumbnail;
|
||||
late PlatformHelper platformHelper;
|
||||
|
||||
setUp(() async {
|
||||
convertBloc = _MockConvertBloc();
|
||||
@ -34,6 +38,8 @@ void main() {
|
||||
|
||||
downloadBloc = _MockDownloadBloc();
|
||||
when(() => downloadBloc.state).thenReturn(const DownloadState());
|
||||
|
||||
platformHelper = _MockPlatformHelper();
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
@ -49,6 +55,34 @@ void main() {
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'does not render PortalAnimationView on SmallShareBody if mobile',
|
||||
(WidgetTester tester) async {
|
||||
tester.setSmallDisplaySize();
|
||||
when(() => platformHelper.isMobile).thenReturn(true);
|
||||
await tester.pumpSubject(
|
||||
ShareBody(platformHelper: platformHelper),
|
||||
convertBloc: convertBloc,
|
||||
downloadBloc: downloadBloc,
|
||||
);
|
||||
expect(find.byType(PortalAnimationView), findsNothing);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'renders PortalAnimationView on SmallShareBody if desktop',
|
||||
(WidgetTester tester) async {
|
||||
tester.setSmallDisplaySize();
|
||||
when(() => platformHelper.isMobile).thenReturn(false);
|
||||
await tester.pumpSubject(
|
||||
ShareBody(platformHelper: platformHelper),
|
||||
convertBloc: convertBloc,
|
||||
downloadBloc: downloadBloc,
|
||||
);
|
||||
expect(find.byType(PortalAnimationView), findsOneWidget);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'renders LargeShareBody in large layout',
|
||||
(WidgetTester tester) async {
|
||||
@ -62,6 +96,36 @@ void main() {
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'does not render PortalAnimationView on LargeShareBody if mobile',
|
||||
(WidgetTester tester) async {
|
||||
tester.setLargeDisplaySize();
|
||||
when(() => platformHelper.isMobile).thenReturn(true);
|
||||
|
||||
await tester.pumpSubject(
|
||||
ShareBody(platformHelper: platformHelper),
|
||||
convertBloc: convertBloc,
|
||||
downloadBloc: downloadBloc,
|
||||
);
|
||||
expect(find.byType(PortalAnimationView), findsNothing);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'renders PortalAnimationView on LargeShareBody if desktop',
|
||||
(WidgetTester tester) async {
|
||||
tester.setLargeDisplaySize();
|
||||
when(() => platformHelper.isMobile).thenReturn(false);
|
||||
|
||||
await tester.pumpSubject(
|
||||
ShareBody(platformHelper: platformHelper),
|
||||
convertBloc: convertBloc,
|
||||
downloadBloc: downloadBloc,
|
||||
);
|
||||
expect(find.byType(PortalAnimationView), findsOneWidget);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('displays a ShareButton', (tester) async {
|
||||
await tester.pumpSubject(
|
||||
ShareBody(),
|
||||
@ -96,8 +160,9 @@ void main() {
|
||||
});
|
||||
|
||||
testWidgets('displays a PortalAnimation', (tester) async {
|
||||
when(() => platformHelper.isMobile).thenReturn(false);
|
||||
await tester.pumpSubject(
|
||||
ShareBody(),
|
||||
ShareBody(platformHelper: platformHelper),
|
||||
convertBloc: convertBloc,
|
||||
downloadBloc: downloadBloc,
|
||||
);
|
||||
@ -110,8 +175,9 @@ void main() {
|
||||
testWidgets(
|
||||
'PortalAnimation is Clickable when animation is completed',
|
||||
(tester) async {
|
||||
when(() => platformHelper.isMobile).thenReturn(false);
|
||||
await tester.pumpSubject(
|
||||
ShareBody(),
|
||||
ShareBody(platformHelper: platformHelper),
|
||||
convertBloc: convertBloc,
|
||||
downloadBloc: downloadBloc,
|
||||
);
|
||||
@ -129,8 +195,9 @@ void main() {
|
||||
testWidgets(
|
||||
'Open the video dialog upon clicking the Portal',
|
||||
(tester) async {
|
||||
when(() => platformHelper.isMobile).thenReturn(false);
|
||||
await tester.pumpSubject(
|
||||
ShareBody(),
|
||||
ShareBody(platformHelper: platformHelper),
|
||||
convertBloc: convertBloc,
|
||||
downloadBloc: downloadBloc,
|
||||
);
|
||||
|
Reference in New Issue
Block a user