添加emoji1
This commit is contained in:
@@ -231,6 +231,15 @@ static void KBSkinInstallNotificationCallback(CFNotificationCenterRef center,
|
||||
[self showSettingView:YES];
|
||||
}
|
||||
|
||||
- (void)keyBoardMainView:(KBKeyBoardMainView *)keyBoardMainView didSelectEmoji:(NSString *)emoji {
|
||||
if (emoji.length == 0) { return; }
|
||||
[self.textDocumentProxy insertText:emoji];
|
||||
}
|
||||
|
||||
- (void)keyBoardMainViewDidTapEmojiSearch:(KBKeyBoardMainView *)keyBoardMainView {
|
||||
[KBHUD showInfo:KBLocalized(@"Search coming soon")];
|
||||
}
|
||||
|
||||
// MARK: - KBFunctionViewDelegate
|
||||
- (void)functionView:(KBFunctionView *)functionView didTapToolActionAtIndex:(NSInteger)index {
|
||||
// 需求:当 index == 0 时,切回键盘主视图
|
||||
|
||||
46
CustomKeyboard/Manager/KBEmojiDataProvider.h
Normal file
46
CustomKeyboard/Manager/KBEmojiDataProvider.h
Normal file
@@ -0,0 +1,46 @@
|
||||
//
|
||||
// KBEmojiDataProvider.h
|
||||
// CustomKeyboard
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
FOUNDATION_EXPORT NSString * const KBEmojiRecentsDidChangeNotification;
|
||||
|
||||
@class KBEmojiCategory, KBEmojiItem;
|
||||
|
||||
@interface KBEmojiItem : NSObject <NSCopying>
|
||||
@property (nonatomic, copy, readonly) NSString *value;
|
||||
@property (nonatomic, copy, readonly) NSString *name;
|
||||
- (instancetype)initWithValue:(NSString *)value name:(NSString *)name;
|
||||
@end
|
||||
|
||||
@interface KBEmojiCategory : NSObject
|
||||
@property (nonatomic, copy, readonly) NSString *identifier;
|
||||
@property (nonatomic, copy, readonly) NSString *displayTitle;
|
||||
@property (nonatomic, copy, readonly) NSString *iconSymbol;
|
||||
@property (nonatomic, assign, readonly, getter=isDynamic) BOOL dynamic;
|
||||
@property (nonatomic, copy, readonly) NSArray<KBEmojiItem *> *items;
|
||||
@end
|
||||
|
||||
@interface KBEmojiDataProvider : NSObject
|
||||
|
||||
+ (instancetype)shared;
|
||||
|
||||
/// 所有分类(按系统顺序),包含“常用”。
|
||||
@property (nonatomic, copy, readonly) NSArray<KBEmojiCategory *> *categories;
|
||||
|
||||
/// 记录一次 emoji 选择,并刷新“常用”分类。
|
||||
- (void)recordEmojiSelection:(NSString *)emoji;
|
||||
|
||||
/// 重新加载 JSON(若首次调用)。
|
||||
- (void)reloadIfNeeded;
|
||||
|
||||
/// 更新当前语言对应的分类标题。
|
||||
- (void)refreshLocalizedTitles;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
270
CustomKeyboard/Manager/KBEmojiDataProvider.m
Normal file
270
CustomKeyboard/Manager/KBEmojiDataProvider.m
Normal file
@@ -0,0 +1,270 @@
|
||||
//
|
||||
// KBEmojiDataProvider.m
|
||||
// CustomKeyboard
|
||||
//
|
||||
|
||||
#import "KBEmojiDataProvider.h"
|
||||
#import "KBLocalizationManager.h"
|
||||
#import "KBConfig.h"
|
||||
|
||||
NSString * const KBEmojiRecentsDidChangeNotification = @"KBEmojiRecentsDidChangeNotification";
|
||||
|
||||
static NSString * const kKBEmojiJSONFileName = @"emoji_categories";
|
||||
static NSString * const kKBEmojiRecentsStoreKey = @"KBEmojiRecentEmojis";
|
||||
static NSString * const kKBEmojiRecentsCategoryId = @"recents";
|
||||
static const NSUInteger kKBEmojiRecentsLimit = 32;
|
||||
|
||||
#pragma mark - Model Implementations
|
||||
|
||||
@interface KBEmojiItem ()
|
||||
@property (nonatomic, copy, readwrite) NSString *value;
|
||||
@property (nonatomic, copy, readwrite) NSString *name;
|
||||
@end
|
||||
|
||||
@implementation KBEmojiItem
|
||||
|
||||
- (instancetype)initWithValue:(NSString *)value name:(NSString *)name {
|
||||
if (self = [super init]) {
|
||||
_value = [value copy];
|
||||
_name = [name copy];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (id)copyWithZone:(NSZone *)zone {
|
||||
KBEmojiItem *item = [[[self class] allocWithZone:zone] initWithValue:self.value name:self.name];
|
||||
return item;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@interface KBEmojiCategory ()
|
||||
@property (nonatomic, copy, readwrite) NSString *identifier;
|
||||
@property (nonatomic, copy) NSDictionary<NSString *, NSString *> *titleMap;
|
||||
@property (nonatomic, copy, readwrite) NSString *displayTitle;
|
||||
@property (nonatomic, copy, readwrite) NSString *iconSymbol;
|
||||
@property (nonatomic, assign, readwrite, getter=isDynamic) BOOL dynamic;
|
||||
@property (nonatomic, copy, readwrite) NSArray<KBEmojiItem *> *items;
|
||||
@end
|
||||
|
||||
@implementation KBEmojiCategory
|
||||
|
||||
- (void)refreshDisplayTitleForLanguage:(NSString *)lang {
|
||||
if (lang.length == 0) {
|
||||
lang = KBLanguageCodeEnglish;
|
||||
}
|
||||
NSString *title = self.titleMap[lang];
|
||||
if (title.length == 0) {
|
||||
if ([lang.lowercaseString hasPrefix:@"zh"]) {
|
||||
title = self.titleMap[@"zh-Hans"] ?: self.titleMap[@"zh-hans"];
|
||||
}
|
||||
}
|
||||
if (title.length == 0) {
|
||||
title = self.titleMap[@"en"];
|
||||
}
|
||||
if (title.length == 0) {
|
||||
title = self.titleMap.allValues.firstObject;
|
||||
}
|
||||
self.displayTitle = title ?: @"";
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
#pragma mark - Data Provider
|
||||
|
||||
@interface KBEmojiDataProvider ()
|
||||
@property (nonatomic, copy) NSArray<KBEmojiCategory *> *categoriesInternal;
|
||||
@property (nonatomic, strong) NSMutableDictionary<NSString *, KBEmojiItem *> *itemLookup;
|
||||
@property (nonatomic, strong) NSMutableOrderedSet<NSString *> *recentValues;
|
||||
@end
|
||||
|
||||
@implementation KBEmojiDataProvider
|
||||
|
||||
+ (instancetype)shared {
|
||||
static KBEmojiDataProvider *m;
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
m = [KBEmojiDataProvider new];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:m
|
||||
selector:@selector(onLocalizationChanged:)
|
||||
name:KBLocalizationDidChangeNotification
|
||||
object:nil];
|
||||
});
|
||||
return m;
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
||||
}
|
||||
|
||||
- (NSArray<KBEmojiCategory *> *)categories {
|
||||
[self reloadIfNeeded];
|
||||
return self.categoriesInternal ?: @[];
|
||||
}
|
||||
|
||||
- (void)reloadIfNeeded {
|
||||
if (self.categoriesInternal.count > 0) { return; }
|
||||
[self loadEmojiJSON];
|
||||
[self refreshLocalizedTitles];
|
||||
[self loadRecentsFromStore];
|
||||
[self rebuildRecentsCategory];
|
||||
}
|
||||
|
||||
- (void)loadEmojiJSON {
|
||||
NSString *path = [[NSBundle mainBundle] pathForResource:kKBEmojiJSONFileName ofType:@"json"];
|
||||
if (path.length == 0) {
|
||||
return;
|
||||
}
|
||||
NSData *data = [NSData dataWithContentsOfFile:path];
|
||||
if (data.length == 0) { return; }
|
||||
|
||||
NSError *err = nil;
|
||||
NSDictionary *root = [NSJSONSerialization JSONObjectWithData:data options:0 error:&err];
|
||||
if (!root || err) {
|
||||
NSLog(@"[Emoji] failed to parse json: %@", err);
|
||||
return;
|
||||
}
|
||||
NSArray *catArray = root[@"categories"];
|
||||
if (![catArray isKindOfClass:NSArray.class]) {
|
||||
return;
|
||||
}
|
||||
|
||||
NSMutableArray<KBEmojiCategory *> *tmpCats = [NSMutableArray arrayWithCapacity:catArray.count];
|
||||
self.itemLookup = [NSMutableDictionary dictionary];
|
||||
|
||||
for (NSDictionary *catDict in catArray) {
|
||||
if (![catDict isKindOfClass:NSDictionary.class]) continue;
|
||||
KBEmojiCategory *category = [KBEmojiCategory new];
|
||||
category.identifier = catDict[@"id"] ?: @"";
|
||||
NSDictionary *titleMap = catDict[@"title"];
|
||||
if ([titleMap isKindOfClass:NSDictionary.class]) {
|
||||
category.titleMap = titleMap;
|
||||
} else {
|
||||
category.titleMap = @{};
|
||||
}
|
||||
NSString *iconKey = catDict[@"icon"];
|
||||
category.iconSymbol = [self symbolForIconKey:iconKey];
|
||||
NSString *type = catDict[@"type"];
|
||||
category.dynamic = [type.lowercaseString isEqualToString:@"dynamic"];
|
||||
|
||||
NSArray *emojiArray = catDict[@"emojis"];
|
||||
NSMutableArray<KBEmojiItem *> *items = [NSMutableArray arrayWithCapacity:[emojiArray count]];
|
||||
if ([emojiArray isKindOfClass:NSArray.class]) {
|
||||
for (NSDictionary *emojiDict in emojiArray) {
|
||||
if (![emojiDict isKindOfClass:NSDictionary.class]) continue;
|
||||
NSString *value = emojiDict[@"value"];
|
||||
if (value.length == 0) continue;
|
||||
NSString *name = emojiDict[@"name"] ?: @"";
|
||||
KBEmojiItem *item = [[KBEmojiItem alloc] initWithValue:value name:name];
|
||||
[items addObject:item];
|
||||
if (value.length > 0) {
|
||||
self.itemLookup[value] = item;
|
||||
}
|
||||
}
|
||||
}
|
||||
category.items = items.copy;
|
||||
[tmpCats addObject:category];
|
||||
}
|
||||
self.categoriesInternal = tmpCats.copy;
|
||||
}
|
||||
|
||||
- (NSString *)symbolForIconKey:(NSString *)key {
|
||||
static NSDictionary<NSString *, NSString *> *map;
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
map = @{
|
||||
@"emoji_tab_recent": @"🕘",
|
||||
@"emoji_tab_people": @"😊",
|
||||
@"emoji_tab_nature": @"🌿",
|
||||
@"emoji_tab_food": @"🍔",
|
||||
@"emoji_tab_activity": @"🏀",
|
||||
@"emoji_tab_travel": @"✈️",
|
||||
@"emoji_tab_objects": @"💡",
|
||||
@"emoji_tab_symbols": @"♾",
|
||||
@"emoji_tab_flags": @"🏳️"
|
||||
};
|
||||
});
|
||||
NSString *symbol = map[key];
|
||||
return symbol.length ? symbol : @"●";
|
||||
}
|
||||
|
||||
- (void)refreshLocalizedTitles {
|
||||
NSString *lang = [KBLocalizationManager shared].currentLanguageCode ?: KBLanguageCodeEnglish;
|
||||
for (KBEmojiCategory *cat in self.categoriesInternal) {
|
||||
[cat refreshDisplayTitleForLanguage:lang];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)onLocalizationChanged:(__unused NSNotification *)note {
|
||||
[self refreshLocalizedTitles];
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:KBEmojiRecentsDidChangeNotification object:nil];
|
||||
}
|
||||
|
||||
- (void)recordEmojiSelection:(NSString *)emoji {
|
||||
if (emoji.length == 0) return;
|
||||
[self reloadIfNeeded];
|
||||
if (!self.recentValues) {
|
||||
self.recentValues = [NSMutableOrderedSet orderedSet];
|
||||
}
|
||||
[self.recentValues removeObject:emoji];
|
||||
[self.recentValues insertObject:emoji atIndex:0];
|
||||
while (self.recentValues.count > kKBEmojiRecentsLimit) {
|
||||
[self.recentValues removeObjectAtIndex:self.recentValues.count - 1];
|
||||
}
|
||||
[self saveRecentsToStore];
|
||||
[self rebuildRecentsCategory];
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:KBEmojiRecentsDidChangeNotification object:nil];
|
||||
}
|
||||
|
||||
- (void)loadRecentsFromStore {
|
||||
NSUserDefaults *defs = [[NSUserDefaults alloc] initWithSuiteName:AppGroup];
|
||||
if (!defs) { defs = NSUserDefaults.standardUserDefaults; }
|
||||
NSArray *stored = [defs objectForKey:kKBEmojiRecentsStoreKey];
|
||||
NSMutableOrderedSet *set = [NSMutableOrderedSet orderedSet];
|
||||
if ([stored isKindOfClass:NSArray.class]) {
|
||||
for (id obj in stored) {
|
||||
if (![obj isKindOfClass:NSString.class]) continue;
|
||||
NSString *str = (NSString *)obj;
|
||||
if (str.length == 0) continue;
|
||||
[set addObject:str];
|
||||
if (set.count >= kKBEmojiRecentsLimit) break;
|
||||
}
|
||||
}
|
||||
self.recentValues = set;
|
||||
}
|
||||
|
||||
- (void)saveRecentsToStore {
|
||||
if (!self.recentValues) return;
|
||||
NSArray *arr = self.recentValues.array;
|
||||
NSUserDefaults *defs = [[NSUserDefaults alloc] initWithSuiteName:AppGroup];
|
||||
if (!defs) { defs = NSUserDefaults.standardUserDefaults; }
|
||||
[defs setObject:arr forKey:kKBEmojiRecentsStoreKey];
|
||||
[defs synchronize];
|
||||
}
|
||||
|
||||
- (void)rebuildRecentsCategory {
|
||||
KBEmojiCategory *recent = [self categoryForIdentifier:kKBEmojiRecentsCategoryId];
|
||||
if (!recent) return;
|
||||
NSArray<NSString *> *values = self.recentValues.array ?: @[];
|
||||
NSMutableArray<KBEmojiItem *> *items = [NSMutableArray arrayWithCapacity:values.count];
|
||||
for (NSString *value in values) {
|
||||
KBEmojiItem *item = self.itemLookup[value];
|
||||
if (!item) {
|
||||
item = [[KBEmojiItem alloc] initWithValue:value name:@""];
|
||||
}
|
||||
[items addObject:item];
|
||||
}
|
||||
recent.items = items.copy;
|
||||
}
|
||||
|
||||
- (KBEmojiCategory *)categoryForIdentifier:(NSString *)identifier {
|
||||
if (identifier.length == 0) return nil;
|
||||
for (KBEmojiCategory *cat in self.categoriesInternal) {
|
||||
if ([cat.identifier isEqualToString:identifier]) {
|
||||
return cat;
|
||||
}
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -20,6 +20,8 @@ typedef NS_ENUM(NSInteger, KBKeyType) {
|
||||
KBKeyTypeSymbolsToggle // 数字面板内的“#+=/123”切换
|
||||
};
|
||||
|
||||
FOUNDATION_EXPORT NSString * const KBKeyIdentifierEmojiPanel;
|
||||
|
||||
/// 字母键的大小写变体标记(非字母键使用 KBKeyCaseVariantNone)
|
||||
typedef NS_ENUM(NSInteger, KBKeyCaseVariant) {
|
||||
KBKeyCaseVariantNone = 0,
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
|
||||
#import "KBKey.h"
|
||||
|
||||
NSString * const KBKeyIdentifierEmojiPanel = @"emoji_panel";
|
||||
|
||||
@implementation KBKey
|
||||
|
||||
+ (instancetype)keyWithTitle:(NSString *)title output:(NSString *)output {
|
||||
|
||||
14802
CustomKeyboard/Resource/emoji_categories.json
Normal file
14802
CustomKeyboard/Resource/emoji_categories.json
Normal file
File diff suppressed because it is too large
Load Diff
33
CustomKeyboard/View/KBEmojiPanelView.h
Normal file
33
CustomKeyboard/View/KBEmojiPanelView.h
Normal file
@@ -0,0 +1,33 @@
|
||||
//
|
||||
// KBEmojiPanelView.h
|
||||
// CustomKeyboard
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@class KBEmojiPanelView, KBSkinTheme;
|
||||
|
||||
@protocol KBEmojiPanelViewDelegate <NSObject>
|
||||
- (void)emojiPanelView:(KBEmojiPanelView *)panel didSelectEmoji:(NSString *)emoji;
|
||||
- (void)emojiPanelViewDidRequestClose:(KBEmojiPanelView *)panel;
|
||||
- (void)emojiPanelViewDidTapSearch:(KBEmojiPanelView *)panel;
|
||||
@end
|
||||
|
||||
@interface KBEmojiPanelView : UIView
|
||||
|
||||
@property (nonatomic, weak) id<KBEmojiPanelViewDelegate> delegate;
|
||||
|
||||
/// 刷新数据(包括常用分类)。
|
||||
- (void)reloadData;
|
||||
|
||||
/// 应用当前主题色
|
||||
- (void)applyTheme:(KBSkinTheme *)theme;
|
||||
|
||||
/// 高亮指定分类
|
||||
- (void)selectCategoryAtIndex:(NSInteger)index;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
459
CustomKeyboard/View/KBEmojiPanelView.m
Normal file
459
CustomKeyboard/View/KBEmojiPanelView.m
Normal file
@@ -0,0 +1,459 @@
|
||||
//
|
||||
// KBEmojiPanelView.m
|
||||
// CustomKeyboard
|
||||
//
|
||||
|
||||
#import "KBEmojiPanelView.h"
|
||||
#import "KBEmojiDataProvider.h"
|
||||
#import "KBSkinManager.h"
|
||||
#import "KBLocalizationManager.h"
|
||||
#import "Masonry.h"
|
||||
|
||||
@interface KBEmojiCollectionCell : UICollectionViewCell
|
||||
@property (nonatomic, strong) UILabel *emojiLabel;
|
||||
- (void)configureWithEmoji:(NSString *)emoji;
|
||||
@end
|
||||
|
||||
@implementation KBEmojiCollectionCell
|
||||
|
||||
- (instancetype)initWithFrame:(CGRect)frame {
|
||||
if (self = [super initWithFrame:frame]) {
|
||||
_emojiLabel = [[UILabel alloc] init];
|
||||
_emojiLabel.font = [UIFont systemFontOfSize:32];
|
||||
_emojiLabel.textAlignment = NSTextAlignmentCenter;
|
||||
_emojiLabel.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
[self.contentView addSubview:_emojiLabel];
|
||||
[NSLayoutConstraint activateConstraints:@[
|
||||
[_emojiLabel.topAnchor constraintEqualToAnchor:self.contentView.topAnchor],
|
||||
[_emojiLabel.bottomAnchor constraintEqualToAnchor:self.contentView.bottomAnchor],
|
||||
[_emojiLabel.leadingAnchor constraintEqualToAnchor:self.contentView.leadingAnchor],
|
||||
[_emojiLabel.trailingAnchor constraintEqualToAnchor:self.contentView.trailingAnchor],
|
||||
]];
|
||||
self.contentView.layer.cornerRadius = 10;
|
||||
self.contentView.layer.masksToBounds = YES;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)prepareForReuse {
|
||||
[super prepareForReuse];
|
||||
self.emojiLabel.text = @"";
|
||||
}
|
||||
|
||||
- (void)configureWithEmoji:(NSString *)emoji {
|
||||
self.emojiLabel.text = emoji ?: @"";
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@interface KBEmojiPanelView () <UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>
|
||||
|
||||
@property (nonatomic, strong) UILabel *titleLabel;
|
||||
@property (nonatomic, strong) UIButton *backButton;
|
||||
@property (nonatomic, strong) UICollectionView *collectionView;
|
||||
@property (nonatomic, strong) UIView *bottomBar;
|
||||
@property (nonatomic, strong) UIScrollView *tabScrollView;
|
||||
@property (nonatomic, strong) UIStackView *tabStackView;
|
||||
@property (nonatomic, strong) UIButton *searchButton;
|
||||
@property (nonatomic, strong) NSArray<UIButton *> *tabButtons;
|
||||
@property (nonatomic, strong) KBEmojiDataProvider *dataProvider;
|
||||
@property (nonatomic, copy) NSArray<KBEmojiCategory *> *categories;
|
||||
@property (nonatomic, assign) NSInteger currentIndex;
|
||||
@property (nonatomic, strong) UIView *magnifierView;
|
||||
@property (nonatomic, strong) UILabel *magnifierLabel;
|
||||
@property (nonatomic, strong) UIColor *tabNormalColor;
|
||||
@property (nonatomic, strong) UIColor *tabSelectedColor;
|
||||
|
||||
@end
|
||||
|
||||
@implementation KBEmojiPanelView
|
||||
|
||||
- (instancetype)initWithFrame:(CGRect)frame {
|
||||
if (self = [super initWithFrame:frame]) {
|
||||
_dataProvider = [KBEmojiDataProvider shared];
|
||||
_currentIndex = 0;
|
||||
[self setupUI];
|
||||
[self registerNotifications];
|
||||
[self reloadData];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
||||
}
|
||||
|
||||
#pragma mark - Setup
|
||||
|
||||
- (void)setupUI {
|
||||
self.backgroundColor = [UIColor colorWithWhite:0.08 alpha:1.0];
|
||||
|
||||
UIView *topBar = [[UIView alloc] init];
|
||||
topBar.backgroundColor = [UIColor clearColor];
|
||||
[self addSubview:topBar];
|
||||
|
||||
self.backButton = [UIButton buttonWithType:UIButtonTypeSystem];
|
||||
self.backButton.titleLabel.font = [UIFont systemFontOfSize:20 weight:UIFontWeightSemibold];
|
||||
[self.backButton setTitle:@"⌨︎" forState:UIControlStateNormal];
|
||||
[self.backButton addTarget:self action:@selector(onBack) forControlEvents:UIControlEventTouchUpInside];
|
||||
[topBar addSubview:self.backButton];
|
||||
|
||||
self.titleLabel = [[UILabel alloc] init];
|
||||
self.titleLabel.font = [UIFont systemFontOfSize:18 weight:UIFontWeightSemibold];
|
||||
self.titleLabel.textColor = [UIColor whiteColor];
|
||||
[topBar addSubview:self.titleLabel];
|
||||
|
||||
[topBar mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.right.equalTo(self);
|
||||
make.top.equalTo(self.mas_top).offset(4);
|
||||
make.height.mas_equalTo(44);
|
||||
}];
|
||||
[self.backButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.equalTo(topBar.mas_left).offset(12);
|
||||
make.centerY.equalTo(topBar);
|
||||
make.width.height.mas_equalTo(32);
|
||||
}];
|
||||
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.equalTo(self.backButton.mas_right).offset(12);
|
||||
make.centerY.equalTo(topBar);
|
||||
make.right.lessThanOrEqualTo(topBar.mas_right).offset(-12);
|
||||
}];
|
||||
|
||||
UICollectionViewFlowLayout *layout = [UICollectionViewFlowLayout new];
|
||||
layout.scrollDirection = UICollectionViewScrollDirectionVertical;
|
||||
layout.minimumInteritemSpacing = 8;
|
||||
layout.minimumLineSpacing = 12;
|
||||
self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
|
||||
self.collectionView.backgroundColor = [UIColor clearColor];
|
||||
self.collectionView.dataSource = self;
|
||||
self.collectionView.delegate = self;
|
||||
self.collectionView.alwaysBounceVertical = YES;
|
||||
[self.collectionView registerClass:KBEmojiCollectionCell.class forCellWithReuseIdentifier:@"KBEmojiCollectionCell"];
|
||||
[self addSubview:self.collectionView];
|
||||
|
||||
self.bottomBar = [[UIView alloc] init];
|
||||
self.bottomBar.backgroundColor = [UIColor clearColor];
|
||||
[self addSubview:self.bottomBar];
|
||||
|
||||
self.searchButton = [UIButton buttonWithType:UIButtonTypeSystem];
|
||||
self.searchButton.layer.cornerRadius = 20;
|
||||
self.searchButton.titleLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightBold];
|
||||
[self.searchButton setTitle:KBLocalized(@"Search") forState:UIControlStateNormal];
|
||||
[self.searchButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
|
||||
[self.searchButton addTarget:self action:@selector(onSearch) forControlEvents:UIControlEventTouchUpInside];
|
||||
[self.bottomBar addSubview:self.searchButton];
|
||||
|
||||
self.tabScrollView = [[UIScrollView alloc] init];
|
||||
self.tabScrollView.showsHorizontalScrollIndicator = NO;
|
||||
self.tabScrollView.backgroundColor = [UIColor clearColor];
|
||||
[self.bottomBar addSubview:self.tabScrollView];
|
||||
|
||||
self.tabStackView = [[UIStackView alloc] init];
|
||||
self.tabStackView.axis = UILayoutConstraintAxisHorizontal;
|
||||
self.tabStackView.spacing = 8;
|
||||
self.tabStackView.alignment = UIStackViewAlignmentCenter;
|
||||
[self.tabScrollView addSubview:self.tabStackView];
|
||||
|
||||
[self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.equalTo(self.mas_left).offset(12);
|
||||
make.right.equalTo(self.mas_right).offset(-12);
|
||||
make.top.equalTo(topBar.mas_bottom).offset(8);
|
||||
make.bottom.equalTo(self.bottomBar.mas_top).offset(-8);
|
||||
}];
|
||||
|
||||
[self.bottomBar mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.right.bottom.equalTo(self);
|
||||
make.height.mas_equalTo(72);
|
||||
}];
|
||||
|
||||
[self.searchButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.right.equalTo(self.bottomBar.mas_right).offset(-16);
|
||||
make.centerY.equalTo(self.bottomBar);
|
||||
make.width.mas_equalTo(84);
|
||||
make.height.mas_equalTo(40);
|
||||
}];
|
||||
|
||||
[self.tabScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.equalTo(self.bottomBar.mas_left).offset(12);
|
||||
make.right.equalTo(self.searchButton.mas_left).offset(-12);
|
||||
make.top.equalTo(self.bottomBar.mas_top).offset(8);
|
||||
make.bottom.equalTo(self.bottomBar.mas_bottom).offset(-8);
|
||||
}];
|
||||
|
||||
[self.tabStackView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.edges.equalTo(self.tabScrollView);
|
||||
make.height.equalTo(self.tabScrollView);
|
||||
}];
|
||||
|
||||
UISwipeGestureRecognizer *leftSwipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(onSwipe:)];
|
||||
leftSwipe.direction = UISwipeGestureRecognizerDirectionLeft;
|
||||
[self addGestureRecognizer:leftSwipe];
|
||||
UISwipeGestureRecognizer *rightSwipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(onSwipe:)];
|
||||
rightSwipe.direction = UISwipeGestureRecognizerDirectionRight;
|
||||
[self addGestureRecognizer:rightSwipe];
|
||||
|
||||
[self applyTheme:[KBSkinManager shared].current];
|
||||
}
|
||||
|
||||
- (void)registerNotifications {
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(onEmojiDataChanged)
|
||||
name:KBEmojiRecentsDidChangeNotification
|
||||
object:nil];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(onLocalizationChanged)
|
||||
name:KBLocalizationDidChangeNotification
|
||||
object:nil];
|
||||
}
|
||||
|
||||
#pragma mark - Data
|
||||
|
||||
- (void)reloadData {
|
||||
self.categories = self.dataProvider.categories;
|
||||
if (self.categories.count == 0) {
|
||||
self.currentIndex = NSNotFound;
|
||||
[self.collectionView reloadData];
|
||||
self.titleLabel.text = @"";
|
||||
return;
|
||||
}
|
||||
NSInteger preserved = self.currentIndex;
|
||||
if (preserved < 0 || preserved >= self.categories.count) {
|
||||
preserved = 0;
|
||||
}
|
||||
[self rebuildTabButtons];
|
||||
[self updateSelectionToIndex:preserved];
|
||||
}
|
||||
|
||||
- (void)rebuildTabButtons {
|
||||
for (UIView *v in self.tabStackView.arrangedSubviews) {
|
||||
[self.tabStackView removeArrangedSubview:v];
|
||||
[v removeFromSuperview];
|
||||
}
|
||||
NSMutableArray<UIButton *> *buttons = [NSMutableArray arrayWithCapacity:self.categories.count];
|
||||
[self.categories enumerateObjectsUsingBlock:^(KBEmojiCategory * _Nonnull cat, NSUInteger idx, BOOL * _Nonnull stop) {
|
||||
UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
|
||||
btn.tag = idx;
|
||||
btn.layer.cornerRadius = 16;
|
||||
btn.layer.masksToBounds = YES;
|
||||
btn.titleLabel.font = [UIFont systemFontOfSize:18];
|
||||
[btn setTitle:cat.iconSymbol ?: @"●" forState:UIControlStateNormal];
|
||||
[btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
|
||||
[btn addTarget:self action:@selector(onTabTapped:) forControlEvents:UIControlEventTouchUpInside];
|
||||
btn.contentEdgeInsets = UIEdgeInsetsMake(0, 12, 0, 12);
|
||||
[self.tabStackView addArrangedSubview:btn];
|
||||
[buttons addObject:btn];
|
||||
}];
|
||||
self.tabButtons = buttons.copy;
|
||||
}
|
||||
|
||||
- (void)updateSelectionToIndex:(NSInteger)index {
|
||||
if (self.categories.count == 0) {
|
||||
self.currentIndex = NSNotFound;
|
||||
[self.collectionView reloadData];
|
||||
self.titleLabel.text = @"";
|
||||
return;
|
||||
}
|
||||
if (index < 0) { index = 0; }
|
||||
if (index >= self.categories.count) { index = self.categories.count - 1; }
|
||||
self.currentIndex = index;
|
||||
KBEmojiCategory *cat = self.categories[index];
|
||||
self.titleLabel.text = cat.displayTitle;
|
||||
[self.collectionView reloadData];
|
||||
[self updateTabHighlightStates];
|
||||
[self scrollTabToVisible:index];
|
||||
}
|
||||
|
||||
- (void)selectCategoryAtIndex:(NSInteger)index {
|
||||
[self updateSelectionToIndex:index];
|
||||
}
|
||||
|
||||
- (void)updateTabHighlightStates {
|
||||
[self.tabButtons enumerateObjectsUsingBlock:^(UIButton * _Nonnull btn, NSUInteger idx, BOOL * _Nonnull stop) {
|
||||
BOOL selected = (idx == self.currentIndex);
|
||||
btn.backgroundColor = selected ? self.tabSelectedColor : self.tabNormalColor;
|
||||
btn.alpha = selected ? 1.0 : 0.6;
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)scrollTabToVisible:(NSInteger)index {
|
||||
if (index < 0 || index >= self.tabButtons.count) return;
|
||||
UIButton *btn = self.tabButtons[index];
|
||||
CGRect rect = [self.tabScrollView convertRect:btn.frame fromView:self.tabStackView];
|
||||
rect = CGRectInset(rect, -12, 0);
|
||||
[self.tabScrollView scrollRectToVisible:rect animated:YES];
|
||||
}
|
||||
|
||||
#pragma mark - Actions
|
||||
|
||||
- (void)onBack {
|
||||
if ([self.delegate respondsToSelector:@selector(emojiPanelViewDidRequestClose:)]) {
|
||||
[self.delegate emojiPanelViewDidRequestClose:self];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)onSearch {
|
||||
if ([self.delegate respondsToSelector:@selector(emojiPanelViewDidTapSearch:)]) {
|
||||
[self.delegate emojiPanelViewDidTapSearch:self];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)onTabTapped:(UIButton *)sender {
|
||||
[self updateSelectionToIndex:sender.tag];
|
||||
}
|
||||
|
||||
- (void)onSwipe:(UISwipeGestureRecognizer *)gesture {
|
||||
if (self.categories.count == 0) return;
|
||||
if (gesture.direction == UISwipeGestureRecognizerDirectionLeft) {
|
||||
if (self.currentIndex + 1 < self.categories.count) {
|
||||
[self updateSelectionToIndex:self.currentIndex + 1];
|
||||
}
|
||||
} else if (gesture.direction == UISwipeGestureRecognizerDirectionRight) {
|
||||
if (self.currentIndex - 1 >= 0) {
|
||||
[self updateSelectionToIndex:self.currentIndex - 1];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)onEmojiDataChanged {
|
||||
[self reloadData];
|
||||
}
|
||||
|
||||
- (void)onLocalizationChanged {
|
||||
[self.searchButton setTitle:KBLocalized(@"Search") forState:UIControlStateNormal];
|
||||
[self reloadData];
|
||||
}
|
||||
|
||||
#pragma mark - Theme
|
||||
|
||||
- (void)applyTheme:(KBSkinTheme *)theme {
|
||||
UIColor *bg = theme.keyboardBackground ?: [UIColor colorWithWhite:0.08 alpha:1.0];
|
||||
self.backgroundColor = bg;
|
||||
self.collectionView.backgroundColor = [UIColor clearColor];
|
||||
self.titleLabel.textColor = theme.keyTextColor ?: [UIColor whiteColor];
|
||||
UIColor *searchColor = theme.accentColor ?: [UIColor colorWithRed:0.35 green:0.35 blue:0.95 alpha:1];
|
||||
self.searchButton.backgroundColor = searchColor;
|
||||
self.tabNormalColor = [UIColor colorWithWhite:1 alpha:0.08];
|
||||
self.tabSelectedColor = theme.accentColor ?: [UIColor colorWithWhite:1 alpha:0.25];
|
||||
[self updateTabHighlightStates];
|
||||
if (self.magnifierView) {
|
||||
self.magnifierView.backgroundColor = theme.keyBackground ?: [UIColor colorWithWhite:1 alpha:0.9];
|
||||
}
|
||||
if (self.magnifierLabel) {
|
||||
self.magnifierLabel.textColor = theme.keyTextColor ?: [UIColor blackColor];
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - Magnifier
|
||||
|
||||
- (void)showMagnifierForEmoji:(NSString *)emoji fromRect:(CGRect)rect {
|
||||
if (!self.magnifierView) {
|
||||
self.magnifierView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 68, 68)];
|
||||
self.magnifierView.layer.cornerRadius = 12;
|
||||
self.magnifierView.layer.masksToBounds = YES;
|
||||
self.magnifierView.layer.shadowColor = [UIColor colorWithWhite:0 alpha:0.3].CGColor;
|
||||
self.magnifierView.layer.shadowOpacity = 0.6;
|
||||
self.magnifierView.layer.shadowOffset = CGSizeMake(0, 2);
|
||||
self.magnifierView.layer.shadowRadius = 3;
|
||||
self.magnifierLabel = [[UILabel alloc] initWithFrame:self.magnifierView.bounds];
|
||||
self.magnifierLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
|
||||
self.magnifierLabel.textAlignment = NSTextAlignmentCenter;
|
||||
self.magnifierLabel.font = [UIFont systemFontOfSize:40];
|
||||
[self.magnifierView addSubview:self.magnifierLabel];
|
||||
self.magnifierView.alpha = 0;
|
||||
[self addSubview:self.magnifierView];
|
||||
}
|
||||
self.magnifierLabel.text = emoji;
|
||||
CGRect converted = [self convertRect:rect fromView:self.collectionView];
|
||||
CGFloat targetX = CGRectGetMidX(converted);
|
||||
CGFloat targetY = CGRectGetMinY(converted) - CGRectGetHeight(self.magnifierView.bounds)/2 - 8;
|
||||
targetX = MAX(CGRectGetWidth(self.magnifierView.bounds)/2 + 8, targetX);
|
||||
targetX = MIN(CGRectGetWidth(self.bounds) - CGRectGetWidth(self.magnifierView.bounds)/2 - 8, targetX);
|
||||
if (targetY < CGRectGetHeight(self.magnifierView.bounds)/2 + 10) {
|
||||
targetY = CGRectGetHeight(self.magnifierView.bounds)/2 + 10;
|
||||
}
|
||||
self.magnifierView.center = CGPointMake(targetX, targetY);
|
||||
self.magnifierView.hidden = NO;
|
||||
[UIView animateWithDuration:0.08 animations:^{
|
||||
self.magnifierView.alpha = 1.0;
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)hideMagnifier {
|
||||
if (!self.magnifierView) return;
|
||||
[UIView animateWithDuration:0.08 animations:^{
|
||||
self.magnifierView.alpha = 0.0;
|
||||
} completion:^(BOOL finished) {
|
||||
self.magnifierView.hidden = YES;
|
||||
}];
|
||||
}
|
||||
|
||||
#pragma mark - UICollectionViewDataSource
|
||||
|
||||
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
|
||||
if (self.currentIndex == NSNotFound || self.currentIndex >= self.categories.count) {
|
||||
return 0;
|
||||
}
|
||||
KBEmojiCategory *cat = self.categories[self.currentIndex];
|
||||
return cat.items.count;
|
||||
}
|
||||
|
||||
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
|
||||
KBEmojiCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"KBEmojiCollectionCell" forIndexPath:indexPath];
|
||||
KBEmojiCategory *cat = self.categories[self.currentIndex];
|
||||
if (indexPath.item < cat.items.count) {
|
||||
KBEmojiItem *item = cat.items[indexPath.item];
|
||||
[cell configureWithEmoji:item.value];
|
||||
} else {
|
||||
[cell configureWithEmoji:@""];
|
||||
}
|
||||
return cell;
|
||||
}
|
||||
|
||||
#pragma mark - UICollectionViewDelegate
|
||||
|
||||
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
|
||||
if (self.currentIndex == NSNotFound || self.currentIndex >= self.categories.count) return;
|
||||
KBEmojiCategory *cat = self.categories[self.currentIndex];
|
||||
if (indexPath.item >= cat.items.count) return;
|
||||
KBEmojiItem *item = cat.items[indexPath.item];
|
||||
if (item.value.length == 0) return;
|
||||
[self.dataProvider recordEmojiSelection:item.value];
|
||||
if ([self.delegate respondsToSelector:@selector(emojiPanelView:didSelectEmoji:)]) {
|
||||
[self.delegate emojiPanelView:self didSelectEmoji:item.value];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)collectionView:(UICollectionView *)collectionView didHighlightItemAtIndexPath:(NSIndexPath *)indexPath {
|
||||
KBEmojiCategory *cat = (self.currentIndex < self.categories.count) ? self.categories[self.currentIndex] : nil;
|
||||
if (indexPath.item >= cat.items.count) return;
|
||||
KBEmojiItem *item = cat.items[indexPath.item];
|
||||
UICollectionViewCell *cell = [collectionView cellForItemAtIndexPath:indexPath];
|
||||
if (!cell) return;
|
||||
[self showMagnifierForEmoji:item.value fromRect:cell.frame];
|
||||
}
|
||||
|
||||
- (void)collectionView:(UICollectionView *)collectionView didUnhighlightItemAtIndexPath:(NSIndexPath *)indexPath {
|
||||
[self hideMagnifier];
|
||||
}
|
||||
|
||||
#pragma mark - UICollectionViewDelegateFlowLayout
|
||||
|
||||
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
|
||||
CGFloat availableWidth = collectionView.bounds.size.width;
|
||||
NSInteger columns = 8;
|
||||
CGFloat spacing = 8;
|
||||
CGFloat totalSpacing = spacing * (columns - 1);
|
||||
CGFloat width = floor((availableWidth - totalSpacing) / columns);
|
||||
if (width < 32) { width = 32; }
|
||||
return CGSizeMake(width, width);
|
||||
}
|
||||
|
||||
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
|
||||
return 12;
|
||||
}
|
||||
|
||||
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
|
||||
return 8;
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -23,6 +23,12 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
/// 点击了右侧设置按钮
|
||||
- (void)keyBoardMainViewDidTapSettings:(KBKeyBoardMainView *)keyBoardMainView;
|
||||
|
||||
/// emoji 视图里选择了一个表情
|
||||
- (void)keyBoardMainView:(KBKeyBoardMainView *)keyBoardMainView didSelectEmoji:(NSString *)emoji;
|
||||
|
||||
/// emoji 面板点击搜索
|
||||
- (void)keyBoardMainViewDidTapEmojiSearch:(KBKeyBoardMainView *)keyBoardMainView;
|
||||
@end
|
||||
|
||||
@interface KBKeyBoardMainView : UIView
|
||||
|
||||
@@ -10,12 +10,15 @@
|
||||
#import "KBKeyboardView.h"
|
||||
#import "KBFunctionView.h"
|
||||
#import "KBKey.h"
|
||||
#import "KBEmojiPanelView.h"
|
||||
#import "Masonry.h"
|
||||
#import "KBSkinManager.h"
|
||||
|
||||
@interface KBKeyBoardMainView ()<KBToolBarDelegate, KBKeyboardViewDelegate>
|
||||
@interface KBKeyBoardMainView ()<KBToolBarDelegate, KBKeyboardViewDelegate, KBEmojiPanelViewDelegate>
|
||||
@property (nonatomic, strong) KBToolBar *topBar;
|
||||
@property (nonatomic, strong) KBKeyboardView *keyboardView;
|
||||
@property (nonatomic, strong) KBEmojiPanelView *emojiView;
|
||||
@property (nonatomic, assign) BOOL emojiPanelVisible;
|
||||
// 注意:功能面板的展示/隐藏由外部控制器决定,此处不再直接管理显隐
|
||||
@end
|
||||
@implementation KBKeyBoardMainView
|
||||
@@ -23,8 +26,7 @@
|
||||
- (instancetype)initWithFrame:(CGRect)frame {
|
||||
if (self = [super initWithFrame:frame]) {
|
||||
self.backgroundColor = [KBSkinManager shared].current.keyboardBackground;
|
||||
|
||||
|
||||
|
||||
// 顶部栏
|
||||
self.topBar = [[KBToolBar alloc] init];
|
||||
self.topBar.delegate = self;
|
||||
@@ -43,18 +45,60 @@
|
||||
make.bottom.equalTo(self.mas_bottom).offset(-bottomInset);
|
||||
}];
|
||||
|
||||
self.emojiView = [[KBEmojiPanelView alloc] init];
|
||||
self.emojiView.hidden = YES;
|
||||
self.emojiView.alpha = 0.0;
|
||||
self.emojiView.delegate = self;
|
||||
[self addSubview:self.emojiView];
|
||||
[self.emojiView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.edges.equalTo(self);
|
||||
}];
|
||||
|
||||
[self.topBar mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.right.equalTo(self);
|
||||
make.top.equalTo(self.mas_top).offset(0);
|
||||
make.bottom.equalTo(self.keyboardView.mas_top).offset(-barSpacing);
|
||||
}];
|
||||
|
||||
// 功能面板切换交由外部控制器处理;此处不直接创建/管理
|
||||
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)setEmojiPanelVisible:(BOOL)visible animated:(BOOL)animated {
|
||||
if (self.emojiPanelVisible == visible) return;
|
||||
self.emojiPanelVisible = visible;
|
||||
if (visible) {
|
||||
[self.emojiView reloadData];
|
||||
self.emojiView.hidden = NO;
|
||||
[self bringSubviewToFront:self.emojiView];
|
||||
} else {
|
||||
self.keyboardView.hidden = NO;
|
||||
self.topBar.hidden = NO;
|
||||
}
|
||||
|
||||
void (^changes)(void) = ^{
|
||||
self.emojiView.alpha = visible ? 1.0 : 0.0;
|
||||
self.keyboardView.alpha = visible ? 0.0 : 1.0;
|
||||
self.topBar.alpha = visible ? 0.0 : 1.0;
|
||||
};
|
||||
void (^completion)(BOOL) = ^(BOOL finished) {
|
||||
self.emojiView.hidden = !visible;
|
||||
self.keyboardView.hidden = visible;
|
||||
self.topBar.hidden = visible;
|
||||
};
|
||||
|
||||
if (animated) {
|
||||
[UIView animateWithDuration:0.22 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:changes completion:completion];
|
||||
} else {
|
||||
changes();
|
||||
completion(YES);
|
||||
}
|
||||
}
|
||||
|
||||
- (void)toggleEmojiPanel {
|
||||
[self setEmojiPanelVisible:!self.emojiPanelVisible animated:YES];
|
||||
}
|
||||
|
||||
|
||||
#pragma mark - KBToolBarDelegate
|
||||
|
||||
@@ -106,12 +150,15 @@
|
||||
[self.delegate keyBoardMainView:self didTapKey:key];
|
||||
}
|
||||
break;
|
||||
case KBKeyTypeCustom:
|
||||
// 自定义占位:切换语言或其它操作
|
||||
case KBKeyTypeCustom: {
|
||||
if ([key.identifier isEqualToString:KBKeyIdentifierEmojiPanel]) {
|
||||
[self toggleEmojiPanel];
|
||||
break;
|
||||
}
|
||||
if ([self.delegate respondsToSelector:@selector(keyBoardMainView:didTapKey:)]) {
|
||||
[self.delegate keyBoardMainView:self didTapKey:key];
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
case KBKeyTypeShift:
|
||||
// Shift 已在 KBKeyboardView 内部处理
|
||||
break;
|
||||
@@ -121,6 +168,25 @@
|
||||
// 切换功能面板交由外部控制器处理(此处不再实现)
|
||||
|
||||
// 设置页展示改由 KeyboardViewController 统一处理
|
||||
#pragma mark - KBEmojiPanelViewDelegate
|
||||
|
||||
- (void)emojiPanelView:(KBEmojiPanelView *)panel didSelectEmoji:(NSString *)emoji {
|
||||
if (emoji.length == 0) return;
|
||||
if ([self.delegate respondsToSelector:@selector(keyBoardMainView:didSelectEmoji:)]) {
|
||||
[self.delegate keyBoardMainView:self didSelectEmoji:emoji];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)emojiPanelViewDidRequestClose:(KBEmojiPanelView *)panel {
|
||||
[self setEmojiPanelVisible:NO animated:YES];
|
||||
}
|
||||
|
||||
- (void)emojiPanelViewDidTapSearch:(KBEmojiPanelView *)panel {
|
||||
if ([self.delegate respondsToSelector:@selector(keyBoardMainViewDidTapEmojiSearch:)]) {
|
||||
[self.delegate keyBoardMainViewDidTapEmojiSearch:self];
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - Theme
|
||||
|
||||
- (void)kb_applyTheme {
|
||||
@@ -130,6 +196,9 @@
|
||||
self.backgroundColor = hasImg ? [UIColor clearColor] : bg;
|
||||
self.keyboardView.backgroundColor = hasImg ? [UIColor clearColor] : bg;
|
||||
[self.keyboardView reloadKeys];
|
||||
if (self.emojiView) {
|
||||
[self.emojiView applyTheme:mgr.current];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -279,10 +279,10 @@ static const CGFloat kKBLettersRow2EdgeSpacerMultiplier = 0.5;
|
||||
title:@"123"
|
||||
output:@""
|
||||
type:KBKeyTypeModeChange];
|
||||
KBKey *customAI = [KBKey keyWithIdentifier:@"ai"
|
||||
title:@"AI"
|
||||
output:@""
|
||||
type:KBKeyTypeCustom];
|
||||
KBKey *emoji = [KBKey keyWithIdentifier:KBKeyIdentifierEmojiPanel
|
||||
title:@"😊"
|
||||
output:@""
|
||||
type:KBKeyTypeCustom];
|
||||
KBKey *space = [KBKey keyWithIdentifier:@"space"
|
||||
title:@"space"
|
||||
output:@" "
|
||||
@@ -291,7 +291,7 @@ static const CGFloat kKBLettersRow2EdgeSpacerMultiplier = 0.5;
|
||||
title:KBLocalized(@"Send")
|
||||
output:@"\n"
|
||||
type:KBKeyTypeReturn];
|
||||
return @[ mode123, customAI, space, ret ];
|
||||
return @[ mode123, emoji, space, ret ];
|
||||
}
|
||||
|
||||
// 底部控制行(数字布局)
|
||||
@@ -300,10 +300,10 @@ static const CGFloat kKBLettersRow2EdgeSpacerMultiplier = 0.5;
|
||||
title:@"abc"
|
||||
output:@""
|
||||
type:KBKeyTypeModeChange];
|
||||
KBKey *customAI = [KBKey keyWithIdentifier:@"ai"
|
||||
title:@"AI"
|
||||
output:@""
|
||||
type:KBKeyTypeCustom];
|
||||
KBKey *emoji = [KBKey keyWithIdentifier:KBKeyIdentifierEmojiPanel
|
||||
title:@"😊"
|
||||
output:@""
|
||||
type:KBKeyTypeCustom];
|
||||
KBKey *space = [KBKey keyWithIdentifier:@"space"
|
||||
title:@"space"
|
||||
output:@" "
|
||||
@@ -312,7 +312,7 @@ static const CGFloat kKBLettersRow2EdgeSpacerMultiplier = 0.5;
|
||||
title:KBLocalized(@"Send")
|
||||
output:@"\n"
|
||||
type:KBKeyTypeReturn];
|
||||
return @[ modeABC, customAI, space, ret ];
|
||||
return @[ modeABC, emoji, space, ret ];
|
||||
}
|
||||
|
||||
#pragma mark - Row Building
|
||||
|
||||
@@ -56,7 +56,7 @@
|
||||
#define API_THEME_RECOMMENDED @"/themes/recommended" // 推荐主题列表
|
||||
|
||||
/// pay
|
||||
#define API_VALIDATE_RECEIPT @"/api/apple/validate-receipt" // 排行榜标签列表
|
||||
#define API_VALIDATE_RECEIPT @"/apple/validate-receipt" // 排行榜标签列表
|
||||
#define API_INAPP_PRODUCT_LIST @"/products/inApp/list" // 查询 type=in-app-purchase 的商品列表
|
||||
#define API_SUBSCRIPTION_PRODUCT_LIST @"/products/subscription/list" // 查询订阅商品列表
|
||||
|
||||
|
||||
@@ -118,6 +118,7 @@
|
||||
0498BDF12EEC0E56006CC1D5 /* FGIAPProductsFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 0498BDE92EEC0E56006CC1D5 /* FGIAPProductsFilter.m */; };
|
||||
0498BDF22EEC0E56006CC1D5 /* NSObject+FGIsNullOrEmpty.m in Sources */ = {isa = PBXBuildFile; fileRef = 0498BDEF2EEC0E56006CC1D5 /* NSObject+FGIsNullOrEmpty.m */; };
|
||||
0498BDF32EEC0E56006CC1D5 /* FGIAPService.m in Sources */ = {isa = PBXBuildFile; fileRef = 0498BDEB2EEC0E56006CC1D5 /* FGIAPService.m */; };
|
||||
0498BDF52EEC50EE006CC1D5 /* emoji_categories.json in Resources */ = {isa = PBXBuildFile; fileRef = 0498BDF42EEC50EE006CC1D5 /* emoji_categories.json */; };
|
||||
049FB20B2EC1C13800FAB05D /* KBSkinBottomActionView.m in Sources */ = {isa = PBXBuildFile; fileRef = 049FB20A2EC1C13800FAB05D /* KBSkinBottomActionView.m */; };
|
||||
049FB20E2EC1CD2800FAB05D /* KBAlert.m in Sources */ = {isa = PBXBuildFile; fileRef = 049FB20D2EC1CD2800FAB05D /* KBAlert.m */; };
|
||||
049FB2112EC1F72F00FAB05D /* KBMyListCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 049FB2102EC1F72F00FAB05D /* KBMyListCell.m */; };
|
||||
@@ -154,6 +155,8 @@
|
||||
04C6EACE2EAF87020089C901 /* CustomKeyboard.appex in Embed Foundation Extensions */ = {isa = PBXBuildFile; fileRef = 04C6EAC62EAF87020089C901 /* CustomKeyboard.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
|
||||
04C6EAD82EAF870B0089C901 /* KeyboardViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 04C6EAD62EAF870B0089C901 /* KeyboardViewController.m */; };
|
||||
04C6EADD2EAF8CEB0089C901 /* KBToolBar.m in Sources */ = {isa = PBXBuildFile; fileRef = 04C6EADC2EAF8CEB0089C901 /* KBToolBar.m */; };
|
||||
04FEDAA12EEDB00100123456 /* KBEmojiDataProvider.m in Sources */ = {isa = PBXBuildFile; fileRef = 04FEDAA02EEDB00100123456 /* KBEmojiDataProvider.m */; };
|
||||
04FEDAB32EEDB05000123456 /* KBEmojiPanelView.m in Sources */ = {isa = PBXBuildFile; fileRef = 04FEDAB22EEDB05000123456 /* KBEmojiPanelView.m */; };
|
||||
04D1F6B22EDFF10A00B12345 /* KBSkinInstallBridge.m in Sources */ = {isa = PBXBuildFile; fileRef = 04D1F6B12EDFF10A00B12345 /* KBSkinInstallBridge.m */; };
|
||||
04D1F6B32EDFF10A00B12345 /* KBSkinInstallBridge.m in Sources */ = {isa = PBXBuildFile; fileRef = 04D1F6B12EDFF10A00B12345 /* KBSkinInstallBridge.m */; };
|
||||
04FC95672EB0546C007BD342 /* KBKey.m in Sources */ = {isa = PBXBuildFile; fileRef = 04FC95652EB0546C007BD342 /* KBKey.m */; };
|
||||
@@ -419,6 +422,7 @@
|
||||
0498BDED2EEC0E56006CC1D5 /* FGIAPVerifyTransaction.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FGIAPVerifyTransaction.h; sourceTree = "<group>"; };
|
||||
0498BDEE2EEC0E56006CC1D5 /* NSObject+FGIsNullOrEmpty.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "NSObject+FGIsNullOrEmpty.h"; sourceTree = "<group>"; };
|
||||
0498BDEF2EEC0E56006CC1D5 /* NSObject+FGIsNullOrEmpty.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "NSObject+FGIsNullOrEmpty.m"; sourceTree = "<group>"; };
|
||||
0498BDF42EEC50EE006CC1D5 /* emoji_categories.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = emoji_categories.json; sourceTree = "<group>"; };
|
||||
049FB2092EC1C13800FAB05D /* KBSkinBottomActionView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = KBSkinBottomActionView.h; sourceTree = "<group>"; };
|
||||
049FB20A2EC1C13800FAB05D /* KBSkinBottomActionView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = KBSkinBottomActionView.m; sourceTree = "<group>"; };
|
||||
049FB20C2EC1CD2800FAB05D /* KBAlert.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = KBAlert.h; sourceTree = "<group>"; };
|
||||
@@ -503,6 +507,10 @@
|
||||
04FC95752EB095DE007BD342 /* KBFunctionPasteView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = KBFunctionPasteView.m; sourceTree = "<group>"; };
|
||||
04FC95772EB09BC8007BD342 /* KBKeyBoardMainView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = KBKeyBoardMainView.h; sourceTree = "<group>"; };
|
||||
04FC95782EB09BC8007BD342 /* KBKeyBoardMainView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = KBKeyBoardMainView.m; sourceTree = "<group>"; };
|
||||
04FEDA9F2EEDB00100123456 /* KBEmojiDataProvider.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = KBEmojiDataProvider.h; sourceTree = "<group>"; };
|
||||
04FEDAA02EEDB00100123456 /* KBEmojiDataProvider.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = KBEmojiDataProvider.m; sourceTree = "<group>"; };
|
||||
04FEDAB12EEDB05000123456 /* KBEmojiPanelView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = KBEmojiPanelView.h; sourceTree = "<group>"; };
|
||||
04FEDAB22EEDB05000123456 /* KBEmojiPanelView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = KBEmojiPanelView.m; sourceTree = "<group>"; };
|
||||
04FC95B02EB0B2CC007BD342 /* KBSettingView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = KBSettingView.h; sourceTree = "<group>"; };
|
||||
04FC95B12EB0B2CC007BD342 /* KBSettingView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = KBSettingView.m; sourceTree = "<group>"; };
|
||||
04FC95C72EB1E4C9007BD342 /* BaseNavigationController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BaseNavigationController.h; sourceTree = "<group>"; };
|
||||
@@ -595,6 +603,7 @@
|
||||
041007D02ECE010100D203BB /* Resource */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
0498BDF42EEC50EE006CC1D5 /* emoji_categories.json */,
|
||||
041007D12ECE012000D203BB /* KBSkinIconMap.strings */,
|
||||
041007D32ECE012500D203BB /* 002.zip */,
|
||||
04791FFA2ED5EAB8004E8522 /* fense.zip */,
|
||||
@@ -956,6 +965,8 @@
|
||||
children = (
|
||||
04A9FE102EB4D0D20020DB6D /* KBFullAccessManager.h */,
|
||||
04A9FE112EB4D0D20020DB6D /* KBFullAccessManager.m */,
|
||||
04FEDA9F2EEDB00100123456 /* KBEmojiDataProvider.h */,
|
||||
04FEDAA02EEDB00100123456 /* KBEmojiDataProvider.m */,
|
||||
);
|
||||
path = Manager;
|
||||
sourceTree = "<group>";
|
||||
@@ -1020,6 +1031,8 @@
|
||||
046131132ECF454500A6FADF /* KBKeyPreviewView.m */,
|
||||
04FC95772EB09BC8007BD342 /* KBKeyBoardMainView.h */,
|
||||
04FC95782EB09BC8007BD342 /* KBKeyBoardMainView.m */,
|
||||
04FEDAB12EEDB05000123456 /* KBEmojiPanelView.h */,
|
||||
04FEDAB22EEDB05000123456 /* KBEmojiPanelView.m */,
|
||||
04FC956E2EB09516007BD342 /* KBFunctionView.h */,
|
||||
04FC956F2EB09516007BD342 /* KBFunctionView.m */,
|
||||
04FC95712EB09570007BD342 /* KBFunctionBarView.h */,
|
||||
@@ -1610,6 +1623,7 @@
|
||||
041007D42ECE012500D203BB /* 002.zip in Resources */,
|
||||
041007D22ECE012000D203BB /* KBSkinIconMap.strings in Resources */,
|
||||
04791FFB2ED5EAB8004E8522 /* fense.zip in Resources */,
|
||||
0498BDF52EEC50EE006CC1D5 /* emoji_categories.json in Resources */,
|
||||
04791FF72ED5B985004E8522 /* Christmas.zip in Resources */,
|
||||
04286A0B2ECD88B400CE730C /* KeyboardAssets.xcassets in Resources */,
|
||||
);
|
||||
@@ -1712,6 +1726,7 @@
|
||||
04A9FE0F2EB481100020DB6D /* KBHUD.m in Sources */,
|
||||
04C6EADD2EAF8CEB0089C901 /* KBToolBar.m in Sources */,
|
||||
04FC95792EB09BC8007BD342 /* KBKeyBoardMainView.m in Sources */,
|
||||
04FEDAB32EEDB05000123456 /* KBEmojiPanelView.m in Sources */,
|
||||
0498BD8C2EE69E15006CC1D5 /* KBTagItemModel.m in Sources */,
|
||||
046131142ECF454500A6FADF /* KBKeyPreviewView.m in Sources */,
|
||||
04FC95732EB09570007BD342 /* KBFunctionBarView.m in Sources */,
|
||||
@@ -1724,6 +1739,7 @@
|
||||
A1B2C3E22EB0C0A100000001 /* KBNetworkManager.m in Sources */,
|
||||
049FB2352EC45C6A00FAB05D /* NetworkStreamHandler.m in Sources */,
|
||||
04FC956A2EB05497007BD342 /* KBKeyButton.m in Sources */,
|
||||
04FEDAA12EEDB00100123456 /* KBEmojiDataProvider.m in Sources */,
|
||||
04FC95B22EB0B2CC007BD342 /* KBSettingView.m in Sources */,
|
||||
04791F8E2ED469C0004E8522 /* KBHostAppLauncher.m in Sources */,
|
||||
049FB23B2EC4766700FAB05D /* KBFunctionTagListView.m in Sources */,
|
||||
|
||||
Reference in New Issue
Block a user