react-native-keyboard-controller 1.0.1 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/android/build.gradle +72 -3
  2. package/android/gradle.properties +1 -1
  3. package/android/src/fabric/java/com/reactnativekeyboardcontroller/KeyboardControllerComponentsRegistry.kt +31 -0
  4. package/android/src/fabric/java/com/reactnativekeyboardcontroller/KeyboardControllerModule.kt +25 -0
  5. package/android/src/fabric/java/com/reactnativekeyboardcontroller/KeyboardControllerViewManager.kt +32 -0
  6. package/android/src/fabric/java/com/reactnativekeyboardcontroller/StatusBarManagerCompatModule.kt +25 -0
  7. package/android/src/main/java/com/reactnativekeyboardcontroller/KeyboardAnimationCallback.kt +188 -0
  8. package/android/src/main/java/com/reactnativekeyboardcontroller/{KeyboardControllerModule.kt → KeyboardControllerModuleImpl.kt} +5 -17
  9. package/android/src/main/java/com/reactnativekeyboardcontroller/KeyboardControllerPackage.kt +5 -0
  10. package/android/src/main/java/com/reactnativekeyboardcontroller/KeyboardControllerViewManagerImpl.kt +71 -0
  11. package/android/src/main/java/com/reactnativekeyboardcontroller/{StatusBarManagerCompatModule.kt → StatusBarManagerCompatImpl.kt} +10 -14
  12. package/android/src/main/jni/Android.mk +42 -0
  13. package/android/src/main/jni/KeyboardControllerComponentsRegistry.cpp +71 -0
  14. package/android/src/main/jni/KeyboardControllerComponentsRegistry.h +35 -0
  15. package/android/src/main/jni/OnLoad.cpp +9 -0
  16. package/android/src/paper/java/com/reactnativekeyboardcontroller/KeyboardControllerModule.kt +31 -0
  17. package/android/src/paper/java/com/reactnativekeyboardcontroller/KeyboardControllerViewManager.kt +26 -0
  18. package/android/src/paper/java/com/reactnativekeyboardcontroller/StatusBarManagerCompatModule.kt +34 -0
  19. package/ios/.clang-format +90 -0
  20. package/ios/KeyboardController.xcodeproj/project.pbxproj +22 -14
  21. package/ios/KeyboardControllerModule-Header.h +6 -2
  22. package/ios/KeyboardControllerModule.mm +105 -0
  23. package/ios/KeyboardControllerView.h +23 -0
  24. package/ios/KeyboardControllerView.mm +81 -0
  25. package/ios/{KeyboardControllerViewManager.m → KeyboardControllerViewManager.mm} +1 -1
  26. package/ios/KeyboardControllerViewManager.swift +13 -64
  27. package/ios/KeyboardMoveEvent.h +18 -0
  28. package/ios/KeyboardMoveEvent.m +74 -0
  29. package/ios/KeyboardMovementObserver.swift +90 -0
  30. package/lib/commonjs/KeyboardControllerViewNativeComponent.js +16 -0
  31. package/lib/commonjs/KeyboardControllerViewNativeComponent.js.map +1 -0
  32. package/lib/commonjs/NativeKeyboardController.js +13 -0
  33. package/lib/commonjs/NativeKeyboardController.js.map +1 -0
  34. package/lib/commonjs/NativeStatusBarManagerCompat.js +13 -0
  35. package/lib/commonjs/NativeStatusBarManagerCompat.js.map +1 -0
  36. package/lib/commonjs/animated.js.map +1 -1
  37. package/lib/commonjs/architecture.js +13 -0
  38. package/lib/commonjs/architecture.js.map +1 -0
  39. package/lib/commonjs/index.js.map +1 -1
  40. package/lib/commonjs/monkey-patch.js +3 -1
  41. package/lib/commonjs/monkey-patch.js.map +1 -1
  42. package/lib/commonjs/native.js +4 -2
  43. package/lib/commonjs/native.js.map +1 -1
  44. package/lib/commonjs/replicas.js.map +1 -1
  45. package/lib/module/KeyboardControllerViewNativeComponent.js +4 -0
  46. package/lib/module/KeyboardControllerViewNativeComponent.js.map +1 -0
  47. package/lib/module/NativeKeyboardController.js +3 -0
  48. package/lib/module/NativeKeyboardController.js.map +1 -0
  49. package/lib/module/NativeStatusBarManagerCompat.js +3 -0
  50. package/lib/module/NativeStatusBarManagerCompat.js.map +1 -0
  51. package/lib/module/animated.js.map +1 -1
  52. package/lib/module/architecture.js +5 -0
  53. package/lib/module/architecture.js.map +1 -0
  54. package/lib/module/index.js.map +1 -1
  55. package/lib/module/monkey-patch.js +2 -1
  56. package/lib/module/monkey-patch.js.map +1 -1
  57. package/lib/module/native.js +3 -2
  58. package/lib/module/native.js.map +1 -1
  59. package/lib/module/replicas.js.map +1 -1
  60. package/lib/typescript/KeyboardControllerViewNativeComponent.d.ts +13 -0
  61. package/lib/typescript/NativeKeyboardController.d.ts +10 -0
  62. package/lib/typescript/NativeStatusBarManagerCompat.d.ts +10 -0
  63. package/lib/typescript/architecture.d.ts +2 -0
  64. package/lib/typescript/native.d.ts +1 -1
  65. package/lib/typescript/replicas.d.ts +3 -5
  66. package/package.json +23 -6
  67. package/react-native-keyboard-controller.podspec +19 -0
  68. package/src/KeyboardControllerViewNativeComponent.ts +23 -0
  69. package/src/NativeKeyboardController.ts +16 -0
  70. package/src/NativeStatusBarManagerCompat.ts +13 -0
  71. package/src/architecture.ts +4 -0
  72. package/src/monkey-patch.tsx +5 -1
  73. package/src/native.ts +12 -7
  74. package/android/src/main/java/com/reactnativekeyboardcontroller/KeyboardControllerViewManager.kt +0 -77
  75. package/android/src/main/java/com/reactnativekeyboardcontroller/TranslateDeferringInsetsAnimationCallback.kt +0 -158
  76. package/ios/KeyboardControllerModule.m +0 -21
  77. package/ios/KeyboardControllerModule.swift +0 -53
  78. package/ios/KeyboardMoveEvent.swift +0 -41
@@ -0,0 +1,71 @@
1
+ #include "KeyboardControllerComponentsRegistry.h"
2
+
3
+ #include <CoreComponentsRegistry.h>
4
+ #include <fbjni/fbjni.h>
5
+ #include <react/renderer/componentregistry/ComponentDescriptorProviderRegistry.h>
6
+ #include <react/renderer/components/rncore/ComponentDescriptors.h>
7
+ #include <react/renderer/components/reactnativekeyboardcontroller/ComponentDescriptors.h>
8
+ #include <memory>
9
+
10
+ namespace facebook {
11
+ namespace react {
12
+
13
+ KeyboardControllerComponentsRegistry::KeyboardControllerComponentsRegistry(
14
+ ComponentFactory *delegate)
15
+ : delegate_(delegate) {}
16
+
17
+ std::shared_ptr<ComponentDescriptorProviderRegistry const>
18
+ KeyboardControllerComponentsRegistry::sharedProviderRegistry() {
19
+ auto providerRegistry = CoreComponentsRegistry::sharedProviderRegistry();
20
+
21
+ // react-native-keyboard-controller
22
+ providerRegistry->add(concreteComponentDescriptorProvider<KeyboardControllerViewComponentDescriptor>());
23
+
24
+ return providerRegistry;
25
+ }
26
+
27
+ jni::local_ref<KeyboardControllerComponentsRegistry::jhybriddata>
28
+ KeyboardControllerComponentsRegistry::initHybrid(
29
+ jni::alias_ref<jclass>,
30
+ ComponentFactory *delegate) {
31
+ auto instance = makeCxxInstance(delegate);
32
+
33
+ auto buildRegistryFunction =
34
+ [](EventDispatcher::Weak const &eventDispatcher,
35
+ ContextContainer::Shared const &contextContainer)
36
+ -> ComponentDescriptorRegistry::Shared {
37
+ auto registry = KeyboardControllerComponentsRegistry::sharedProviderRegistry()
38
+ ->createComponentDescriptorRegistry(
39
+ {eventDispatcher, contextContainer});
40
+
41
+ auto mutableRegistry =
42
+ std::const_pointer_cast<ComponentDescriptorRegistry>(registry);
43
+
44
+ mutableRegistry->setFallbackComponentDescriptor(
45
+ std::make_shared<UnimplementedNativeViewComponentDescriptor>(
46
+ ComponentDescriptorParameters{
47
+ eventDispatcher, contextContainer, nullptr}));
48
+
49
+ return registry;
50
+ };
51
+
52
+ delegate->buildRegistryFunction = buildRegistryFunction;
53
+ return instance;
54
+ }
55
+
56
+ void KeyboardControllerComponentsRegistry::registerNatives() {
57
+ registerHybrid({
58
+ makeNativeMethod("initHybrid", KeyboardControllerComponentsRegistry::initHybrid),
59
+ });
60
+
61
+ // This is a temporary solution that allows components exported by react-native-keyboard-controller
62
+ // library to be added to the main component registry. This code is triggered
63
+ // when c++ react-native-keyboard-controller library is initialized and is needed because RN's autolinking
64
+ // does not currently support Fabric components. As a consequence, users would need
65
+ // to manually put library initialization calls in their ReactNativeHost implementation
66
+ // which is undesirable.
67
+ sharedProviderRegistry();
68
+ }
69
+
70
+ } // namespace react
71
+ } // namespace facebook
@@ -0,0 +1,35 @@
1
+ #pragma once
2
+
3
+ #include <ComponentFactory.h>
4
+ #include <fbjni/fbjni.h>
5
+ #include <react/renderer/componentregistry/ComponentDescriptorProviderRegistry.h>
6
+ #include <react/renderer/componentregistry/ComponentDescriptorRegistry.h>
7
+ #include <memory>
8
+
9
+ namespace facebook {
10
+ namespace react {
11
+
12
+ class KeyboardControllerComponentsRegistry
13
+ : public facebook::jni::HybridClass<KeyboardControllerComponentsRegistry> {
14
+ public:
15
+ constexpr static auto kJavaDescriptor =
16
+ "Lcom/reactnativekeyboardcontroller/KeyboardControllerComponentsRegistry;";
17
+
18
+ static void registerNatives();
19
+
20
+ explicit KeyboardControllerComponentsRegistry(ComponentFactory *delegate);
21
+
22
+ private:
23
+ friend HybridBase;
24
+
25
+ static std::shared_ptr<ComponentDescriptorProviderRegistry const> sharedProviderRegistry();
26
+
27
+ const ComponentFactory *delegate_;
28
+
29
+ static jni::local_ref<jhybriddata> initHybrid(
30
+ jni::alias_ref<jclass>,
31
+ ComponentFactory *delegate);
32
+ };
33
+
34
+ } // namespace react
35
+ } // namespace facebook
@@ -0,0 +1,9 @@
1
+ #include <fbjni/fbjni.h>
2
+
3
+ #include "KeyboardControllerComponentsRegistry.h"
4
+
5
+ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *) {
6
+ return facebook::jni::initialize(vm, [] {
7
+ facebook::react::KeyboardControllerComponentsRegistry::registerNatives();
8
+ });
9
+ }
@@ -0,0 +1,31 @@
1
+ package com.reactnativekeyboardcontroller
2
+
3
+ import com.facebook.react.bridge.ReactApplicationContext
4
+ import com.facebook.react.bridge.ReactContextBaseJavaModule
5
+ import com.facebook.react.bridge.ReactMethod
6
+
7
+ class KeyboardControllerModule(mReactContext: ReactApplicationContext) : ReactContextBaseJavaModule(mReactContext) {
8
+ private val module = KeyboardControllerModuleImpl(mReactContext)
9
+
10
+ override fun getName(): String = KeyboardControllerModuleImpl.NAME
11
+
12
+ @ReactMethod(isBlockingSynchronousMethod = true)
13
+ fun setInputMode(mode: Int) {
14
+ module.setInputMode(mode)
15
+ }
16
+
17
+ @ReactMethod(isBlockingSynchronousMethod = true)
18
+ fun setDefaultMode() {
19
+ module.setDefaultMode()
20
+ }
21
+
22
+ @ReactMethod
23
+ fun addListener(eventName: String?) {
24
+ /* Required for RN built-in Event Emitter Calls. */
25
+ }
26
+
27
+ @ReactMethod
28
+ fun removeListeners(count: Int?) {
29
+ /* Required for RN built-in Event Emitter Calls. */
30
+ }
31
+ }
@@ -0,0 +1,26 @@
1
+ package com.reactnativekeyboardcontroller
2
+
3
+ import com.facebook.react.bridge.ReactApplicationContext
4
+ import com.facebook.react.uimanager.ThemedReactContext
5
+ import com.facebook.react.uimanager.annotations.ReactProp
6
+ import com.facebook.react.views.view.ReactViewGroup
7
+ import com.facebook.react.views.view.ReactViewManager
8
+
9
+ class KeyboardControllerViewManager(mReactContext: ReactApplicationContext) : ReactViewManager() {
10
+ private val manager = KeyboardControllerViewManagerImpl(mReactContext)
11
+
12
+ override fun getName(): String = KeyboardControllerViewManagerImpl.NAME
13
+
14
+ override fun createViewInstance(reactContext: ThemedReactContext): ReactViewGroup {
15
+ return manager.createViewInstance(reactContext)
16
+ }
17
+
18
+ @ReactProp(name = "statusBarTranslucent")
19
+ fun setStatusBarTranslucent(view: ReactViewGroup, isStatusBarTranslucent: Boolean) {
20
+ manager.setStatusBarTranslucent(view, isStatusBarTranslucent)
21
+ }
22
+
23
+ override fun getExportedCustomDirectEventTypeConstants(): MutableMap<String, Any> {
24
+ return manager.getExportedCustomDirectEventTypeConstants()
25
+ }
26
+ }
@@ -0,0 +1,34 @@
1
+ package com.reactnativekeyboardcontroller
2
+
3
+ import android.os.Build
4
+ import androidx.annotation.RequiresApi
5
+ import com.facebook.react.bridge.ReactApplicationContext
6
+ import com.facebook.react.bridge.ReactContextBaseJavaModule
7
+ import com.facebook.react.bridge.ReactMethod
8
+
9
+ class StatusBarManagerCompatModule(private val mReactContext: ReactApplicationContext) : ReactContextBaseJavaModule(mReactContext) {
10
+ private val module = StatusBarManagerCompatImpl(mReactContext)
11
+
12
+ override fun getName(): String = StatusBarManagerCompatImpl.NAME
13
+
14
+ @ReactMethod
15
+ private fun setHidden(hidden: Boolean) {
16
+ module.setHidden(hidden)
17
+ }
18
+
19
+ @ReactMethod
20
+ @RequiresApi(Build.VERSION_CODES.LOLLIPOP)
21
+ private fun setColor(color: Int, animated: Boolean) {
22
+ module.setColor(color, animated)
23
+ }
24
+
25
+ @ReactMethod
26
+ private fun setTranslucent(translucent: Boolean) {
27
+ module.setTranslucent(translucent)
28
+ }
29
+
30
+ @ReactMethod
31
+ private fun setStyle(style: String) {
32
+ module.setStyle(style)
33
+ }
34
+ }
@@ -0,0 +1,90 @@
1
+ ---
2
+ AccessModifierOffset: -1
3
+ AlignAfterOpenBracket: AlwaysBreak
4
+ AlignConsecutiveAssignments: false
5
+ AlignConsecutiveDeclarations: false
6
+ AlignEscapedNewlinesLeft: true
7
+ AlignOperands: false
8
+ AlignTrailingComments: false
9
+ AllowAllParametersOfDeclarationOnNextLine: false
10
+ AllowShortBlocksOnASingleLine: false
11
+ AllowShortCaseLabelsOnASingleLine: false
12
+ AllowShortFunctionsOnASingleLine: Empty
13
+ AllowShortIfStatementsOnASingleLine: false
14
+ AllowShortLoopsOnASingleLine: false
15
+ AlwaysBreakAfterReturnType: None
16
+ AlwaysBreakBeforeMultilineStrings: true
17
+ AlwaysBreakTemplateDeclarations: true
18
+ BinPackArguments: false
19
+ BinPackParameters: false
20
+ BraceWrapping:
21
+ AfterClass: false
22
+ AfterControlStatement: false
23
+ AfterEnum: false
24
+ AfterFunction: false
25
+ AfterNamespace: false
26
+ AfterObjCDeclaration: false
27
+ AfterStruct: false
28
+ AfterUnion: false
29
+ BeforeCatch: false
30
+ BeforeElse: false
31
+ IndentBraces: false
32
+ BreakBeforeBinaryOperators: None
33
+ BreakBeforeBraces: Attach
34
+ BreakBeforeTernaryOperators: true
35
+ BreakConstructorInitializersBeforeComma: false
36
+ BreakAfterJavaFieldAnnotations: false
37
+ BreakStringLiterals: false
38
+ ColumnLimit: 80
39
+ CommentPragmas: '^ IWYU pragma:'
40
+ ConstructorInitializerAllOnOneLineOrOnePerLine: true
41
+ ConstructorInitializerIndentWidth: 4
42
+ ContinuationIndentWidth: 4
43
+ Cpp11BracedListStyle: true
44
+ DerivePointerAlignment: false
45
+ DisableFormat: false
46
+ ForEachMacros: [ FOR_EACH_RANGE, FOR_EACH, ]
47
+ IncludeCategories:
48
+ - Regex: '^<.*\.h(pp)?>'
49
+ Priority: 1
50
+ - Regex: '^<.*'
51
+ Priority: 2
52
+ - Regex: '.*'
53
+ Priority: 3
54
+ IndentCaseLabels: true
55
+ IndentWidth: 2
56
+ IndentWrappedFunctionNames: false
57
+ KeepEmptyLinesAtTheStartOfBlocks: false
58
+ MacroBlockBegin: ''
59
+ MacroBlockEnd: ''
60
+ MaxEmptyLinesToKeep: 1
61
+ NamespaceIndentation: None
62
+ ObjCBlockIndentWidth: 2
63
+ ObjCSpaceAfterProperty: true
64
+ ObjCSpaceBeforeProtocolList: true
65
+ PenaltyBreakBeforeFirstCallParameter: 1
66
+ PenaltyBreakComment: 300
67
+ PenaltyBreakFirstLessLess: 120
68
+ PenaltyBreakString: 1000
69
+ PenaltyExcessCharacter: 1000000
70
+ PenaltyReturnTypeOnItsOwnLine: 200
71
+ PointerAlignment: Right
72
+ ReflowComments: true
73
+ SortIncludes: true
74
+ SpaceAfterCStyleCast: false
75
+ SpaceBeforeAssignmentOperators: true
76
+ SpaceBeforeParens: ControlStatements
77
+ SpaceInEmptyParentheses: false
78
+ SpacesBeforeTrailingComments: 1
79
+ SpacesInAngles: false
80
+ SpacesInContainerLiterals: true
81
+ SpacesInCStyleCastParentheses: false
82
+ SpacesInParentheses: false
83
+ SpacesInSquareBrackets: false
84
+ Standard: Cpp11
85
+ TabWidth: 8
86
+ UseTab: Never
87
+ ---
88
+ Language: ObjC
89
+ ColumnLimit: 100
90
+ BreakBeforeBraces: WebKit
@@ -7,9 +7,10 @@
7
7
  objects = {
8
8
 
9
9
  /* Begin PBXBuildFile section */
10
- F359D34D28133BE1000B6AFE /* KeyboardControllerModule.swift in Sources */ = {isa = PBXBuildFile; fileRef = F359D34C28133BE1000B6AFE /* KeyboardControllerModule.swift */; };
11
- F359D34F28133C26000B6AFE /* KeyboardControllerModule.m in Sources */ = {isa = PBXBuildFile; fileRef = F359D34E28133C26000B6AFE /* KeyboardControllerModule.m */; };
12
- F3FF0915281851CC006831B1 /* KeyboardMoveEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = F3FF0914281851CC006831B1 /* KeyboardMoveEvent.swift */; };
10
+ F333F8D428996B8D0015B05F /* KeyboardControllerView.mm in Sources */ = {isa = PBXBuildFile; fileRef = F333F8D228996B8D0015B05F /* KeyboardControllerView.mm */; };
11
+ F359D34F28133C26000B6AFE /* KeyboardControllerModule.mm in Sources */ = {isa = PBXBuildFile; fileRef = F359D34E28133C26000B6AFE /* KeyboardControllerModule.mm */; };
12
+ F3626A0728B3FE760021B2D9 /* KeyboardMovementObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = F3626A0628B3FE760021B2D9 /* KeyboardMovementObserver.swift */; };
13
+ F3F50669289E653B003091D6 /* KeyboardMoveEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = F3F50668289E653B003091D6 /* KeyboardMoveEvent.m */; };
13
14
  F4FF95D7245B92E800C19C63 /* KeyboardControllerViewManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4FF95D6245B92E800C19C63 /* KeyboardControllerViewManager.swift */; };
14
15
  /* End PBXBuildFile section */
15
16
 
@@ -27,11 +28,14 @@
27
28
 
28
29
  /* Begin PBXFileReference section */
29
30
  134814201AA4EA6300B7C361 /* libKeyboardController.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libKeyboardController.a; sourceTree = BUILT_PRODUCTS_DIR; };
30
- B3E7B5891CC2AC0600A0062D /* KeyboardControllerViewManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KeyboardControllerViewManager.m; sourceTree = "<group>"; };
31
- F359D34C28133BE1000B6AFE /* KeyboardControllerModule.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyboardControllerModule.swift; sourceTree = "<group>"; };
32
- F359D34E28133C26000B6AFE /* KeyboardControllerModule.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = KeyboardControllerModule.m; sourceTree = "<group>"; };
31
+ B3E7B5891CC2AC0600A0062D /* KeyboardControllerViewManager.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = KeyboardControllerViewManager.mm; sourceTree = "<group>"; };
32
+ F333F8D128996B1C0015B05F /* KeyboardControllerView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = KeyboardControllerView.h; sourceTree = "<group>"; };
33
+ F333F8D228996B8D0015B05F /* KeyboardControllerView.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = KeyboardControllerView.mm; sourceTree = "<group>"; };
34
+ F359D34E28133C26000B6AFE /* KeyboardControllerModule.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = KeyboardControllerModule.mm; sourceTree = "<group>"; };
33
35
  F359D35028133C6F000B6AFE /* KeyboardControllerModule-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "KeyboardControllerModule-Header.h"; sourceTree = "<group>"; };
34
- F3FF0914281851CC006831B1 /* KeyboardMoveEvent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyboardMoveEvent.swift; sourceTree = "<group>"; };
36
+ F3626A0628B3FE760021B2D9 /* KeyboardMovementObserver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyboardMovementObserver.swift; sourceTree = "<group>"; };
37
+ F3F50667289E653B003091D6 /* KeyboardMoveEvent.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = KeyboardMoveEvent.h; sourceTree = "<group>"; };
38
+ F3F50668289E653B003091D6 /* KeyboardMoveEvent.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = KeyboardMoveEvent.m; sourceTree = "<group>"; };
35
39
  F4FF95D5245B92E700C19C63 /* KeyboardController-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "KeyboardController-Bridging-Header.h"; sourceTree = "<group>"; };
36
40
  F4FF95D6245B92E800C19C63 /* KeyboardControllerViewManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyboardControllerViewManager.swift; sourceTree = "<group>"; };
37
41
  /* End PBXFileReference section */
@@ -58,12 +62,15 @@
58
62
  58B511D21A9E6C8500147676 = {
59
63
  isa = PBXGroup;
60
64
  children = (
61
- F3FF0914281851CC006831B1 /* KeyboardMoveEvent.swift */,
65
+ F3F50667289E653B003091D6 /* KeyboardMoveEvent.h */,
66
+ F3F50668289E653B003091D6 /* KeyboardMoveEvent.m */,
67
+ F3626A0628B3FE760021B2D9 /* KeyboardMovementObserver.swift */,
68
+ F333F8D228996B8D0015B05F /* KeyboardControllerView.mm */,
69
+ F333F8D128996B1C0015B05F /* KeyboardControllerView.h */,
62
70
  F359D35028133C6F000B6AFE /* KeyboardControllerModule-Header.h */,
63
- F359D34E28133C26000B6AFE /* KeyboardControllerModule.m */,
64
- F359D34C28133BE1000B6AFE /* KeyboardControllerModule.swift */,
71
+ F359D34E28133C26000B6AFE /* KeyboardControllerModule.mm */,
65
72
  F4FF95D6245B92E800C19C63 /* KeyboardControllerViewManager.swift */,
66
- B3E7B5891CC2AC0600A0062D /* KeyboardControllerViewManager.m */,
73
+ B3E7B5891CC2AC0600A0062D /* KeyboardControllerViewManager.mm */,
67
74
  F4FF95D5245B92E700C19C63 /* KeyboardController-Bridging-Header.h */,
68
75
  134814211AA4EA7D00B7C361 /* Products */,
69
76
  );
@@ -126,10 +133,11 @@
126
133
  isa = PBXSourcesBuildPhase;
127
134
  buildActionMask = 2147483647;
128
135
  files = (
129
- F3FF0915281851CC006831B1 /* KeyboardMoveEvent.swift in Sources */,
130
- F359D34F28133C26000B6AFE /* KeyboardControllerModule.m in Sources */,
131
- F359D34D28133BE1000B6AFE /* KeyboardControllerModule.swift in Sources */,
136
+ F3626A0728B3FE760021B2D9 /* KeyboardMovementObserver.swift in Sources */,
137
+ F359D34F28133C26000B6AFE /* KeyboardControllerModule.mm in Sources */,
132
138
  F4FF95D7245B92E800C19C63 /* KeyboardControllerViewManager.swift in Sources */,
139
+ F333F8D428996B8D0015B05F /* KeyboardControllerView.mm in Sources */,
140
+ F3F50669289E653B003091D6 /* KeyboardMoveEvent.m in Sources */,
133
141
  );
134
142
  runOnlyForDeploymentPostprocessing = 0;
135
143
  };
@@ -1,10 +1,14 @@
1
1
  //
2
- // Module-Bridging-Header.h
2
+ // KeyboardControllerModule-Header.h
3
3
  // KeyboardController
4
4
  //
5
5
  // Created by Kiryl Ziusko on 22.04.22.
6
6
  // Copyright © 2022 Facebook. All rights reserved.
7
7
  //
8
8
 
9
- #import <React/RCTBridgeModule.h>
10
9
  #import <React/RCTEventEmitter.h>
10
+
11
+ @interface KeyboardController : RCTEventEmitter
12
+ + (KeyboardController *)shared;
13
+ - (void)sendEvent:(NSString *)name body:(id)body;
14
+ @end
@@ -0,0 +1,105 @@
1
+ //
2
+ // KeyboardControllerModule.m
3
+ // KeyboardController
4
+ //
5
+ // Created by Kiryl Ziusko on 22.04.22.
6
+ // Copyright © 2022 Facebook. All rights reserved.
7
+ //
8
+
9
+ #import <React/RCTBridgeModule.h>
10
+ #import <React/RCTEventEmitter.h>
11
+
12
+ // Thanks to this guard, we won't import this header when we build for the old architecture.
13
+ #ifdef RCT_NEW_ARCH_ENABLED
14
+ #import <FBReactNativeSpec/FBReactNativeSpec.h>
15
+ #import "RNKeyboardControllerSpec.h"
16
+ #endif
17
+
18
+ #import "KeyboardControllerModule-Header.h"
19
+
20
+ #import <React/RCTEventDispatcherProtocol.h>
21
+
22
+ #ifdef RCT_NEW_ARCH_ENABLED
23
+ @interface KeyboardController () <NativeKeyboardControllerSpec>
24
+ @end
25
+ #endif
26
+
27
+ @implementation KeyboardController {
28
+ bool hasListeners;
29
+ }
30
+
31
+ static KeyboardController *shared = nil;
32
+
33
+ RCT_EXPORT_MODULE()
34
+
35
+ - (instancetype)init
36
+ {
37
+ self = [super init];
38
+ shared = self;
39
+
40
+ return self;
41
+ }
42
+
43
+ + (BOOL)requiresMainQueueSetup
44
+ {
45
+ return NO;
46
+ }
47
+
48
+ #ifdef RCT_NEW_ARCH_ENABLED
49
+ - (void)setDefaultMode
50
+ #else
51
+ RCT_EXPORT_METHOD(setDefaultMode)
52
+ #endif
53
+ {
54
+ }
55
+
56
+ #ifdef RCT_NEW_ARCH_ENABLED
57
+ - (void)setInputMode:(double)mode
58
+ #else
59
+ RCT_EXPORT_METHOD(setInputMode : (nonnull NSNumber *)mode)
60
+ #endif
61
+ {
62
+ }
63
+
64
+ + (KeyboardController *)shared
65
+ {
66
+ return shared;
67
+ }
68
+
69
+ - (void)startObserving
70
+ {
71
+ hasListeners = YES;
72
+ }
73
+
74
+ - (void)stopObserving
75
+ {
76
+ hasListeners = NO;
77
+ }
78
+
79
+ - (void)sendEvent:(NSString *)name body:(id)body
80
+ {
81
+ if (hasListeners) {
82
+ [self sendEventWithName:name body:body];
83
+ }
84
+ }
85
+
86
+ - (NSArray<NSString *> *)supportedEvents
87
+ {
88
+ return @[
89
+ @"KeyboardController::keyboardWillShow",
90
+ @"KeyboardController::keyboardDidShow",
91
+ @"KeyboardController::keyboardWillHide",
92
+ @"KeyboardController::keyboardDidHide",
93
+ ];
94
+ }
95
+
96
+ // Thanks to this guard, we won't compile this code when we build for the old architecture.
97
+ #ifdef RCT_NEW_ARCH_ENABLED
98
+ - (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
99
+ (const facebook::react::ObjCTurboModule::InitParams &)params
100
+ {
101
+ return std::make_shared<facebook::react::NativeKeyboardControllerSpecJSI>(params);
102
+ }
103
+ #endif
104
+
105
+ @end
@@ -0,0 +1,23 @@
1
+ //
2
+ // KeyboardControllerView.h
3
+ // KeyboardController
4
+ //
5
+ // Created by Kiryl Ziusko on 2.08.22.
6
+ // Copyright © 2022 Facebook. All rights reserved.
7
+ //
8
+
9
+ #pragma once
10
+
11
+ // This guard prevent this file to be compiled in the old architecture.
12
+ #ifdef RCT_NEW_ARCH_ENABLED
13
+ #import <React/RCTViewComponentView.h>
14
+ #import <UIKit/UIKit.h>
15
+
16
+ NS_ASSUME_NONNULL_BEGIN
17
+
18
+ @interface KeyboardControllerView : RCTViewComponentView
19
+ @end
20
+
21
+ NS_ASSUME_NONNULL_END
22
+
23
+ #endif /* RCT_NEW_ARCH_ENABLED */
@@ -0,0 +1,81 @@
1
+ //
2
+ // KeyboardControllerView.mm
3
+ // KeyboardController
4
+ //
5
+ // Created by Kiryl Ziusko on 2.08.22.
6
+ // Copyright © 2022 Facebook. All rights reserved.
7
+ //
8
+
9
+ // This guard prevent the code from being compiled in the old architecture
10
+ #ifdef RCT_NEW_ARCH_ENABLED
11
+ #import "KeyboardControllerView.h"
12
+ #import "KeyboardMoveEvent.h"
13
+ #import "react_native_keyboard_controller-Swift.h"
14
+
15
+ #import <react/renderer/components/RNKeyboardControllerViewSpec/ComponentDescriptors.h>
16
+ #import <react/renderer/components/RNKeyboardControllerViewSpec/EventEmitters.h>
17
+ #import <react/renderer/components/RNKeyboardControllerViewSpec/Props.h>
18
+ #import <react/renderer/components/RNKeyboardControllerViewSpec/RCTComponentViewHelpers.h>
19
+
20
+ #import <React/RCTBridge+Private.h>
21
+
22
+ #import "KeyboardControllerModule-Header.h"
23
+ #import "RCTFabricComponentsPlugins.h"
24
+
25
+ using namespace facebook::react;
26
+
27
+ @interface KeyboardControllerView () <RCTKeyboardControllerViewViewProtocol>
28
+
29
+ @end
30
+
31
+ @implementation KeyboardControllerView {
32
+ KeyboardMovementObserver *observer;
33
+ }
34
+
35
+ + (ComponentDescriptorProvider)componentDescriptorProvider
36
+ {
37
+ return concreteComponentDescriptorProvider<KeyboardControllerViewComponentDescriptor>();
38
+ }
39
+
40
+ - (instancetype)initWithFrame:(CGRect)frame
41
+ {
42
+ if (self = [super initWithFrame:frame]) {
43
+ static const auto defaultProps = std::make_shared<const KeyboardControllerViewProps>();
44
+ _props = defaultProps;
45
+
46
+ observer = [[KeyboardMovementObserver alloc]
47
+ initWithHandler:^(NSNumber *height, NSNumber *progress) {
48
+ if (self->_eventEmitter) {
49
+ std::dynamic_pointer_cast<const facebook::react::KeyboardControllerViewEventEmitter>(
50
+ self->_eventEmitter)
51
+ ->onKeyboardMove(
52
+ facebook::react::KeyboardControllerViewEventEmitter::OnKeyboardMove{
53
+ .height = [height intValue], .progress = static_cast<Float>(self.tag)});
54
+ }
55
+
56
+ // TODO: use built-in _eventEmitter once NativeAnimated module will use ModernEventemitter
57
+ RCTBridge *bridge = [RCTBridge currentBridge];
58
+ if (bridge) {
59
+ KeyboardMoveEvent *keyboardMoveEvent =
60
+ [[KeyboardMoveEvent alloc] initWithReactTag:@(self.tag)
61
+ height:height
62
+ progress:progress];
63
+ [bridge.eventDispatcher sendEvent:keyboardMoveEvent];
64
+ }
65
+ }
66
+ onNotify:^(NSString *event, NSDictionary *data) {
67
+ [KeyboardController.shared sendEvent:event body:data];
68
+ }];
69
+ [observer mount];
70
+ }
71
+
72
+ return self;
73
+ }
74
+
75
+ Class<RCTComponentViewProtocol> KeyboardControllerViewCls(void)
76
+ {
77
+ return KeyboardControllerView.class;
78
+ }
79
+
80
+ @end
81
+ #endif
@@ -1,6 +1,6 @@
1
1
  #import <React/RCTViewManager.h>
2
2
 
3
- @interface RCT_EXTERN_MODULE(KeyboardControllerViewManager, RCTViewManager)
3
+ @interface RCT_EXTERN_MODULE (KeyboardControllerViewManager, RCTViewManager)
4
4
 
5
5
  RCT_EXPORT_VIEW_PROPERTY(onKeyboardMove, RCTDirectEventBlock);
6
6