Make RCTKeyboardObserver TurboModule-compatible

Summary:
See title.

Changelog:
[iOS][Added] - Make RCTKeyboardObserver TurboModule-compatible

Reviewed By: shergin

Differential Revision: D18130902

fbshipit-source-id: 79dff2aeede7cb2485d48597a1f80e546c107e7a
This commit is contained in:
Ramanpreet Nara 2019-11-01 11:54:44 -07:00 коммит произвёл Facebook Github Bot
Родитель dc12676e3a
Коммит 6481a124da
5 изменённых файлов: 22 добавлений и 2 удалений

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

@ -78,6 +78,9 @@ rn_apple_library(
) + react_module_plugin_providers(
name = "StatusBarManager",
native_class_func = "RCTStatusBarManagerCls",
) + react_module_plugin_providers(
name = "KeyboardObserver",
native_class_func = "RCTKeyboardObserverCls",
),
plugins_header = "FBCoreModulesPlugins.h",
preprocessor_flags = OBJC_ARC_PREPROCESSOR_FLAGS + get_debug_preprocessor_flags() + rn_extra_build_flags() + [

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

@ -42,6 +42,7 @@ Class RCTAlertManagerCls(void) __attribute__((used));
Class RCTAsyncLocalStorageCls(void) __attribute__((used));
Class RCTTimingCls(void) __attribute__((used));
Class RCTStatusBarManagerCls(void) __attribute__((used));
Class RCTKeyboardObserverCls(void) __attribute__((used));
#ifdef __cplusplus
}

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

@ -31,6 +31,7 @@ Class RCTCoreModulesClassProvider(const char *name) {
{"AsyncLocalStorage", RCTAsyncLocalStorageCls},
{"Timing", RCTTimingCls},
{"StatusBarManager", RCTStatusBarManagerCls},
{"KeyboardObserver", RCTKeyboardObserverCls},
};
auto p = sCoreModuleClassMap.find(name);

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

@ -7,10 +7,16 @@
#import "RCTKeyboardObserver.h"
#import "RCTEventDispatcher.h"
#import <FBReactNativeSpec/FBReactNativeSpec.h>
#import <React/RCTEventDispatcher.h>
#import "CoreModulesPlugins.h"
static NSDictionary *RCTParseKeyboardNotification(NSNotification *notification);
@interface RCTKeyboardObserver() <NativeKeyboardObserverSpec>
@end
@implementation RCTKeyboardObserver
RCT_EXPORT_MODULE()
@ -72,6 +78,11 @@ IMPLEMENT_KEYBOARD_HANDLER(keyboardDidHide)
IMPLEMENT_KEYBOARD_HANDLER(keyboardWillChangeFrame)
IMPLEMENT_KEYBOARD_HANDLER(keyboardDidChangeFrame)
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModuleWithJsInvoker:(std::shared_ptr<facebook::react::CallInvoker>)jsInvoker
{
return std::make_shared<facebook::react::NativeKeyboardObserverSpecJSI>(self, jsInvoker);
}
@end
NS_INLINE NSDictionary *RCTRectDictionaryValue(CGRect rect)
@ -109,7 +120,7 @@ static NSDictionary *RCTParseKeyboardNotification(NSNotification *notification)
CGRect beginFrame = [userInfo[UIKeyboardFrameBeginUserInfoKey] CGRectValue];
CGRect endFrame = [userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
NSTimeInterval duration = [userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue];
UIViewAnimationCurve curve = [userInfo[UIKeyboardAnimationCurveUserInfoKey] integerValue];
UIViewAnimationCurve curve = static_cast<UIViewAnimationCurve>([userInfo[UIKeyboardAnimationCurveUserInfoKey] integerValue]);
NSInteger isLocalUserInfoKey = [userInfo[UIKeyboardIsLocalUserInfoKey] integerValue];
return @{
@ -121,3 +132,7 @@ static NSDictionary *RCTParseKeyboardNotification(NSNotification *notification)
};
#endif
}
Class RCTKeyboardObserverCls(void) {
return RCTKeyboardObserver.class;
}