Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 31 additions & 30 deletions src/ios/CDVDecimalKeyboard.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ - (void)pluginInitialize {
selector:@selector(appDidBecomeActive:)
name:UIApplicationDidBecomeActiveNotification
object:nil];


}
- (void) appWillResignActive: (NSNotification*) n{
isAppInBackground = YES;
Expand All @@ -38,7 +38,7 @@ - (void) appDidBecomeActive: (NSNotification*) n{
if(isAppInBackground==YES){
isAppInBackground = NO;
[self processKeyboardShownEvent];

}
}

Expand Down Expand Up @@ -71,22 +71,22 @@ - (void) addDecimalButton{
forControlEvents:UIControlEventTouchDown];
[decimalButton addTarget:self action:@selector(buttonPressCancel:)
forControlEvents:UIControlEventTouchUpOutside];


decimalButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
[decimalButton setTitleEdgeInsets:UIEdgeInsetsMake(-20.0f, 0.0f, 0.0f, 0.0f)];
[decimalButton setBackgroundColor: [UIColor colorWithRed:210/255.0 green:213/255.0 blue:218/255.0 alpha:1.0]];

// locate keyboard view
UIWindow* tempWindow = nil;
NSArray* openWindows = [[UIApplication sharedApplication] windows];

for(UIWindow* object in openWindows){
if([[object description] hasPrefix:@"<UIRemoteKeyboardWindow"] == YES){
tempWindow = object;
}
}

if(tempWindow ==nil){
//for ios 8
for(UIWindow* object in openWindows){
Expand All @@ -96,7 +96,7 @@ - (void) addDecimalButton{
}
}


UIView* keyboard;
for(int i=0; i<[tempWindow.subviews count]; i++) {
keyboard = [tempWindow.subviews objectAtIndex:i];
Expand All @@ -109,7 +109,7 @@ - (void) removeDecimalButton{
[decimalButton removeFromSuperview];
decimalButton=nil;
stopSearching=NO;

}
- (void) deleteDecimalButton{
[decimalButton removeFromSuperview];
Expand All @@ -122,21 +122,21 @@ - (void) keyboardWillAppear: (NSNotification*) n{
NSDictionary* info = [n userInfo];
NSNumber* value = [info objectForKey:UIKeyboardAnimationDurationUserInfoKey];
double dValue = [value doubleValue];

if(dValue <= 0.0){
[self removeDecimalButton];
return;
}

dispatch_time_t delay = dispatch_time(DISPATCH_TIME_NOW, NSEC_PER_SEC * dValue);
dispatch_after(delay, dispatch_get_main_queue(), ^(void){
[self processKeyboardShownEvent];
});


}
- (void) processKeyboardShownEvent{
[self isTextAndDecimal:^(BOOL isDecimalKeyRequired) {
[self isTextOrNumberAndDecimal:^(BOOL isDecimalKeyRequired) {
// create custom button
if(decimalButton == nil){
if(isDecimalKeyRequired){
Expand Down Expand Up @@ -165,17 +165,19 @@ - (void)buttonPressCancel:(UIButton *)button{
[decimalButton setBackgroundColor: [UIColor colorWithRed:210/255.0 green:213/255.0 blue:218/255.0 alpha:1.0]];
}

- (void) isTextAndDecimal:(void (^)(BOOL isTextAndDecimal))completionHandler {
- (void) isTextOrNumberAndDecimal:(void (^)(BOOL isTextOrNumberAndDecimal))completionHandler {
[self evaluateJavaScript:@"DecimalKeyboard.getActiveElementType();"
completionHandler:^(NSString * _Nullable response, NSError * _Nullable error) {
BOOL isText = [response isEqual:@"text"];

if (isText) {
BOOL isNumber = [response isEqual:@"number"];
BOOL isTel = [response isEqual:@"tel"];

if (isText || isNumber || isTel) {
[self evaluateJavaScript:@"DecimalKeyboard.isDecimal();"
completionHandler:^(NSString * _Nullable response, NSError * _Nullable error) {
BOOL isDecimal = [response isEqual:@"true"] || [response isEqual:@"1"];
BOOL isTextAndDecimal = isText && isDecimal;
completionHandler(isTextAndDecimal);
BOOL isTextOrNumberAndDecimal = (isText || isNumber || isTel) && isDecimal;
completionHandler(isTextOrNumberAndDecimal);
}];
} else {
completionHandler(NO);
Expand All @@ -185,13 +187,13 @@ - (void) isTextAndDecimal:(void (^)(BOOL isTextAndDecimal))completionHandler {

BOOL stopSearching=NO;
- (void)listSubviewsOfView:(UIView *)view {

// Get the subviews of the view
NSArray *subviews = [view subviews];

// Return if there are no subviews
if ([subviews count] == 0) return; // COUNT CHECK LINE

for (UIView *subview in subviews) {
if(stopSearching==YES){
break;
Expand All @@ -204,20 +206,20 @@ - (void)listSubviewsOfView:(UIView *)view {
CGFloat x = 0;
CGFloat y =ui.frame.size.height;
for(UIView *nView in ui.subviews){

if([[nView description] hasPrefix:@"<UIKBKeyView"] == YES){
//all keys of same size;
height = nView.frame.size.height;
width = nView.frame.size.width-1.5;
y = y-(height-1);
cgButton = CGRectMake(x, y, width, height);
break;

}

}
}

[self listSubviewsOfView:subview];
}
}
Expand All @@ -230,7 +232,7 @@ - (void) evaluateJavaScript:(NSString *)script
NSString *response = [webview stringByEvaluatingJavaScriptFromString:script];
if (completionHandler) completionHandler(response, nil);
}

else if ([self.webView isKindOfClass:WKWebView.class]) {
WKWebView *webview = (WKWebView*)self.webView;
[webview evaluateJavaScript:script completionHandler:^(id result, NSError *error) {
Expand All @@ -240,8 +242,7 @@ - (void) evaluateJavaScript:(NSString *)script
}
}];
}

}

@end