Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #1359 from mstepanov/timob-7540

[TIMOB-7540] iOS: update userInteractionEnabled when listeners added/removed
  • Loading branch information...
commit 2bc40688ccc6e26a8514ea179ae8323509f1832a 2 parents 6249fc0 + aae4ab7
Stephen Tramer authored
Showing with 16 additions and 27 deletions.
  1. +0 −2  iphone/Classes/TiUIView.h
  2. +16 −25 iphone/Classes/TiUIView.m
View
2  iphone/Classes/TiUIView.h
@@ -45,8 +45,6 @@ void ModifyScrollViewForKeyboardHeightAndContentHeightWithResponderRect(UIScroll
// Touch detection
BOOL changedInteraction;
BOOL handlesTouches;
- BOOL handlesTaps;
- BOOL handlesSwipes;
UIView *touchDelegate; // used for touch delegate forwarding
BOOL animating;
View
41 iphone/Classes/TiUIView.m
@@ -246,9 +246,18 @@ -(BOOL)proxyHasTouchListener
-(void)updateTouchHandling
{
BOOL touchEventsSupported = [self viewSupportsBaseTouchEvents];
- handlesTaps = touchEventsSupported && [self proxyHasTapListener];
- handlesTouches = touchEventsSupported && [self proxyHasTouchListener];
- handlesSwipes = touchEventsSupported && [proxy _hasListeners:@"swipe"];
+ handlesTouches = touchEventsSupported && (
+ [self proxyHasTouchListener]
+ || [self proxyHasTapListener]
+ || [proxy _hasListeners:@"swipe"]
+ || [proxy _hasListeners:@"pinch"]
+ || [proxy _hasListeners:@"longpress"]);
+
+ // If a user has not explicitly set whether or not the view interacts, base it on whether or
+ // not it handles events, and if not, set it to the interaction default.
+ if (!changedInteraction) {
+ self.userInteractionEnabled = handlesTouches || [self interactionDefault];
+ }
}
-(void)initializeState
@@ -259,12 +268,6 @@ -(void)initializeState
self.backgroundColor = [UIColor clearColor];
self.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
-
- // If a user has not explicitly set whether or not the view interacts, base it on whether or
- // not it handles events, and if not, set it to the interaction default.
- if (!changedInteraction) {
- self.userInteractionEnabled = (handlesTouches || handlesTaps || handlesSwipes) || [self interactionDefault];
- }
}
-(void)configurationSet
@@ -959,7 +962,7 @@ - (BOOL)interactionEnabled
- (BOOL)hasTouchableListener
{
- return (handlesSwipes|| handlesTaps || handlesTouches);
+ return handlesTouches;
}
- (UIView *)hitTest:(CGPoint) point withEvent:(UIEvent *)event
@@ -1140,10 +1143,7 @@ -(void)removeGestureRecognizerOfClass:(Class)c
-(void)handleListenerAddedWithEvent:(NSString *)event
{
ENSURE_UI_THREAD_1_ARG(event);
- if ([self proxyHasTouchListener])
- {
- handlesTouches = YES;
- }
+ [self updateTouchHandling];
if ([event isEqualToString:@"singletap"]) {
[[self singleTapRecognizer] setEnabled:YES];
@@ -1177,17 +1177,8 @@ -(void)handleListenerRemovedWithEvent:(NSString *)event
ENSURE_UI_THREAD_1_ARG(event);
// unfortunately on a remove, we have to check all of them
// since we might be removing one but we still have others
-
- if (handlesTouches &&
- [self.proxy _hasListeners:@"touchstart"]==NO &&
- [self.proxy _hasListeners:@"touchmove"]==NO &&
- [self.proxy _hasListeners:@"touchcancel"]==NO &&
- [self.proxy _hasListeners:@"touchend"]==NO &&
- [self.proxy _hasListeners:@"click"]==NO &&
- [self.proxy _hasListeners:@"dblclick"]==NO)
- {
- handlesTouches = NO;
- }
+
+ [self updateTouchHandling];
if ([event isEqualToString:@"singletap"]) {
[singleTapRecognizer setEnabled:NO];
return;
Please sign in to comment.
Something went wrong with that request. Please try again.