From f383bf2b83c42cca96df5704c3b6c5ceba7fbb54 Mon Sep 17 00:00:00 2001 From: Stanislav Vishnevskiy Date: Thu, 25 Jun 2015 09:14:19 -0700 Subject: [PATCH] [LayoutAnimation] RCTAnimationTypeKeyboard Summary: This adds the Keyboard animation type for when you want to animate UI based on the keyboard appearing/disappearing. Closes https://github.com/facebook/react-native/pull/1366 Github Author: Stanislav Vishnevskiy Test Plan: Imported from GitHub, without a `Test Plan:` line. --- Libraries/Animation/LayoutAnimation.js | 1 + React/Base/RCTConvert.m | 1 + React/Modules/RCTUIManager.m | 17 ++++++++++------- React/Views/RCTAnimationType.h | 1 + 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/Libraries/Animation/LayoutAnimation.js b/Libraries/Animation/LayoutAnimation.js index c297123ba..fbfc2d44f 100644 --- a/Libraries/Animation/LayoutAnimation.js +++ b/Libraries/Animation/LayoutAnimation.js @@ -23,6 +23,7 @@ var TypesEnum = { easeInEaseOut: true, easeIn: true, easeOut: true, + keyboard: true, }; var Types = keyMirror(TypesEnum); diff --git a/React/Base/RCTConvert.m b/React/Base/RCTConvert.m index 8461db3e9..6347bcc01 100644 --- a/React/Base/RCTConvert.m +++ b/React/Base/RCTConvert.m @@ -997,6 +997,7 @@ RCT_ENUM_CONVERTER(RCTAnimationType, (@{ @"easeIn": @(RCTAnimationTypeEaseIn), @"easeOut": @(RCTAnimationTypeEaseOut), @"easeInEaseOut": @(RCTAnimationTypeEaseInEaseOut), + @"keyboard": @(RCTAnimationTypeKeyboard), }), RCTAnimationTypeEaseInEaseOut, integerValue) @end diff --git a/React/Modules/RCTUIManager.m b/React/Modules/RCTUIManager.m index a69b8e7dd..959379a87 100644 --- a/React/Modules/RCTUIManager.m +++ b/React/Modules/RCTUIManager.m @@ -51,20 +51,23 @@ static NSDictionary *RCTPropsMerge(NSDictionary *beforeProps, NSDictionary *newP @implementation RCTAnimation -static UIViewAnimationCurve UIViewAnimationCurveFromRCTAnimationType(RCTAnimationType type) +static UIViewAnimationOptions UIViewAnimationOptionsFromRCTAnimationType(RCTAnimationType type) { switch (type) { case RCTAnimationTypeLinear: - return UIViewAnimationCurveLinear; + return UIViewAnimationOptionCurveLinear; case RCTAnimationTypeEaseIn: - return UIViewAnimationCurveEaseIn; + return UIViewAnimationOptionCurveEaseIn; case RCTAnimationTypeEaseOut: - return UIViewAnimationCurveEaseOut; + return UIViewAnimationOptionCurveEaseOut; case RCTAnimationTypeEaseInEaseOut: - return UIViewAnimationCurveEaseInOut; + return UIViewAnimationOptionCurveEaseInOut; + case RCTAnimationTypeKeyboard: + // http://stackoverflow.com/questions/18870447/how-to-use-the-default-ios7-uianimation-curve + return (UIViewAnimationOptions)(7 << 16); default: RCTLogError(@"Unsupported animation type %zd", type); - return UIViewAnimationCurveEaseInOut; + return UIViewAnimationOptionCurveEaseInOut; } } @@ -116,7 +119,7 @@ static UIViewAnimationCurve UIViewAnimationCurveFromRCTAnimationType(RCTAnimatio } else { UIViewAnimationOptions options = UIViewAnimationOptionBeginFromCurrentState | - UIViewAnimationCurveFromRCTAnimationType(_animationType); + UIViewAnimationOptionsFromRCTAnimationType(_animationType); [UIView animateWithDuration:_duration delay:_delay diff --git a/React/Views/RCTAnimationType.h b/React/Views/RCTAnimationType.h index 1426b54cb..0f2703ea6 100644 --- a/React/Views/RCTAnimationType.h +++ b/React/Views/RCTAnimationType.h @@ -15,4 +15,5 @@ typedef NS_ENUM(NSInteger, RCTAnimationType) { RCTAnimationTypeEaseIn, RCTAnimationTypeEaseOut, RCTAnimationTypeEaseInEaseOut, + RCTAnimationTypeKeyboard, };