diff --git a/CustomKeyboard/View/EmojiView/KBEmojiPanelView.h b/CustomKeyboard/View/EmojiView/KBEmojiPanelView.h index 3629d92..d58cd1d 100644 --- a/CustomKeyboard/View/EmojiView/KBEmojiPanelView.h +++ b/CustomKeyboard/View/EmojiView/KBEmojiPanelView.h @@ -13,6 +13,8 @@ NS_ASSUME_NONNULL_BEGIN - (void)emojiPanelView:(KBEmojiPanelView *)panel didSelectEmoji:(NSString *)emoji; - (void)emojiPanelViewDidRequestClose:(KBEmojiPanelView *)panel; - (void)emojiPanelViewDidTapSearch:(KBEmojiPanelView *)panel; +@optional +- (void)emojiPanelViewDidTapDelete:(KBEmojiPanelView *)panel; @end @interface KBEmojiPanelView : UIView diff --git a/CustomKeyboard/View/EmojiView/KBEmojiPanelView.m b/CustomKeyboard/View/EmojiView/KBEmojiPanelView.m index 48a1ee4..34ca9b3 100644 --- a/CustomKeyboard/View/EmojiView/KBEmojiPanelView.m +++ b/CustomKeyboard/View/EmojiView/KBEmojiPanelView.m @@ -19,6 +19,7 @@ @property (nonatomic, strong) UIView *bottomBar; @property (nonatomic, strong) UIScrollView *tabScrollView; @property (nonatomic, strong) UIStackView *tabStackView; +@property (nonatomic, strong) UIButton *deleteButton; //@property (nonatomic, strong) UIButton *searchButton; @property (nonatomic, strong) NSArray *tabButtons; @property (nonatomic, strong) KBEmojiDataProvider *dataProvider; @@ -119,6 +120,15 @@ self.tabStackView.alignment = UIStackViewAlignmentFill; [self.tabScrollView addSubview:self.tabStackView]; + self.deleteButton = [UIButton buttonWithType:UIButtonTypeCustom]; + self.deleteButton.layer.cornerRadius = 16; + self.deleteButton.layer.masksToBounds = YES; + self.deleteButton.titleLabel.font = [UIFont systemFontOfSize:18 weight:UIFontWeightSemibold]; + [self.deleteButton setTitle:@"⌫" forState:UIControlStateNormal]; + [self.deleteButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; + [self.deleteButton addTarget:self action:@selector(onDelete) forControlEvents:UIControlEventTouchUpInside]; + [self.bottomBar addSubview:self.deleteButton]; + [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.mas_left).offset(12); make.right.equalTo(self.mas_right).offset(-12); @@ -140,8 +150,7 @@ [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.right.equalTo(self.bottomBar.mas_right).offset(-12); + make.right.equalTo(self.deleteButton.mas_left).offset(-12); make.top.equalTo(self.bottomBar.mas_top).offset(4); make.bottom.equalTo(self.bottomBar.mas_bottom).offset(-4); }]; @@ -151,6 +160,13 @@ make.height.equalTo(self.tabScrollView); }]; + [self.deleteButton mas_makeConstraints:^(MASConstraintMaker *make) { + make.right.equalTo(self.bottomBar.mas_right).offset(-12); + make.centerY.equalTo(self.bottomBar); + make.width.mas_equalTo(44); + make.height.equalTo(self.tabScrollView); + }]; + UISwipeGestureRecognizer *leftSwipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(onSwipe:)]; leftSwipe.direction = UISwipeGestureRecognizerDirectionLeft; [self addGestureRecognizer:leftSwipe]; @@ -167,7 +183,6 @@ } - (void)updateTabButtonCornerRadii { - if (self.tabButtons.count == 0) { return; } for (UIButton *btn in self.tabButtons) { CGFloat radius = MIN(CGRectGetHeight(btn.bounds), CGRectGetWidth(btn.bounds)) / 2.0; if (radius <= 0) { continue; } @@ -176,6 +191,15 @@ btn.layer.cornerCurve = kCACornerCurveContinuous; } } + if (self.deleteButton) { + CGFloat radius = MIN(CGRectGetHeight(self.deleteButton.bounds), CGRectGetWidth(self.deleteButton.bounds)) / 2.0; + if (radius > 0) { + self.deleteButton.layer.cornerRadius = radius; + if (@available(iOS 13.0, *)) { + self.deleteButton.layer.cornerCurve = kCACornerCurveContinuous; + } + } + } } - (void)registerNotifications { @@ -283,6 +307,12 @@ } } +- (void)onDelete { + if ([self.delegate respondsToSelector:@selector(emojiPanelViewDidTapDelete:)]) { + [self.delegate emojiPanelViewDidTapDelete:self]; + } +} + - (void)onTabTapped:(UIButton *)sender { [self updateSelectionToIndex:sender.tag]; } @@ -321,6 +351,11 @@ self.tabNormalColor = [UIColor colorWithWhite:1 alpha:0.08]; self.tabSelectedColor = theme.accentColor ?: [UIColor colorWithWhite:1 alpha:0.25]; [self updateTabHighlightStates]; + if (self.deleteButton) { + self.deleteButton.backgroundColor = self.tabNormalColor; + UIColor *deleteTitleColor = theme.keyTextColor ?: [UIColor whiteColor]; + [self.deleteButton setTitleColor:deleteTitleColor forState:UIControlStateNormal]; + } if (self.magnifierView) { self.magnifierView.backgroundColor = theme.keyBackground ?: [UIColor colorWithWhite:1 alpha:0.9]; } diff --git a/CustomKeyboard/View/KBKeyBoardMainView.m b/CustomKeyboard/View/KBKeyBoardMainView.m index 1427a1b..99d695c 100644 --- a/CustomKeyboard/View/KBKeyBoardMainView.m +++ b/CustomKeyboard/View/KBKeyBoardMainView.m @@ -187,6 +187,13 @@ } } +- (void)emojiPanelViewDidTapDelete:(KBEmojiPanelView *)panel { + if ([self.delegate respondsToSelector:@selector(keyBoardMainView:didTapKey:)]) { + KBKey *backspace = [KBKey keyWithTitle:@"" type:KBKeyTypeBackspace]; + [self.delegate keyBoardMainView:self didTapKey:backspace]; + } +} + #pragma mark - Theme - (void)kb_applyTheme {