Comments (7)
@stewones if you use Angular I can share a snippet where im also using KeyboardResize.None
and implemented my own css animation using a directive where the ion-footer
get animated on top of keyboard:
import { Directive, ElementRef } from '@angular/core';
import { Capacitor, PluginListenerHandle } from '@capacitor/core';
import { Keyboard, KeyboardResize } from '@capacitor/keyboard';
import { AnimationController } from '@ionic/angular';
@Directive({
selector: '[cdfyAnimateWithKeyboard]'
})
export class AnimateWithKeyboardDirective {
public keyboardWillShowListener?: PluginListenerHandle;
public keyboardWillHideListener?: PluginListenerHandle;
public resizeModeBackup?: KeyboardResize;
public keyBoardHeight = 0;
public isKeyboardVisible = false;
public isIos = Capacitor.getPlatform() === 'ios';
public animation = this.animationController
.create()
.addElement(this.elementRef.nativeElement)
.easing('cubic-bezier(0.17,0.54,0.42,0.79)')
.duration(250);
public constructor(
private elementRef: ElementRef<HTMLElement>,
private animationController: AnimationController
) {}
public async ngOnInit(): Promise<void> {
// Only handle keyboard events on ios
if (this.isIos) {
await this.handleKeyboardWillShow();
await this.handleKeyboardWillHide();
}
}
public async handleKeyboardWillShow(): Promise<void> {
this.resizeModeBackup = await Keyboard.getResizeMode().then(
(result) => result.mode
);
await Keyboard.setResizeMode({ mode: KeyboardResize.None });
this.keyboardWillShowListener = await Keyboard.addListener(
'keyboardWillShow',
({ keyboardHeight }) => {
this.keyBoardHeight = keyboardHeight;
this.animation.keyframes([
{ offset: 0, transform: 'translate3d(0, 0, 0)' },
{
offset: 1,
transform: `translate3d(0, -${this.keyBoardHeight}px, 0)`
}
]);
if (!this.isKeyboardVisible) {
this.animation.play().catch(() => {});
this.isKeyboardVisible = true;
}
}
);
}
public async handleKeyboardWillHide(): Promise<void> {
this.keyboardWillHideListener = await Keyboard.addListener(
'keyboardWillHide',
() => {
this.animation.keyframes([
{
offset: 0,
transform: `translate3d(0, -${this.keyBoardHeight}px, 0)`
},
{ offset: 1, transform: 'translate3d(0, 0, 0)' }
]);
if (this.isKeyboardVisible) {
this.animation.play().catch(() => {});
this.isKeyboardVisible = false;
}
}
);
}
public async ngOnDestroy(): Promise<void> {
const promises: Promise<void>[] = [];
if (this.resizeModeBackup) {
promises.push(Keyboard.setResizeMode({ mode: this.resizeModeBackup }));
}
if (this.keyboardWillShowListener) {
promises.push(this.keyboardWillShowListener.remove());
}
if (this.keyboardWillHideListener) {
promises.push(this.keyboardWillHideListener.remove());
}
await Promise.all(promises);
}
}
<ion-footer cdfyAnimateWithKeyboard>
<ion-toolbar color="light">
<ion-button
color="primary"
expand="block"
>
Fortfahren
</ion-button>
</ion-toolbar>
</ion-footer>
Using this approach, there is also no flicker. Here's the result:
RPReplay_Final1712775245.MP4
from capacitor.
Hi @stewones
The issue you're encountering is because the HTML content is moved on top of the keyboard (flickering).
This is not a issue of Ionic or Capacitor, but how the Webview is handling resizing.
You can manage the resizing on your own by changing capacitor.config.ts
const config: CapacitorConfig = {
...
Keyboard: {
resize: KeyboardResize.None,
},
...
},
};
https://capacitorjs.com/docs/apis/keyboard#configuration
You can also work with Ionic Keyboard Events to implement your own smooth keyboard transition like described in this blog.
You can read more about this issue here.
from capacitor.
Hi @stewones
The issue you're encountering is because the HTML content is moved on top of the keyboard (flickering). This is not a issue of Ionic or Capacitor, but how the Webview is handling resizing. You can manage the resizing on your own by changing
capacitor.config.ts
const config: CapacitorConfig = { ... Keyboard: { resize: KeyboardResize.None, }, ... }, };https://capacitorjs.com/docs/apis/keyboard#configuration
You can also work with Ionic Keyboard Events to implement your own smooth keyboard transition like described in this blog.
You can read more about this issue here.
I don't want to change the resize behavior, it doesn't work well for my use case.
yes I believe this is an issue with Capacitor and the webview. have you watched the video in full? see what happens in the end, the flash stops when I switch the OS theme to light.
That's true the other way around too. here's a video with the setting inverted (native background #000 and ionic light theme)
// capacitor.json
{
"backgroundColor": "#000000",
"ios": {
"backgroundColor": "#000000"
},
"android": {
"backgroundColor": "#000000"
}
}
RPReplay_Final1712706965.MP4
from capacitor.
As DwieDima said, this is really the WebView internals resizing, in the Capacitor Testapp I've set the background color to red to make it more evident and I see black flashes instead of red flashes. So adding this feature might fix the problem for you, but not for all users, will depend on the app internals.
The backgroundColor
was added for preventing a flash when changing from the splash screen to the WebView, that's why it's only considered to be set on the app startup and not programmatically, because in most cases the background color will not be seen again once the WebView appears.
The backgroundColor
configuration just sets the background color of the Webview on Android and the WebView and it's ScrollView on iOS, that's accessible from plugins code, so you could create a plugin that sets the background color from native side.
from capacitor.
As DwieDima said, this is really the WebView internals resizing, in the Capacitor Testapp I've set the background color to red to make it more evident and I see black flashes instead of red flashes. So adding this feature might fix the problem for you, but not for all users, will depend on the app internals.
The
backgroundColor
was added for preventing a flash when changing from the splash screen to the WebView, that's why it's only considered to be set on the app startup and not programmatically, because in most cases the background color will not be seen again once the WebView appears.The
backgroundColor
configuration just sets the background color of the Webview on Android and the WebView and it's ScrollView on iOS, that's accessible from plugins code, so you could create a plugin that sets the background color from native side.
Thanks @jcesarmobile that makes sense. Yeah I recall having long conversations on Slack with you about the backgroundColor
capability, back in the Capacitor alpha/beta days.
While I disagree with you about the functionality only benefiting my use case, I agree that a plugin could make this happen and that was my plan since the beginning. I just thought that having it in the core would make more sense.
btw here's a video with the native background set as red as you mentioned. I barely see any black flash on both themes. so I still believe this could be a great addition.
RPReplay_Final1712769572.MP4
from capacitor.
and this is why KeyboardResize.None
doesn't work for me. I doubt this is only my case.
RPReplay_Final1712770616.MP4
from capacitor.
Hell yeah, that's even better. Thanks for sharing 👍
from capacitor.
Related Issues (20)
- [Feature]: Panoramic images HOT 2
- [Bug]: HttpRequestHandler.java for Android has parseJSON Exception problem HOT 3
- [Feature]: native camera resolution, rotation and max size settings HOT 3
- [Bug]: iOS crash in Http Plugin HOT 13
- [Bug]: Can't Inspect WebView on iOS when setup with SPM HOT 3
- Allow to set minSdkVersion outside of android folder[Feature]: HOT 3
- [Bug]: Custom Native iOS Code Plugin not Registered HOT 2
- [Bug]: <input capture> opens file picker instead of camera on Google Pixel running Android 14 HOT 4
- Please add onWindowFocusChanged to the bridge[Feature]: HOT 2
- [Bug]: iOS App fails to build with 'WKWebView+Capacitor.h: No such file or directory' after migrating existing app to Cap v6 HOT 2
- [Bug]: capacitor/[email protected] conflicts with capacitor/[email protected] HOT 8
- [Bug]: HTTP-Plugin on iOS: load events not fired HOT 3
- [Bug]: XHR onreadystatechange not working for non POST requests HOT 2
- [Feature]: Allow encrypting cookies before storing them
- [Bug]: duplicate values in `packageClassList` HOT 5
- [Bug]: Android live reload doesn't work, but build works fine. Error: java.lang.IllegalArgumentException: allowedOriginRules HOT 6
- [Bug]: Capacitor Preferences API not worked when Trash the App. HOT 3
- [Feature]: Add a flag for `ios run` to allow for building with Rosetta enabled HOT 4
- [Bug]: HOT 3
- [Bug]: Error: "IDnow" plugin is not implemented on ios HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from capacitor.