feat: add composer autofocus management for improved chat input experience
- Introduced ComposerAutofocusEnabled provider to manage the auto-focus state of the chat composer, allowing for better control over user interactions. - Updated ModernChatInput to respect the autofocus setting, ensuring the keyboard behavior aligns with user intent and context. - Enhanced ChatPage to suppress auto-focus when opening the slide drawer, improving user experience during navigation. - Refactored SlideDrawer to include an onOpenStart callback for dismissing the keyboard, ensuring a smoother transition when the drawer is opened.
This commit is contained in:
@@ -158,7 +158,12 @@ class _ModernChatInputState extends ConsumerState<ModernChatInput>
|
||||
}
|
||||
|
||||
void _ensureFocusedIfEnabled() {
|
||||
if (!widget.enabled || _focusNode.hasFocus || _pendingFocus) {
|
||||
// Respect global suppression flag to avoid re-opening keyboard
|
||||
final autofocusEnabled = ref.read(composerAutofocusEnabledProvider);
|
||||
if (!widget.enabled ||
|
||||
_focusNode.hasFocus ||
|
||||
_pendingFocus ||
|
||||
!autofocusEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -629,7 +634,8 @@ class _ModernChatInputState extends ConsumerState<ModernChatInput>
|
||||
final selectedToolIds = ref.watch(selectedToolIdsProvider);
|
||||
|
||||
final focusTick = ref.watch(inputFocusTriggerProvider);
|
||||
if (focusTick != _lastHandledFocusTick) {
|
||||
final autofocusEnabled = ref.watch(composerAutofocusEnabledProvider);
|
||||
if (autofocusEnabled && focusTick != _lastHandledFocusTick) {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (!mounted || _isDeactivated) return;
|
||||
_ensureFocusedIfEnabled();
|
||||
@@ -1010,6 +1016,10 @@ class _ModernChatInputState extends ConsumerState<ModernChatInput>
|
||||
behavior: HitTestBehavior.opaque,
|
||||
onTap: () {
|
||||
if (!widget.enabled) return;
|
||||
// Explicit user intent to focus: re-enable autofocus and focus
|
||||
try {
|
||||
ref.read(composerAutofocusEnabledProvider.notifier).set(true);
|
||||
} catch (_) {}
|
||||
_ensureFocusedIfEnabled();
|
||||
},
|
||||
child: Semantics(
|
||||
|
||||
Reference in New Issue
Block a user