fix(player): 收起键盘不关闭评论输入弹窗
This commit is contained in:
1 parent
f9f77090d9
commit
cb58f649c1
2 files changed
+36
-40
No files matched your search
@@ -35,21 +35,16 @@ class CommentComposerSheet extends StatefulWidget {
|
||||
State<CommentComposerSheet> createState() => _CommentComposerSheetState();
|
||||
}
|
||||
|
||||
class _CommentComposerSheetState extends State<CommentComposerSheet>
|
||||
with WidgetsBindingObserver {
|
||||
class _CommentComposerSheetState extends State<CommentComposerSheet> {
|
||||
final _input = TextEditingController();
|
||||
final _inputFocus = FocusNode();
|
||||
final _keyboardInset = KeyboardInsetNotifier.instance;
|
||||
bool _keyboardWasVisible = false;
|
||||
bool _hadFocus = false;
|
||||
bool _closing = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
WidgetsBinding.instance.addObserver(this);
|
||||
_input.addListener(_onInputChanged);
|
||||
_inputFocus.addListener(_onFocusChanged);
|
||||
_keyboardInset.addListener(_onKeyboardInsetChanged);
|
||||
widget.controller.addListener(_onControllerChanged);
|
||||
unawaited(_keyboardInset.start());
|
||||
@@ -57,9 +52,7 @@ class _CommentComposerSheetState extends State<CommentComposerSheet>
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
WidgetsBinding.instance.removeObserver(this);
|
||||
_input.removeListener(_onInputChanged);
|
||||
_inputFocus.removeListener(_onFocusChanged);
|
||||
_keyboardInset.removeListener(_onKeyboardInsetChanged);
|
||||
widget.controller.removeListener(_onControllerChanged);
|
||||
_input.dispose();
|
||||
@@ -75,36 +68,9 @@ class _CommentComposerSheetState extends State<CommentComposerSheet>
|
||||
if (mounted) setState(() {});
|
||||
}
|
||||
|
||||
void _onFocusChanged() {
|
||||
if (!mounted) return;
|
||||
final hasFocus = _inputFocus.hasFocus;
|
||||
if (_hadFocus && !hasFocus) {
|
||||
_closeSheet();
|
||||
}
|
||||
_hadFocus = hasFocus;
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
void _onKeyboardInsetChanged() {
|
||||
if (!mounted) return;
|
||||
setState(() {});
|
||||
_syncKeyboardVisibility(_keyboardHeight(context));
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeMetrics() {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (!mounted) return;
|
||||
_syncKeyboardVisibility(_keyboardHeight(context));
|
||||
});
|
||||
}
|
||||
|
||||
void _syncKeyboardVisibility(double keyboardHeight) {
|
||||
if (keyboardHeight > 0) {
|
||||
_keyboardWasVisible = true;
|
||||
return;
|
||||
}
|
||||
if (_keyboardWasVisible) _closeSheet();
|
||||
}
|
||||
|
||||
double _keyboardHeight(BuildContext context) => math.max(
|
||||
@@ -254,10 +220,6 @@ class _CommentComposerSheetState extends State<CommentComposerSheet>
|
||||
focusedBorder: InputBorder.none,
|
||||
),
|
||||
onTap: signedIn ? null : _authenticate,
|
||||
onTapOutside: (_) {
|
||||
_inputFocus.unfocus();
|
||||
_closeSheet();
|
||||
},
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
|
||||
Reference in new issue
Block a user