-
Notifications
You must be signed in to change notification settings - Fork 7
/
KBResizeLegacy.x
168 lines (137 loc) · 6.09 KB
/
KBResizeLegacy.x
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#import <EmojiLibrary/Header.h>
#import <PSHeader/Misc.h>
#import <UIKit/UIKeyboardImpl.h>
#import <UIKit/UIApplication+Private.h>
#import <version.h>
#import <dlfcn.h>
#import "../EmojiLayout/PSEmojiLayout.h"
extern NSString *UIKeyboardGetCurrentInputMode();
NSString *keyboardName() {
UIKeyboardLayoutStar *layout = [UIKeyboardImpl.activeInstance _layout];
return layout.keyplane.name;
}
BOOL isEmojiInput() {
return [UIKeyboardGetCurrentInputMode() isEqualToString:@"emoji@sw=Emoji"];
}
%hook UIKeyboardImpl
+ (CGSize)sizeForInterfaceOrientation:(NSInteger)orientation {
CGSize size = %orig;
if (isEmojiInput())
size.height = [SoftPSEmojiLayout keyboardHeight:keyboardName()];
return size;
}
+ (CGSize)defaultSizeForInterfaceOrientation:(NSInteger)orientation {
CGSize size = %orig;
if (isEmojiInput())
size.height = [SoftPSEmojiLayout keyboardHeight:keyboardName()];
return size;
}
+ (CGSize)keyboardSizeForInterfaceOrientation:(NSInteger)orientation {
CGSize size = %orig;
if (isEmojiInput())
size.height = [SoftPSEmojiLayout keyboardHeight:keyboardName()];
return size;
}
%end
%hook UIKeyboardLayoutStar
- (void)resizeForKeyplaneSize:(CGSize)size {
CGSize newSize = [%c(UIKeyboardImpl) isSplit] ? size
: [UIKeyboardImpl keyboardSizeForInterfaceOrientation:[[UIApplication sharedApplication] _frontMostAppOrientation]];
%orig(newSize);
}
%end
void modifyScroll(UIKBShape *shape, CGFloat height) {
shape.frame = CGRectMake(shape.frame.origin.x, shape.frame.origin.y, shape.frame.size.width, height);
shape.paddedFrame = CGRectMake(shape.paddedFrame.origin.x, shape.paddedFrame.origin.y, shape.paddedFrame.size.width, height);
}
void modifyBar(UIKBShape *shape, CGFloat scrollViewHeight, CGFloat barHeight) {
shape.frame = CGRectMake(shape.frame.origin.x, scrollViewHeight, shape.frame.size.width, barHeight);
shape.paddedFrame = CGRectMake(shape.paddedFrame.origin.x, scrollViewHeight, shape.paddedFrame.size.width, barHeight);
}
void modifyKeyboard(UIKBTree *keyboard, NSString *name) {
if (containsString(name, @"Emoji")) {
CGFloat keyboardHeight = [SoftPSEmojiLayout keyboardHeight:name];
CGFloat barHeight = [SoftPSEmojiLayout barHeight:name];
CGFloat scrollViewHeight = keyboardHeight - barHeight;
UIKBShape *kbShape = (UIKBShape *)(keyboard.properties[@"KBshape"]);
if (kbShape)
kbShape.frame = CGRectMake(kbShape.frame.origin.x, kbShape.frame.origin.y, kbShape.frame.size.width, keyboardHeight);
UIKBTree *subtree = keyboard.subtrees[0];
UIKBTree *Emoji_InputView_Keylayout = subtree.subtrees[0];
UIKBTree *Emoji_InputView_Keys_GeometrySet = Emoji_InputView_Keylayout.subtrees[1];
UIKBTree *Emoji_InputView_Geometry_List = Emoji_InputView_Keys_GeometrySet.subtrees[0];
UIKBShape *Emoji_InputView_Geometry_List_shape = Emoji_InputView_Geometry_List.subtrees[0];
modifyScroll(Emoji_InputView_Geometry_List_shape, scrollViewHeight);
UIKBTree *Emoji_Category_Control_Keylayout = subtree.subtrees[1];
UIKBTree *Emoji_Category_Control_Keys_GeometrySet = Emoji_Category_Control_Keylayout.subtrees[1];
UIKBTree *Emoji_Category_Control_Geometry_List = Emoji_Category_Control_Keys_GeometrySet.subtrees[0];
UIKBShape *Emoji_Category_Control_Geometry_List_shape = Emoji_Category_Control_Geometry_List.subtrees[0];
modifyBar(Emoji_Category_Control_Geometry_List_shape, scrollViewHeight, barHeight);
UIKBTree *Emoji_Control_Keylayout = subtree.subtrees[2];
UIKBTree *Emoji_Control_Keys_GeometrySet = Emoji_Control_Keylayout.subtrees[1];
UIKBTree *Emoji_Control_Geometry_List = Emoji_Control_Keys_GeometrySet.subtrees[0];
for (UIKBShape *shape in Emoji_Control_Geometry_List.subtrees) {
modifyBar(shape, scrollViewHeight, barHeight);
}
}
}
%group iOS70
%hook TIKeyboardFactory
- (UIKBTree *)keyboardWithName:(NSString *)name inCache:(id)cache {
UIKBTree *keyboard = %orig;
modifyKeyboard(keyboard, name);
return keyboard;
}
%end
%end
%group iOS6
%hook TIKeyboardFactory
- (UIKBTree *)keyboardWithName:(NSString *)name {
UIKBTree *keyboard = %orig;
modifyKeyboard(keyboard, name);
return keyboard;
}
%end
%hook UIKeyboardEmojiCategoryBar_iPad
- (id)initWithFrame:(CGRect)frame keyboard:(UIKBTree *)keyboard key:(UIKBTree *)key state:(int)state {
UIKBShape *shape = key.shape;
if (shape) {
CGFloat height = [SoftPSEmojiLayout scrollViewHeight:keyboard.name];
CGFloat height2 = [SoftPSEmojiLayout barHeight:keyboard.name];
CGRect newFrame = CGRectMake(shape.frame.origin.x, height, shape.frame.size.width, height2);
shape.frame = newFrame;
key.shape = shape;
frame = CGRectMake(shape.frame.origin.x, height, shape.frame.size.width, height2);
}
self = %orig(frame, keyboard, key, state);
return self;
}
%end
%hook UIKeyboardEmojiScrollView
- (id)initWithFrame:(CGRect)frame keyboard:(UIKBTree *)keyboard key:(UIKBTree *)key state:(int)state {
NSString *keyboardName = keyboard.name;
if (key && [keyboardName rangeOfString:@"Emoji"].location != NSNotFound && [key.name isEqualToString:@"Emoji-InputView-Key"]) {
UIKBShape *shape2 = key.shape;
CGFloat height = [SoftPSEmojiLayout scrollViewHeight:keyboardName];
CGRect newFrame2 = CGRectMake(shape2.frame.origin.x, shape2.frame.origin.y, shape2.frame.size.width, height);
shape2.frame = newFrame2;
CGRect paddedFrame2 = CGRectMake(shape2.paddedFrame.origin.x, shape2.paddedFrame.origin.y, shape2.paddedFrame.size.width, height);
shape2.paddedFrame = paddedFrame2;
key.shape = shape2;
frame = CGRectMake(frame.origin.x, frame.origin.y, frame.size.width, height);
}
return %orig(frame, keyboard, key, state);
}
%end
%end
%ctor {
if (IS_IOS_OR_NEWER(iOS_7_1))
return;
dlopen(realPath2(@"/System/Library/PrivateFrameworks/TextInput.framework/TextInput"), RTLD_NOW);
%init;
if (IS_IOS_OR_NEWER(iOS_7_0)) {
%init(iOS70);
} else {
%init(iOS6);
}
}