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

fix: KeyboardAvoidingView height when "Prefer Cross-Fade Transitions" is enabled #34503

Conversation

gabrieldonadel
Copy link
Collaborator

@gabrieldonadel gabrieldonadel commented Aug 26, 2022

Summary

Fix KeyboardAvoidingView height on iOS when "Prefer Cross-Fade Transitions" is enabled by adding an additional check to _relativeKeyboardHeight verifying if prefersCrossFadeTransitions() is true and keyboardFrame.screenY is 0 and treating this special case. The issue was caused by the native RCTKeyboardObserver where the endFrame reported by UIKeyboardWillChangeFrameNotification returns height = 0 when Prefer Cross-Fade Transitions" is enabled
and unfortunelly there isn't much we can do on the native side to fix it.

Closes #31484
Closes #29974

Changelog

[iOS] [Fixed] - Fix KeyboardAvoidingView height when "Prefer Cross-Fade Transitions" is enabled

Test Plan

On iOS 14+

  1. Access Settings > "General" > "Accessibility" > "Reduce Motion", enable "Reduce Motion" then enable "Prefer Cross-Fade Transitions".
  2. Open the RNTester app and navigate to the KeyboardAvoidingView page
  3. Focus and blur inputs and observe the keyboard behaving correctly
Screen.Recording.2022-08-26.at.01.32.17.mov

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Aug 26, 2022
@react-native-bot react-native-bot added Bug Platform: iOS iOS applications. labels Aug 26, 2022
@facebook-github-bot facebook-github-bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Aug 26, 2022
@analysis-bot
Copy link

analysis-bot commented Aug 26, 2022

Platform Engine Arch Size (bytes) Diff
android hermes arm64-v8a 7,618,232 -16,250
android hermes armeabi-v7a 7,032,488 -13,914
android hermes x86 7,918,294 -18,019
android hermes x86_64 7,891,912 -16,263
android jsc arm64-v8a 9,495,801 -16,098
android jsc armeabi-v7a 8,273,423 -13,769
android jsc x86 9,433,588 -17,881
android jsc x86_64 10,026,574 -16,118

Base commit: df0b690
Branch: main

@gabrieldonadel gabrieldonadel force-pushed the fix/keyboard-avoiding-view-cross-fade-transitions branch from 0fdab0f to d91e124 Compare August 26, 2022 12:09
@analysis-bot
Copy link

analysis-bot commented Aug 26, 2022

Platform Engine Arch Size (bytes) Diff
ios - universal n/a --

Base commit: df0b690
Branch: main

@facebook-github-bot
Copy link
Contributor

@cipolleschi has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@@ -107,14 +120,14 @@ class KeyboardAvoidingView extends React.Component<Props, State> {
}
};

_updateBottomIfNecessary = () => {
_updateBottomIfNecessary = async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call sites for function _updateBottomIfNecessary is not using await, as a side effect the function call this.props.onLayout(event) now won't wait for _updateBottomIfNecessary to finish.

As per the doc, This event is fired immediately once the layout has been calculated

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohh good point, I added an await to the _updateBottomIfNecessary call to ensure everything is properly calculated before the this.props.onLayout function is called.

@facebook-github-bot
Copy link
Contributor

@cipolleschi has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@react-native-bot
Copy link
Collaborator

This pull request was successfully merged by @gabrieldonadel in 4b9382c.

When will my fix make it into a release? | Upcoming Releases

@react-native-bot react-native-bot added the Merged This PR has been merged. label Aug 31, 2022
@gabrieldonadel gabrieldonadel deleted the fix/keyboard-avoiding-view-cross-fade-transitions branch August 31, 2022 14:55
dmytrorykun pushed a commit that referenced this pull request Sep 14, 2022
… is enabled (#34503)

Summary:
Fix `KeyboardAvoidingView`  height on iOS when "Prefer Cross-Fade Transitions" is enabled by adding an additional check to `_relativeKeyboardHeight` verifying if `prefersCrossFadeTransitions()` is true and `keyboardFrame.screenY` is `0` and treating this special case. The issue was caused  by the native RCTKeyboardObserver where the `endFrame` reported by `UIKeyboardWillChangeFrameNotification` returns `height = 0` when Prefer Cross-Fade Transitions" is enabled
and unfortunelly there isn't much we can do on the native side to fix it.

Closes #31484
Closes #29974

[iOS] [Fixed] - Fix KeyboardAvoidingView height when "Prefer Cross-Fade Transitions" is enabled

Pull Request resolved: #34503

Test Plan:
**On iOS 14+**

1.  Access Settings > "General" > "Accessibility" > "Reduce Motion", enable "Reduce Motion" then enable "Prefer Cross-Fade Transitions".
2. Open the RNTester app and navigate to the KeyboardAvoidingView page
3. Focus and blur inputs and observe the keyboard behaving correctly

https://user-images.githubusercontent.com/11707729/186822671-801872be-7db1-4c5c-904b-1987441c1326.mov

Reviewed By: jacdebug

Differential Revision: D39055213

Pulled By: cipolleschi

fbshipit-source-id: fac17cbe02867e0fe522397f6cb59a8b51c1840f
kelset added a commit that referenced this pull request Oct 3, 2022
kelset pushed a commit that referenced this pull request Oct 3, 2022
… is enabled (#34503)

Summary:
Fix `KeyboardAvoidingView`  height on iOS when "Prefer Cross-Fade Transitions" is enabled by adding an additional check to `_relativeKeyboardHeight` verifying if `prefersCrossFadeTransitions()` is true and `keyboardFrame.screenY` is `0` and treating this special case. The issue was caused  by the native RCTKeyboardObserver where the `endFrame` reported by `UIKeyboardWillChangeFrameNotification` returns `height = 0` when Prefer Cross-Fade Transitions" is enabled
and unfortunelly there isn't much we can do on the native side to fix it.

Closes #31484
Closes #29974

## Changelog

[iOS] [Fixed] - Fix KeyboardAvoidingView height when "Prefer Cross-Fade Transitions" is enabled

Pull Request resolved: #34503

Test Plan:
**On iOS 14+**

1.  Access Settings > "General" > "Accessibility" > "Reduce Motion", enable "Reduce Motion" then enable "Prefer Cross-Fade Transitions".
2. Open the RNTester app and navigate to the KeyboardAvoidingView page
3. Focus and blur inputs and observe the keyboard behaving correctly

https://user-images.githubusercontent.com/11707729/186822671-801872be-7db1-4c5c-904b-1987441c1326.mov

Reviewed By: jacdebug

Differential Revision: D39055213

Pulled By: cipolleschi

fbshipit-source-id: fac17cbe02867e0fe522397f6cb59a8b51c1840f
alphatrl pushed a commit to taskade/react-native that referenced this pull request Oct 17, 2022
… is enabled (facebook#34503)

Summary:
Fix `KeyboardAvoidingView`  height on iOS when "Prefer Cross-Fade Transitions" is enabled by adding an additional check to `_relativeKeyboardHeight` verifying if `prefersCrossFadeTransitions()` is true and `keyboardFrame.screenY` is `0` and treating this special case. The issue was caused  by the native RCTKeyboardObserver where the `endFrame` reported by `UIKeyboardWillChangeFrameNotification` returns `height = 0` when Prefer Cross-Fade Transitions" is enabled
and unfortunelly there isn't much we can do on the native side to fix it.

Closes facebook#31484
Closes facebook#29974

## Changelog

[iOS] [Fixed] - Fix KeyboardAvoidingView height when "Prefer Cross-Fade Transitions" is enabled

Pull Request resolved: facebook#34503

Test Plan:
**On iOS 14+**

1.  Access Settings > "General" > "Accessibility" > "Reduce Motion", enable "Reduce Motion" then enable "Prefer Cross-Fade Transitions".
2. Open the RNTester app and navigate to the KeyboardAvoidingView page
3. Focus and blur inputs and observe the keyboard behaving correctly

https://user-images.githubusercontent.com/11707729/186822671-801872be-7db1-4c5c-904b-1987441c1326.mov

Reviewed By: jacdebug

Differential Revision: D39055213

Pulled By: cipolleschi

fbshipit-source-id: fac17cbe02867e0fe522397f6cb59a8b51c1840f

# Conflicts:
#	Libraries/Components/Keyboard/KeyboardAvoidingView.js
alphatrl pushed a commit to taskade/react-native that referenced this pull request Oct 17, 2022
… is enabled (facebook#34503)

Summary:
Fix `KeyboardAvoidingView`  height on iOS when "Prefer Cross-Fade Transitions" is enabled by adding an additional check to `_relativeKeyboardHeight` verifying if `prefersCrossFadeTransitions()` is true and `keyboardFrame.screenY` is `0` and treating this special case. The issue was caused  by the native RCTKeyboardObserver where the `endFrame` reported by `UIKeyboardWillChangeFrameNotification` returns `height = 0` when Prefer Cross-Fade Transitions" is enabled
and unfortunelly there isn't much we can do on the native side to fix it.

Closes facebook#31484
Closes facebook#29974

## Changelog

[iOS] [Fixed] - Fix KeyboardAvoidingView height when "Prefer Cross-Fade Transitions" is enabled

Pull Request resolved: facebook#34503

Test Plan:
**On iOS 14+**

1.  Access Settings > "General" > "Accessibility" > "Reduce Motion", enable "Reduce Motion" then enable "Prefer Cross-Fade Transitions".
2. Open the RNTester app and navigate to the KeyboardAvoidingView page
3. Focus and blur inputs and observe the keyboard behaving correctly

https://user-images.githubusercontent.com/11707729/186822671-801872be-7db1-4c5c-904b-1987441c1326.mov

Reviewed By: jacdebug

Differential Revision: D39055213

Pulled By: cipolleschi

fbshipit-source-id: fac17cbe02867e0fe522397f6cb59a8b51c1840f

# Conflicts:
#	Libraries/Components/Keyboard/KeyboardAvoidingView.js
facebook-github-bot pushed a commit that referenced this pull request Jan 24, 2023
…refer Cross-Fade Transitions is enabled (#35933)

Summary:
Similar to the issue here #34503 but this is also happening if we just use `ScrollView` and `TextInput` with `automaticallyAdjustKeyboardInsets` enabled.

When we enable `Prefer Cross-Fade Transitions` in `iOS` we get a keyboard height of `0` which causes the inset/offset miscalculation and the content jumps up when the keyboard gets hidden.

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry.

Pick one each for the category and type tags:

[IOS] [FIXED] - Fix ScrollView `automaticallyAdjustKeyboardInsets` not resetting when Prefer Cross-Fade Transitions is enabled and keyboard hides

For more details, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->

[IOS] [FIXED] - Fix ScrollView `automaticallyAdjustKeyboardInsets` not resetting when Prefer Cross-Fade Transitions is enabled and keyboard hides

Pull Request resolved: #35933

Test Plan:
Tested with brand new react native project with/without the fix

before fix `automaticallyAdjustKeyboardInsets` with enabled/disabled opening/closing keyboard

https://user-images.githubusercontent.com/6507800/214039873-33bfb016-f99f-4644-9174-20bf32cf07d6.mov

after fix `automaticallyAdjustKeyboardInsets` with enabled/disabled opening/closing keyboard

https://user-images.githubusercontent.com/6507800/214039887-4054a749-ab15-4399-b6a9-73dc9283aa6b.mov

Reviewed By: christophpurrer

Differential Revision: D42686390

Pulled By: jacdebug

fbshipit-source-id: 98488e0c9639c19a4acae1a1de1a5fde411e2462
OlimpiaZurek pushed a commit to OlimpiaZurek/react-native that referenced this pull request May 22, 2023
…refer Cross-Fade Transitions is enabled (facebook#35933)

Summary:
Similar to the issue here facebook#34503 but this is also happening if we just use `ScrollView` and `TextInput` with `automaticallyAdjustKeyboardInsets` enabled.

When we enable `Prefer Cross-Fade Transitions` in `iOS` we get a keyboard height of `0` which causes the inset/offset miscalculation and the content jumps up when the keyboard gets hidden.

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry.

Pick one each for the category and type tags:

[IOS] [FIXED] - Fix ScrollView `automaticallyAdjustKeyboardInsets` not resetting when Prefer Cross-Fade Transitions is enabled and keyboard hides

For more details, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->

[IOS] [FIXED] - Fix ScrollView `automaticallyAdjustKeyboardInsets` not resetting when Prefer Cross-Fade Transitions is enabled and keyboard hides

Pull Request resolved: facebook#35933

Test Plan:
Tested with brand new react native project with/without the fix

before fix `automaticallyAdjustKeyboardInsets` with enabled/disabled opening/closing keyboard

https://user-images.githubusercontent.com/6507800/214039873-33bfb016-f99f-4644-9174-20bf32cf07d6.mov

after fix `automaticallyAdjustKeyboardInsets` with enabled/disabled opening/closing keyboard

https://user-images.githubusercontent.com/6507800/214039887-4054a749-ab15-4399-b6a9-73dc9283aa6b.mov

Reviewed By: christophpurrer

Differential Revision: D42686390

Pulled By: jacdebug

fbshipit-source-id: 98488e0c9639c19a4acae1a1de1a5fde411e2462
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. Platform: iOS iOS applications. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.
Projects
None yet
5 participants