Skip to content

Commit 773a21f

Browse files
committed
fix(ios): iOS18 adaptation of TextView component
1 parent 1083ed3 commit 773a21f

File tree

5 files changed

+32
-16
lines changed

5 files changed

+32
-16
lines changed

renderer/native/ios/renderer/component/textinput/HippyTextField.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,13 @@
3232
@end
3333

3434
@interface HippyUITextField : UITextField
35+
/// iOS18's UITextInput adds an `editable` property, to avoid conflict, rename to `canEdit`
36+
@property (nonatomic, assign) BOOL canEdit;
3537
@property (nonatomic, assign) BOOL textWasPasted;
3638
@property (nonatomic, weak) id<HippyUITextFieldResponseDelegate> responderDelegate;
3739

3840
@property (nonatomic, copy) HippyDirectEventBlock onBlur;
3941
@property (nonatomic, copy) HippyDirectEventBlock onFocus;
40-
@property (nonatomic, assign) BOOL editable;
4142
@end
4243

4344
@interface HippyTextField : HippyBaseTextInput <UITextFieldDelegate>

renderer/native/ios/renderer/component/textinput/HippyTextField.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ - (void)setReturnKeyType:(UIReturnKeyType) returnKeyType{
6363
}
6464
}
6565

66-
- (void)setEditable:(BOOL)editable {
67-
_editable = editable;
68-
[self setEnabled:editable];
66+
- (void)setCanEdit:(BOOL)canEdit {
67+
_canEdit = canEdit;
68+
[self setEnabled:canEdit];
6969
}
7070

7171
- (void)paste:(id)sender {

renderer/native/ios/renderer/component/textinput/HippyTextView.h

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,35 @@
2121
*/
2222

2323
#import <UIKit/UIKit.h>
24-
2524
#import "HippyView.h"
2625
#import "HippyBaseTextInput.h"
2726
#import "UIView+Hippy.h"
2827

29-
@protocol NativeRenderUITextViewResponseDelegate <NSObject>
28+
29+
/// Response delegate of HippyUITextView
30+
@protocol HippyUITextViewResponseDelegate <NSObject>
3031
@required
3132
- (void)textview_becomeFirstResponder;
3233
- (void)textview_resignFirstResponder;
3334
@end
3435

35-
@interface NativeRenderUITextView : UITextView
36+
37+
/// UITextView's Hippy Extension
38+
@interface HippyUITextView : UITextView
39+
/// iOS18's UITextInput adds an `editable` property, which conflicts with the one defined in HippyUITextField.
40+
/// For consistency, we added a canEdit property here too, which has the same meaning as editable
41+
@property (nonatomic, assign) BOOL canEdit;
42+
/// Indicate whether text was pasted
3643
@property (nonatomic, assign) BOOL textWasPasted;
37-
@property (nonatomic, weak) id<NativeRenderUITextViewResponseDelegate> responderDelegate;
44+
/// Response delegate of HippyUITextView
45+
@property (nonatomic, weak) id<HippyUITextViewResponseDelegate> responderDelegate;
3846
@end
3947

48+
49+
/// Hippy multi-line TextView component
4050
@interface HippyTextView : HippyBaseTextInput <UITextViewDelegate> {
4151
@protected
42-
NativeRenderUITextView *_textView;
52+
HippyUITextView *_textView;
4353
}
4454

4555
@property (nonatomic, assign) BOOL autoCorrect;

renderer/native/ios/renderer/component/textinput/HippyTextView.mm

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,14 @@
2121
*/
2222

2323
#import "HippyTextView.h"
24-
2524
#import "HippyConvert.h"
2625
#import "HippyShadowText.h"
2726
#import "HippyText.h"
2827
#import "HippyUtils.h"
2928
#import "HippyTextSelection.h"
3029
#import "UIView+Hippy.h"
3130

32-
@implementation NativeRenderUITextView
31+
@implementation HippyUITextView
3332

3433
- (void)paste:(id)sender {
3534
_textWasPasted = YES;
@@ -70,9 +69,15 @@ - (UIColor*)caretColor{
7069
- (void)setCaretColor:(UIColor*)color{
7170
self.tintColor = color;
7271
}
72+
73+
- (void)setCanEdit:(BOOL)canEdit {
74+
_canEdit = canEdit;
75+
[self setEditable:canEdit];
76+
}
77+
7378
@end
7479

75-
@interface HippyTextView () <NativeRenderUITextViewResponseDelegate>
80+
@interface HippyTextView () <HippyUITextViewResponseDelegate>
7681

7782
/// ParagraphStyle for TextView and PlaceholderView,
7883
/// used for lineHeight config and etc.
@@ -130,7 +135,7 @@ - (instancetype)initWithFrame:(CGRect)frame {
130135
[self setContentInset:UIEdgeInsetsZero];
131136
_placeholderTextColor = [self defaultPlaceholderTextColor];
132137
_blurOnSubmit = NO;
133-
_textView = [[NativeRenderUITextView alloc] initWithFrame:CGRectZero];
138+
_textView = [[HippyUITextView alloc] initWithFrame:CGRectZero];
134139
_textView.responderDelegate = self;
135140
_textView.backgroundColor = [UIColor clearColor];
136141
_textView.textColor = [UIColor blackColor];
@@ -557,7 +562,7 @@ static BOOL findMismatch(NSString *first, NSString *second, NSRange *firstRange,
557562
return YES;
558563
}
559564

560-
- (BOOL)textView:(NativeRenderUITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
565+
- (BOOL)textView:(HippyUITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
561566
if (_onKeyPress) {
562567
NSString *resultKey = text;
563568
if ([text isEqualToString:@" "]) {
@@ -627,7 +632,7 @@ - (BOOL)textView:(NativeRenderUITextView *)textView shouldChangeTextInRange:(NSR
627632
return YES;
628633
}
629634

630-
- (void)textViewDidChangeSelection:(NativeRenderUITextView *)textView {
635+
- (void)textViewDidChangeSelection:(HippyUITextView *)textView {
631636
if (_onSelectionChange && textView.selectedTextRange != _previousSelectionRange
632637
&& ![textView.selectedTextRange isEqual:_previousSelectionRange]) {
633638
_previousSelectionRange = textView.selectedTextRange;

renderer/native/ios/renderer/component/textinput/HippyTextViewManager.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ - (HippyShadowView *)shadowView {
159159
HIPPY_EXPORT_VIEW_PROPERTY(clearTextOnFocus, BOOL)
160160
HIPPY_REMAP_VIEW_PROPERTY(color, textView.textColor, UIColor)
161161
HIPPY_REMAP_VIEW_PROPERTY(textAlign, textView.textAlignment, NSTextAlignment)
162-
HIPPY_REMAP_VIEW_PROPERTY(editable, textView.editable, BOOL)
162+
HIPPY_REMAP_VIEW_PROPERTY(editable, textView.canEdit, BOOL)
163163
HIPPY_REMAP_VIEW_PROPERTY(enablesReturnKeyAutomatically, textView.enablesReturnKeyAutomatically, BOOL)
164164
HIPPY_REMAP_VIEW_PROPERTY(keyboardType, textView.keyboardType, UIKeyboardType)
165165
HIPPY_REMAP_VIEW_PROPERTY(keyboardAppearance, textView.keyboardAppearance, UIKeyboardAppearance)

0 commit comments

Comments
 (0)