Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: scroll assist does not re-run when changing keyboards #22940

Closed
maxfloden opened this issue Feb 18, 2021 · 7 comments · Fixed by #28174
Closed

bug: scroll assist does not re-run when changing keyboards #22940

maxfloden opened this issue Feb 18, 2021 · 7 comments · Fixed by #28174
Labels
package: core @ionic/core package type: bug a confirmed bug report

Comments

@maxfloden
Copy link

Bug Report

Ionic version:
[ ] 4.x
[x] 5.x

Current behavior:
On iOS14 keyboard height changes when selecting Emojis, this causes ion-input field to be hidden by keyboard. Switching back from Emoji to ABC shows input field again as keyboard height again decreases.

Expected behavior:
Input field should always show above keyboard, not behind.

Steps to reproduce:

Related code:

html

<ion-content>
  <div class="backdrop_container"  (click)="goBack()"></div>
</ion-content>

<ion-footer>
  <ion-list lines="none">
    <ion-item>
      <ion-input [(ngModel)]="message" type="text" placeholder="{{'COMMENT.saysomething_pl | translate'}}"></ion-input>
      <ion-button (click)="submit()">
          <img src="../../../assets/icon/chat-send.svg" width="25px"/>
      </ion-button> 
    </ion-item>
  </ion-list>
</ion-footer>

scss

ion-content{
    --background: transparent;
 
    .backdrop_container{
        display: flex;
        flex: 1;
        width: 100%;
        height: 100%;
    }
    
}

ion-footer {
    ion-input{
        height: 40px !important;
    }

    ion-button{
        width: 45px !important;
        height: 45px !important;
        padding: 0;
        --background: var(--ion-color-green);
        --border-radius: 25px;
        margin-left: 10px;
        display: flex;
        justify-content: center;
        align-items: center;
    }
}

Other information:

Ionic info:

Ionic:

   Ionic CLI                     : 6.12.4 (/Users/xxx/.nvm/versions/node/v14.15.1/lib/node_modules/@ionic/cli)
   Ionic Framework               : @ionic/angular 5.5.4
   @angular-devkit/build-angular : 0.901.14
   @angular-devkit/schematics    : 9.1.14
   @angular/cli                  : 9.1.14
   @ionic/angular-toolkit        : 2.3.3

Cordova:

   Cordova CLI       : 10.0.0
   Cordova Platforms : ios 6.2.0
   Cordova Plugins   : cordova-plugin-ionic-webview 5.0.0, (and 11 other plugins)

Utility:

   cordova-res (update available: 0.15.3) : 0.15.2
   native-run                             : 1.3.0

System:

   ios-sim : 8.0.2
   NodeJS  : v14.15.1 (/Users/xxx/.nvm/versions/node/v14.15.1/bin/node)
   npm     : 6.14.8
   OS      : macOS Big Sur
   Xcode   : Xcode 12.3 Build version 12C33
@ionitron-bot ionitron-bot bot added the triage label Feb 18, 2021
@maxfloden maxfloden changed the title bug: bug: Keyboard hide input field on iOS14 when switching to Emojis from ABC and keyboard height increases Feb 18, 2021
@maxfloden maxfloden changed the title bug: Keyboard hide input field on iOS14 when switching to Emojis from ABC and keyboard height increases bug: Keyboard hide input field on iOS14 when switching to Emojis and keyboard height increases Feb 18, 2021
@liamdebeasi liamdebeasi changed the title bug: Keyboard hide input field on iOS14 when switching to Emojis and keyboard height increases bug: scroll assist does not re-run when changing keyboards Feb 18, 2021
@liamdebeasi liamdebeasi added package: core @ionic/core package type: bug a confirmed bug report labels Feb 18, 2021
@ionitron-bot ionitron-bot bot removed the triage label Feb 18, 2021
@elenche
Copy link

elenche commented Jun 12, 2023

@liamdebeasi any progress on this issue? Do you need reproduction link or more info?
Facing the same thing in iOS 16.

Added listener to the Capacitor Keyboard events, and the following happens:

  • Press on input field -> event keyboardDidShow fires, keyboard shows up, content is correctly pushed up
  • Press on emoji field on keyboard -> event keyboardDidShow fires, emoji keyboard shows up, content is reset (and hidden behind the keyboard)
  • Press away from keyboard -> event keyboardDidHide fires

@liamdebeasi
Copy link
Contributor

The remaining step is figuring out a good solution for the problem. Scroll assist currently runs on input focus, but it sounds like we also need it to run when the keyboard changes. We might be able to rely on ionKeyboardDidShow to re-run scroll assist since that would cover web and native. The tricky part will be to make sure that it doesn't re-run whenever inputs are focused for the first time (since the keyboard will also open then)

@liamdebeasi liamdebeasi added type: bug a confirmed bug report and removed type: bug a confirmed bug report labels Jun 13, 2023
@elenche
Copy link

elenche commented Jun 13, 2023

@liamdebeasi thank you for your explanation.

Upon further research it seems that this is related to another issue that seemed to happen when upgrading to @capacitor/[email protected] and is fixed in ionic version 7.0.9.
I downgraded to @capacitor/[email protected] and the issue we're facing here disappeared. I haven't had the chance to test if being on @capacitor/[email protected] and [email protected] will fix the issue because I can't upgrade to Ionic 7 right now.

@liamdebeasi
Copy link
Contributor

liamdebeasi commented Jun 13, 2023

That issue was fixed in the Capacitor Keyboard plugin and released a few days ago: ionic-team/capacitor#6642 (comment)

@liamdebeasi
Copy link
Contributor

liamdebeasi commented Sep 14, 2023

Hi everyone,

Here is a dev build with a proposed fix if you are interested in testing: 7.3.4-dev.11694698515.1504c90b

Install Example:

npm install @ionic/[email protected]

Note on behavior:

  1. In Cordova/Capacitor scroll assist will re-run whenever the keyboard changes.
  2. In a browser/PWA scroll assist will only re-run whenever the keyboard geometry changes. We don't have a cross browser way of detecting when the keyboard opens yet.

edit: I found a bug so I included a new dev build

github-merge-queue bot pushed a commit that referenced this issue Sep 19, 2023
#28169)

Issue number: Part of #22940

---------

<!-- Please do not submit updates to dependencies unless it fixes an
issue. -->

<!-- Please try to limit your pull request to one type (bugfix, feature,
etc). Submit multiple pull requests if needed. -->

## What is the current behavior?
<!-- Please describe the current behavior that you are modifying. -->

While working on a fix for #22940, I discovered another bug that
impacted the reliability of my proposed fix for #22940. When we compute
the scroll data (i.e. how much the input needs to be scrolled by), we
subtract the `keyboardHeight` from the `platformHeight` (i.e. the
viewport height):
https://github.com/ionic-team/ionic-framework/blob/1015c06cbef4ceb10d43e722157c04844d984509/core/src/utils/input-shims/hacks/scroll-data.ts#L34

Every time we tap between inputs (even if the keyboard is already open)
we re-run scroll assist because the newly focused input could be
partially obscured by the keyboard. However, in this case we scroll by
too much because we effectively subtract the keyboard height twice. This
is because by the time we compute `platformHeight`, the platform
dimensions have already shrunk to account for the keyboard (when the
webview resizes).

As a result, when we subtract `keyboardHeight` we get a visible area
that is much smaller than the actual visible area.

Examples below with different resize modes. Notice that with the
"Native" resize mode (entire webview resizes when keyboard is open)
tapping into other inputs scrolls the content by much more than it needs
to.

| Body | Native | Ionic | None |
| - | - | - | - |
| <video
src="https://github.com/ionic-team/ionic-framework/assets/2721089/06d1cd20-0349-4a59-ad85-c1c8a8a03caa"></video>
| <video
src="https://github.com/ionic-team/ionic-framework/assets/2721089/1d4e8363-a69b-45c4-931c-d6227e548ec9"></video>
| <video
src="https://github.com/ionic-team/ionic-framework/assets/2721089/7e4304c1-7d56-48c8-aed8-16fc7e51641a"></video>
| <video
src="https://github.com/ionic-team/ionic-framework/assets/2721089/7869c5e0-b202-46e1-af82-49e41b3b067e"></video>
|

## What is the new behavior?
<!-- Please describe the behavior or changes that are being added by
this PR. -->

- We now compute the viewport height on load rather than on focus. This
ensures that we always use the full viewport height when computing the
visible area.

| Body | Native | Ionic | None |
| - | - | - | - |
| <video
src="https://github.com/ionic-team/ionic-framework/assets/2721089/c5a66287-0cad-42db-bece-da16edad60e3"></video>
| <video
src="https://github.com/ionic-team/ionic-framework/assets/2721089/372a45c8-e8bd-43d2-bf50-d87b7250e9b3"></video>
| <video
src="https://github.com/ionic-team/ionic-framework/assets/2721089/3d656467-8e2e-48cc-8d72-dc89a67ef8b1"></video>
| <video
src="https://github.com/ionic-team/ionic-framework/assets/2721089/19969535-7d06-404c-98e4-ae49957e0ffe"></video>
|



## Does this introduce a breaking change?

- [ ] Yes
- [x] No

<!-- If this introduces a breaking change, please describe the impact
and migration path for existing applications below. -->


## Other information

<!-- Any other information that is important to this PR such as
screenshots of how the component looks before and after the change. -->

Dev build: `7.3.4-dev.11694548895.1578981b`
github-merge-queue bot pushed a commit that referenced this issue Sep 19, 2023
Issue number: resolves #22940

---------

<!-- Please do not submit updates to dependencies unless it fixes an
issue. -->

<!-- Please try to limit your pull request to one type (bugfix, feature,
etc). Submit multiple pull requests if needed. -->

## What is the current behavior?
<!-- Please describe the current behavior that you are modifying. -->

Scroll assist does not run when changing keyboards. This means that
inputs can be hidden under the keyboard if the new keyboard is larger
than the previous keyboard.

## What is the new behavior?
<!-- Please describe the behavior or changes that are being added by
this PR. -->

- On Browsers/PWAs scroll assist will re-run when the keyboard geometry
changes. We don't have a cross-browser way of detecting keyboard changes
yet, so this is the best we have for now.
- On Cordova/Capacitor scroll assist will re-run when the keyboard
changes, even if the overall keyboard geometry does not change.


In the example below, we are changing keyboards while an input is
focused:
| `main` | branch |
| - | - |
| <video
src="https://github.com/ionic-team/ionic-framework/assets/2721089/715e176a-6724-4308-ae3e-15b5bea308ac"></video>
| <video
src="https://github.com/ionic-team/ionic-framework/assets/2721089/b9ccd482-720a-409b-a089-b3330c1e405c"></video>
|

Breakdown per-resize mode:

| Native | None | Ionic | Body |
| - | - | - | - |
| <video
src="https://github.com/ionic-team/ionic-framework/assets/2721089/b930ac5f-3398-4887-a8ca-a57708adc66d"></video>
| <video
src="https://github.com/ionic-team/ionic-framework/assets/2721089/68465854-94d0-4e00-940c-c4674a43b6a3"></video>
| <video
src="https://github.com/ionic-team/ionic-framework/assets/2721089/561f313a-9caf-4c9e-ab15-9c4383f0e3ee"></video>
| <video
src="https://github.com/ionic-team/ionic-framework/assets/2721089/300b8894-ad2a-43bc-8e82-ecd68afd407e"></video>
|

## Does this introduce a breaking change?

- [ ] Yes
- [x] No

<!-- If this introduces a breaking change, please describe the impact
and migration path for existing applications below. -->


## Other information

<!-- Any other information that is important to this PR such as
screenshots of how the component looks before and after the change. -->

Dev build: `7.3.4-dev.11694706860.14b2710d`

---------

Co-authored-by: Amanda Johnston <[email protected]>
@liamdebeasi
Copy link
Contributor

Thanks for the issue. This has been resolved via #28174, and a fix will be available in an upcoming release of Ionic Framework. Feel free to continue testing the dev build, and let me know if you run into any issues.

liamdebeasi added a commit that referenced this issue Sep 22, 2023
#28169)

Issue number: Part of #22940

---------

<!-- Please do not submit updates to dependencies unless it fixes an
issue. -->

<!-- Please try to limit your pull request to one type (bugfix, feature,
etc). Submit multiple pull requests if needed. -->

## What is the current behavior?
<!-- Please describe the current behavior that you are modifying. -->

While working on a fix for #22940, I discovered another bug that
impacted the reliability of my proposed fix for #22940. When we compute
the scroll data (i.e. how much the input needs to be scrolled by), we
subtract the `keyboardHeight` from the `platformHeight` (i.e. the
viewport height):
https://github.com/ionic-team/ionic-framework/blob/1015c06cbef4ceb10d43e722157c04844d984509/core/src/utils/input-shims/hacks/scroll-data.ts#L34

Every time we tap between inputs (even if the keyboard is already open)
we re-run scroll assist because the newly focused input could be
partially obscured by the keyboard. However, in this case we scroll by
too much because we effectively subtract the keyboard height twice. This
is because by the time we compute `platformHeight`, the platform
dimensions have already shrunk to account for the keyboard (when the
webview resizes).

As a result, when we subtract `keyboardHeight` we get a visible area
that is much smaller than the actual visible area.

Examples below with different resize modes. Notice that with the
"Native" resize mode (entire webview resizes when keyboard is open)
tapping into other inputs scrolls the content by much more than it needs
to.

| Body | Native | Ionic | None |
| - | - | - | - |
| <video
src="https://github.com/ionic-team/ionic-framework/assets/2721089/06d1cd20-0349-4a59-ad85-c1c8a8a03caa"></video>
| <video
src="https://github.com/ionic-team/ionic-framework/assets/2721089/1d4e8363-a69b-45c4-931c-d6227e548ec9"></video>
| <video
src="https://github.com/ionic-team/ionic-framework/assets/2721089/7e4304c1-7d56-48c8-aed8-16fc7e51641a"></video>
| <video
src="https://github.com/ionic-team/ionic-framework/assets/2721089/7869c5e0-b202-46e1-af82-49e41b3b067e"></video>
|

## What is the new behavior?
<!-- Please describe the behavior or changes that are being added by
this PR. -->

- We now compute the viewport height on load rather than on focus. This
ensures that we always use the full viewport height when computing the
visible area.

| Body | Native | Ionic | None |
| - | - | - | - |
| <video
src="https://github.com/ionic-team/ionic-framework/assets/2721089/c5a66287-0cad-42db-bece-da16edad60e3"></video>
| <video
src="https://github.com/ionic-team/ionic-framework/assets/2721089/372a45c8-e8bd-43d2-bf50-d87b7250e9b3"></video>
| <video
src="https://github.com/ionic-team/ionic-framework/assets/2721089/3d656467-8e2e-48cc-8d72-dc89a67ef8b1"></video>
| <video
src="https://github.com/ionic-team/ionic-framework/assets/2721089/19969535-7d06-404c-98e4-ae49957e0ffe"></video>
|



## Does this introduce a breaking change?

- [ ] Yes
- [x] No

<!-- If this introduces a breaking change, please describe the impact
and migration path for existing applications below. -->


## Other information

<!-- Any other information that is important to this PR such as
screenshots of how the component looks before and after the change. -->

Dev build: `7.3.4-dev.11694548895.1578981b`
liamdebeasi added a commit that referenced this issue Sep 22, 2023
Issue number: resolves #22940

---------

<!-- Please do not submit updates to dependencies unless it fixes an
issue. -->

<!-- Please try to limit your pull request to one type (bugfix, feature,
etc). Submit multiple pull requests if needed. -->

## What is the current behavior?
<!-- Please describe the current behavior that you are modifying. -->

Scroll assist does not run when changing keyboards. This means that
inputs can be hidden under the keyboard if the new keyboard is larger
than the previous keyboard.

## What is the new behavior?
<!-- Please describe the behavior or changes that are being added by
this PR. -->

- On Browsers/PWAs scroll assist will re-run when the keyboard geometry
changes. We don't have a cross-browser way of detecting keyboard changes
yet, so this is the best we have for now.
- On Cordova/Capacitor scroll assist will re-run when the keyboard
changes, even if the overall keyboard geometry does not change.


In the example below, we are changing keyboards while an input is
focused:
| `main` | branch |
| - | - |
| <video
src="https://github.com/ionic-team/ionic-framework/assets/2721089/715e176a-6724-4308-ae3e-15b5bea308ac"></video>
| <video
src="https://github.com/ionic-team/ionic-framework/assets/2721089/b9ccd482-720a-409b-a089-b3330c1e405c"></video>
|

Breakdown per-resize mode:

| Native | None | Ionic | Body |
| - | - | - | - |
| <video
src="https://github.com/ionic-team/ionic-framework/assets/2721089/b930ac5f-3398-4887-a8ca-a57708adc66d"></video>
| <video
src="https://github.com/ionic-team/ionic-framework/assets/2721089/68465854-94d0-4e00-940c-c4674a43b6a3"></video>
| <video
src="https://github.com/ionic-team/ionic-framework/assets/2721089/561f313a-9caf-4c9e-ab15-9c4383f0e3ee"></video>
| <video
src="https://github.com/ionic-team/ionic-framework/assets/2721089/300b8894-ad2a-43bc-8e82-ecd68afd407e"></video>
|

## Does this introduce a breaking change?

- [ ] Yes
- [x] No

<!-- If this introduces a breaking change, please describe the impact
and migration path for existing applications below. -->


## Other information

<!-- Any other information that is important to this PR such as
screenshots of how the component looks before and after the change. -->

Dev build: `7.3.4-dev.11694706860.14b2710d`

---------

Co-authored-by: Amanda Johnston <[email protected]>
liamdebeasi added a commit that referenced this issue Sep 26, 2023
#28169)

Issue number: Part of #22940

---------

<!-- Please do not submit updates to dependencies unless it fixes an
issue. -->

<!-- Please try to limit your pull request to one type (bugfix, feature,
etc). Submit multiple pull requests if needed. -->

## What is the current behavior?
<!-- Please describe the current behavior that you are modifying. -->

While working on a fix for #22940, I discovered another bug that
impacted the reliability of my proposed fix for #22940. When we compute
the scroll data (i.e. how much the input needs to be scrolled by), we
subtract the `keyboardHeight` from the `platformHeight` (i.e. the
viewport height):
https://github.com/ionic-team/ionic-framework/blob/1015c06cbef4ceb10d43e722157c04844d984509/core/src/utils/input-shims/hacks/scroll-data.ts#L34

Every time we tap between inputs (even if the keyboard is already open)
we re-run scroll assist because the newly focused input could be
partially obscured by the keyboard. However, in this case we scroll by
too much because we effectively subtract the keyboard height twice. This
is because by the time we compute `platformHeight`, the platform
dimensions have already shrunk to account for the keyboard (when the
webview resizes).

As a result, when we subtract `keyboardHeight` we get a visible area
that is much smaller than the actual visible area.

Examples below with different resize modes. Notice that with the
"Native" resize mode (entire webview resizes when keyboard is open)
tapping into other inputs scrolls the content by much more than it needs
to.

| Body | Native | Ionic | None |
| - | - | - | - |
| <video
src="https://github.com/ionic-team/ionic-framework/assets/2721089/06d1cd20-0349-4a59-ad85-c1c8a8a03caa"></video>
| <video
src="https://github.com/ionic-team/ionic-framework/assets/2721089/1d4e8363-a69b-45c4-931c-d6227e548ec9"></video>
| <video
src="https://github.com/ionic-team/ionic-framework/assets/2721089/7e4304c1-7d56-48c8-aed8-16fc7e51641a"></video>
| <video
src="https://github.com/ionic-team/ionic-framework/assets/2721089/7869c5e0-b202-46e1-af82-49e41b3b067e"></video>
|

## What is the new behavior?
<!-- Please describe the behavior or changes that are being added by
this PR. -->

- We now compute the viewport height on load rather than on focus. This
ensures that we always use the full viewport height when computing the
visible area.

| Body | Native | Ionic | None |
| - | - | - | - |
| <video
src="https://github.com/ionic-team/ionic-framework/assets/2721089/c5a66287-0cad-42db-bece-da16edad60e3"></video>
| <video
src="https://github.com/ionic-team/ionic-framework/assets/2721089/372a45c8-e8bd-43d2-bf50-d87b7250e9b3"></video>
| <video
src="https://github.com/ionic-team/ionic-framework/assets/2721089/3d656467-8e2e-48cc-8d72-dc89a67ef8b1"></video>
| <video
src="https://github.com/ionic-team/ionic-framework/assets/2721089/19969535-7d06-404c-98e4-ae49957e0ffe"></video>
|



## Does this introduce a breaking change?

- [ ] Yes
- [x] No

<!-- If this introduces a breaking change, please describe the impact
and migration path for existing applications below. -->


## Other information

<!-- Any other information that is important to this PR such as
screenshots of how the component looks before and after the change. -->

Dev build: `7.3.4-dev.11694548895.1578981b`
liamdebeasi added a commit that referenced this issue Sep 26, 2023
Issue number: resolves #22940

---------

<!-- Please do not submit updates to dependencies unless it fixes an
issue. -->

<!-- Please try to limit your pull request to one type (bugfix, feature,
etc). Submit multiple pull requests if needed. -->

## What is the current behavior?
<!-- Please describe the current behavior that you are modifying. -->

Scroll assist does not run when changing keyboards. This means that
inputs can be hidden under the keyboard if the new keyboard is larger
than the previous keyboard.

## What is the new behavior?
<!-- Please describe the behavior or changes that are being added by
this PR. -->

- On Browsers/PWAs scroll assist will re-run when the keyboard geometry
changes. We don't have a cross-browser way of detecting keyboard changes
yet, so this is the best we have for now.
- On Cordova/Capacitor scroll assist will re-run when the keyboard
changes, even if the overall keyboard geometry does not change.


In the example below, we are changing keyboards while an input is
focused:
| `main` | branch |
| - | - |
| <video
src="https://github.com/ionic-team/ionic-framework/assets/2721089/715e176a-6724-4308-ae3e-15b5bea308ac"></video>
| <video
src="https://github.com/ionic-team/ionic-framework/assets/2721089/b9ccd482-720a-409b-a089-b3330c1e405c"></video>
|

Breakdown per-resize mode:

| Native | None | Ionic | Body |
| - | - | - | - |
| <video
src="https://github.com/ionic-team/ionic-framework/assets/2721089/b930ac5f-3398-4887-a8ca-a57708adc66d"></video>
| <video
src="https://github.com/ionic-team/ionic-framework/assets/2721089/68465854-94d0-4e00-940c-c4674a43b6a3"></video>
| <video
src="https://github.com/ionic-team/ionic-framework/assets/2721089/561f313a-9caf-4c9e-ab15-9c4383f0e3ee"></video>
| <video
src="https://github.com/ionic-team/ionic-framework/assets/2721089/300b8894-ad2a-43bc-8e82-ecd68afd407e"></video>
|

## Does this introduce a breaking change?

- [ ] Yes
- [x] No

<!-- If this introduces a breaking change, please describe the impact
and migration path for existing applications below. -->


## Other information

<!-- Any other information that is important to this PR such as
screenshots of how the component looks before and after the change. -->

Dev build: `7.3.4-dev.11694706860.14b2710d`

---------

Co-authored-by: Amanda Johnston <[email protected]>
@ionitron-bot
Copy link

ionitron-bot bot commented Oct 19, 2023

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.

@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Oct 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
package: core @ionic/core package type: bug a confirmed bug report
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants