Skip to content

Commit c5b87b3

Browse files
duom青源duom青源
duom青源
authored and
duom青源
committed
feat: bugfix
1 parent 2c6973a commit c5b87b3

22 files changed

+490
-20
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,4 @@ android/keystores/debug.keystore
6767
.turbo/
6868

6969
# generated by bob
70-
lib/
70+
# lib/

android/src/main/java/com/variabletextinput/VariableTextInputViewManager.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -256,11 +256,11 @@ public void setUnderlineColor(VariableTextInput view, @Nullable Integer underlin
256256
}
257257
@ReactProp(name = "onSelectionChange", defaultBoolean = false)
258258
public void setOnSelectionChange(final VariableTextInput view, boolean onSelectionChange) {
259-
if (onSelectionChange) {
260-
view.setSelectionWatcher(new ReactSelectionWatcher(view));
261-
} else {
262-
view.setSelectionWatcher(null);
263-
}
259+
// if (onSelectionChange) {
260+
// view.setSelectionWatcher(new ReactSelectionWatcher(view));
261+
// } else {
262+
// view.setSelectionWatcher(null);
263+
// }
264264
}
265265
@ReactProp(name = "keyboardType")
266266
public void setKeyboardType(VariableTextInput view, String keyboardType) {
@@ -351,6 +351,6 @@ public Map<String, Object> getConstants() {
351351
"onAndroidChange",
352352
MapBuilder.of("registrationName", "onAndroidChange")
353353
).put( "onAndroidContentSizeChange",
354-
MapBuilder.of("registrationName", "onAndroidContentSizeChange")).put("onAndroidSubmitEditing",MapBuilder.of("registrationName","onAndroidSubmitEditing")).build();
354+
MapBuilder.of("registrationName", "onAndroidTextInput")).put("onAndroidTextInput",MapBuilder.of("registrationName","onAndroidTextInput")).build();
355355
}
356356
}

android/src/main/java/com/variabletextinput/view/VariableTextInput.java

+11-1
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,17 @@ public void onTextChanged(CharSequence s, int start, int before, int count) {
138138
}
139139
String newText = s.toString().substring(start, start + count);
140140
String oldText = mPreviousText.substring(start, start + before);
141+
WritableMap onTextInputEvent = Arguments.createMap();
142+
if (newText.length()>oldText.length()){
143+
String t = newText.replace(oldText,"");
144+
onTextInputEvent.putString("text", t);
145+
}else {
146+
onTextInputEvent.putString("text", "");
147+
}
148+
final Context context = getContext();
149+
if (context instanceof ReactContext) {
150+
((ReactContext) context).getJSModule(RCTEventEmitter.class).receiveEvent(getId(), "onAndroidTextInput", onTextInputEvent);
151+
}
141152
// Don't send same text changes
142153
if (count == before && newText.equals(oldText)) {
143154
return;
@@ -153,7 +164,6 @@ public void onTextChanged(CharSequence s, int start, int before, int count) {
153164
}
154165
WritableMap event = Arguments.createMap();
155166
event.putString("text", s.toString());
156-
final Context context = getContext();
157167
if (context instanceof ReactContext) {
158168
((ReactContext) context).getJSModule(RCTEventEmitter.class).receiveEvent(getId(), "onAndroidChange", event);
159169
}

example/src/App.tsx

+6
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
IATTextViewBase,
1313
IInserTextAttachmentItem,
1414
ITextType,
15+
IVTTextInputData,
1516
VariableTextInputView,
1617
} from 'react-native-variable-text-input';
1718
export const App = () => {
@@ -91,6 +92,10 @@ export const App = () => {
9192
const sub = (e: any) => {
9293
console.log('rrrrr===>', e);
9394
};
95+
const onTextInput = (event: IVTTextInputData) => {
96+
//todo
97+
console.log('=====>', event);
98+
};
9499
return (
95100
<ScrollView contentContainerStyle={styles.container}>
96101
<VariableTextInputView
@@ -103,6 +108,7 @@ export const App = () => {
103108
blurOnSubmit={true}
104109
onSubmitEditing={sub}
105110
keyboardAppearance={'dark'}
111+
onTextInput={onTextInput}
106112
/>
107113
<View style={{ flexDirection: 'row', marginTop: 40 }}>
108114
<TouchableOpacity onPress={blur} style={{ marginLeft: 20 }}>

ios/VariableTextInput.h

+2
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,12 @@ NS_ASSUME_NONNULL_BEGIN
4545
@property(nonatomic, copy) RCTBubblingEventBlock onChange;
4646
@property (nonatomic, copy, nullable) RCTDirectEventBlock onContentSizeChange;
4747
@property(nonatomic, copy) RCTBubblingEventBlock onSubmitEditing;
48+
@property(nonatomic,copy, nullable)RCTDirectEventBlock onTag;
4849
@property(nonatomic, copy, nullable) RCTDirectEventBlock onTextInput;
4950
@property(nonatomic, strong) NSDictionary *defultTypingAttributes;
5051
@property(nonatomic, strong) NSArray *tags;
5152
@property(nonatomic, strong) NSString *keyWord;
53+
@property(nonatomic,strong)NSString *tagStr;
5254
@property(nonatomic, assign) Boolean startKeyWord;
5355
@property (nonatomic, strong) NSLayoutConstraint *heightConstraint;
5456
@property (nonatomic, assign) CGFloat paddingTop;

ios/VariableTextInput.m

+30-1
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,22 @@ - (void)textViewDidChange:(UITextView *)textView {
328328
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
329329
NSString *oldStr = [self getStrContentInRange:NSMakeRange(0, [self.attributedText length])];
330330
NSString *newStr = [NSString stringWithFormat:@"%@%@",oldStr,text];
331+
[self handleTags:text];
332+
if(self.tagStr != nil && ![self.tagStr isEqualToString:@""]){
333+
if(self.keyWord == nil){
334+
self.keyWord = @"";
335+
}else{
336+
self.keyWord = [NSString stringWithFormat:@"%@%@",self.keyWord,text];
337+
self.keyWord = [self.keyWord stringByReplacingOccurrencesOfString:self.tagStr withString:@""];
338+
339+
}
340+
if (_onTag) {
341+
_onTag(@{
342+
@"tag": _tagStr,
343+
@"keyWord": _keyWord,
344+
});
345+
}
346+
}
331347
if (self.max_TextLength>0 && newStr.length>self.max_TextLength) {
332348
return NO;
333349
}
@@ -347,7 +363,20 @@ - (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range r
347363
}
348364
return YES;
349365
}
350-
366+
-(void)handleTags:(NSString *)text {
367+
__block Boolean istags =NO;
368+
__block NSString *tagStr = @"";
369+
[self.tags enumerateObjectsWithOptions:NSEnumerationReverse usingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
370+
NSLog(@"%@----%@",self.tags[idx],[NSThread currentThread]);
371+
NSString *str = self.tags[idx];
372+
if([str isEqualToString:text]){
373+
istags = YES;
374+
tagStr = text;
375+
self.tagStr = tagStr;
376+
self.keyWord = @"";
377+
}
378+
}];
379+
}
351380
- (void)textViewDidBeginEditing:(UITextView *)textView {
352381
//todo
353382
}

ios/VariableTextInputViewManager.m

+17-1
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ @implementation VariableTextInputViewManager
3030
[view setValue: [RCTConvert UIColor:json] forKeyPath: @"placeholderTextColor"];
3131
}
3232
RCT_EXPORT_VIEW_PROPERTY(onTextInput, RCTDirectEventBlock)
33+
RCT_EXPORT_VIEW_PROPERTY(onTag, RCTDirectEventBlock)
3334

3435
RCT_EXPORT_VIEW_PROPERTY(onChange, RCTBubblingEventBlock)
3536
RCT_EXPORT_VIEW_PROPERTY(onContentSizeChange, RCTBubblingEventBlock)
36-
3737
RCT_CUSTOM_VIEW_PROPERTY(textAlign, NSTextAlignment, VariableTextInput)
3838
{
3939
[view setTextAlignment:[RCTConvert NSTextAlignment:json]];
@@ -92,11 +92,20 @@ @implementation VariableTextInputViewManager
9292
[self insertTextEmoji:rnImageData];
9393
});
9494
}
95+
RCT_EXPORT_METHOD(dismissTag)
96+
{
97+
dispatch_async(dispatch_get_main_queue(), ^{
98+
self.textInput.tagStr = @"";
99+
self.textInput.keyWord = @"";
100+
});
101+
}
95102
- (UIView *)view
96103
{
97104
_textInput = [[VariableTextInput alloc]init];
98105
_textInput.textContainerInset = UIEdgeInsetsZero;
99106
_textInput.textContainer.lineFragmentPadding = 0;
107+
_textInput.tagStr = @"";
108+
_textInput.keyWord = @"";
100109
_textInput.blurOnSubmit = true;
101110
return _textInput;
102111
}
@@ -221,7 +230,14 @@ -(void)insertTagText:(NSDictionary *)mention{
221230
[dic setObject:color forKey:@"NSColor"];
222231
CGSize textSize = [showStr sizeWithAttributes:self.textInput.typingAttributes];
223232
UIImage *image = [self drawImageWithColor:[UIColor clearColor] size:textSize text:[NSString stringWithFormat:@"%@",showStr] textAttributes:dic circular:NO];
233+
if(_textInput.tagStr != nil && ![_textInput.tagStr isEqualToString:@""]){
234+
_textInput.text = [_textInput.text stringByReplacingOccurrencesOfString:[NSString stringWithFormat:@"%@%@",_textInput.tagStr,_textInput.keyWord] withString:@""];
235+
NSAttributedString *attString = _textInput.attributedText;
236+
_textInput.tagStr = @"";
237+
_textInput.keyWord = @"";
238+
}
224239
[self setTextAttachment:image tag:emojiTag size:textSize copyStr:copyStr];
240+
225241
}
226242
-(void)setAttributedText:(NSArray *)arr{
227243
NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc]init];

lib/commonjs/VariableTextInputView.js

+156
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)