iOS: Provide correct animation function for hiding keyboard

Summary:
Currently, `7 << 16` is used as the animation easing function for both the showing and hiding of the keyboard.

Instead, `7 << 16` should be used for showing the keyboard and `6 << 16` for hiding the keyboard.

For details, see: http://stackoverflow.com/questions/18870447/how-to-use-the-default-ios7-uianimation-curve/19439283#19439283

**Test plan (required)**

Testing animating the position of a view to coordinate with the keyboard hiding and showing and it looks good.

Adam Comella
Microsoft Corp.
Closes https://github.com/facebook/react-native/pull/7372

Differential Revision: D3300464

Pulled By: nicklockwood

fbshipit-source-id: 3fdc161f709de11deb7de511aad28767f5d80bd6
This commit is contained in:
Adam Comella 2016-05-13 15:40:41 -07:00 коммит произвёл Facebook Github Bot 6
Родитель cac5ce3b93
Коммит 03edc75b56
1 изменённых файлов: 26 добавлений и 1 удалений

Просмотреть файл

@ -65,6 +65,8 @@ NSString *const RCTUIManagerRootViewKey = @"RCTUIManagerRootViewKey";
@end @end
static UIViewAnimationCurve _currentKeyboardAnimationCurve;
@implementation RCTAnimation @implementation RCTAnimation
static UIViewAnimationOptions UIViewAnimationOptionsFromRCTAnimationType(RCTAnimationType type) static UIViewAnimationOptions UIViewAnimationOptionsFromRCTAnimationType(RCTAnimationType type)
@ -80,13 +82,34 @@ static UIViewAnimationOptions UIViewAnimationOptionsFromRCTAnimationType(RCTAnim
return UIViewAnimationOptionCurveEaseInOut; return UIViewAnimationOptionCurveEaseInOut;
case RCTAnimationTypeKeyboard: case RCTAnimationTypeKeyboard:
// http://stackoverflow.com/questions/18870447/how-to-use-the-default-ios7-uianimation-curve // http://stackoverflow.com/questions/18870447/how-to-use-the-default-ios7-uianimation-curve
return (UIViewAnimationOptions)(7 << 16); return (UIViewAnimationOptions)(_currentKeyboardAnimationCurve << 16);
default: default:
RCTLogError(@"Unsupported animation type %zd", type); RCTLogError(@"Unsupported animation type %zd", type);
return UIViewAnimationOptionCurveEaseInOut; return UIViewAnimationOptionCurveEaseInOut;
} }
} }
// Use a custom initialization function rather than implementing `+initialize` so that we can control
// when the initialization code runs. `+initialize` runs immediately before the first message is sent
// to the class which may be too late for us. By this time, we may have missed some
// `UIKeyboardWillChangeFrameNotification`s.
+ (void)initializeStatics
{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillChangeFrame:)
name:UIKeyboardWillChangeFrameNotification
object:nil];
});
}
+ (void)keyboardWillChangeFrame:(NSNotification *)notification
{
NSDictionary *userInfo = notification.userInfo;
_currentKeyboardAnimationCurve = [userInfo[UIKeyboardAnimationCurveUserInfoKey] integerValue];
}
- (instancetype)initWithDuration:(NSTimeInterval)duration dictionary:(NSDictionary *)config - (instancetype)initWithDuration:(NSTimeInterval)duration dictionary:(NSDictionary *)config
{ {
if (!config) { if (!config) {
@ -317,6 +340,8 @@ RCT_EXPORT_MODULE()
selector:@selector(interfaceOrientationWillChange:) selector:@selector(interfaceOrientationWillChange:)
name:UIApplicationWillChangeStatusBarOrientationNotification name:UIApplicationWillChangeStatusBarOrientationNotification
object:nil]; object:nil];
[RCTAnimation initializeStatics];
} }
- (dispatch_queue_t)methodQueue - (dispatch_queue_t)methodQueue