The component of Rn TextInput used as a searchbar pit.

Source: Internet
Author: User

Recently made a note-type app, mainly for drilling RN development technology. which has a search function.

A problem was identified during the implementation of this feature:

For example, I enter China, each callback to the text is in the g-> gu so, not convenient for the search key. For iOS native development, this scenario can be resolved by judging the input type and combining the use of the following APIs:

-(void) Searchtextfielddidchange: (Uitextfield *) TextField

{

NSString *lang = [[Uitextinputmode currentinputmode] primarylanguage]; Keyboard Input Mode

if (![ Chineseinclude IsIncludeChineseInString:self.searchField.text] && [self.searchField.text length] < 2)

{

Less than 2 English characters, do not start the search; When text is emptied, only the default receptionist is displayed.

if ([self.searchField.text length] = = 0)

{

Self.matchedreceivers = [self selectedtypedefaultreceivers];

[Self.popuplist Reloaddata];

}

Return

}

if ([lang isequaltostring:@ "Zh-hans"])

{

Simplified Chinese input, including simplified pinyin, fitness wubi, simplified handwriting

Uitextrange *selectedrange = [TextField markedtextrange];

uitextposition* SelectionStart = Selectedrange.start;

uitextposition* selectionend = selectedrange.end;

Nsinteger length = [TextField offsetfromposition:selectionstart toposition:selectionend];

if (length!= 0)

{

Return

}

Else

{

Ddloginfo (@ "searchtextfielddidchangeinreal,%@", self.searchField.text);

[NSObject cancelpreviousperformrequestswithtarget:self selector: @selector (dothesearching) Object:nil];

[Self performselector: @selector (dothesearching) Withobject:nil afterdelay:0.5];

}

}

Else

{

[NSObject cancelpreviousperformrequestswithtarget:self selector: @selector (dothesearching) Object:nil];

[Self performselector: @selector (dothesearching) Withobject:nil afterdelay:0.5];

}

}
The main is to filter out the contents of the Markedtextrange, if in this state does not trigger the callback. For example, I enter the "medium" will trigger the search, but the input word half of the time will not take "G" to do the search match. But such an effect is currently difficult to solve from RN here.
Finally put a picture for everyone to understand this scene.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.