react-native-keyboard-controller 1.16.8 → 1.17.1

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 (110) hide show
  1. package/README.md +2 -8
  2. package/android/src/fabric/java/com/reactnativekeyboardcontroller/OverKeyboardViewManager.kt +11 -0
  3. package/android/src/main/java/com/reactnativekeyboardcontroller/views/overlay/OverKeyboardViewGroup.kt +55 -4
  4. package/android/src/main/jni/CMakeLists.txt +85 -0
  5. package/android/src/main/jni/reactnativekeyboardcontroller.h +23 -0
  6. package/common/cpp/react/renderer/components/reactnativekeyboardcontroller/RNKCKeyboardControllerViewComponentDescriptor.h +21 -0
  7. package/common/cpp/react/renderer/components/reactnativekeyboardcontroller/RNKCKeyboardControllerViewShadowNode.cpp +7 -0
  8. package/common/cpp/react/renderer/components/reactnativekeyboardcontroller/RNKCKeyboardControllerViewShadowNode.h +23 -0
  9. package/common/cpp/react/renderer/components/reactnativekeyboardcontroller/RNKCKeyboardControllerViewState.h +21 -0
  10. package/common/cpp/react/renderer/components/reactnativekeyboardcontroller/RNKCKeyboardGestureAreaComponentDescriptor.h +20 -0
  11. package/common/cpp/react/renderer/components/reactnativekeyboardcontroller/RNKCKeyboardGestureAreaShadowNode.cpp +7 -0
  12. package/common/cpp/react/renderer/components/reactnativekeyboardcontroller/RNKCKeyboardGestureAreaShadowNode.h +23 -0
  13. package/common/cpp/react/renderer/components/reactnativekeyboardcontroller/RNKCKeyboardGestureAreaState.h +21 -0
  14. package/common/cpp/react/renderer/components/reactnativekeyboardcontroller/RNKCOverKeyboardViewComponentDescriptor.h +31 -0
  15. package/common/cpp/react/renderer/components/reactnativekeyboardcontroller/RNKCOverKeyboardViewShadowNode.cpp +7 -0
  16. package/common/cpp/react/renderer/components/reactnativekeyboardcontroller/RNKCOverKeyboardViewShadowNode.h +23 -0
  17. package/common/cpp/react/renderer/components/reactnativekeyboardcontroller/RNKCOverKeyboardViewState.cpp +12 -0
  18. package/common/cpp/react/renderer/components/reactnativekeyboardcontroller/RNKCOverKeyboardViewState.h +43 -0
  19. package/ios/KeyboardController-Bridging-Header.h +0 -1
  20. package/ios/delegates/KCTextInputCompositeDelegate.swift +16 -1
  21. package/ios/objc/{RCTUITextView+DelegateManager.h → UITextView+DelegateManager.h} +2 -4
  22. package/ios/objc/{RCTUITextView+DelegateManager.m → UITextView+DelegateManager.m} +3 -3
  23. package/ios/observers/FocusedInputObserver.swift +5 -3
  24. package/ios/views/KeyboardControllerView.mm +1 -1
  25. package/ios/views/KeyboardGestureAreaManager.mm +1 -1
  26. package/ios/views/OverKeyboardViewManager.mm +1 -1
  27. package/jest/index.js +14 -1
  28. package/lib/commonjs/components/KeyboardAvoidingView/index.js +2 -2
  29. package/lib/commonjs/components/KeyboardAvoidingView/index.js.map +1 -1
  30. package/lib/commonjs/components/KeyboardAwareScrollView/index.js +3 -3
  31. package/lib/commonjs/components/KeyboardAwareScrollView/index.js.map +1 -1
  32. package/lib/commonjs/components/KeyboardStickyView/index.js +12 -12
  33. package/lib/commonjs/components/KeyboardStickyView/index.js.map +1 -1
  34. package/lib/commonjs/hooks/index.js +12 -0
  35. package/lib/commonjs/hooks/index.js.map +1 -1
  36. package/lib/commonjs/hooks/useKeyboardState/index.js +34 -0
  37. package/lib/commonjs/hooks/useKeyboardState/index.js.map +1 -0
  38. package/lib/commonjs/internal.js +2 -1
  39. package/lib/commonjs/internal.js.map +1 -1
  40. package/lib/commonjs/module.js +11 -4
  41. package/lib/commonjs/module.js.map +1 -1
  42. package/lib/commonjs/specs/KeyboardControllerViewNativeComponent.js +3 -1
  43. package/lib/commonjs/specs/KeyboardControllerViewNativeComponent.js.map +1 -1
  44. package/lib/commonjs/specs/KeyboardGestureAreaNativeComponent.js +3 -1
  45. package/lib/commonjs/specs/KeyboardGestureAreaNativeComponent.js.map +1 -1
  46. package/lib/commonjs/specs/OverKeyboardViewNativeComponent.js +3 -1
  47. package/lib/commonjs/specs/OverKeyboardViewNativeComponent.js.map +1 -1
  48. package/lib/commonjs/types.js.map +1 -1
  49. package/lib/commonjs/utils/findNodeHandle/index.js +9 -0
  50. package/lib/commonjs/utils/findNodeHandle/index.js.map +1 -0
  51. package/lib/commonjs/utils/findNodeHandle/index.native.js +13 -0
  52. package/lib/commonjs/utils/findNodeHandle/index.native.js.map +1 -0
  53. package/lib/commonjs/views/OverKeyboardView/index.js +10 -4
  54. package/lib/commonjs/views/OverKeyboardView/index.js.map +1 -1
  55. package/lib/module/components/KeyboardAvoidingView/index.js +2 -2
  56. package/lib/module/components/KeyboardAvoidingView/index.js.map +1 -1
  57. package/lib/module/components/KeyboardAwareScrollView/index.js +2 -2
  58. package/lib/module/components/KeyboardAwareScrollView/index.js.map +1 -1
  59. package/lib/module/components/KeyboardStickyView/index.js +13 -13
  60. package/lib/module/components/KeyboardStickyView/index.js.map +1 -1
  61. package/lib/module/hooks/index.js +1 -0
  62. package/lib/module/hooks/index.js.map +1 -1
  63. package/lib/module/hooks/useKeyboardState/index.js +27 -0
  64. package/lib/module/hooks/useKeyboardState/index.js.map +1 -0
  65. package/lib/module/internal.js +2 -1
  66. package/lib/module/internal.js.map +1 -1
  67. package/lib/module/module.js +11 -4
  68. package/lib/module/module.js.map +1 -1
  69. package/lib/module/specs/KeyboardControllerViewNativeComponent.js +3 -1
  70. package/lib/module/specs/KeyboardControllerViewNativeComponent.js.map +1 -1
  71. package/lib/module/specs/KeyboardGestureAreaNativeComponent.js +3 -1
  72. package/lib/module/specs/KeyboardGestureAreaNativeComponent.js.map +1 -1
  73. package/lib/module/specs/OverKeyboardViewNativeComponent.js +3 -1
  74. package/lib/module/specs/OverKeyboardViewNativeComponent.js.map +1 -1
  75. package/lib/module/types.js.map +1 -1
  76. package/lib/module/utils/findNodeHandle/index.js +2 -0
  77. package/lib/module/utils/findNodeHandle/index.js.map +1 -0
  78. package/lib/module/utils/findNodeHandle/index.native.js +3 -0
  79. package/lib/module/utils/findNodeHandle/index.native.js.map +1 -0
  80. package/lib/module/views/OverKeyboardView/index.js +10 -4
  81. package/lib/module/views/OverKeyboardView/index.js.map +1 -1
  82. package/lib/typescript/hooks/index.d.ts +1 -0
  83. package/lib/typescript/hooks/useKeyboardState/index.d.ts +2 -0
  84. package/lib/typescript/internal.d.ts +2 -1
  85. package/lib/typescript/types.d.ts +4 -1
  86. package/lib/typescript/utils/findNodeHandle/index.d.ts +4 -0
  87. package/lib/typescript/utils/findNodeHandle/index.native.d.ts +2 -0
  88. package/package.json +4 -1
  89. package/react-native-keyboard-controller.podspec +8 -0
  90. package/react-native.config.js +14 -0
  91. package/src/components/KeyboardAvoidingView/index.tsx +14 -7
  92. package/src/components/KeyboardAwareScrollView/index.tsx +2 -2
  93. package/src/components/KeyboardStickyView/index.tsx +18 -17
  94. package/src/hooks/index.ts +1 -0
  95. package/src/hooks/useKeyboardState/index.ts +38 -0
  96. package/src/internal.ts +2 -1
  97. package/src/module.ts +11 -4
  98. package/src/specs/KeyboardControllerViewNativeComponent.ts +3 -3
  99. package/src/specs/KeyboardGestureAreaNativeComponent.ts +3 -3
  100. package/src/specs/OverKeyboardViewNativeComponent.ts +3 -3
  101. package/src/types.ts +4 -1
  102. package/src/utils/findNodeHandle/index.native.ts +3 -0
  103. package/src/utils/findNodeHandle/index.ts +6 -0
  104. package/src/views/OverKeyboardView/index.tsx +11 -4
  105. package/lib/commonjs/architecture.js +0 -8
  106. package/lib/commonjs/architecture.js.map +0 -1
  107. package/lib/module/architecture.js +0 -2
  108. package/lib/module/architecture.js.map +0 -1
  109. package/lib/typescript/architecture.d.ts +0 -1
  110. package/src/architecture.ts +0 -1
package/README.md CHANGED
@@ -22,17 +22,11 @@ Keyboard manager which works in identical way on both iOS and Android.
22
22
 
23
23
  ## Installation
24
24
 
25
- Install `react-native-keyboard-controller` package from npm:
26
-
27
- ```shell
28
- yarn add react-native-keyboard-controller
29
- # or
30
- npm install react-native-keyboard-controller --save
31
- ```
25
+ Check out the [installation](https://kirillzyusko.github.io/react-native-keyboard-controller/docs/installation) section of docs for the detailed installation instructions.
32
26
 
33
27
  ## Documentation
34
28
 
35
- Check out our dedicated documentation page for info about this library, API reference and more: [https://kirillzyusko.github.io/react-native-keyboard-controller/](https://kirillzyusko.github.io/react-native-keyboard-controller/)
29
+ Check out the dedicated documentation page for information about this library, API reference and more: [https://kirillzyusko.github.io/react-native-keyboard-controller/](https://kirillzyusko.github.io/react-native-keyboard-controller/)
36
30
 
37
31
  ## Contributing
38
32
 
@@ -2,6 +2,8 @@ package com.reactnativekeyboardcontroller
2
2
 
3
3
  import com.facebook.react.bridge.ReactApplicationContext
4
4
  import com.facebook.react.uimanager.LayoutShadowNode
5
+ import com.facebook.react.uimanager.ReactStylesDiffMap
6
+ import com.facebook.react.uimanager.StateWrapper
5
7
  import com.facebook.react.uimanager.ThemedReactContext
6
8
  import com.facebook.react.uimanager.ViewGroupManager
7
9
  import com.facebook.react.uimanager.ViewManagerDelegate
@@ -30,6 +32,15 @@ class OverKeyboardViewManager(
30
32
 
31
33
  override fun getShadowNodeClass(): Class<out LayoutShadowNode> = OverKeyboardHostShadowNode::class.java
32
34
 
35
+ override fun updateState(
36
+ view: OverKeyboardHostView,
37
+ props: ReactStylesDiffMap,
38
+ stateWrapper: StateWrapper,
39
+ ): Any? {
40
+ view.stateWrapper = stateWrapper
41
+ return null
42
+ }
43
+
33
44
  @ReactProp(name = "visible")
34
45
  override fun setVisible(
35
46
  view: OverKeyboardHostView,
@@ -7,12 +7,20 @@ import android.view.MotionEvent
7
7
  import android.view.View
8
8
  import android.view.WindowManager
9
9
  import com.facebook.react.bridge.UiThreadUtil
10
+ import com.facebook.react.bridge.WritableMap
11
+ import com.facebook.react.bridge.WritableNativeMap
10
12
  import com.facebook.react.config.ReactFeatureFlags
11
13
  import com.facebook.react.uimanager.JSTouchDispatcher
14
+ import com.facebook.react.uimanager.StateWrapper
12
15
  import com.facebook.react.uimanager.ThemedReactContext
13
16
  import com.facebook.react.uimanager.UIManagerHelper
14
17
  import com.facebook.react.uimanager.events.EventDispatcher
15
18
  import com.facebook.react.views.view.ReactViewGroup
19
+ import com.reactnativekeyboardcontroller.extensions.dp
20
+ import com.reactnativekeyboardcontroller.extensions.getDisplaySize
21
+ import com.reactnativekeyboardcontroller.log.Logger
22
+
23
+ private val TAG = OverKeyboardHostView::class.qualifiedName
16
24
 
17
25
  @SuppressLint("ViewConstructor")
18
26
  class OverKeyboardHostView(
@@ -22,6 +30,12 @@ class OverKeyboardHostView(
22
30
  private var windowManager: WindowManager = reactContext.getSystemService(Context.WINDOW_SERVICE) as WindowManager
23
31
  private var hostView: OverKeyboardRootViewGroup = OverKeyboardRootViewGroup(reactContext)
24
32
 
33
+ var stateWrapper: StateWrapper?
34
+ get() = hostView.stateWrapper
35
+ set(stateWrapper) {
36
+ hostView.stateWrapper = stateWrapper
37
+ }
38
+
25
39
  init {
26
40
  hostView.eventDispatcher = dispatcher
27
41
  }
@@ -100,6 +114,7 @@ class OverKeyboardRootViewGroup(
100
114
  private val jsTouchDispatcher: JSTouchDispatcher = JSTouchDispatcher(this)
101
115
  private var jsPointerDispatcher: JSPointerDispatcherCompat? = null
102
116
  internal var eventDispatcher: EventDispatcher? = null
117
+ internal var stateWrapper: StateWrapper? = null
103
118
  internal var isAttached = false
104
119
 
105
120
  init {
@@ -111,20 +126,40 @@ class OverKeyboardRootViewGroup(
111
126
  // region life cycles
112
127
  override fun onAttachedToWindow() {
113
128
  super.onAttachedToWindow()
129
+ val displaySize = reactContext.getDisplaySize()
130
+ stretchTo(width = displaySize.x, height = displaySize.y)
114
131
  isAttached = true
115
132
  }
116
133
 
117
134
  override fun onDetachedFromWindow() {
118
135
  super.onDetachedFromWindow()
136
+ stretchTo(width = 0, height = 0)
119
137
  isAttached = false
120
138
  }
139
+
140
+ override fun onSizeChanged(
141
+ width: Int,
142
+ height: Int,
143
+ oldWidth: Int,
144
+ oldHeight: Int,
145
+ ) {
146
+ super.onSizeChanged(width, height, oldWidth, oldHeight)
147
+ stretchTo(width, height)
148
+ }
149
+
121
150
  // endregion
122
151
 
123
152
  // region Touch events handling
124
153
  override fun onInterceptTouchEvent(event: MotionEvent): Boolean {
125
154
  eventDispatcher?.let { eventDispatcher ->
126
- jsTouchDispatcher.handleTouchEvent(event, eventDispatcher)
127
- jsPointerDispatcher?.handleMotionEventCompat(event, eventDispatcher, true)
155
+ try {
156
+ jsTouchDispatcher.handleTouchEvent(event, eventDispatcher)
157
+ jsPointerDispatcher?.handleMotionEventCompat(event, eventDispatcher, true)
158
+ } catch (
159
+ @Suppress("detekt:TooGenericExceptionCaught") e: RuntimeException,
160
+ ) {
161
+ Logger.w(TAG, "Can not handle touch event", e)
162
+ }
128
163
  }
129
164
  return super.onInterceptTouchEvent(event)
130
165
  }
@@ -132,8 +167,14 @@ class OverKeyboardRootViewGroup(
132
167
  @SuppressLint("ClickableViewAccessibility")
133
168
  override fun onTouchEvent(event: MotionEvent): Boolean {
134
169
  eventDispatcher?.let { eventDispatcher ->
135
- jsTouchDispatcher.handleTouchEvent(event, eventDispatcher)
136
- jsPointerDispatcher?.handleMotionEventCompat(event, eventDispatcher, false)
170
+ try {
171
+ jsTouchDispatcher.handleTouchEvent(event, eventDispatcher)
172
+ jsPointerDispatcher?.handleMotionEventCompat(event, eventDispatcher, false)
173
+ } catch (
174
+ @Suppress("detekt:TooGenericExceptionCaught") e: RuntimeException,
175
+ ) {
176
+ Logger.w(TAG, "Can not handle touch event", e)
177
+ }
137
178
  }
138
179
  super.onTouchEvent(event)
139
180
  // In case when there is no children interested in handling touch event, we return true from
@@ -184,4 +225,14 @@ class OverKeyboardRootViewGroup(
184
225
  reactContext.reactApplicationContext.handleException(RuntimeException(t))
185
226
  }
186
227
  // endregion
228
+
229
+ private fun stretchTo(
230
+ width: Int,
231
+ height: Int,
232
+ ) {
233
+ val newStateData: WritableMap = WritableNativeMap()
234
+ newStateData.putDouble("screenWidth", width.toFloat().dp)
235
+ newStateData.putDouble("screenHeight", height.toFloat().dp)
236
+ stateWrapper?.updateState(newStateData)
237
+ }
187
238
  }
@@ -0,0 +1,85 @@
1
+ cmake_minimum_required(VERSION 3.13)
2
+ set(CMAKE_VERBOSE_MAKEFILE ON)
3
+
4
+ set(LIB_LITERAL reactnativekeyboardcontroller)
5
+ set(LIB_TARGET_NAME react_codegen_${LIB_LITERAL})
6
+
7
+ set(LIB_ANDROID_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../..)
8
+ set(LIB_COMMON_DIR ${LIB_ANDROID_DIR}/../common/cpp)
9
+ set(LIB_COMMON_COMPONENTS_DIR ${LIB_COMMON_DIR}/react/renderer/components/${LIB_LITERAL})
10
+ set(LIB_ANDROID_GENERATED_JNI_DIR ${LIB_ANDROID_DIR}/build/generated/source/codegen/jni)
11
+ set(LIB_ANDROID_GENERATED_COMPONENTS_DIR ${LIB_ANDROID_GENERATED_JNI_DIR}/react/renderer/components/${LIB_LITERAL})
12
+
13
+ add_compile_options(
14
+ -fexceptions
15
+ -frtti
16
+ -std=c++20
17
+ -Wall
18
+ -Wpedantic
19
+ -Wno-gnu-zero-variadic-macro-arguments
20
+ -Wno-dollar-in-identifier-extension
21
+ )
22
+
23
+ file(GLOB LIB_CUSTOM_SRCS CONFIGURE_DEPENDS *.cpp ${LIB_COMMON_COMPONENTS_DIR}/*.cpp)
24
+ file(GLOB LIB_CODEGEN_SRCS CONFIGURE_DEPENDS ${LIB_ANDROID_GENERATED_JNI_DIR}/*.cpp ${LIB_ANDROID_GENERATED_COMPONENTS_DIR}/*.cpp)
25
+
26
+ add_library(
27
+ ${LIB_TARGET_NAME}
28
+ SHARED
29
+ ${LIB_CUSTOM_SRCS}
30
+ ${LIB_CODEGEN_SRCS}
31
+ )
32
+
33
+ target_include_directories(
34
+ ${LIB_TARGET_NAME}
35
+ PUBLIC
36
+ .
37
+ ${LIB_COMMON_DIR}
38
+ ${LIB_ANDROID_GENERATED_JNI_DIR}
39
+ ${LIB_ANDROID_GENERATED_COMPONENTS_DIR}
40
+ )
41
+
42
+ if(ReactAndroid_VERSION_MINOR GREATER_EQUAL 76)
43
+ target_link_libraries(
44
+ ${LIB_TARGET_NAME}
45
+ ReactAndroid::reactnative
46
+ ReactAndroid::jsi
47
+ fbjni::fbjni
48
+ )
49
+ else()
50
+ target_link_libraries(
51
+ ${LIB_TARGET_NAME}
52
+ fbjni
53
+ folly_runtime
54
+ glog
55
+ jsi
56
+ react_codegen_rncore
57
+ react_debug
58
+ react_nativemodule_core
59
+ react_render_core
60
+ react_render_debug
61
+ react_render_graphics
62
+ react_render_mapbuffer
63
+ react_render_componentregistry
64
+ react_utils
65
+ rrc_view
66
+ turbomodulejsijni
67
+ yoga
68
+ )
69
+ endif()
70
+
71
+ target_compile_options(
72
+ ${LIB_TARGET_NAME}
73
+ PRIVATE
74
+ -DLOG_TAG=\"ReactNative\"
75
+ -fexceptions
76
+ -frtti
77
+ -std=c++20
78
+ -Wall
79
+ )
80
+
81
+ target_include_directories(
82
+ ${CMAKE_PROJECT_NAME}
83
+ PUBLIC
84
+ ${CMAKE_CURRENT_SOURCE_DIR}
85
+ )
@@ -0,0 +1,23 @@
1
+ #pragma once
2
+
3
+ #include <ReactCommon/JavaTurboModule.h>
4
+ #include <ReactCommon/TurboModule.h>
5
+ #include <jsi/jsi.h>
6
+
7
+ /**
8
+ * Note this import and that it is not present in autogenerated header file
9
+ * under android/build/generated/source/codegen/jni/reactnativekeyboardcontroller.h
10
+ *
11
+ * Here we are overriding autogenerated component descriptors by prioritizing our custom headers via include path setup.
12
+ */
13
+ #include <react/renderer/components/reactnativekeyboardcontroller/RNKCKeyboardControllerViewComponentDescriptor.h>
14
+ #include <react/renderer/components/reactnativekeyboardcontroller/RNKCKeyboardGestureAreaComponentDescriptor.h>
15
+ #include <react/renderer/components/reactnativekeyboardcontroller/RNKCOverKeyboardViewComponentDescriptor.h>
16
+
17
+ #include <memory>
18
+ #include <string>
19
+
20
+ namespace facebook::react {
21
+ JSI_EXPORT
22
+ std::shared_ptr<TurboModule> reactnativekeyboardcontroller_ModuleProvider(const std::string &moduleName, const JavaTurboModule::InitParams &params);
23
+ } // namespace facebook::react
@@ -0,0 +1,21 @@
1
+ #pragma once
2
+
3
+ #include "RNKCKeyboardControllerViewShadowNode.h"
4
+
5
+ #include <react/debug/react_native_assert.h>
6
+ #include <react/renderer/components/reactnativekeyboardcontroller/Props.h>
7
+ #include <react/renderer/core/ConcreteComponentDescriptor.h>
8
+
9
+ namespace facebook::react {
10
+
11
+ class KeyboardControllerViewComponentDescriptor final
12
+ : public ConcreteComponentDescriptor<KeyboardControllerViewShadowNode> {
13
+ public:
14
+ using ConcreteComponentDescriptor::ConcreteComponentDescriptor;
15
+ void adopt(ShadowNode &shadowNode) const override {
16
+ react_native_assert(dynamic_cast<KeyboardControllerViewShadowNode *>(&shadowNode));
17
+ ConcreteComponentDescriptor::adopt(shadowNode);
18
+ }
19
+ };
20
+
21
+ } // namespace facebook::react
@@ -0,0 +1,7 @@
1
+ #include "RNKCKeyboardControllerViewShadowNode.h"
2
+
3
+ namespace facebook::react {
4
+
5
+ extern const char KeyboardControllerViewComponentName[] = "KeyboardControllerView";
6
+
7
+ } // namespace facebook::react
@@ -0,0 +1,23 @@
1
+ #pragma once
2
+
3
+ #include "RNKCKeyboardControllerViewState.h"
4
+
5
+ #include <react/renderer/components/reactnativekeyboardcontroller/EventEmitters.h>
6
+ #include <react/renderer/components/reactnativekeyboardcontroller/Props.h>
7
+ #include <react/renderer/components/view/ConcreteViewShadowNode.h>
8
+ #include <jsi/jsi.h>
9
+
10
+ namespace facebook::react {
11
+
12
+ JSI_EXPORT extern const char KeyboardControllerViewComponentName[];
13
+
14
+ /*
15
+ * `ShadowNode` for <KeyboardControllerView> component.
16
+ */
17
+ using KeyboardControllerViewShadowNode = ConcreteViewShadowNode<
18
+ KeyboardControllerViewComponentName,
19
+ KeyboardControllerViewProps,
20
+ KeyboardControllerViewEventEmitter,
21
+ KeyboardControllerViewState>;
22
+
23
+ } // namespace facebook::react
@@ -0,0 +1,21 @@
1
+ #pragma once
2
+
3
+ #ifdef ANDROID
4
+ #include <folly/dynamic.h>
5
+ #endif
6
+
7
+ namespace facebook::react {
8
+
9
+ class KeyboardControllerViewState {
10
+ public:
11
+ KeyboardControllerViewState() = default;
12
+
13
+ #ifdef ANDROID
14
+ KeyboardControllerViewState(KeyboardControllerViewState const &previousState, folly::dynamic data) {}
15
+ folly::dynamic getDynamic() const {
16
+ return {};
17
+ }
18
+ #endif
19
+ };
20
+
21
+ } // namespace facebook::react
@@ -0,0 +1,20 @@
1
+ #pragma once
2
+
3
+ #include "RNKCKeyboardGestureAreaShadowNode.h"
4
+
5
+ #include <react/debug/react_native_assert.h>
6
+ #include <react/renderer/components/reactnativekeyboardcontroller/Props.h>
7
+ #include <react/renderer/core/ConcreteComponentDescriptor.h>
8
+
9
+ namespace facebook::react {
10
+ class KeyboardGestureAreaComponentDescriptor final
11
+ : public ConcreteComponentDescriptor<KeyboardGestureAreaShadowNode> {
12
+ public:
13
+ using ConcreteComponentDescriptor::ConcreteComponentDescriptor;
14
+ void adopt(ShadowNode &shadowNode) const override {
15
+ react_native_assert(dynamic_cast<KeyboardGestureAreaShadowNode *>(&shadowNode));
16
+ ConcreteComponentDescriptor::adopt(shadowNode);
17
+ }
18
+ };
19
+
20
+ } // namespace facebook::react
@@ -0,0 +1,7 @@
1
+ #include "RNKCKeyboardGestureAreaShadowNode.h"
2
+
3
+ namespace facebook::react {
4
+
5
+ extern const char KeyboardGestureAreaComponentName[] = "KeyboardGestureArea";
6
+
7
+ } // namespace facebook::react
@@ -0,0 +1,23 @@
1
+ #pragma once
2
+
3
+ #include "RNKCKeyboardGestureAreaState.h"
4
+
5
+ #include <react/renderer/components/reactnativekeyboardcontroller/EventEmitters.h>
6
+ #include <react/renderer/components/reactnativekeyboardcontroller/Props.h>
7
+ #include <react/renderer/components/view/ConcreteViewShadowNode.h>
8
+ #include <jsi/jsi.h>
9
+
10
+ namespace facebook::react {
11
+
12
+ JSI_EXPORT extern const char KeyboardGestureAreaComponentName[];
13
+
14
+ /*
15
+ * `ShadowNode` for <KeyboardGestureArea> component.
16
+ */
17
+ using KeyboardGestureAreaShadowNode = ConcreteViewShadowNode<
18
+ KeyboardGestureAreaComponentName,
19
+ KeyboardGestureAreaProps,
20
+ KeyboardGestureAreaEventEmitter,
21
+ KeyboardGestureAreaState>;
22
+
23
+ } // namespace facebook::react
@@ -0,0 +1,21 @@
1
+ #pragma once
2
+
3
+ #ifdef ANDROID
4
+ #include <folly/dynamic.h>
5
+ #endif
6
+
7
+ namespace facebook::react {
8
+
9
+ class KeyboardGestureAreaState {
10
+ public:
11
+ KeyboardGestureAreaState() = default;
12
+
13
+ #ifdef ANDROID
14
+ KeyboardGestureAreaState(KeyboardGestureAreaState const &previousState, folly::dynamic data) {}
15
+ folly::dynamic getDynamic() const {
16
+ return {};
17
+ }
18
+ #endif
19
+ };
20
+
21
+ } // namespace facebook::react
@@ -0,0 +1,31 @@
1
+ #pragma once
2
+
3
+ #include "RNKCOverKeyboardViewShadowNode.h"
4
+
5
+ #include <react/debug/react_native_assert.h>
6
+ #include <react/renderer/components/reactnativekeyboardcontroller/Props.h>
7
+ #include <react/renderer/core/ConcreteComponentDescriptor.h>
8
+
9
+ namespace facebook::react {
10
+
11
+ class OverKeyboardViewComponentDescriptor final
12
+ : public ConcreteComponentDescriptor<OverKeyboardViewShadowNode> {
13
+ public:
14
+ using ConcreteComponentDescriptor::ConcreteComponentDescriptor;
15
+ void adopt(ShadowNode &shadowNode) const override {
16
+ auto& layoutableShadowNode =
17
+ static_cast<YogaLayoutableShadowNode&>(shadowNode);
18
+ auto& stateData =
19
+ static_cast<const OverKeyboardViewShadowNode::ConcreteState&>(
20
+ *shadowNode.getState())
21
+ .getData();
22
+
23
+ layoutableShadowNode.setSize(
24
+ Size{stateData.screenSize.width, stateData.screenSize.height});
25
+ layoutableShadowNode.setPositionType(YGPositionTypeAbsolute);
26
+
27
+ ConcreteComponentDescriptor::adopt(shadowNode);
28
+ }
29
+ };
30
+
31
+ } // namespace facebook::react
@@ -0,0 +1,7 @@
1
+ #include "RNKCOverKeyboardViewShadowNode.h"
2
+
3
+ namespace facebook::react {
4
+
5
+ extern const char OverKeyboardViewComponentName[] = "OverKeyboardView";
6
+
7
+ } // namespace facebook::react
@@ -0,0 +1,23 @@
1
+ #pragma once
2
+
3
+ #include "RNKCOverKeyboardViewState.h"
4
+
5
+ #include <react/renderer/components/reactnativekeyboardcontroller/EventEmitters.h>
6
+ #include <react/renderer/components/reactnativekeyboardcontroller/Props.h>
7
+ #include <react/renderer/components/view/ConcreteViewShadowNode.h>
8
+ #include <jsi/jsi.h>
9
+
10
+ namespace facebook::react {
11
+
12
+ JSI_EXPORT extern const char OverKeyboardViewComponentName[];
13
+
14
+ /*
15
+ * `ShadowNode` for <OverKeyboardView> component.
16
+ */
17
+ using OverKeyboardViewShadowNode = ConcreteViewShadowNode<
18
+ OverKeyboardViewComponentName,
19
+ OverKeyboardViewProps,
20
+ OverKeyboardViewEventEmitter,
21
+ OverKeyboardViewState>;
22
+
23
+ } // namespace facebook::react
@@ -0,0 +1,12 @@
1
+ #include "RNKCOverKeyboardViewState.h"
2
+
3
+ namespace facebook::react {
4
+
5
+ #ifdef ANDROID
6
+ folly::dynamic OverKeyboardViewState::getDynamic() const {
7
+ return folly::dynamic::object("screenWidth", screenSize.width)(
8
+ "screenHeight", screenSize.height);
9
+ }
10
+ #endif
11
+
12
+ } // namespace facebook::react
@@ -0,0 +1,43 @@
1
+ #pragma once
2
+
3
+ #include <react/renderer/core/graphicsConversions.h>
4
+ #include <react/renderer/graphics/Float.h>
5
+
6
+ #ifdef ANDROID
7
+ #include <folly/dynamic.h>
8
+ #endif
9
+
10
+ #include <memory>
11
+
12
+ namespace facebook::react {
13
+
14
+ /*
15
+ * State for <OverKeyboardViewState> component.
16
+ */
17
+ class OverKeyboardViewState final {
18
+ public:
19
+ using Shared = std::shared_ptr<const OverKeyboardViewState>;
20
+
21
+
22
+ OverKeyboardViewState() {}
23
+ OverKeyboardViewState(Size screenSize_) : screenSize(screenSize_) {}
24
+
25
+ #ifdef ANDROID
26
+ OverKeyboardViewState(
27
+ const OverKeyboardViewState& previousState,
28
+ folly::dynamic data)
29
+ : screenSize(Size{
30
+ (Float)data["screenWidth"].getDouble(),
31
+ (Float)data["screenHeight"].getDouble()}) {}
32
+ #endif
33
+
34
+ const Size screenSize{};
35
+
36
+ #ifdef ANDROID
37
+ folly::dynamic getDynamic() const;
38
+ #endif
39
+
40
+ #pragma mark - Getters
41
+ };
42
+
43
+ } // namespace facebook::react
@@ -1,4 +1,3 @@
1
1
  #import <React/RCTTouchHandler.h>
2
2
  #import <React/RCTUIManager.h>
3
- #import <React/RCTUITextView.h>
4
3
  #import <React/RCTViewManager.h>
@@ -65,7 +65,7 @@ class KCTextInputCompositeDelegate: NSObject, UITextViewDelegate, UITextFieldDel
65
65
  // MARK: setters/getters
66
66
 
67
67
  public func setTextViewDelegate(delegate: UITextViewDelegate?) {
68
- // remove KVO from any old textField
68
+ // remove KVO from any old textView
69
69
  if let oldTextField = observedTextFieldForSelection {
70
70
  removeSelectionRangeObserver(from: oldTextField)
71
71
  }
@@ -96,6 +96,21 @@ class KCTextInputCompositeDelegate: NSObject, UITextViewDelegate, UITextFieldDel
96
96
  }
97
97
  }
98
98
 
99
+ public func canSubstituteTextFieldDelegate(delegate: UITextFieldDelegate?) -> Bool {
100
+ let type = String(describing: delegate)
101
+ if type.range(of: "SQIPTextFieldInputModifier") != nil {
102
+ // SQIPTextFieldInputModifier is a private class used internally by Square.
103
+ // It forwards input events to the keyboard-controller delegate.
104
+ // To prevent an infinite loop, we avoid setting our delegate in this case.
105
+ // Since Square's SDK is used imperatively and doesn't allow adding custom components,
106
+ // keyboard-controller components cannot be used in this context,
107
+ // so it's safe to skip replacing the delegate.
108
+ return false
109
+ }
110
+
111
+ return true
112
+ }
113
+
99
114
  // Getter for the active delegate
100
115
  public var activeDelegate: AnyObject? {
101
116
  return textViewDelegate ?? textFieldDelegate
@@ -1,13 +1,11 @@
1
1
  //
2
- // RCTTextView+DelegateManager.h
2
+ // UITextView+DelegateManager.h
3
3
  // react-native-keyboard-controller
4
4
  //
5
5
  // Created by Kiryl Ziusko on 24/04/2024.
6
6
  //
7
7
 
8
- #import <React/RCTUITextView.h>
9
-
10
- @interface RCTUITextView (DelegateManager)
8
+ @interface UITextView (DelegateManager)
11
9
 
12
10
  - (void)setForceDelegate:(id<UITextViewDelegate>)delegate;
13
11
 
@@ -1,14 +1,14 @@
1
1
  //
2
- // RCTUITextView+DelegateManager.m
2
+ // UITextView+DelegateManager.m
3
3
  // react-native-keyboard-controller
4
4
  //
5
5
  // Created by Kiryl Ziusko on 24/04/2024.
6
6
  //
7
7
 
8
8
  #import <objc/runtime.h>
9
- #import "RCTUITextView+DelegateManager.h"
9
+ #import "UITextView+DelegateManager.h"
10
10
 
11
- @implementation RCTUITextView (DelegateManager)
11
+ @implementation UITextView (DelegateManager)
12
12
 
13
13
  /**
14
14
  * We are aware that delegate is set by RN on mount and we can not re-define it
@@ -228,14 +228,16 @@ public class FocusedInputObserver: NSObject {
228
228
 
229
229
  private func substituteDelegate(_ input: UIResponder?) {
230
230
  if let textField = input as? UITextField {
231
- if !(textField.delegate is KCTextInputCompositeDelegate) {
231
+ if !(textField.delegate is KCTextInputCompositeDelegate),
232
+ delegate.canSubstituteTextFieldDelegate(delegate: textField.delegate)
233
+ {
232
234
  delegate.setTextFieldDelegate(delegate: textField.delegate, textField: textField)
233
235
  textField.delegate = delegate
234
236
  }
235
237
  } else if let textView = input as? UITextView {
236
238
  if !(textView.delegate is KCTextInputCompositeDelegate) {
237
239
  delegate.setTextViewDelegate(delegate: textView.delegate)
238
- (textView as? RCTUITextView)?.setForceDelegate(delegate)
240
+ textView.setForceDelegate(delegate)
239
241
  }
240
242
  }
241
243
  // dispatch onSelectionChange on focus
@@ -248,7 +250,7 @@ public class FocusedInputObserver: NSObject {
248
250
  if let textField = input as? UITextField, let oldDelegate = delegate.activeDelegate as? UITextFieldDelegate {
249
251
  textField.delegate = oldDelegate
250
252
  } else if let textView = input as? UITextView, let oldDelegate = delegate.activeDelegate as? UITextViewDelegate {
251
- (textView as? RCTUITextView)?.setForceDelegate(oldDelegate)
253
+ textView.setForceDelegate(oldDelegate)
252
254
  }
253
255
  }
254
256
 
@@ -20,10 +20,10 @@
20
20
  #import <react_native_keyboard_controller/react_native_keyboard_controller-Swift.h>
21
21
  #endif
22
22
 
23
- #import <react/renderer/components/reactnativekeyboardcontroller/ComponentDescriptors.h>
24
23
  #import <react/renderer/components/reactnativekeyboardcontroller/EventEmitters.h>
25
24
  #import <react/renderer/components/reactnativekeyboardcontroller/Props.h>
26
25
  #import <react/renderer/components/reactnativekeyboardcontroller/RCTComponentViewHelpers.h>
26
+ #import <react/renderer/components/reactnativekeyboardcontroller/RNKCKeyboardControllerViewComponentDescriptor.h>
27
27
 
28
28
  #import "KeyboardControllerModule-Header.h"
29
29
  #import "RCTFabricComponentsPlugins.h"