Skip to content

Commit 13dfb32

Browse files
authored
fix: set delegate to all UITextView (#902)
## 📜 Description Set delegate to all `UITextView`s. ## 💡 Motivation and Context We had a similar problem on Android: #776 Basically if we caste field to `RCTUITextView` then there is a chance, that we will not be able to cast it if it's a subclass of `UITextView` (i. e. other 3rd party libs). So the correct solution is to cast current responder to its basic class. The reason why I added this code in #426 was the fact that only `RCTUITextView` had own delegate setter. However since we operate on `ivar` level we can bypass any setter (not only for a specific class), so I decided to move that extensions to a basic class (UITextView). It'll fix two problems: - potential incompatibility with other 4rd party libs (the one that we had with Stripe); - will fix a problem when compilation fails with dynamic frameworks. The reason why compilation fails is because `RCTUITextView` most likely is not a public class, as per: > **Static Pods**: When you use static linking (without `use_frameworks!` in your Podfile), the React Native library is compiled directly into your app’s binary. All symbols, including `RCTUITextView`, are included at compile time, making them available to your extension even if they’re not part of the public API. > **Dynamic Pods**: With dynamic frameworks (enabled by `use_frameworks`!), dependencies like React Native are built as separate frameworks that are linked at runtime. Only symbols exported in the framework’s public interface are accessible to your app. If `RCTUITextView` is an internal class—not exposed in React Native’s public headers—the linker won’t find it, resulting in the undefined symbol error. So the correct fix would be just move extension to base class level. Closes #876 ## 📢 Changelog <!-- High level overview of important changes --> <!-- For example: fixed status bar manipulation; added new types declarations; --> <!-- If your changes don't affect one of platform/language below - then remove this platform/language --> ### iOS - move `setForceDelegate` from `RCTUITextView` to `UITextView`; ## 🤔 How Has This Been Tested? Tested manually in FabricExample app with dynamic pods. ## 📸 Screenshots (if appropriate): <img width="467" alt="image" src="https://github.com/user-attachments/assets/7dc03cc1-11b2-4a39-94c4-157ef9b6ad14" /> ## 📝 Checklist - [x] CI successfully passed - [x] I added new mocks and corresponding unit-tests if library API was changed
1 parent b27ed8a commit 13dfb32

4 files changed

+7
-10
lines changed
-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
#import <React/RCTTouchHandler.h>
22
#import <React/RCTUIManager.h>
3-
#import <React/RCTUITextView.h>
43
#import <React/RCTViewManager.h>

ios/objc/RCTUITextView+DelegateManager.h renamed to ios/objc/UITextView+DelegateManager.h

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
//
2-
// RCTTextView+DelegateManager.h
2+
// UITextView+DelegateManager.h
33
// react-native-keyboard-controller
44
//
55
// Created by Kiryl Ziusko on 24/04/2024.
66
//
77

8-
#import <React/RCTUITextView.h>
9-
10-
@interface RCTUITextView (DelegateManager)
8+
@interface UITextView (DelegateManager)
119

1210
- (void)setForceDelegate:(id<UITextViewDelegate>)delegate;
1311

ios/objc/RCTUITextView+DelegateManager.m renamed to ios/objc/UITextView+DelegateManager.m

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
//
2-
// RCTUITextView+DelegateManager.m
2+
// UITextView+DelegateManager.m
33
// react-native-keyboard-controller
44
//
55
// Created by Kiryl Ziusko on 24/04/2024.
66
//
77

88
#import <objc/runtime.h>
9-
#import "RCTUITextView+DelegateManager.h"
9+
#import "UITextView+DelegateManager.h"
1010

11-
@implementation RCTUITextView (DelegateManager)
11+
@implementation UITextView (DelegateManager)
1212

1313
/**
1414
* We are aware that delegate is set by RN on mount and we can not re-define it

ios/observers/FocusedInputObserver.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ public class FocusedInputObserver: NSObject {
235235
} else if let textView = input as? UITextView {
236236
if !(textView.delegate is KCTextInputCompositeDelegate) {
237237
delegate.setTextViewDelegate(delegate: textView.delegate)
238-
(textView as? RCTUITextView)?.setForceDelegate(delegate)
238+
textView.setForceDelegate(delegate)
239239
}
240240
}
241241
// dispatch onSelectionChange on focus
@@ -248,7 +248,7 @@ public class FocusedInputObserver: NSObject {
248248
if let textField = input as? UITextField, let oldDelegate = delegate.activeDelegate as? UITextFieldDelegate {
249249
textField.delegate = oldDelegate
250250
} else if let textView = input as? UITextView, let oldDelegate = delegate.activeDelegate as? UITextViewDelegate {
251-
(textView as? RCTUITextView)?.setForceDelegate(oldDelegate)
251+
textView.setForceDelegate(oldDelegate)
252252
}
253253
}
254254

0 commit comments

Comments
 (0)