Skip to content

Commit

Permalink
fix(ios): iOS18 adaptation of TextView component
Browse files Browse the repository at this point in the history
  • Loading branch information
wwwcg committed Jul 29, 2024
1 parent 6512de3 commit e1207fe
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 5 deletions.
3 changes: 2 additions & 1 deletion ios/sdk/component/textinput/HippyTextField.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,13 @@
@end

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

@property (nonatomic, copy) HippyDirectEventBlock onBlur;
@property (nonatomic, copy) HippyDirectEventBlock onFocus;
@property (nonatomic, assign) BOOL editable;
@end

@interface HippyTextField : HippyBaseTextInput <UITextFieldDelegate>
Expand Down
6 changes: 3 additions & 3 deletions ios/sdk/component/textinput/HippyTextField.m
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ - (void)setKeyboardType:(UIKeyboardType)keyboardType {
self.text = tempPwdStr;
}

- (void)setEditable:(BOOL)editable {
_editable = editable;
[self setEnabled:editable];
- (void)setCanEdit:(BOOL)canEdit {
_canEdit = canEdit;
[self setEnabled:canEdit];
}

- (void)paste:(id)sender {
Expand Down
3 changes: 3 additions & 0 deletions ios/sdk/component/textinput/HippyTextView.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
@end

@interface HippyUITextView : UITextView
/// iOS18's UITextInput adds an `editable` property, which conflicts with the one defined in HippyUITextField.
/// For consistency, we added a canEdit property here too, which has the same meaning as editable
@property (nonatomic, assign) BOOL canEdit;
@property (nonatomic, assign) BOOL textWasPasted;
@property (nonatomic, weak) id<HippyUITextViewResponseDelegate> responderDelegate;
@end
Expand Down
5 changes: 5 additions & 0 deletions ios/sdk/component/textinput/HippyTextView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ - (void)didMoveToWindow {
}
}

- (void)setCanEdit:(BOOL)canEdit {
_canEdit = canEdit;
[self setEditable:canEdit];
}

@end

@interface HippyTextView () <HippyUITextViewResponseDelegate>
Expand Down
2 changes: 1 addition & 1 deletion ios/sdk/component/textinput/HippyTextViewManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ - (HippyShadowView *)shadowView {
HIPPY_EXPORT_VIEW_PROPERTY(clearTextOnFocus, BOOL)
HIPPY_REMAP_VIEW_PROPERTY(color, textView.textColor, UIColor)
HIPPY_REMAP_VIEW_PROPERTY(textAlign, textView.textAlignment, NSTextAlignment)
HIPPY_REMAP_VIEW_PROPERTY(editable, textView.editable, BOOL)
HIPPY_REMAP_VIEW_PROPERTY(editable, textView.canEdit, BOOL)
HIPPY_REMAP_VIEW_PROPERTY(enablesReturnKeyAutomatically, textView.enablesReturnKeyAutomatically, BOOL)
HIPPY_REMAP_VIEW_PROPERTY(keyboardType, textView.keyboardType, UIKeyboardType)
HIPPY_REMAP_VIEW_PROPERTY(keyboardAppearance, textView.keyboardAppearance, UIKeyboardAppearance)
Expand Down

0 comments on commit e1207fe

Please sign in to comment.