Added search in text of some components
Summary: Added a possibility to search for the text not only in name and id of components but also in text for all components, that conforms to a protocol <SKTextSearchable> Reviewed By: priteshrnandgaonkar Differential Revision: D16108297 fbshipit-source-id: 31da4ac6762c487ef644d62c9576d9eff43e8cd4
This commit is contained in:
committed by
Facebook Github Bot
parent
6e1483edfa
commit
7551b6da04
@@ -22,6 +22,7 @@
|
||||
|
||||
#import <FlipperKitLayoutPlugin/SKHighlightOverlay.h>
|
||||
#import <FlipperKitLayoutPlugin/SKObject.h>
|
||||
#import <FlipperKitLayoutTextSearchable/FKTextSearchable.h>
|
||||
|
||||
#import "SKSubDescriptor.h"
|
||||
#import "SKComponentLayoutWrapper.h"
|
||||
@@ -193,6 +194,24 @@
|
||||
[touch finish];
|
||||
}
|
||||
|
||||
- (BOOL)matchesQuery:(NSString *)query forNode:(id)node {
|
||||
if ([super matchesQuery:query forNode:node]) {
|
||||
return YES;
|
||||
}
|
||||
if ([node isKindOfClass:[SKComponentLayoutWrapper class]]) {
|
||||
const auto layoutWrapper = (SKComponentLayoutWrapper *)node;
|
||||
if ([layoutWrapper.component conformsToProtocol:@protocol(FKTextSearchable)]) {
|
||||
NSString *text = ((id<FKTextSearchable>)layoutWrapper.component).searchableText;
|
||||
return [self string:text contains:query];
|
||||
}
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (BOOL)string:(NSString *)string contains:(NSString *)substring {
|
||||
return string != nil && substring != nil && [string rangeOfString: substring options: NSCaseInsensitiveSearch].location != NSNotFound;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user