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

[TIMOB-10361] added touchPassThrough property on iOS which allows touches to go throug... #2696

Closed
wants to merge 7 commits into from
Closed
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.OnHierarchyChangeListener;
import android.view.MotionEvent;

/**
* Base layout class for all Titanium views.
Expand Down Expand Up @@ -77,6 +78,7 @@ public enum LayoutArrangement {
private static final int HAS_SIZE_FILL_CONFLICT = 1;
private static final int NO_SIZE_FILL_CONFLICT = 2;

private boolean touchPassThrough = false;
// We need these two constructors for backwards compatibility with modules

/**
Expand Down Expand Up @@ -929,4 +931,16 @@ public void setProxy(TiViewProxy proxy)
this.proxy = new WeakReference<TiViewProxy>(proxy);
}

public void setTouchPassThrough(boolean passthrough)
{
touchPassThrough = passthrough;
}

@Override
public boolean dispatchTouchEvent(MotionEvent event)
{
if (touchPassThrough) return false;
return super.dispatchTouchEvent(event);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,10 @@ public void propertyChanged(String key, Object oldValue, Object newValue, KrollP
if (nativeView != null) {
nativeView.setKeepScreenOn(TiConvert.toBoolean(newValue));
}
} else if (key.equals(TiC.PROPERTY_TOUCH_PASSTHROUGH)) {
if (nativeView instanceof TiCompositeLayout) {
((TiCompositeLayout) nativeView).setTouchPassThrough(TiConvert.toBoolean(newValue));
}
} else {
Log.d(TAG, "Unhandled property key: " + key, Log.DEBUG_MODE);
}
Expand Down Expand Up @@ -646,6 +650,12 @@ public void processProperties(KrollDict d)
}
}

if (d.containsKey(TiC.PROPERTY_TOUCH_PASSTHROUGH)) {
if (nativeView instanceof TiCompositeLayout) {
((TiCompositeLayout) nativeView).setTouchPassThrough(TiConvert.toBoolean(d, TiC.PROPERTY_TOUCH_PASSTHROUGH));
}
}

Integer bgColor = null;

// Default background processing.
Expand Down
2 changes: 2 additions & 0 deletions iphone/Classes/TiUIView.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ void ModifyScrollViewForKeyboardHeightAndContentHeightWithResponderRect(UIScroll
BOOL handlesTouches;
UIView *touchDelegate; // used for touch delegate forwarding
BOOL animating;

BOOL touchPassThrough;

UITapGestureRecognizer* singleTapRecognizer;
UITapGestureRecognizer* doubleTapRecognizer;
Expand Down
20 changes: 18 additions & 2 deletions iphone/Classes/TiUIView.m
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ - (id) init
self = [super init];
if (self != nil)
{

touchPassThrough = false;
}
return self;
}
Expand Down Expand Up @@ -571,6 +571,15 @@ -(BOOL) touchEnabled {
return touchEnabled;
}

-(void)setTouchPassThrough_:(id)arg
{
touchPassThrough = [TiUtils boolValue:arg];
}

-(BOOL)touchPassThrough {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because how the data flows, you don't need to implement this method. From JS, foo.touchPassThrough never consults with the view, only with the proxy, which has already stashed away the property before even passing it on to setTouchPassThrough_.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well how would the proxy know that it needs to change the Bool touchPassThrough from the view itself?
Remember that i need to have access to that property within hitTest.

EDIT: you are just talking about the getter right? If so i dont like not to write it because the proxy value and the view value could (shouldnt) be out of sync.

return touchPassThrough;
}

-(UIView *)gradientWrapperView
{
return self;
Expand Down Expand Up @@ -1004,7 +1013,14 @@ - (UIView *)hitTest:(CGPoint) point withEvent:(UIEvent *)event
}
*/

return [super hitTest:point withEvent:event];
UIView *hitView = [super hitTest:point withEvent:event];
if (touchPassThrough)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor nitpick: This could be more elegantly written as
if (touchPassThrough && (hitview == self))
{
return nil;
}
return hitView;

{
if (hitView != self)
return hitView;
return nil;
}
return hitView;
}

// TODO: Revisit this design decision in post-1.3.0
Expand Down