Skip to content

Commit

Permalink
fix: support prefer cross-fade transitions in useAnimatedKeyboard
Browse files Browse the repository at this point in the history
On iOS, when Prefer Cross-Fade Transitions is enabled, the keyboard
position and height is reported differently (0 instead of Y position
value matching height of the frame.) Override the initial and target
keyboard height when this preference is enabled.
  • Loading branch information
mhoran committed Nov 26, 2024
1 parent 49a4899 commit 606096c
Showing 1 changed file with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,17 @@ - (void)keyboardWillChangeFrame:(NSNotification *)notification
_initialKeyboardHeight = windowSize.height - beginFrame.origin.y;
_targetKeyboardHeight = windowSize.height - endFrame.origin.y;

bool prefersCrossFade = false;
#if __has_include(<UIKit/UIAccessibility.h>)
prefersCrossFade = UIAccessibilityPrefersCrossFadeTransitions();
#endif
if (prefersCrossFade && beginFrame.origin.y == 0) {
_initialKeyboardHeight = 0;
}
if (prefersCrossFade && endFrame.origin.y == 0) {
_targetKeyboardHeight = 0;
}

/*
This may seem a bit confusing, but usually, the state should be either OPENED or CLOSED.
However, if it shows as OPENING, it means that the interactive dismissal was canceled.
Expand Down

0 comments on commit 606096c

Please sign in to comment.