mirror of
https://github.com/status-im/react-native.git
synced 2025-02-10 16:36:25 +00:00
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:
parent
cac5ce3b93
commit
03edc75b56
@ -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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user