This commit is contained in:
启星
2025-08-08 10:49:36 +08:00
parent 6400cf78bb
commit b5ce3d580a
8780 changed files with 978183 additions and 0 deletions

View File

@@ -0,0 +1,34 @@
//
// TUISearchBar_Minimalist.h
// Pods
//
// Created by harvy on 2020/12/23.
// Copyright © 2023 Tencent. All rights reserved.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@class TUISearchBar_Minimalist;
@protocol TUISearchBarDelegate_Minimalist <NSObject>
@optional
- (void)searchBarDidEnterSearch:(TUISearchBar_Minimalist *)searchBar;
- (void)searchBarDidCancelClicked:(TUISearchBar_Minimalist *)searchBar;
- (void)searchBar:(TUISearchBar_Minimalist *)searchBar searchText:(NSString *)key;
@end
@interface TUISearchBar_Minimalist : UIView
@property(nonatomic, strong, readonly) UISearchBar *searchBar;
@property(nonatomic, weak) id<TUISearchBarDelegate_Minimalist> delegate;
// use weak, prevent circular references
@property(nonatomic, weak) UIViewController *parentVC;
- (void)setEntrance:(BOOL)isEntrance;
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,135 @@
//
// TUISearchBar_Minimalist.m
// Pods
//
// Created by harvy on 2020/12/23.
// Copyright © 2023 Tencent. All rights reserved.
//
#import "TUISearchBar_Minimalist.h"
#import <TIMCommon/TIMDefine.h>
#import <TUICore/TUICore.h>
#import <TUICore/TUIDarkModel.h>
#import <TUICore/TUIGlobalization.h>
#import <TUICore/TUIThemeManager.h>
#import <TUICore/UIView+TUILayout.h>
#import "TUISearchViewController_Minimalist.h"
@interface TUISearchBar_Minimalist () <UISearchBarDelegate>
@property(nonatomic, strong) UISearchBar *searchBar;
@property(nonatomic, assign) BOOL isEntrance;
@end
@implementation TUISearchBar_Minimalist
@synthesize delegate;
- (void)setEntrance:(BOOL)isEntrance {
self.isEntrance = isEntrance;
[self setupViews];
}
- (UIColor *)bgColorOfSearchBar {
return RGBA(255, 255, 255, 1);
}
- (void)setupViews {
self.backgroundColor = self.bgColorOfSearchBar;
_searchBar = [[UISearchBar alloc] init];
_searchBar.placeholder = TIMCommonLocalizableString(Search);
_searchBar.backgroundImage = [UIImage new];
_searchBar.barTintColor = UIColor.redColor;
_searchBar.showsCancelButton = NO;
_searchBar.searchTextField.textAlignment = isRTL()?NSTextAlignmentRight:NSTextAlignmentLeft;
_searchBar.delegate = self;
_searchBar.showsCancelButton = !self.isEntrance;
if (@available(iOS 13.0, *)) {
_searchBar.searchTextField.backgroundColor = RGBA(246, 246, 246, 1);
}
[self addSubview:_searchBar];
[self enableCancelButton];
}
- (void)layoutSubviews {
[super layoutSubviews];
self.searchBar.frame = CGRectMake(10, 5, self.mm_w - 10 - 10, self.mm_h - 5 - 5);
[self updateSearchIcon];
}
- (void)updateSearchIcon {
if ([self.searchBar isFirstResponder] || self.searchBar.text.length || !self.isEntrance) {
self.backgroundColor = self.superview.backgroundColor;
} else {
self.backgroundColor = self.bgColorOfSearchBar;
}
[self.searchBar setPositionAdjustment:UIOffsetZero forSearchBarIcon:UISearchBarIconSearch];
}
- (void)showSearchVC {
TUISearchViewController_Minimalist *vc = [[TUISearchViewController_Minimalist alloc] init];
TUINavigationController *nav = [[TUINavigationController alloc] initWithRootViewController:(UIViewController *)vc];
nav.modalPresentationStyle = UIModalPresentationFullScreen;
UIViewController *parentVC = self.parentVC;
if (parentVC) {
[parentVC presentViewController:nav animated:NO completion:nil];
}
}
#pragma mark - UISearchBarDelegate
- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar {
[self showSearchVC];
if (self.isEntrance && [self.delegate respondsToSelector:@selector(searchBarDidEnterSearch:)]) {
[self.delegate searchBarDidEnterSearch:self];
}
__weak typeof(self) weakSelf = self;
dispatch_async(dispatch_get_main_queue(), ^{
[weakSelf updateSearchIcon];
});
return !self.isEntrance;
}
- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar {
if ([self.delegate respondsToSelector:@selector(searchBarDidCancelClicked:)]) {
[self.delegate searchBarDidCancelClicked:self];
}
}
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar {
if ([self.delegate respondsToSelector:@selector(searchBar:searchText:)]) {
[self.delegate searchBar:self searchText:searchBar.text];
}
}
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText {
if ([self.delegate respondsToSelector:@selector(searchBar:searchText:)]) {
[self.delegate searchBar:self searchText:searchBar.text];
}
}
- (void)searchBarTextDidEndEditing:(UISearchBar *)searchBar {
[self enableCancelButton];
}
- (void)enableCancelButton {
__weak typeof(self) weakSelf = self;
dispatch_async(dispatch_get_main_queue(), ^{
UIButton *cancelBtn = [weakSelf.searchBar valueForKeyPath:@"cancelButton"];
for (UIButton *view in cancelBtn.subviews) {
if ([view isKindOfClass:UIButton.class]) {
view.userInteractionEnabled = YES;
view.enabled = YES;
}
}
cancelBtn.enabled = YES;
cancelBtn.userInteractionEnabled = YES;
[cancelBtn setTitleColor:[UIColor systemBlueColor] forState:UIControlStateNormal];
[UIBarButtonItem appearanceWhenContainedInInstancesOfClasses:@[ [UISearchBar class] ]].title = TIMCommonLocalizableString(TUIKitSearchItemCancel);
;
});
}
@end

View File

@@ -0,0 +1,22 @@
//
// TUISearchEmptyView_Minimalist.h
// TUISearch
//
// Created by wyl on 2022/12/19.
// Copyright © 2023 Tencent. All rights reserved.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface TUISearchEmptyView_Minimalist : UIView
@property(nonatomic, strong) UIImageView *midImage;
@property(nonatomic, strong) UILabel *tipsLabel;
- (instancetype)initWithImage:(UIImage *)img Text:(NSString *)text;
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,44 @@
//
// TUISearchEmptyView_Minimalist.m
// TUISearch
//
// Created by wyl on 2022/12/19.
// Copyright © 2023 Tencent. All rights reserved.
//
#import "TUISearchEmptyView_Minimalist.h"
#import <TIMCommon/TIMDefine.h>
@implementation TUISearchEmptyView_Minimalist
- (instancetype)initWithImage:(UIImage *)img Text:(NSString *)text {
self = [super init];
if (self) {
self.tipsLabel.text = text;
self.midImage = [[UIImageView alloc] initWithImage:img];
[self addSubview:self.tipsLabel];
[self addSubview:self.midImage];
}
return self;
}
- (void)layoutSubviews {
[super layoutSubviews];
self.midImage.frame = CGRectMake((self.bounds.size.width - kScale390(105)) * 0.5, 0, kScale390(105), kScale390(105));
[self.tipsLabel sizeToFit];
self.tipsLabel.frame = CGRectMake((self.bounds.size.width - self.tipsLabel.frame.size.width) * 0.5,
self.midImage.frame.origin.y + self.midImage.frame.size.height + kScale390(10), self.tipsLabel.frame.size.width,
self.tipsLabel.frame.size.height);
}
- (UILabel *)tipsLabel {
if (_tipsLabel == nil) {
_tipsLabel = [[UILabel alloc] init];
_tipsLabel.textColor = [UIColor tui_colorWithHex:@"#999999"];
_tipsLabel.font = [UIFont systemFontOfSize:14.0];
_tipsLabel.textAlignment = NSTextAlignmentCenter;
}
return _tipsLabel;
}
@end

View File

@@ -0,0 +1,29 @@
//
// TUISearchResultHeaderFooterView.h
// Pods
//
// Created by harvy on 2020/12/24.
// Copyright © 2023 Tencent. All rights reserved.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface TUISearchResultHeaderFooterView_Minimalist : UITableViewHeaderFooterView
@property(nonatomic, assign) BOOL isFooter;
@property(nonatomic, assign) BOOL showMoreBtn;
@property(nonatomic, copy) NSString *__nullable title;
@property(nonatomic, copy) dispatch_block_t __nullable onTap;
@end
@interface TUISearchChatHistoryResultHeaderView_Minimalist : UITableViewHeaderFooterView
@property(nonatomic, copy) NSString *__nullable title;
@property(nonatomic, copy) dispatch_block_t __nullable onTap;
- (void)configPlaceHolderImage:(UIImage *)img imgUrl:(NSString *)imgurl Text:(NSString *)text;
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,273 @@
//
// TUISearchResultHeaderFooterView_Minimalist.m
// Pods
//
// Created by harvy on 2020/12/24.
// Copyright © 2023 Tencent. All rights reserved.
//
#import "TUISearchResultHeaderFooterView_Minimalist.h"
#import <TIMCommon/TIMDefine.h>
#import <TUICore/TUIThemeManager.h>
@interface TUISearchResultHeaderFooterView_Minimalist ()
@property(nonatomic, strong) UIImageView *iconView;
@property(nonatomic, strong) UILabel *titleLabel;
@property(nonatomic, strong) UIButton *moreBtn;
@end
@implementation TUISearchResultHeaderFooterView_Minimalist
- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier {
if (self = [super initWithReuseIdentifier:reuseIdentifier]) {
[self setupViews];
}
return self;
}
- (void)setupViews {
[self.contentView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap:)]];
self.contentView.backgroundColor = TIMCommonDynamicColor(@"form_bg_color", @"#FFFFFF");
_iconView = [[UIImageView alloc] init];
_iconView.image = [UIImage imageNamed:TUISearchImagePath(@"search")];
[self.contentView addSubview:_iconView];
_titleLabel = [[UILabel alloc] init];
_titleLabel.text = @"";
_titleLabel.font = [UIFont boldSystemFontOfSize:24.0];
[self.contentView addSubview:_titleLabel];
_moreBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[_moreBtn setTitle:TIMCommonLocalizableString(More) forState:UIControlStateNormal];
[_moreBtn setTitleColor:[UIColor systemBlueColor] forState:UIControlStateNormal];
_moreBtn.titleLabel.font = [UIFont boldSystemFontOfSize:kScale390(12)];
_moreBtn.userInteractionEnabled = NO;
[self.contentView addSubview:_moreBtn];
}
- (void)tap:(UITapGestureRecognizer *)tap {
if (self.onTap) {
self.onTap();
}
}
- (void)setIsFooter:(BOOL)isFooter {
_isFooter = isFooter;
self.iconView.hidden = !self.isFooter;
self.iconView.hidden = !self.isFooter;
UIColor *footerColor = TIMCommonDynamicColor(@"primary_theme_color", @"#147AFF");
self.titleLabel.textColor = self.isFooter ? footerColor : [UIColor darkGrayColor];
}
- (void)setShowMoreBtn:(BOOL)showMoreBtn {
_showMoreBtn = showMoreBtn;
self.moreBtn.hidden = !showMoreBtn;
}
- (void)setTitle:(NSString *)title {
_title = title;
self.titleLabel.text = title;
}
+ (BOOL)requiresConstraintBasedLayout {
return YES;
}
// this is Apple's recommended place for adding/updating constraints
- (void)updateConstraints {
[super updateConstraints];
if (self.isFooter) {
[self.iconView mas_remakeConstraints:^(MASConstraintMaker *make) {
make.centerY.mas_equalTo(self.contentView);
make.height.width.mas_equalTo(20);
if(isRTL()){
make.right.mas_equalTo(self.contentView.mas_right).mas_offset(-10);
}
else {
make.left.mas_equalTo(self.contentView.mas_left).mas_offset(10);
}
}];
[self.titleLabel sizeToFit];
[self.titleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
if(isRTL()) {
make.right.mas_equalTo(self.iconView.mas_left).mas_offset(-10);
}
else{
make.left.mas_equalTo(self.iconView.mas_right).mas_offset(10);
}
make.centerY.mas_equalTo(self.contentView);
make.width.mas_equalTo(self.titleLabel.frame.size.width);
make.height.mas_equalTo(self.titleLabel.font.lineHeight);
}];
MASAttachKeys(self.iconView,self.titleLabel);
} else {
[self.titleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
if(isRTL()) {
make.left.mas_equalTo(self.moreBtn.mas_right).mas_offset(kScale390(16));
make.right.mas_equalTo(self.contentView.mas_right).mas_offset(-kScale390(16));
}
else{
make.left.mas_equalTo(self.contentView.mas_left).mas_offset(kScale390(16));
make.right.mas_equalTo(self.moreBtn.mas_left).mas_offset(-kScale390(16));
}
// make.leading.mas_equalTo(self.contentView.mas_leading).mas_offset(kScale390(16));
make.centerY.mas_equalTo(self.contentView);
// make.trailing.mas_equalTo(self.contentView.mas_trailing).mas_offset(-10);
make.height.mas_equalTo(self.titleLabel.font.lineHeight);
}];
[self.moreBtn sizeToFit];
[self.moreBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
if(isRTL()) {
make.left.mas_equalTo(self.contentView).mas_offset(kScale390(10));
}
else{
make.right.mas_equalTo(self.contentView).mas_offset(-kScale390(10));
}
make.centerY.mas_equalTo(self.contentView.mas_centerY);
make.width.mas_equalTo(self.moreBtn.frame.size.width);
make.height.mas_equalTo(self.moreBtn.frame.size.height);
}];
MASAttachKeys(self.titleLabel,self.moreBtn);
}
}
- (void)layoutSubviews {
[super layoutSubviews];
}
- (void)setFrame:(CGRect)frame {
if (self.isFooter) {
CGSize size = frame.size;
size.height -= 10;
frame.size = size;
}
[super setFrame:frame];
}
@end
@interface TUISearchChatHistoryResultHeaderView_Minimalist ()
@property(nonatomic, strong) UIImageView *iconView;
@property(nonatomic, strong) UILabel *titleLabel;
@property(nonatomic, strong) UIImageView *rowAccessoryView;
@property(nonatomic, strong) UIView *separtorView;
@end
@implementation TUISearchChatHistoryResultHeaderView_Minimalist
- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier {
if (self = [super initWithReuseIdentifier:reuseIdentifier]) {
[self setupViews];
}
return self;
}
- (void)setupViews {
[self.contentView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap:)]];
self.contentView.backgroundColor = TIMCommonDynamicColor(@"form_bg_color", @"#FFFFFF");
_iconView = [[UIImageView alloc] init];
_iconView.image = [UIImage imageNamed:TUISearchImagePath(@"search")];
[self.contentView addSubview:_iconView];
_titleLabel = [[UILabel alloc] init];
_titleLabel.text = @"";
_titleLabel.font = [UIFont boldSystemFontOfSize:14.0];
[self.contentView addSubview:_titleLabel];
_rowAccessoryView = [[UIImageView alloc] init];
_rowAccessoryView.image = [[UIImage imageNamed:TUISearchImagePath(@"right")] rtl_imageFlippedForRightToLeftLayoutDirection];
[self.contentView addSubview:_rowAccessoryView];
_separtorView = [[UIView alloc] init];
_separtorView.backgroundColor = TIMCommonDynamicColor(@"separator_color", @"#DBDBDB");
[self.contentView addSubview:_separtorView];
}
- (void)configPlaceHolderImage:(UIImage *)img imgUrl:(NSString *)imgurl Text:(NSString *)text {
[_iconView sd_setImageWithURL:[NSURL URLWithString:imgurl] placeholderImage:img];
_titleLabel.text = text;
// tell constraints they need updating
[self setNeedsUpdateConstraints];
// update constraints now so we can animate the change
[self updateConstraintsIfNeeded];
[self layoutIfNeeded];
}
- (void)tap:(UITapGestureRecognizer *)tap {
if (self.onTap) {
self.onTap();
}
}
- (void)setTitle:(NSString *)title {
_title = title;
self.titleLabel.text = title;
}
// this is Apple's recommended place for adding/updating constraints
- (void)updateConstraints {
[super updateConstraints];
CGFloat imgWitdh = kScale390(40);
[self.iconView mas_remakeConstraints:^(MASConstraintMaker *make) {
make.centerY.mas_equalTo(self.contentView);
make.height.width.mas_equalTo(kScale390(40));
if(isRTL()){
make.right.mas_equalTo(self.contentView.mas_right).mas_offset(-kScale390(16));
}
else {
make.left.mas_equalTo(self.contentView.mas_left).mas_offset(kScale390(16));
}
}];
if ([TUIConfig defaultConfig].avatarType == TAvatarTypeRounded) {
self.iconView.layer.masksToBounds = YES;
self.iconView.layer.cornerRadius = imgWitdh / 2.0;
} else if ([TUIConfig defaultConfig].avatarType == TAvatarTypeRadiusCorner) {
self.iconView.layer.masksToBounds = YES;
self.iconView.layer.cornerRadius = [TUIConfig defaultConfig].avatarCornerRadius;
}
[self.titleLabel sizeToFit];
[self.titleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
if(isRTL()){
make.right.mas_equalTo(self.iconView.mas_left).mas_offset(-kScale390(8));
}
else {
make.left.mas_equalTo(self.iconView.mas_right).mas_offset(kScale390(8));
}
make.centerY.mas_equalTo(self.contentView);
make.width.mas_equalTo(self.titleLabel.frame.size.width);
make.height.mas_equalTo(self.titleLabel.frame.size.height);
}];
[self.rowAccessoryView mas_remakeConstraints:^(MASConstraintMaker *make) {
make.height.width.mas_equalTo(10);
make.centerY.mas_equalTo(self.contentView);
if(isRTL()){
make.left.mas_equalTo(self.contentView.mas_left).mas_offset(10);
}
else {
make.right.mas_equalTo(self.contentView.mas_right).mas_offset(-10);
}
// make.trailing.mas_equalTo(self.contentView).mas_offset(-10);
}];
[self.separtorView mas_remakeConstraints:^(MASConstraintMaker *make) {
make.leading.mas_equalTo(10);
make.bottom.mas_equalTo(self.contentView).mas_offset(-1);
make.width.mas_equalTo(self.contentView);
make.height.mas_equalTo(1);
}];
}
- (void)layoutSubviews {
[super layoutSubviews];
}
@end

View File

@@ -0,0 +1,27 @@
//
// TUISearchResultListController.h
// Pods
//
// Created by harvy on 2020/12/25.
// Copyright © 2023 Tencent. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "TUISearchDataProvider.h"
@class TUISearchResultCellModel;
NS_ASSUME_NONNULL_BEGIN
@interface TUISearchResultListController_Minimalist : UIViewController
- (instancetype)initWithResults:(NSArray<TUISearchResultCellModel *> *__nullable)results
keyword:(NSString *__nullable)keyword
module:(TUISearchResultModule)module
param:(NSDictionary<TUISearchParamKey, id> *__nullable)param;
@property(nonatomic, copy) NSString *headerConversationShowName;
@property(nonatomic, copy) NSString *headerConversationURL;
@property(nonatomic, strong) UIImage *headerConversationAvatar;
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,390 @@
//
// TUISearchResultListController_Minimalist.m
// Pods
//
// Created by harvy on 2020/12/25.
// Copyright © 2023 Tencent. All rights reserved.
//
#import "TUISearchResultListController_Minimalist.h"
#import <TIMCommon/TIMDefine.h>
#import <TUICore/TUICore.h>
#import "TUISearchBar_Minimalist.h"
#import "TUISearchEmptyView_Minimalist.h"
#import "TUISearchResultCellModel.h"
#import "TUISearchResultCell_Minimalist.h"
#import "TUISearchResultHeaderFooterView_Minimalist.h"
@interface TUISearchResultListController_Minimalist () <UITableViewDelegate, UITableViewDataSource, TUISearchBarDelegate_Minimalist, TUISearchResultDelegate>
@property(nonatomic, strong) NSMutableArray<TUISearchResultCellModel *> *results;
@property(nonatomic, copy) NSString *keyword;
@property(nonatomic, assign) TUISearchResultModule module;
@property(nonatomic, strong) NSDictionary<TUISearchParamKey, id> *param;
@property(nonatomic, strong) TUISearchDataProvider *dataProvider;
@property(nonatomic, strong) TUISearchBar_Minimalist *searchBar;
@property(nonatomic, strong) UITableView *tableView;
@property(nonatomic, strong) TUISearchEmptyView_Minimalist *noDataEmptyView;
@property(nonatomic, assign) BOOL allowPageRequest;
@property(nonatomic, assign) NSUInteger pageIndex;
@end
@implementation TUISearchResultListController_Minimalist
static NSString *const Id = @"cell";
static NSString *const HFId = @"HFId";
static NSString *const HistoryHFId = @"HistoryHFId";
- (instancetype)initWithResults:(NSArray<TUISearchResultCellModel *> *__nullable)results
keyword:(NSString *__nullable)keyword
module:(TUISearchResultModule)module
param:(NSDictionary<TUISearchParamKey, id> *__nullable)param;
{
if (self = [super init]) {
_results = (module == TUISearchResultModuleChatHistory) ? [NSMutableArray arrayWithArray:@[]] : [NSMutableArray arrayWithArray:results];
_keyword = keyword;
_module = module;
_dataProvider = [[TUISearchDataProvider alloc] init];
_dataProvider.delegate = self;
_param = param;
_allowPageRequest = (module == TUISearchResultModuleChatHistory);
_pageIndex = 0;
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationController.navigationBar.backgroundColor = [UIColor whiteColor];
[self.navigationController.navigationBar setBackgroundImage:[self imageWithColor:[UIColor whiteColor]] forBarMetrics:UIBarMetricsDefault];
self.navigationController.navigationBar.shadowImage = [UIImage new];
self.view.backgroundColor = [UIColor whiteColor];
UIImage *image = [UIImage imageNamed:TIMCommonImagePath(@"nav_back")];
image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
image = [image rtl_imageFlippedForRightToLeftLayoutDirection];
UIBarButtonItem *back = [[UIBarButtonItem alloc] initWithImage:image style:UIBarButtonItemStylePlain target:self action:@selector(back)];
self.navigationItem.leftBarButtonItems = @[ back ];
self.navigationItem.leftItemsSupplementBackButton = NO;
_searchBar = [[TUISearchBar_Minimalist alloc] init];
[_searchBar setEntrance:NO];
_searchBar.delegate = self;
_searchBar.searchBar.text = self.keyword;
self.navigationItem.titleView = _searchBar;
_tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
_tableView.delegate = self;
_tableView.dataSource = self;
_tableView.backgroundColor = [UIColor whiteColor];
_tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
_tableView.rowHeight = 60.f;
[_tableView registerClass:TUISearchResultCell_Minimalist.class forCellReuseIdentifier:Id];
[_tableView registerClass:TUISearchResultHeaderFooterView_Minimalist.class forHeaderFooterViewReuseIdentifier:HFId];
[_tableView registerClass:TUISearchChatHistoryResultHeaderView_Minimalist.class forHeaderFooterViewReuseIdentifier:HistoryHFId];
[self.view addSubview:_tableView];
self.noDataEmptyView.frame = CGRectMake(0, kScale390(42), self.view.bounds.size.width - 20, 200);
[self.tableView addSubview:self.noDataEmptyView];
if (self.module == TUISearchResultModuleChatHistory) {
[self.dataProvider searchForKeyword:self.searchBar.searchBar.text forModules:self.module param:self.param];
}
}
- (void)back {
[self.navigationController popViewControllerAnimated:YES];
}
- (void)viewWillLayoutSubviews {
[super viewWillLayoutSubviews];
self.tableView.frame = self.view.bounds;
self.searchBar.frame = CGRectMake(0, 0, self.view.mm_w, 44);
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.navigationController.navigationBar.backgroundColor = [UIColor whiteColor];
[self.navigationController.navigationBar setBackgroundImage:[self imageWithColor:[UIColor whiteColor]] forBarMetrics:UIBarMetricsDefault];
self.navigationController.navigationBar.shadowImage = [UIImage new];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
self.navigationController.navigationBar.backgroundColor = nil;
[self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
self.navigationController.navigationBar.shadowImage = nil;
}
- (TUISearchEmptyView_Minimalist *)noDataEmptyView {
if (_noDataEmptyView == nil) {
_noDataEmptyView = [[TUISearchEmptyView_Minimalist alloc] initWithImage:TUISearchBundleThemeImage(@"", @"search_not_found_icon")
Text:TIMCommonLocalizableString(TUIKitSearchNoResultLists)];
_noDataEmptyView.hidden = YES;
}
return _noDataEmptyView;
}
#pragma mark - Table view data source
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.results.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
TUISearchResultCell_Minimalist *cell = [tableView dequeueReusableCellWithIdentifier:Id forIndexPath:indexPath];
if (indexPath.row >= self.results.count) {
return cell;
}
TUISearchResultCellModel *model = self.results[indexPath.row];
model.avatarType = TAvatarTypeRadiusCorner;
[cell fillWithData:model];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:NO];
if (indexPath.row >= self.results.count) {
return;
}
TUISearchResultCellModel *cellModel = self.results[indexPath.row];
TUISearchResultCell_Minimalist *cell = [tableView cellForRowAtIndexPath:indexPath];
if (self.module == TUISearchResultModuleChatHistory) {
cellModel.avatarImage = self.headerConversationAvatar ?: cell.avatarView.image;
cellModel.title = self.headerConversationShowName ?: cell.title_label.text;
} else {
cellModel.avatarImage = cell.avatarView.image;
cellModel.title = cell.title_label.text;
}
[self onSelectModel:cellModel module:self.module];
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
return 0;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
if (self.module == TUISearchResultModuleChatHistory) {
if (self.results.count == 0) {
return 0;
} else {
TUISearchResultCellModel *cellModel = self.results[0];
if ([cellModel.context isKindOfClass:NSDictionary.class]) {
return 0;
} else {
return kScale390(64);
}
}
} else {
return self.results.count == 0 ? 0 : 30;
}
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
if (self.module == TUISearchResultModuleChatHistory) {
TUISearchChatHistoryResultHeaderView_Minimalist *headerView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:HistoryHFId];
TUISearchResultCellModel *cellModel = self.results[0];
[headerView configPlaceHolderImage:self.headerConversationAvatar imgUrl:self.headerConversationURL Text:self.headerConversationShowName];
headerView.onTap = ^{
[self headerViewJump2ChatViewController:cellModel];
};
return headerView;
} else {
TUISearchResultHeaderFooterView_Minimalist *headerView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:HFId];
headerView.showMoreBtn = NO;
headerView.title = titleForModule(self.module, YES);
headerView.isFooter = NO;
return headerView;
}
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
return nil;
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
[self.view endEditing:YES];
[self.searchBar endEditing:YES];
if (self.allowPageRequest && scrollView.contentOffset.y + scrollView.bounds.size.height > scrollView.contentSize.height) {
self.allowPageRequest = NO;
NSMutableDictionary *param = [NSMutableDictionary dictionaryWithDictionary:self.param];
param[TUISearchChatHistoryParamKeyPage] = @(self.pageIndex);
param[TUISearchChatHistoryParamKeyCount] = @(TUISearchDefaultPageSize);
self.param = [NSDictionary dictionaryWithDictionary:param];
[self.dataProvider searchForKeyword:self.searchBar.searchBar.text forModules:self.module param:self.param];
}
}
- (void)onBack {
[self.navigationController popViewControllerAnimated:YES];
}
- (void)headerViewJump2ChatViewController:(TUISearchResultCellModel *)cellModel {
if ([cellModel.context isKindOfClass:V2TIMMessage.class]) {
V2TIMMessage *message = cellModel.context;
NSString *title = message.userID;
if (self.headerConversationShowName.length > 0) {
title = self.headerConversationShowName;
}
NSDictionary *param = @{
TUICore_TUIChatObjectFactory_ChatViewController_Title : title ?: @"",
TUICore_TUIChatObjectFactory_ChatViewController_UserID : message.userID ?: @"",
TUICore_TUIChatObjectFactory_ChatViewController_GroupID : message.groupID ?: @"",
TUICore_TUIChatObjectFactory_ChatViewController_AvatarImage : self.headerConversationAvatar ?: [[UIImage alloc] init],
TUICore_TUIChatObjectFactory_ChatViewController_AvatarUrl : self.headerConversationURL ?: @"",
};
[self.navigationController pushViewController:TUICore_TUIChatObjectFactory_ChatViewController_Minimalist param:param forResult:nil];
} else if (([cellModel.context isKindOfClass:NSDictionary.class])) {
NSDictionary *convInfo = cellModel.context;
V2TIMConversation *conversation = convInfo[kSearchChatHistoryConverationInfo];
NSString *title = cellModel.title ?: cellModel.titleAttributeString.string;
if (self.headerConversationShowName.length > 0) {
title = self.headerConversationShowName;
}
NSDictionary *param = @{
TUICore_TUIChatObjectFactory_ChatViewController_Title : title ?: @"",
TUICore_TUIChatObjectFactory_ChatViewController_UserID : conversation.userID ?: @"",
TUICore_TUIChatObjectFactory_ChatViewController_GroupID : conversation.groupID ?: @"",
TUICore_TUIChatObjectFactory_ChatViewController_AvatarImage : self.headerConversationAvatar ?: [[UIImage alloc] init],
TUICore_TUIChatObjectFactory_ChatViewController_AvatarUrl : self.headerConversationURL ?: @"",
};
[self.navigationController pushViewController:TUICore_TUIChatObjectFactory_ChatViewController_Minimalist param:param forResult:nil];
}
}
- (void)onSelectModel:(TUISearchResultCellModel *)cellModel module:(TUISearchResultModule)module {
[self.searchBar endEditing:YES];
if (module == TUISearchResultModuleChatHistory) {
if (![cellModel.context isKindOfClass:NSDictionary.class]) {
if ([cellModel.context isKindOfClass:V2TIMMessage.class]) {
V2TIMMessage *message = cellModel.context;
NSString *title = message.userID;
if (cellModel.title.length > 0) {
title = cellModel.title;
}
NSDictionary *param = @{
TUICore_TUIChatObjectFactory_ChatViewController_Title : title ?: @"",
TUICore_TUIChatObjectFactory_ChatViewController_UserID : message.userID ?: @"",
TUICore_TUIChatObjectFactory_ChatViewController_GroupID : message.groupID ?: @"",
TUICore_TUIChatObjectFactory_ChatViewController_AvatarImage : cellModel.avatarImage ?: [[UIImage alloc] init],
TUICore_TUIChatObjectFactory_ChatViewController_HighlightKeyword : self.searchBar.searchBar.text ?: @"",
TUICore_TUIChatObjectFactory_ChatViewController_LocateMessage : message,
};
[self.navigationController pushViewController:TUICore_TUIChatObjectFactory_ChatViewController_Minimalist param:param forResult:nil];
return;
}
return;
}
NSDictionary *convInfo = cellModel.context;
NSString *conversationId = convInfo[kSearchChatHistoryConversationId];
V2TIMConversation *conversation = convInfo[kSearchChatHistoryConverationInfo];
NSArray *msgs = convInfo[kSearchChatHistoryConversationMsgs];
NSMutableArray *results = [NSMutableArray array];
for (V2TIMMessage *message in msgs) {
TUISearchResultCellModel *model = [[TUISearchResultCellModel alloc] init];
model.title = message.nickName ?: message.sender;
NSString *desc = [TUISearchDataProvider matchedTextForMessage:message withKey:self.searchBar.searchBar.text];
model.detailsAttributeString = [TUISearchDataProvider attributeStringWithText:desc key:self.searchBar.searchBar.text];
model.avatarUrl = message.faceURL;
model.groupType = conversation.groupID;
model.avatarImage = conversation.type == V2TIM_C2C ? DefaultAvatarImage : DefaultGroupAvatarImageByGroupType(conversation.groupType);
model.context = message;
[results addObject:model];
}
TUISearchResultListController_Minimalist *vc =
[[TUISearchResultListController_Minimalist alloc] initWithResults:results
keyword:self.searchBar.searchBar.text
module:module
param:@{TUISearchChatHistoryParamKeyConversationId : conversationId}];
vc.headerConversationAvatar = cellModel.avatarImage;
vc.headerConversationShowName = cellModel.title;
[self.navigationController pushViewController:vc animated:YES];
return;
}
NSDictionary *param = nil;
NSString *title = cellModel.title ?: cellModel.titleAttributeString.string;
if (module == TUISearchResultModuleContact && [cellModel.context isKindOfClass:V2TIMFriendInfo.class]) {
V2TIMFriendInfo *friend = cellModel.context;
param = @{
TUICore_TUIChatObjectFactory_ChatViewController_Title : title ?: @"",
TUICore_TUIChatObjectFactory_ChatViewController_UserID : friend.userID ?: @"",
TUICore_TUIChatObjectFactory_ChatViewController_AvatarImage : cellModel.avatarImage ?: [UIImage new],
};
}
if (module == TUISearchResultModuleGroup && [cellModel.context isKindOfClass:V2TIMGroupInfo.class]) {
V2TIMGroupInfo *group = cellModel.context;
param = @{
TUICore_TUIChatObjectFactory_ChatViewController_Title : title ?: @"",
TUICore_TUIChatObjectFactory_ChatViewController_GroupID : group.groupID ?: @"",
TUICore_TUIChatObjectFactory_ChatViewController_AvatarImage : cellModel.avatarImage ?: [UIImage new],
};
}
[self.navigationController pushViewController:TUICore_TUIChatObjectFactory_ChatViewController_Minimalist param:param forResult:nil];
}
#pragma mark - TUISearchBarDelegate
- (void)searchBarDidCancelClicked:(TUISearchBar_Minimalist *)searchBar {
[self dismissViewControllerAnimated:NO completion:nil];
}
- (void)searchBar:(TUISearchBar_Minimalist *)searchBar searchText:(NSString *)key {
[self.results removeAllObjects];
self.allowPageRequest = YES;
self.pageIndex = 0;
NSMutableDictionary *param = [NSMutableDictionary dictionaryWithDictionary:self.param];
param[TUISearchChatHistoryParamKeyPage] = @(self.pageIndex);
self.param = [NSDictionary dictionaryWithDictionary:param];
[self.dataProvider searchForKeyword:key forModules:self.module param:self.param];
}
#pragma mark - TUISearchResultDelegate
- (void)onSearchResults:(NSDictionary<NSNumber *, NSArray<TUISearchResultCellModel *> *> *)results forModules:(TUISearchResultModule)modules {
NSArray *arrayM = [results objectForKey:@(modules)];
if (arrayM == nil) {
arrayM = @[];
}
self.noDataEmptyView.hidden = YES;
if ((arrayM.count == 0) && (self.results.count == 0)) {
self.noDataEmptyView.hidden = NO;
if (self.searchBar.searchBar.text.length == 0) {
self.noDataEmptyView.hidden = YES;
}
}
[self.results addObjectsFromArray:arrayM];
[self.tableView reloadData];
self.allowPageRequest = (arrayM.count >= TUISearchDefaultPageSize);
self.pageIndex = (arrayM.count < TUISearchDefaultPageSize) ? self.pageIndex : self.pageIndex + 1;
if (!self.allowPageRequest) {
}
}
- (void)onSearchError:(NSString *)errMsg {
NSLog(@"search error: %@", errMsg);
}
- (UIImage *)imageWithColor:(UIColor *)color {
CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [color CGColor]);
CGContextFillRect(context, rect);
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
@end

View File

@@ -0,0 +1,17 @@
//
// TUISearchViewController.h
// Pods
//
// Created by harvy on 2020/12/24.
// Copyright © 2023 Tencent. All rights reserved.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface TUISearchViewController_Minimalist : UIViewController
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,327 @@
//
// TUISearchViewController_Minimalist.m
// Pods
//
// Created by harvy on 2020/12/24.
// Copyright © 2023 Tencent. All rights reserved.
//
#import "TUISearchViewController_Minimalist.h"
#import <TIMCommon/TIMDefine.h>
#import <TUICore/TUICore.h>
#import "TUISearchBar_Minimalist.h"
#import "TUISearchDataProvider.h"
#import "TUISearchEmptyView_Minimalist.h"
#import "TUISearchResultCellModel.h"
#import "TUISearchResultCell_Minimalist.h"
#import "TUISearchResultHeaderFooterView_Minimalist.h"
#import "TUISearchResultListController_Minimalist.h"
@interface TUISearchViewController_Minimalist () <UITableViewDelegate, UITableViewDataSource, TUISearchBarDelegate_Minimalist, TUISearchResultDelegate>
@property(nonatomic, strong) TUISearchBar_Minimalist *searchBar;
@property(nonatomic, strong) UITableView *tableView;
@property(nonatomic, strong) TUISearchDataProvider *dataProvider;
@property(nonatomic, strong) TUISearchEmptyView_Minimalist *noDataEmptyView;
@end
@implementation TUISearchViewController_Minimalist
static NSString *const Id = @"cell";
static NSString *const HFId = @"HFId";
- (void)viewDidLoad {
[super viewDidLoad];
_dataProvider = [[TUISearchDataProvider alloc] init];
_dataProvider.delegate = self;
[self setupViews];
[TUITool addUnsupportNotificationInVC:self];
}
- (void)dealloc {
NSLog(@"%s dealloc", __FUNCTION__);
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)setupViews {
self.view.backgroundColor = [UIColor whiteColor];
_searchBar = [[TUISearchBar_Minimalist alloc] init];
[_searchBar setEntrance:NO];
_searchBar.delegate = self;
self.navigationItem.titleView = _searchBar;
_tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
_tableView.delegate = self;
_tableView.dataSource = self;
_tableView.backgroundColor = [UIColor whiteColor];
_tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
_tableView.rowHeight = kScale390(72);
[_tableView registerClass:TUISearchResultCell_Minimalist.class forCellReuseIdentifier:Id];
[_tableView registerClass:TUISearchResultHeaderFooterView_Minimalist.class forHeaderFooterViewReuseIdentifier:HFId];
[self.view addSubview:_tableView];
self.noDataEmptyView.frame = CGRectMake(0, kScale390(42), self.view.bounds.size.width - 20, 200);
[self.tableView addSubview:self.noDataEmptyView];
[_searchBar.searchBar becomeFirstResponder];
}
- (void)viewWillLayoutSubviews {
[super viewWillLayoutSubviews];
self.tableView.frame = self.view.bounds;
self.searchBar.frame = CGRectMake(0, 0, self.view.mm_w, 44);
}
- (UIColor *)navBackColor {
return [UIColor whiteColor];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
if (@available(iOS 15.0, *)) {
UINavigationBarAppearance *appearance = [UINavigationBarAppearance new];
[appearance configureWithDefaultBackground];
appearance.shadowColor = nil;
appearance.backgroundEffect = nil;
appearance.backgroundColor = [self navBackColor];
UINavigationBar *navigationBar = self.navigationController.navigationBar;
navigationBar.backgroundColor = [self navBackColor];
navigationBar.barTintColor = [self navBackColor];
navigationBar.shadowImage = [UIImage new];
navigationBar.standardAppearance = appearance;
navigationBar.scrollEdgeAppearance = appearance;
} else {
UINavigationBar *navigationBar = self.navigationController.navigationBar;
navigationBar.backgroundColor = [self navBackColor];
navigationBar.barTintColor = [self navBackColor];
navigationBar.shadowImage = [UIImage new];
}
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
}
- (TUISearchEmptyView_Minimalist *)noDataEmptyView {
if (_noDataEmptyView == nil) {
_noDataEmptyView = [[TUISearchEmptyView_Minimalist alloc] initWithImage:TUISearchBundleThemeImage(@"", @"search_not_found_icon")
Text:TIMCommonLocalizableString(TUIKitSearchNoResultLists)];
_noDataEmptyView.hidden = YES;
}
return _noDataEmptyView;
}
#pragma mark - TUISearchResultDelegate
- (void)onSearchError:(NSString *)errMsg {
}
- (void)onSearchResults:(NSDictionary<NSNumber *, NSArray<TUISearchResultCellModel *> *> *)results forModules:(TUISearchResultModule)modules {
self.noDataEmptyView.hidden = YES;
if (!results || results.allKeys.count == 0) {
self.noDataEmptyView.hidden = NO;
if (self.searchBar.searchBar.text.length == 0) {
self.noDataEmptyView.hidden = YES;
}
}
[self.tableView reloadData];
}
#pragma mark - UITableViewDataSourceTUITableViewDelegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return self.dataProvider.resultSet.allKeys.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSArray *results = [self resultForSection:section];
return results.count > kMaxNumOfPerModule ? kMaxNumOfPerModule : results.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
TUISearchResultCell_Minimalist *cell = [tableView dequeueReusableCellWithIdentifier:Id forIndexPath:indexPath];
TUISearchResultModule module = TUISearchResultModuleContact;
NSArray *results = [self resultForSection:indexPath.section module:&module];
if (results.count <= indexPath.row) {
return cell;
}
TUISearchResultCellModel *model = results[indexPath.row];
model.avatarType = TAvatarTypeRadiusCorner;
[cell fillWithData:model];
return cell;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
return [UIView new];
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
return 20;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
TUISearchResultModule module = TUISearchResultModuleContact;
[self resultForSection:section module:&module];
TUISearchResultHeaderFooterView_Minimalist *headerView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:HFId];
headerView.isFooter = NO;
headerView.showMoreBtn = YES;
headerView.title = titleForModule(module, YES);
__weak typeof(self) weakSelf = self;
NSArray *results = [self resultForSection:section module:&module];
headerView.onTap = ^{
[weakSelf onSelectMoreModule:module results:results];
};
return headerView;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return 30;
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
[self.view endEditing:YES];
[self.searchBar endEditing:YES];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:NO];
TUISearchResultModule module = TUISearchResultModuleContact;
NSArray *results = [self resultForSection:indexPath.section module:&module];
if (results.count <= indexPath.row) {
return;
}
TUISearchResultCellModel *cellModel = results[indexPath.row];
TUISearchResultCell_Minimalist *cell = [tableView cellForRowAtIndexPath:indexPath];
cellModel.avatarImage = cell.avatarView.image;
cellModel.title = cell.title_label.text;
[self onSelectModel:cellModel module:module];
}
#pragma mark - action
- (void)onSelectModel:(TUISearchResultCellModel *)cellModel module:(TUISearchResultModule)module {
[self.searchBar endEditing:YES];
if (module == TUISearchResultModuleChatHistory) {
if (![cellModel.context isKindOfClass:NSDictionary.class]) {
return;
}
NSDictionary *convInfo = cellModel.context;
NSString *conversationId = convInfo[kSearchChatHistoryConversationId];
V2TIMConversation *conversation = convInfo[kSearchChatHistoryConverationInfo];
NSArray *msgs = convInfo[kSearchChatHistoryConversationMsgs];
NSMutableArray *results = [NSMutableArray array];
for (V2TIMMessage *message in msgs) {
TUISearchResultCellModel *model = [[TUISearchResultCellModel alloc] init];
model.title = message.nickName ?: message.sender;
NSString *desc = [TUISearchDataProvider matchedTextForMessage:message withKey:self.searchBar.searchBar.text];
model.detailsAttributeString = [TUISearchDataProvider attributeStringWithText:desc key:self.searchBar.searchBar.text];
model.avatarUrl = message.faceURL;
model.groupType = conversation.groupType;
model.avatarImage = conversation.type == V2TIM_C2C ? DefaultAvatarImage : DefaultGroupAvatarImageByGroupType(conversation.groupType);
;
model.context = message;
[results addObject:model];
}
TUISearchResultListController_Minimalist *vc =
[[TUISearchResultListController_Minimalist alloc] initWithResults:results
keyword:self.searchBar.searchBar.text
module:module
param:@{TUISearchChatHistoryParamKeyConversationId : conversationId}];
vc.headerConversationAvatar = cellModel.avatarImage;
vc.headerConversationShowName = cellModel.title;
[self.navigationController pushViewController:vc animated:YES];
return;
}
NSDictionary *param = nil;
NSString *title = cellModel.title ?: cellModel.titleAttributeString.string;
if (module == TUISearchResultModuleContact && [cellModel.context isKindOfClass:V2TIMFriendInfo.class]) {
V2TIMFriendInfo *friend = cellModel.context;
param = @{
TUICore_TUIChatObjectFactory_ChatViewController_Title : title ?: @"",
TUICore_TUIChatObjectFactory_ChatViewController_UserID : friend.userID ?: @"",
TUICore_TUIChatObjectFactory_ChatViewController_AvatarImage : cellModel.avatarImage ?: [UIImage new],
};
}
if (module == TUISearchResultModuleGroup && [cellModel.context isKindOfClass:V2TIMGroupInfo.class]) {
V2TIMGroupInfo *group = cellModel.context;
param = @{
TUICore_TUIChatObjectFactory_ChatViewController_Title : title ?: @"",
TUICore_TUIChatObjectFactory_ChatViewController_GroupID : group.groupID ?: @"",
TUICore_TUIChatObjectFactory_ChatViewController_AvatarImage : cellModel.avatarImage ?: [UIImage new],
};
}
[self.navigationController pushViewController:TUICore_TUIChatObjectFactory_ChatViewController_Minimalist param:param forResult:nil];
}
- (void)onSelectMoreModule:(TUISearchResultModule)module results:(NSArray<TUISearchResultCellModel *> *)results {
TUISearchResultListController_Minimalist *vc = [[TUISearchResultListController_Minimalist alloc] initWithResults:results
keyword:self.searchBar.searchBar.text
module:module
param:nil];
[self.navigationController pushViewController:vc animated:YES];
}
#pragma mark - viewmodel
- (NSArray *)resultForSection:(NSInteger)section {
return [self resultForSection:section module:nil];
}
- (NSArray *)resultForSection:(NSInteger)section module:(TUISearchResultModule *)module {
NSArray *keys = self.dataProvider.resultSet.allKeys;
if (section >= keys.count) {
return 0;
}
keys = [keys sortedArrayUsingComparator:^NSComparisonResult(NSNumber *obj1, NSNumber *obj2) {
return [obj1 intValue] < [obj2 intValue] ? NSOrderedAscending : NSOrderedDescending;
}];
NSNumber *key = keys[section];
if (module) {
*module = (TUISearchResultModule)[key integerValue];
}
return [self.dataProvider.resultSet objectForKey:key];
}
#pragma mark - TUISearchBarDelegate
- (void)searchBarDidCancelClicked:(TUISearchBar_Minimalist *)searchBar {
[self dismissViewControllerAnimated:NO completion:nil];
}
- (void)searchBar:(TUISearchBar_Minimalist *)searchBar searchText:(NSString *)key {
[self.dataProvider searchForKeyword:key forModules:TUISearchResultModuleAll param:nil];
}
- (UIImage *)imageWithColor:(UIColor *)color {
CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [color CGColor]);
CGContextFillRect(context, rect);
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
@end
@interface IUSearchView_Minimalist : UIView
@property(nonatomic, strong) UIView *view;
@end
@implementation IUSearchView_Minimalist
- (instancetype)init {
self = [super init];
if (self) {
self.view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];
[self addSubview:self.view];
}
return self;
}
@end