Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

* Fix: issue #2 Can't click on Anything #5

Merged
merged 1 commit into from
Sep 7, 2018
Merged
Show file tree
Hide file tree
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
58 changes: 51 additions & 7 deletions Unity/Assets/Plugins/iOS/MobileInput.mm
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#define SET_TEXT @"SET_TEXT"
#define GET_TEXT @"GET_TEXT"
#define SET_RECT @"SET_RECT"
#define ON_FOCUS @"ON_FOCUS"
#define ON_UNFOCUS @"ON_UNFOCUS"
#define SET_FOCUS @"SET_FOCUS"
#define SET_VISIBLE @"SET_VISIBLE"
#define TEXT_CHANGE @"TEXT_CHANGE"
Expand Down Expand Up @@ -192,6 +194,19 @@ -(void) tapAction:(id)sender{
}
}

-(BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
{
// Allow buttons to receive press events. All other views will get ignored
for( id foundView in self.subviews )
{
if( [foundView isKindOfClass:[MobileInput class]] )
{
return YES;
}
}
return NO;
}

-(void) setObserverForOrientationChanging {
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:[UIDevice currentDevice]];
Expand Down Expand Up @@ -238,10 +253,6 @@ @implementation MobileInput
+(void) init:(UIViewController *)viewController {
unityViewController = viewController;
mapMobileInput = [[NSMutableDictionary alloc] init];
CGRect frameView = unityViewController.view.frame;
frameView.origin = CGPointMake(0.0f, 0.0f);
viewPlugin = [[MobileInputHoldView alloc] initHoldView:frameView];
[unityViewController.view addSubview:viewPlugin];
}

+(void) processMessage:(int)inputId data:(NSString *)data {
Expand Down Expand Up @@ -321,6 +332,8 @@ -(void) setRect:(NSDictionary *)data {
editView.frame = CGRectMake(x, y, width, height);
}

BOOL multiline;

-(void) create:(NSDictionary *)data {
NSString *placeholder = [data valueForKey:@"placeholder"];
NSString *font = [data valueForKey:@"font"];
Expand Down Expand Up @@ -352,7 +365,8 @@ -(void) create:(NSDictionary *)data {
NSString *contentType = [data valueForKey:@"content_type"];
NSString *alignment = [data valueForKey:@"align"];
BOOL withDoneButton = [[data valueForKey:@"with_done_button"] boolValue];
BOOL multiline = [[data valueForKey:@"multiline"] boolValue];
BOOL withClearButton = [[data valueForKey:@"with_clear_button"] boolValue];
multiline = [[data valueForKey:@"multiline"] boolValue];

BOOL autoCorr = NO;
BOOL password = NO;
Expand Down Expand Up @@ -494,17 +508,22 @@ -(void) create:(NSDictionary *)data {
textField.contentVerticalAlignment = valign;
textField.contentHorizontalAlignment = halign;
textField.textAlignment = textAlign;
if (withClearButton)
textField.clearButtonMode = UITextFieldViewModeWhileEditing;
textField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:placeholder attributes:@{NSForegroundColorAttributeName: placeHolderColor}];
textField.delegate = self;
if (keyType == UIKeyboardTypeEmailAddress)
textField.autocapitalizationType = UITextAutocapitalizationTypeNone;
[textField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
[textField addTarget:self action:@selector(textFieldActive:) forControlEvents:UIControlEventEditingDidBegin];
[textField addTarget:self action:@selector(textFieldInActive:) forControlEvents:UIControlEventEditingDidEnd];
[textField setSecureTextEntry:password];
if (keyboardDoneButtonView != nil)
textField.inputAccessoryView = keyboardDoneButtonView;
editView = textField;
}
[viewPlugin addSubview:editView];
[unityViewController.view addSubview:editView];

NSMutableDictionary *msg = [[NSMutableDictionary alloc] init];
[msg setValue:READY forKey:@"msg"];
[self sendData:msg];
Expand Down Expand Up @@ -533,7 +552,6 @@ -(int) getLineCount {
return 0;
}


-(void) remove {
[[NSNotificationCenter defaultCenter] removeObserver:self];
[editView resignFirstResponder];
Expand Down Expand Up @@ -578,7 +596,21 @@ -(void) textViewDidChange:(UITextView *)textView {
[self onTextChange:textView.text];
}

- (void) textViewDidBeginEditing:(UITextView *)textView
{
if (multiline) {
NSMutableDictionary *msg = [[NSMutableDictionary alloc] init];
[msg setValue:ON_FOCUS forKey:@"msg"];
[self sendData:msg];
}
}

-(void) textViewDidEndEditing:(UITextView *)textView {
if (multiline) {
NSMutableDictionary *msg = [[NSMutableDictionary alloc] init];
[msg setValue:ON_UNFOCUS forKey:@"msg"];
[self sendData:msg];
}
[self onTextEditEnd:textView.text];
}

Expand All @@ -602,6 +634,18 @@ - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRang
return YES;
}

-(void) textFieldActive:(UITextField *)theTextField {
NSMutableDictionary *msg = [[NSMutableDictionary alloc] init];
[msg setValue:ON_FOCUS forKey:@"msg"];
[self sendData:msg];
}

-(void) textFieldInActive:(UITextField *)theTextField {
NSMutableDictionary *msg = [[NSMutableDictionary alloc] init];
[msg setValue:ON_UNFOCUS forKey:@"msg"];
[self sendData:msg];
}

-(void) textFieldDidChange:(UITextField *)theTextField {
[self onTextChange:theTextField.text];
}
Expand Down
Loading