On-screen keyboard covers fixed position input in ionic - ios

I am trying to build a simple messaging view in ionic. My view looks as follows:
Initial screenshot
My problem is when I focus the input on iOs, the keyboard covers the input, however on an Android device, the input moved along with the appearing keyboard as expected.
My understanding that if I use position: fixed and indicate bottom value (say, bottom: 16px) the input should appear 16px above the page fold both when the keyboard is open and when it isn't.
For reference, this is the result I get when I try to focus the input on an actual iOs device.
On-screen keyboard covers up input

I had this problem with ion-textarea. I'm using ionic 4 beta 17 - ionic keyboard 2.1.3
I am still not using native keyboard, but maybe will try.
What I did is hookup the keyboardDidShow event and scrolled the active document into view. Look at this code:
ngOnInit() {
window.addEventListener('keyboardDidShow', () => {
const el = document.getElementById('myElement');
//myElement would be the input you have. Or you can just scroll into view the active element, like
// document.activeElement.scrollIntoView();
if (document.activeElement === el)
el.scrollIntoView();
});
}

Related

displaying keyboard in Safari iOS after focus on input after page loads (modal shows) in Angular

I need to set focus and open keyboard after page loads or modal with input is shown.
Simple .focus() works in Android and also in iPad in landscape mode.
However in portrait mode and on iPhone focus is set but keyboard not shown.
I tried also solution with adding and focusing on additional element, but it doesn't work with Angular. (IOS show keyboard on input focus)
#ViewChild('searchBarInput') searchBarInput: ElementRef;
ngAfterViewInit(): void {
setTimeout(()=> {
this.searchBarInput.nativeElement.focus();
this.searchBarInput.nativeElement.click();
},180);
}
test application:
https://inputfocus.vercel.app/
expectation is that after page is loaded and focus set, user can start typing.
It is simplified version - I need this on modal, but behaviour on iOS is similar
I think I found the solution.
on iOS (iphone) and iPad portrait mode, focus() needs to be triggered by user action.
So we need to set this immediately after use clicks button showing modal or new div with target input field.
We can create this new field automatically, set focus, and remove it after moving focus to target field.
On button click we need to create temporary input, append to existing container (close to our input) and focus on it.
btnClicked() {
this.showModal = true;
this.searchBar = this.renderer2.selectRootElement('#searchBar', true);
// 2nd argument preserves existing content
// setting helper field and focusing on it
this.inputHelper = this.renderer2.createElement('input');
this.renderer2.appendChild(this.searchBar, this.inputHelper);
this.inputHelper.focus();
let event = new KeyboardEvent('touchstart',{'bubbles':true});
this.searchBarButton.nativeElement.dispatchEvent(event);
}
after modal/target input is shown, we move focus and remove temporary one:
initiateKeyboard() {
setTimeout(()=> {
this.searchBarInput.nativeElement.focus();
this.renderer2.removeChild(this.searchBar, this.inputHelper);
},180);
}
and template:
<div id="searchBar">
<input type="button" class="button is-link is-light" value="Search" (click)="btnClicked()" (touchstart)="initiateKeyboard()" #searchBarButton>
</div>
You just need to remember that iPhone may zoom screen, so you need to adjust parameters of temporary input.
working solution: https://inputfocus.vercel.app/

In iOS, Cursor position is not able to update from the Started event using the "SelectedTextRange"

Description
In iOS, not able to update the cursor position manually from the started event using the "SelectedTextRange" property on focus. Please refer to the below sample and screenshot.
Steps to Reproduce
Create a custom control.
Create native control by inheriting from UITextField.
Hook started the event in native.
Use the below code snippet to update the cursor position from the started event.
Code Snippet:
var positionToSet = this.GetPosition(this.BeginningOfDocument, 3);
if (positionToSet != null)
{
this.SelectedTextRange = this.GetTextRange(positionToSet, positionToSet);
}
(OR)
Run the attached sample.
Cursor should be positioned in the 3rd index (next to 3) while focusing on the control.
Expected Behavior
The cursor should be positioned at the third index (next to 3) as shown in the below screenshot.
Actual Behavior
The cursor gets positioned at the last.
Sample:
https://github.com/xamarin/Xamarin.Forms/files/7653944/CustomControl.zip
Note:
Issue reproduced only on or above iOS device 14.4.
Its necessary to queue the change so that it occurs after Started event returns:
CoreFoundation.DispatchQueue.MainQueue.DispatchAsync( () => {
this.SelectedTextRange = this.GetTextRange(positionToSet, positionToSet);
});
Based on Leo Dabus' answer in swift.
Tested on iOS simulator, iPhone 11, iOS 15.0.

How to position input onFocus so that it won't stay behind the keyboard [React-Native]

I am having difficulties with forms in my react-native ios app. I want my inputs to position themselves onFocus so that they will be visible when keyboard opens. I used scrollResponderScrollNativeHandleToKeyboard which was recommended in other issues, but it is really buggy. Sometimes it works sometimes it doesn't.
inputFocused(refName) {
let scrollResponder = this.scrollView.getScrollResponder();
scrollResponder.scrollResponderScrollNativeHandleToKeyboard(
ReactNative.findNodeHandle(this[refName]),
270,
true
);
}

Phonegap prevent scrolling when show keyboard

On Phonegap application, is there any way to prevent page scrolling when a text-input is focused and the soft keyboard shows?
In case of no way, Is there any way to scroll the page to the position of text input instead of 'bring' the text input onto center of screen?
in phonegap 2.6 there is a new option to prevent scrolling by resizing the webview. take a look at the documentation and find the KeyboardShrinksView option.
cheers
I've used this javascript code with some success. It overrides the window.scrollTo function and cancels it out...
window.oldScrollTo = window.scrollTo;
window.scrollTo = function (x, y) {
console.log("window.scrollTo");
return;
};

Flex Mobile iPad - Softkeyboard still showing up on textInput Component

I am creating an iPad app in which I have a textInput component that when it is in focus is suppose to call a callout with a spinner in it. The problem is that the softkeyboard is showing up every time I touch the textInput component. I have tried everything I could find which includes the following:
private function onActivating(event:SoftKeyboardEvent):void
{
event.preventDefault();
}
<s:TextInput softKeyboardActivating="onActivating(event)" />
and
<s:TextInput needsSoftKeyboard = "False"/>
Both of these examples are still having the softkeyboard show up.
Have you tried to simply disable the TextInput and change the styles so it doesn't look disabled? Touch events may not trigger though but short of styling a label [as suggested above] you'll have to do some trickery one way or another.

Resources