fix(player): 评论面板自适应高度并只顶起输入框

This commit is contained in:
Zhou Weidong committed 2026-10-21 12:07:30 +08:00
1 parent 97735763a1
commit ab476cab7d
3 files changed
+266 -99

No files matched your search

+105 -1
View File
@@ -305,6 +305,101 @@ void main() {
);
});
testWidgets('should_size_short_list_to_content', (tester) async {
tester.view.physicalSize = const Size(390, 844);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
final repository = FakeCommentRepository(
pages: [
CommentPage(
comments: [
commentFixture(id: '10', content: 'Short list one'),
commentFixture(id: '11', content: 'Short list two'),
],
),
],
);
await _pumpSheet(tester, repository: repository);
final sheet = find.byKey(const Key('player-comments-sheet'));
expect(tester.getSize(sheet).height, lessThan(520));
final lastCommentBottom = tester
.getBottomLeft(find.byKey(const Key('comment-item-11')))
.dy;
final composerTop = tester
.getTopLeft(find.byKey(const Key('comment-composer')))
.dy;
expect(composerTop - lastCommentBottom, lessThan(80));
});
testWidgets('should_keep_minimum_height_for_empty_state', (tester) async {
final repository = FakeCommentRepository(pages: [const CommentPage()]);
await _pumpSheet(tester, repository: repository);
expect(
tester.getSize(find.byKey(const Key('player-comments-sheet'))).height,
greaterThanOrEqualTo(220),
);
});
testWidgets('should_keep_long_comment_list_scrollable', (tester) async {
tester.view.physicalSize = const Size(390, 844);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
final repository = FakeCommentRepository(
pages: [CommentPage(comments: _comments(30))],
);
await _pumpSheet(tester, repository: repository);
final scrolledComment = find.byKey(const Key('comment-item-12'));
final before = tester.getTopLeft(scrolledComment).dy;
await tester.drag(
find.byKey(const Key('comment-list')),
const Offset(0, -300),
);
await tester.pumpAndSettle();
expect(tester.getTopLeft(scrolledComment).dy, lessThan(before));
expect(
tester.getSize(find.byKey(const Key('player-comments-sheet'))).height,
520,
);
});
testWidgets('should_keep_sheet_fixed_and_move_only_composer_for_keyboard', (
tester,
) async {
tester.view.physicalSize = const Size(390, 844);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
addTearDown(tester.view.resetViewInsets);
final repository = FakeCommentRepository(
pages: [CommentPage(comments: _comments(30))],
);
await _pumpSheet(tester, repository: repository);
final sheet = find.byKey(const Key('player-comments-sheet'));
final input = find.byKey(const Key('comment-composer'));
final first = find.byKey(const Key('comment-item-10'));
final sheetTop = tester.getTopLeft(sheet).dy;
final inputTop = tester.getTopLeft(input).dy;
final firstTop = tester.getTopLeft(first).dy;
tester.view.viewInsets = const FakeViewPadding(bottom: 180);
await tester.pump();
await tester.pump(const Duration(milliseconds: 160));
expect(tester.getTopLeft(sheet).dy, closeTo(sheetTop, 0.1));
expect(tester.getTopLeft(first).dy, closeTo(firstTop, 0.1));
expect(tester.getTopLeft(input).dy, lessThan(inputTop - 100));
});
testWidgets('should_hide_comment_like_controls', (tester) async {
final repository = FakeCommentRepository(
pages: [
@@ -560,7 +655,11 @@ Future<AuthController> _pumpSheet(
'/': (_) => const Scaffold(backgroundColor: AppColors.ink),
'/comments': (_) => const Scaffold(
backgroundColor: AppColors.ink,
body: DramaCommentsSheet(drama: _drama),
resizeToAvoidBottomInset: false,
body: Align(
alignment: Alignment.bottomCenter,
child: DramaCommentsSheet(drama: _drama),
),
),
},
),
@@ -602,6 +701,11 @@ Future<AuthController> _auth() async {
return auth;
}
List<DramaComment> _comments(int count) => [
for (var index = 0; index < count; index++)
commentFixture(id: '${index + 10}', content: 'Comment ${index + 1}'),
];
class _TestAuthController extends AuthController {
_TestAuthController(super.api, super.store, {required this._signedIn});