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
@@ -83,9 +83,17 @@ Pod::Spec.new do |spec|
|
|||||||
"HEADER_SEARCH_PATHS" => header_search_paths }
|
"HEADER_SEARCH_PATHS" => header_search_paths }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
spec.subspec 'FlipperKitLayoutTextSearchable' do |ss|
|
||||||
|
ss.header_dir = 'FlipperKitLayoutTextSearchable'
|
||||||
|
ss.compiler_flags = folly_compiler_flags
|
||||||
|
ss.source_files = 'iOS/Plugins/FlipperKitLayoutPlugin/FlipperKitLayoutTextSearchable/FKTextSearchable.h'
|
||||||
|
ss.public_header_files = 'iOS/Plugins/FlipperKitLayoutPlugin/FlipperKitLayoutTextSearchable/FKTextSearchable.h'
|
||||||
|
end
|
||||||
|
|
||||||
spec.subspec "FlipperKitLayoutPlugin" do |ss|
|
spec.subspec "FlipperKitLayoutPlugin" do |ss|
|
||||||
ss.header_dir = "FlipperKitLayoutPlugin"
|
ss.header_dir = "FlipperKitLayoutPlugin"
|
||||||
ss.dependency 'FlipperKit/Core'
|
ss.dependency 'FlipperKit/Core'
|
||||||
|
ss.dependency 'FlipperKit/FlipperKitLayoutTextSearchable'
|
||||||
ss.dependency 'Yoga', yoga_version
|
ss.dependency 'Yoga', yoga_version
|
||||||
ss.dependency 'YogaKit', yogakit_version
|
ss.dependency 'YogaKit', yogakit_version
|
||||||
ss.compiler_flags = folly_compiler_flags
|
ss.compiler_flags = folly_compiler_flags
|
||||||
@@ -112,6 +120,7 @@ Pod::Spec.new do |spec|
|
|||||||
ss.dependency 'Yoga', yoga_version
|
ss.dependency 'Yoga', yoga_version
|
||||||
ss.dependency 'ComponentKit', '~> 0.27'
|
ss.dependency 'ComponentKit', '~> 0.27'
|
||||||
ss.dependency 'FlipperKit/FlipperKitLayoutPlugin'
|
ss.dependency 'FlipperKit/FlipperKitLayoutPlugin'
|
||||||
|
ss.dependency 'FlipperKit/FlipperKitLayoutTextSearchable'
|
||||||
ss.compiler_flags = folly_compiler_flags
|
ss.compiler_flags = folly_compiler_flags
|
||||||
ss.public_header_files = 'iOS/Plugins/FlipperKitLayoutPlugin/FlipperKitLayoutComponentKitSupport/FlipperKitLayoutComponentKitSupport.h',
|
ss.public_header_files = 'iOS/Plugins/FlipperKitLayoutPlugin/FlipperKitLayoutComponentKitSupport/FlipperKitLayoutComponentKitSupport.h',
|
||||||
'iOS/Plugins/FlipperKitLayoutPlugin/FlipperKitLayoutComponentKitSupport/SKSubDescriptor.h'
|
'iOS/Plugins/FlipperKitLayoutPlugin/FlipperKitLayoutComponentKitSupport/SKSubDescriptor.h'
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
|
|
||||||
#import <FlipperKitLayoutPlugin/SKHighlightOverlay.h>
|
#import <FlipperKitLayoutPlugin/SKHighlightOverlay.h>
|
||||||
#import <FlipperKitLayoutPlugin/SKObject.h>
|
#import <FlipperKitLayoutPlugin/SKObject.h>
|
||||||
|
#import <FlipperKitLayoutTextSearchable/FKTextSearchable.h>
|
||||||
|
|
||||||
#import "SKSubDescriptor.h"
|
#import "SKSubDescriptor.h"
|
||||||
#import "SKComponentLayoutWrapper.h"
|
#import "SKComponentLayoutWrapper.h"
|
||||||
@@ -193,6 +194,24 @@
|
|||||||
[touch finish];
|
[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
|
@end
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
#if FB_SONARKIT_ENABLED
|
#if FB_SONARKIT_ENABLED
|
||||||
|
|
||||||
#import "SKNodeDescriptor.h"
|
#import "SKNodeDescriptor.h"
|
||||||
|
#import <FlipperKitLayoutTextSearchable/FKTextSearchable.h>
|
||||||
|
|
||||||
@implementation SKNodeDescriptor
|
@implementation SKNodeDescriptor
|
||||||
{
|
{
|
||||||
@@ -71,7 +72,13 @@
|
|||||||
|
|
||||||
- (BOOL)matchesQuery:(NSString *)query forNode:(id)node {
|
- (BOOL)matchesQuery:(NSString *)query forNode:(id)node {
|
||||||
NSString *name = [self nameForNode: 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 {
|
- (BOOL)string:(NSString *)string contains:(NSString *)substring {
|
||||||
@@ -80,4 +87,5 @@
|
|||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#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