Skip to content

Commit

Permalink
Merge pull request #2589 from vishalduggal/timob-9958
Browse files Browse the repository at this point in the history
[TIMOB-9958] IOS: TextArea does not fire click events.
  • Loading branch information
Stephen Tramer committed Jul 18, 2012
2 parents a0b5d9b + 675e7fb commit cb66b60
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 11 deletions.
8 changes: 8 additions & 0 deletions iphone/Classes/TiUITextArea.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@

#import "TiUITextWidget.h"

@interface TiUITextViewImpl : UITextView {
@private
TiUIView * touchHandler;
UIView * touchedContentView;
}
-(void)setTouchHandler:(TiUIView*)handler;
@end

@interface TiUITextArea : TiUITextWidget <UITextViewDelegate>
{
@private
Expand Down
83 changes: 72 additions & 11 deletions iphone/Classes/TiUITextArea.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,64 @@
#import "Webcolor.h"
#import "TiApp.h"

@implementation TiUITextViewImpl

-(void)setTouchHandler:(TiUIView*)handler
{
//Assign only. No retain
touchHandler = handler;
}

- (BOOL)touchesShouldBegin:(NSSet *)touches withEvent:(UIEvent *)event inContentView:(UIView *)view
{
//If the content view is of type TiUIView touch events will automatically propagate
//If it is not of type TiUIView we will fire touch events with ourself as source
if ([view isKindOfClass:[TiUIView class]]) {
touchedContentView= view;
}
else {
touchedContentView = nil;
}
return [super touchesShouldBegin:touches withEvent:event inContentView:view];
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
//When userInteractionEnabled is false we do nothing since touch events are automatically
//propagated. If it is dragging do not do anything.
//The reason we are not checking tracking (like in scrollview) is because for some
//reason UITextView always returns true for tracking after the initial focus
if (!self.dragging && self.userInteractionEnabled && (touchedContentView == nil) ) {
[touchHandler processTouchesBegan:touches withEvent:event];
}
[super touchesBegan:touches withEvent:event];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
if (!self.dragging && self.userInteractionEnabled && (touchedContentView == nil) ) {
[touchHandler processTouchesMoved:touches withEvent:event];
}
[super touchesMoved:touches withEvent:event];
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
if (!self.dragging && self.userInteractionEnabled && (touchedContentView == nil) ) {
[touchHandler processTouchesEnded:touches withEvent:event];
}
[super touchesEnded:touches withEvent:event];
}

- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
if (!self.dragging && self.userInteractionEnabled && (touchedContentView == nil) ) {
[touchHandler processTouchesCancelled:touches withEvent:event];
}
[super touchesCancelled:touches withEvent:event];
}
@end


@implementation TiUITextArea

#pragma mark Internal
Expand All @@ -25,17 +83,20 @@ -(void)frameSizeChanged:(CGRect)frame bounds:(CGRect)bounds

-(UIView<UITextInputTraits>*)textWidgetView
{
if (textWidgetView==nil)
{
textWidgetView = [[UITextView alloc] initWithFrame:CGRectZero];
((UITextView *)textWidgetView).delegate = self;
[self addSubview:textWidgetView];
[(UITextView *)textWidgetView setContentInset:UIEdgeInsetsZero];
self.clipsToBounds = YES;
((UITextView *)textWidgetView).text = @""; //Setting TextArea text to empty string
WARN_IF_BACKGROUND_THREAD_OBJ; //NSNotificationCenter is not threadsafe!
}
return textWidgetView;
if (textWidgetView==nil)
{
TiUITextViewImpl *textViewImpl = [[TiUITextViewImpl alloc] initWithFrame:CGRectZero];
textViewImpl.delaysContentTouches = NO;
[textViewImpl setTouchHandler:self];
textViewImpl.delegate = self;
[self addSubview:textViewImpl];
[textViewImpl setContentInset:UIEdgeInsetsZero];
self.clipsToBounds = YES;
textViewImpl.text = @""; //Setting TextArea text to empty string

textWidgetView = textViewImpl;
}
return textWidgetView;
}

#pragma mark Public APIs
Expand Down
2 changes: 2 additions & 0 deletions iphone/Classes/TiUIView.m
Original file line number Diff line number Diff line change
Expand Up @@ -1219,6 +1219,8 @@ -(void)handleListenerRemovedWithEvent:(NSString *)event

[self updateTouchHandling];
if ([event isEqualToString:@"swipe"]) {
[[self gestureRecognizerForEvent:@"uswipe"] setEnabled:NO];
[[self gestureRecognizerForEvent:@"dswipe"] setEnabled:NO];
[[self gestureRecognizerForEvent:@"rswipe"] setEnabled:NO];
[[self gestureRecognizerForEvent:@"lswipe"] setEnabled:NO];
}
Expand Down

0 comments on commit cb66b60

Please sign in to comment.