diff --git a/packages/react-native-reanimated/apple/reanimated/apple/keyboardObserver/REAKeyboardEventObserver.mm b/packages/react-native-reanimated/apple/reanimated/apple/keyboardObserver/REAKeyboardEventObserver.mm index 1a0fe309c9f..9dfd6c154b1 100644 --- a/packages/react-native-reanimated/apple/reanimated/apple/keyboardObserver/REAKeyboardEventObserver.mm +++ b/packages/react-native-reanimated/apple/reanimated/apple/keyboardObserver/REAKeyboardEventObserver.mm @@ -173,22 +173,11 @@ - (float)getAnimatingKeyboardHeight - (void)updateKeyboardFrame { - CGFloat keyboardHeight = 0; bool isKeyboardAnimationRunning = [self hasAnyAnimation:_measuringView]; if (isKeyboardAnimationRunning) { - keyboardHeight = [self getAnimatingKeyboardHeight]; - } else { - // measuring view is no longer running an animation, we should settle in OPEN/CLOSE state - if (_state == OPENING || _state == CLOSING) { - _state = _state == OPENING ? OPEN : CLOSED; - } - if (_state == OPEN || _state == CLOSED) { - keyboardHeight = _targetKeyboardHeight; - } - // stop display link updates if no animation is running - [[self getDisplayLink] setPaused:YES]; + CGFloat keyboardHeight = [self getAnimatingKeyboardHeight]; + [self runListeners:keyboardHeight]; } - [self runListeners:keyboardHeight]; } - (void)keyboardWillChangeFrame:(NSNotification *)notification @@ -237,8 +226,6 @@ - (void)keyboardWillChangeFrame:(NSNotification *)notification self->_measuringView.frame = CGRectMake(0, -1, 0, self->_targetKeyboardHeight); }]; [self runUpdater]; - } else { - [self runListeners:_targetKeyboardHeight]; } } @@ -266,6 +253,10 @@ - (int)subscribeForKeyboardEvents:(KeyboardEventListenerBlock)listener selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil]; + [notificationCenter addObserver:self + selector:@selector(keyboardDidHide:) + name:UIKeyboardDidHideNotification + object:nil]; } [self->_listeners setObject:listener forKey:listenerId]; @@ -283,6 +274,7 @@ - (void)unsubscribeFromKeyboardEvents:(int)listenerId [notificationCenter removeObserver:self name:UIKeyboardWillShowNotification object:nil]; [notificationCenter removeObserver:self name:UIKeyboardDidShowNotification object:nil]; [notificationCenter removeObserver:self name:UIKeyboardWillHideNotification object:nil]; + [notificationCenter removeObserver:self name:UIKeyboardDidHideNotification object:nil]; } }); } @@ -305,6 +297,15 @@ - (void)keyboardWillShow:(NSNotification *)notification - (void)keyboardDidShow:(NSNotification *)notification { + [[self getDisplayLink] setPaused:YES]; + + auto window = [[[UIApplication sharedApplication] delegate] window]; + CGSize windowSize = window.frame.size; + auto keyboardView = [self getKeyboardView]; + _targetKeyboardHeight = windowSize.height - keyboardView.frame.origin.y; + _state = OPEN; + [self runListeners:_targetKeyboardHeight]; + if (_isKeyboardObserverAttached) { return; } @@ -328,6 +329,15 @@ - (void)keyboardWillHide:(NSNotification *)notification [self keyboardWillChangeFrame:notification]; } +- (void)keyboardDidHide:(NSNotification *)notification +{ + [[self getDisplayLink] setPaused:YES]; + + _targetKeyboardHeight = 0; + _state = CLOSED; + [self runListeners:_targetKeyboardHeight]; +} + - (void)updateKeyboardHeightDuringInteractiveDismiss:(CGPoint)oldKeyboardFrame newKeyboardFrame:(CGPoint)newKeyboardFrame {