From 3b5e5da3ac9922e56c2623758a0bae43977cd4be Mon Sep 17 00:00:00 2001 From: Pratiksha Khandagale Date: Mon, 3 Jun 2024 14:22:29 +0530 Subject: [PATCH] Keyboard issue fixed --- .../bot-messages/bot-messages.component.html | 30 +++++++----- .../bot-messages/bot-messages.component.scss | 25 +++++++++- .../bot-messages/bot-messages.component.ts | 49 +++++++++++++++++-- 3 files changed, 85 insertions(+), 19 deletions(-) diff --git a/src/app/components/bot-messages/bot-messages.component.html b/src/app/components/bot-messages/bot-messages.component.html index 3b9448d..31b0270 100644 --- a/src/app/components/bot-messages/bot-messages.component.html +++ b/src/app/components/bot-messages/bot-messages.component.html @@ -1,4 +1,4 @@ - +
@@ -15,7 +15,7 @@
- {{msg?.time}} + {{msg?.time}}
@@ -29,8 +29,11 @@
-
- + + +
+ - +
- - {{durationDisplay}} + + {{durationDisplay}}
- << {{'Swipe left to cancel' | translate }} - - - + << {{'Swipe left to cancel' | translate }} + + +
- +
diff --git a/src/app/components/bot-messages/bot-messages.component.scss b/src/app/components/bot-messages/bot-messages.component.scss index 9bbe265..d778b35 100644 --- a/src/app/components/bot-messages/bot-messages.component.scss +++ b/src/app/components/bot-messages/bot-messages.component.scss @@ -41,7 +41,7 @@ ion-content{ } } .bot-input { - position: fixed; + // position: fixed !important; bottom: 0; width: 100%; padding: 1rem; @@ -94,6 +94,11 @@ ion-content{ } } +.keyboard-open { + transform: translateY(-50%); } + + + .audio_msg { display: flex; @@ -141,4 +146,20 @@ ion-content{ .unlike { transform: scale(-1); margin-left: 0.75rem !important; -} \ No newline at end of file +} +ion-content { + --padding-bottom: 60px; /* Adjust this value if needed to prevent the input from hiding */ + } + + ion-footer { + ion-toolbar { + display: flex; + align-items: center; + ion-input { + flex: 1; + } + ion-button { + margin-left: 10px; + } + } + } diff --git a/src/app/components/bot-messages/bot-messages.component.ts b/src/app/components/bot-messages/bot-messages.component.ts index 60b60c8..2dd9855 100644 --- a/src/app/components/bot-messages/bot-messages.component.ts +++ b/src/app/components/bot-messages/bot-messages.component.ts @@ -33,6 +33,8 @@ export class BotMessagesComponent implements OnInit, AfterViewInit { disabled = false; audioRef!: HTMLAudioElement; keyboardOpen: boolean = false; + keyboardHeight: number = 0; + constructor( private record: RecordingService, private ngZone: NgZone, @@ -60,10 +62,17 @@ export class BotMessagesComponent implements OnInit, AfterViewInit { this.handleBackNavigation(); } }) - Keyboard.addListener('keyboardWillShow', () => { - console.log('keyboard will show'); - this.content.scrollToBottom(); - }) + + Keyboard.addListener('keyboardWillShow', (info) => { + this.keyboardHeight = info.keyboardHeight; + this.adjustForKeyboard(); + }); + + Keyboard.addListener('keyboardWillHide', () => { + this.keyboardHeight = 0; + this.adjustForKeyboard(); + }); + this.record.startEndEvent$.subscribe((res: any) => { this.ngZone.run(() => { this.startRecording = res; @@ -85,6 +94,28 @@ export class BotMessagesComponent implements OnInit, AfterViewInit { }); } + private adjustForKeyboard() { + const inputElement = document.querySelector('ion-footer'); + if (inputElement) { + (inputElement as HTMLElement).style.marginBottom = `${this.keyboardHeight}px`; + } + + const contentElement = document.querySelector('ion-content'); + if (contentElement) { + (contentElement as HTMLElement).style.bottom = `${this.keyboardHeight}px`; + } + this.scrollToBottom(); + } + + + public scrollToBottom() { + this.keyboardOpen = true; + + setTimeout(() => { + this.content.scrollToBottom(300); + }, 100); + } + ngOnChanges() { console.log('ng onchanges ', this.config); if (this.config?.notification && this.config?.notif?.body) { @@ -95,10 +126,20 @@ export class BotMessagesComponent implements OnInit, AfterViewInit { onInputFocus() { this.keyboardOpen = true; + Keyboard.addListener('keyboardWillShow', () => { + setTimeout(() => this.scrollToBottom(), 300); + }); } onInputBlur() { this.keyboardOpen = false; + Keyboard.removeAllListeners(); + + } + + ngOnDestroy() { + // Remove keyboard event listeners + Keyboard.removeAllListeners(); } ionViewWillEnter() {