chore: import upstream snapshot with attribution

This commit is contained in:
wehub-resource-sync
2026-07-13 12:35:01 +08:00
commit a2e318a963
2974 changed files with 158180 additions and 0 deletions
@@ -0,0 +1,18 @@
//
// TLMoreKeyboardCell.h
// TLChat
//
// Created by 李伯坤 on 16/2/18.
// Copyright © 2016年 李伯坤. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "TLMoreKeyboardItem.h"
@interface TLMoreKeyboardCell : UICollectionViewCell
@property (nonatomic, strong) TLMoreKeyboardItem *item;
@property (nonatomic, strong) void(^clickBlock)(TLMoreKeyboardItem *item);
@end
@@ -0,0 +1,94 @@
//
// TLMoreKeyboardCell.m
// TLChat
//
// Created by 李伯坤 on 16/2/18.
// Copyright © 2016年 李伯坤. All rights reserved.
//
#import "TLMoreKeyboardCell.h"
#import "UIImage+Color.h"
@interface TLMoreKeyboardCell()
@property (nonatomic, strong) UIButton *iconButton;
@property (nonatomic, strong) UILabel *titleLabel;
@end
@implementation TLMoreKeyboardCell
- (id)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
[self.contentView addSubview:self.iconButton];
[self.contentView addSubview:self.titleLabel];
[self p_addMasonry];
}
return self;
}
- (void)setItem:(TLMoreKeyboardItem *)item
{
_item = item;
if (item == nil) {
[self.titleLabel setHidden:YES];
[self.iconButton setHidden:YES];
[self setUserInteractionEnabled:NO];
return;
}
[self setUserInteractionEnabled:YES];
[self.titleLabel setHidden:NO];
[self.iconButton setHidden:NO];
[self.titleLabel setText:item.title];
[self.iconButton setImage:[UIImage imageNamed:item.imagePath] forState:UIControlStateNormal];
}
#pragma mark - Event Response -
- (void)iconButtonDown:(UIButton *)sender
{
self.clickBlock(self.item);
}
#pragma mark - Private Methods -
- (void)p_addMasonry
{
[self.iconButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.contentView);
make.centerX.mas_equalTo(self.contentView);
make.width.mas_equalTo(self.contentView);
make.height.mas_equalTo(self.iconButton.mas_width);
}];
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(self.contentView);
make.bottom.mas_equalTo(self.contentView);
}];
}
#pragma mark - Getter -
- (UIButton *)iconButton
{
if (_iconButton == nil) {
_iconButton = [[UIButton alloc] init];
[_iconButton.layer setMasksToBounds:YES];
[_iconButton.layer setCornerRadius:5.0f];
[_iconButton.layer setBorderWidth:BORDER_WIDTH_1PX];
[_iconButton.layer setBorderColor:[UIColor grayColor].CGColor];
[_iconButton setBackgroundImage:[UIImage imageWithColor:[UIColor colorGrayLine]] forState:UIControlStateHighlighted];
[_iconButton addTarget:self action:@selector(iconButtonDown:) forControlEvents:UIControlEventTouchUpInside];
}
return _iconButton;
}
- (UILabel *)titleLabel
{
if (_titleLabel == nil) {
_titleLabel = [[UILabel alloc] init];
[_titleLabel setFont:[UIFont systemFontOfSize:12.0f]];
[_titleLabel setTextColor:[UIColor grayColor]];
}
return _titleLabel;
}
@end
@@ -0,0 +1,16 @@
//
// TLMoreKeyboardDelegate.h
// TLChat
//
// Created by 李伯坤 on 16/2/20.
// Copyright © 2016年 李伯坤. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "TLMoreKeyboardItem.h"
@protocol TLMoreKeyboardDelegate <NSObject>
@optional
- (void)moreKeyboard:(id)keyboard didSelectedFunctionItem:(TLMoreKeyboardItem *)funcItem;
@end
@@ -0,0 +1,35 @@
//
// TLMoreKeyboardItem.h
// TLChat
//
// Created by 李伯坤 on 16/2/18.
// Copyright © 2016年 李伯坤. All rights reserved.
//
#import <Foundation/Foundation.h>
typedef NS_ENUM(NSUInteger, TLMoreKeyboardItemType) {
TLMoreKeyboardItemTypeImage,
TLMoreKeyboardItemTypeCamera,
TLMoreKeyboardItemTypeVideo,
TLMoreKeyboardItemTypeVideoCall,
TLMoreKeyboardItemTypeWallet,
TLMoreKeyboardItemTypeTransfer,
TLMoreKeyboardItemTypePosition,
TLMoreKeyboardItemTypeFavorite,
TLMoreKeyboardItemTypeBusinessCard,
TLMoreKeyboardItemTypeVoice,
TLMoreKeyboardItemTypeCards,
};
@interface TLMoreKeyboardItem : NSObject
@property (nonatomic, assign) TLMoreKeyboardItemType type;
@property (nonatomic, strong) NSString *title;
@property (nonatomic, strong) NSString *imagePath;
+ (TLMoreKeyboardItem *)createByType:(TLMoreKeyboardItemType)type title:(NSString *)title imagePath:(NSString *)imagePath;
@end
@@ -0,0 +1,23 @@
//
// TLMoreKeyboardItem.m
// TLChat
//
// Created by 李伯坤 on 16/2/18.
// Copyright © 2016年 李伯坤. All rights reserved.
//
#import "TLMoreKeyboardItem.h"
@implementation TLMoreKeyboardItem
+ (TLMoreKeyboardItem *)createByType:(TLMoreKeyboardItemType)type title:(NSString *)title imagePath:(NSString *)imagePath
{
TLMoreKeyboardItem *item = [[TLMoreKeyboardItem alloc] init];
item.type = type;
item.title = title;
item.imagePath = imagePath;
return item;
}
@end
@@ -0,0 +1,17 @@
//
// TLMoreKeyboard+CollectionView.h
// TLChat
//
// Created by 李伯坤 on 16/3/17.
// Copyright © 2016年 李伯坤. All rights reserved.
//
#import "TLMoreKeyboard.h"
@interface TLMoreKeyboard (CollectionView) <UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout>
@property (nonatomic, assign, readonly) NSInteger pageItemCount;
- (void)registerCellClass;
@end
@@ -0,0 +1,98 @@
//
// TLMoreKeyboard+CollectionView.m
// TLChat
//
// Created by 李伯坤 on 16/3/17.
// Copyright © 2016年 李伯坤. All rights reserved.
//
#import "TLMoreKeyboard+CollectionView.h"
#import "TLMoreKeyboardCell.h"
#define SPACE_TOP 15
#define WIDTH_CELL 60
@implementation TLMoreKeyboard (CollectionView)
#pragma mark - Public Methods -
- (void)registerCellClass
{
[self.collectionView registerClass:[TLMoreKeyboardCell class] forCellWithReuseIdentifier:@"TLMoreKeyboardCell"];
}
#pragma mark - Delegate -
//MARK: UICollectionViewDataSource
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
return self.chatMoreKeyboardData.count / self.pageItemCount + (self.chatMoreKeyboardData.count % self.pageItemCount == 0 ? 0 : 1);
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return self.pageItemCount;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
TLMoreKeyboardCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"TLMoreKeyboardCell" forIndexPath:indexPath];
NSUInteger index = indexPath.section * self.pageItemCount + indexPath.row;
NSUInteger tIndex = [self p_transformIndex:index]; // 矩阵坐标转置
if (tIndex >= self.chatMoreKeyboardData.count) {
[cell setItem:nil];
}
else {
[cell setItem:self.chatMoreKeyboardData[tIndex]];
}
__weak typeof(self) weakSelf = self;
[cell setClickBlock:^(TLMoreKeyboardItem *sItem) {
if (weakSelf.delegate && [weakSelf.delegate respondsToSelector:@selector(moreKeyboard:didSelectedFunctionItem:)]) {
[weakSelf.delegate moreKeyboard:weakSelf didSelectedFunctionItem:sItem];
}
}];
return cell;
}
//MARK: UICollectionViewDelegateFlowLayout
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
return CGSizeMake(WIDTH_CELL, (collectionView.height - SPACE_TOP) / 2 * 0.93);
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
{
return (collectionView.width - WIDTH_CELL * self.pageItemCount / 2) / (self.pageItemCount / 2 + 1);
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
{
return (collectionView.height - SPACE_TOP) / 2 * 0.07;
}
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
CGFloat space = (collectionView.width - WIDTH_CELL * self.pageItemCount / 2) / (self.pageItemCount / 2 + 1);
return UIEdgeInsetsMake(SPACE_TOP, space, 0, space);
}
//Mark: UIScrollViewDelegate
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
[self.pageControl setCurrentPage:(int)(scrollView.contentOffset.x / scrollView.width)];
}
#pragma mark - Private Methods -
- (NSUInteger)p_transformIndex:(NSUInteger)index
{
NSUInteger page = index / self.pageItemCount;
index = index % self.pageItemCount;
NSUInteger x = index / 2;
NSUInteger y = index % 2;
return self.pageItemCount / 2 * y + x + page * self.pageItemCount;
}
#pragma mark - # Getter
- (NSInteger)pageItemCount
{
return 8;
}
@end
@@ -0,0 +1,26 @@
//
// TLMoreKeyboard.h
// TLChat
//
// Created by 李伯坤 on 16/2/17.
// Copyright © 2016年 李伯坤. All rights reserved.
//
#import "TLBaseKeyboard.h"
#import "TLKeyboardDelegate.h"
#import "TLMoreKeyboardDelegate.h"
#import "TLMoreKeyboardItem.h"
@interface TLMoreKeyboard : TLBaseKeyboard
@property (nonatomic, assign) id<TLMoreKeyboardDelegate> delegate;
@property (nonatomic, strong) NSMutableArray *chatMoreKeyboardData;
@property (nonatomic, strong) UICollectionView *collectionView;
@property (nonatomic, strong) UIPageControl *pageControl;
+ (TLMoreKeyboard *)keyboard;
@end
@@ -0,0 +1,120 @@
//
// TLMoreKeyboard.m
// TLChat
//
// Created by 李伯坤 on 16/2/17.
// Copyright © 2016年 李伯坤. All rights reserved.
//
#import "TLMoreKeyboard.h"
#import "TLMoreKeyboard+CollectionView.h"
#import "TLChatMacros.h"
static TLMoreKeyboard *moreKB;
@implementation TLMoreKeyboard
+ (TLMoreKeyboard *)keyboard
{
static dispatch_once_t once;
dispatch_once(&once, ^{
moreKB = [[TLMoreKeyboard alloc] init];
});
return moreKB;
}
- (id)init
{
if (self = [super init]) {
[self setBackgroundColor:[UIColor colorGrayForChatBar]];
[self addSubview:self.collectionView];
[self addSubview:self.pageControl];
[self p_addMasonry];
[self registerCellClass];
}
return self;
}
- (CGFloat)keyboardHeight
{
return HEIGHT_CHAT_KEYBOARD;
}
#pragma mark - # Public Methods
- (void)setChatMoreKeyboardData:(NSMutableArray *)chatMoreKeyboardData
{
_chatMoreKeyboardData = chatMoreKeyboardData;
[self.collectionView reloadData];
NSUInteger pageNumber = chatMoreKeyboardData.count / self.pageItemCount + (chatMoreKeyboardData.count % self.pageItemCount == 0 ? 0 : 1);
[self.pageControl setNumberOfPages:pageNumber];
}
- (void)reset
{
[self.collectionView scrollRectToVisible:CGRectMake(0, 0, self.collectionView.width, self.collectionView.height) animated:NO];
}
#pragma mark - # Event Response
- (void)pageControlChanged:(UIPageControl *)pageControl
{
[self.collectionView scrollRectToVisible:CGRectMake(self.collectionView.width * pageControl.currentPage, 0, self.collectionView.width, self.collectionView.height) animated:YES];
}
#pragma mark - Private Methods -
- (void)p_addMasonry
{
[self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self);
make.left.and.right.mas_equalTo(self);
make.bottom.mas_equalTo(-25);
}];
[self.pageControl mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.and.right.mas_equalTo(self);
make.height.mas_equalTo(20);
make.bottom.mas_equalTo(-2);
}];
}
- (void)drawRect:(CGRect)rect
{
[super drawRect:rect];
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(context, 0.5);
CGContextSetStrokeColorWithColor(context, [UIColor colorGrayLine].CGColor);
CGContextBeginPath(context);
CGContextMoveToPoint(context, 0, 0);
CGContextAddLineToPoint(context, SCREEN_WIDTH, 0);
CGContextStrokePath(context);
}
#pragma mark - # Getter
- (UICollectionView *)collectionView
{
if (_collectionView == nil) {
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
[layout setScrollDirection:UICollectionViewScrollDirectionHorizontal];
_collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
[_collectionView setBackgroundColor:[UIColor clearColor]];
[_collectionView setPagingEnabled:YES];
[_collectionView setDataSource:self];
[_collectionView setDelegate:self];
[_collectionView setShowsHorizontalScrollIndicator:NO];
[_collectionView setShowsHorizontalScrollIndicator:NO];
[_collectionView setScrollsToTop:NO];
}
return _collectionView;
}
- (UIPageControl *)pageControl
{
if (_pageControl == nil) {
_pageControl = [[UIPageControl alloc] init];
[_pageControl setPageIndicatorTintColor:[UIColor colorGrayLine]];
[_pageControl setCurrentPageIndicatorTintColor:[UIColor grayColor]];
[_pageControl addTarget:self action:@selector(pageControlChanged:) forControlEvents:UIControlEventValueChanged];
}
return _pageControl;
}
@end