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
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#if FB_SONARKIT_ENABLED
|
||||
|
||||
#import "SKNodeDescriptor.h"
|
||||
#import <FlipperKitLayoutTextSearchable/FKTextSearchable.h>
|
||||
|
||||
@implementation SKNodeDescriptor
|
||||
{
|
||||
@@ -71,7 +72,13 @@
|
||||
|
||||
- (BOOL)matchesQuery:(NSString *)query forNode:(id)node {
|
||||
NSString *name = [self nameForNode: node];
|
||||
return [self string:name contains:query] || [self string:[self identifierForNode: node] contains: query];
|
||||
NSString *text = nil;
|
||||
if ([node conformsToProtocol:@protocol(FKTextSearchable)]) {
|
||||
text = [node searchableText];
|
||||
}
|
||||
return [self string:name contains:query] ||
|
||||
[self string:[self identifierForNode: node] contains: query] ||
|
||||
[self string:text contains:query];
|
||||
}
|
||||
|
||||
- (BOOL)string:(NSString *)string contains:(NSString *)substring {
|
||||
@@ -80,4 +87,5 @@
|
||||
|
||||
@end
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the LICENSE
|
||||
* file in the root directory of this source tree.
|
||||
*/
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
@protocol FKTextSearchable <NSObject>
|
||||
|
||||
- (NSString *)searchableText;
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user