Merge pull request #700 from zjs81/fix/translation-sheet-inset-recompute
Recompute translation sheet height cap when insets change
This commit is contained in:
2 files changed
+66
-28
No files matched your search
@@ -41,31 +41,33 @@ Future<void> showMessageTranslationSheet({
|
|||||||
required ValueChanged<bool> onEnabledChanged,
|
required ValueChanged<bool> onEnabledChanged,
|
||||||
required ValueChanged<String?> onLanguageSelected,
|
required ValueChanged<String?> onLanguageSelected,
|
||||||
}) {
|
}) {
|
||||||
final callerMedia = MediaQuery.of(context);
|
|
||||||
final navMedia =
|
|
||||||
MediaQuery.maybeOf(Navigator.of(context).context) ?? callerMedia;
|
|
||||||
final callerBottom = math.max(
|
|
||||||
callerMedia.viewInsets.bottom,
|
|
||||||
math.max(callerMedia.viewPadding.bottom, callerMedia.padding.bottom),
|
|
||||||
);
|
|
||||||
final navBottom = math.max(
|
|
||||||
navMedia.viewInsets.bottom,
|
|
||||||
math.max(navMedia.viewPadding.bottom, navMedia.padding.bottom),
|
|
||||||
);
|
|
||||||
final extraBottom = math.max(0.0, callerBottom - navBottom);
|
|
||||||
final safeTop = math.max(
|
|
||||||
math.max(callerMedia.viewPadding.top, callerMedia.padding.top),
|
|
||||||
math.max(navMedia.viewPadding.top, navMedia.padding.top),
|
|
||||||
);
|
|
||||||
final bottomSafeInset = math.max(
|
|
||||||
math.max(callerMedia.viewPadding.bottom, callerMedia.padding.bottom),
|
|
||||||
math.max(navMedia.viewPadding.bottom, navMedia.padding.bottom),
|
|
||||||
);
|
|
||||||
|
|
||||||
return showMeshSheet<void>(
|
return showMeshSheet<void>(
|
||||||
context,
|
context,
|
||||||
builder: (sheetContext) {
|
builder: (sheetContext) {
|
||||||
final sheetMedia = MediaQuery.of(sheetContext);
|
final sheetMedia = MediaQuery.of(sheetContext);
|
||||||
|
final callerMedia =
|
||||||
|
(context.mounted ? MediaQuery.maybeOf(context) : null) ?? sheetMedia;
|
||||||
|
final navContext = Navigator.maybeOf(sheetContext)?.context;
|
||||||
|
final navMedia =
|
||||||
|
(navContext != null ? MediaQuery.maybeOf(navContext) : null) ??
|
||||||
|
callerMedia;
|
||||||
|
final callerBottom = math.max(
|
||||||
|
callerMedia.viewInsets.bottom,
|
||||||
|
math.max(callerMedia.viewPadding.bottom, callerMedia.padding.bottom),
|
||||||
|
);
|
||||||
|
final navBottom = math.max(
|
||||||
|
navMedia.viewInsets.bottom,
|
||||||
|
math.max(navMedia.viewPadding.bottom, navMedia.padding.bottom),
|
||||||
|
);
|
||||||
|
final extraBottom = math.max(0.0, callerBottom - navBottom);
|
||||||
|
final safeTop = math.max(
|
||||||
|
math.max(callerMedia.viewPadding.top, callerMedia.padding.top),
|
||||||
|
math.max(navMedia.viewPadding.top, navMedia.padding.top),
|
||||||
|
);
|
||||||
|
final bottomSafeInset = math.max(
|
||||||
|
math.max(callerMedia.viewPadding.bottom, callerMedia.padding.bottom),
|
||||||
|
math.max(navMedia.viewPadding.bottom, navMedia.padding.bottom),
|
||||||
|
);
|
||||||
final screenHeight = math.min(
|
final screenHeight = math.min(
|
||||||
callerMedia.size.height,
|
callerMedia.size.height,
|
||||||
sheetMedia.size.height,
|
sheetMedia.size.height,
|
||||||
|
|||||||
@@ -54,13 +54,7 @@ Future<void> _openSheet(
|
|||||||
builder: (context, child) {
|
builder: (context, child) {
|
||||||
final media = MediaQuery.of(context);
|
final media = MediaQuery.of(context);
|
||||||
return MediaQuery(
|
return MediaQuery(
|
||||||
data: media.copyWith(
|
data: media.copyWith(textScaler: TextScaler.linear(textScale)),
|
||||||
size: size,
|
|
||||||
padding: padding,
|
|
||||||
viewPadding: viewPadding,
|
|
||||||
viewInsets: viewInsets,
|
|
||||||
textScaler: TextScaler.linear(textScale),
|
|
||||||
),
|
|
||||||
child: child!,
|
child: child!,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
@@ -128,6 +122,48 @@ void main() {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
testWidgets(
|
||||||
|
'sheet recomputes height cap and expands when keyboard inset closes',
|
||||||
|
(tester) async {
|
||||||
|
await _openSheet(
|
||||||
|
tester,
|
||||||
|
size: const Size(320, 568),
|
||||||
|
padding: const EdgeInsets.only(top: 48),
|
||||||
|
viewPadding: const EdgeInsets.only(top: 48, bottom: 34),
|
||||||
|
viewInsets: const EdgeInsets.only(bottom: 300),
|
||||||
|
);
|
||||||
|
|
||||||
|
final listFinder = find.byType(CustomScrollView);
|
||||||
|
expect(listFinder, findsOneWidget);
|
||||||
|
final compressedHeaderTop = tester
|
||||||
|
.getTopLeft(find.byType(BottomSheetHeader))
|
||||||
|
.dy;
|
||||||
|
final compressedBottom = tester.getBottomLeft(listFinder).dy;
|
||||||
|
final compressedContentHeight = compressedBottom - compressedHeaderTop;
|
||||||
|
expect(compressedContentHeight, lessThanOrEqualTo(220.0));
|
||||||
|
|
||||||
|
// Dismiss the keyboard while the sheet remains open.
|
||||||
|
tester.view.viewInsets = FakeViewPadding.zero;
|
||||||
|
tester.view.padding = const FakeViewPadding(top: 48, bottom: 34);
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
final expandedHeaderTop = tester
|
||||||
|
.getTopLeft(find.byType(BottomSheetHeader))
|
||||||
|
.dy;
|
||||||
|
final expandedListFinder = find.byType(ListView);
|
||||||
|
expect(expandedListFinder, findsOneWidget);
|
||||||
|
final expandedBottom = tester.getBottomLeft(expandedListFinder).dy;
|
||||||
|
final expandedContentHeight = expandedBottom - expandedHeaderTop;
|
||||||
|
|
||||||
|
expect(expandedContentHeight, greaterThan(compressedContentHeight));
|
||||||
|
expect(expandedContentHeight, greaterThan(400.0));
|
||||||
|
expect(
|
||||||
|
tester.getRect(find.byType(BottomSheet)).height,
|
||||||
|
greaterThan(450.0),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
testWidgets(
|
testWidgets(
|
||||||
'toggling switch, filtering languages, and selecting target or app language works',
|
'toggling switch, filtering languages, and selecting target or app language works',
|
||||||
(tester) async {
|
(tester) async {
|
||||||
|
|||||||
Reference in new issue
Block a user