fix(player): 评论输入改为透明浮层并消除收起键盘抖动
This commit is contained in:
1 parent
5b4526cb97
commit
4908dc9d76
3 files changed
+198
-147
No files matched your search
@@ -41,6 +41,7 @@ class DramaCommentsSheet extends StatefulWidget {
|
||||
class _DramaCommentsSheetState extends State<DramaCommentsSheet> {
|
||||
late final CommentRepository _comments;
|
||||
late final CommentController _controller;
|
||||
OverlayEntry? _composerOverlay;
|
||||
OverlayEntry? _successOverlay;
|
||||
Timer? _successOverlayTimer;
|
||||
int? _serverCount;
|
||||
@@ -61,6 +62,7 @@ class _DramaCommentsSheetState extends State<DramaCommentsSheet> {
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_removeComposerOverlay();
|
||||
_successOverlayTimer?.cancel();
|
||||
_successOverlay?.remove();
|
||||
_controller.dispose();
|
||||
@@ -86,20 +88,38 @@ class _DramaCommentsSheetState extends State<DramaCommentsSheet> {
|
||||
Future<void> _openComposer({DramaComment? replyTo}) async {
|
||||
await ensureSignedIn(context);
|
||||
if (!mounted || !context.read<AuthController>().isSignedIn) return;
|
||||
final published = await showModalBottomSheet<bool>(
|
||||
context: context,
|
||||
isScrollControlled: true,
|
||||
isDismissible: true,
|
||||
backgroundColor: Colors.transparent,
|
||||
barrierColor: Colors.transparent,
|
||||
showDragHandle: false,
|
||||
builder: (_) =>
|
||||
CommentComposerSheet(controller: _controller, replyTo: replyTo),
|
||||
_removeComposerOverlay();
|
||||
final entry = OverlayEntry(
|
||||
builder: (_) => CommentComposerSheet(
|
||||
controller: _controller,
|
||||
replyTo: replyTo,
|
||||
onDismiss: _closeComposer,
|
||||
onPosted: _handleComposerPosted,
|
||||
),
|
||||
);
|
||||
if (published == true && mounted) {
|
||||
_showPostSuccess();
|
||||
await _refreshCount();
|
||||
setState(() => _composerOverlay = entry);
|
||||
Overlay.of(context, rootOverlay: true).insert(entry);
|
||||
}
|
||||
|
||||
void _handleComposerPosted() {
|
||||
_closeComposer();
|
||||
_showPostSuccess();
|
||||
unawaited(_refreshCount());
|
||||
}
|
||||
|
||||
void _closeComposer() {
|
||||
if (!mounted) {
|
||||
_removeComposerOverlay();
|
||||
return;
|
||||
}
|
||||
setState(_removeComposerOverlay);
|
||||
}
|
||||
|
||||
void _removeComposerOverlay() {
|
||||
final entry = _composerOverlay;
|
||||
_composerOverlay = null;
|
||||
if (entry?.mounted ?? false) entry!.remove();
|
||||
FocusManager.instance.primaryFocus?.unfocus();
|
||||
}
|
||||
|
||||
void _handleDismissLayerTap() {
|
||||
@@ -133,7 +153,7 @@ class _DramaCommentsSheetState extends State<DramaCommentsSheet> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final sheetHeight = _sheetHeight(context);
|
||||
return Stack(
|
||||
final content = Stack(
|
||||
fit: StackFit.expand,
|
||||
children: [
|
||||
Positioned.fill(
|
||||
@@ -179,6 +199,13 @@ class _DramaCommentsSheetState extends State<DramaCommentsSheet> {
|
||||
),
|
||||
],
|
||||
);
|
||||
return PopScope(
|
||||
canPop: _composerOverlay == null,
|
||||
onPopInvokedWithResult: (didPop, _) {
|
||||
if (!didPop && _composerOverlay != null) _closeComposer();
|
||||
},
|
||||
child: content,
|
||||
);
|
||||
}
|
||||
|
||||
Widget _content(BuildContext context) {
|
||||
|
||||
Reference in new issue
Block a user