Skip to content

Commit a0d6fe2

Browse files
committed
Fix the issue where the promo WebView does not respond to click events
1 parent 09714fb commit a0d6fe2

File tree

1 file changed

+20
-48
lines changed

1 file changed

+20
-48
lines changed

affirm/src/main/java/com/affirm/android/PromotionWebView.java

+20-48
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import android.content.Context;
44
import android.os.Build;
55
import android.util.AttributeSet;
6+
import android.view.GestureDetector;
67
import android.view.MotionEvent;
78
import android.view.View;
89
import android.webkit.CookieManager;
@@ -49,60 +50,31 @@ public PromotionWebView(Context context, AttributeSet attrs) {
4950
AffirmUtils.debuggableWebView(getContext());
5051
setWebViewClient(new PromoWebViewClient(this));
5152
setWebChromeClient(new AffirmWebChromeClient(this));
52-
53-
54-
setOnTouchListener(new View.OnTouchListener() {
55-
56-
private static final int FINGER_RELEASED = 0;
57-
private static final int FINGER_TOUCHED = 1;
58-
private static final int FINGER_DRAGGING = 2;
59-
private static final int FINGER_UNDEFINED = 3;
60-
61-
private int fingerState = FINGER_RELEASED;
62-
53+
GestureDetector gestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
6354
@Override
64-
public boolean onTouch(View view, MotionEvent motionEvent) {
65-
66-
switch (motionEvent.getAction()) {
67-
68-
case MotionEvent.ACTION_DOWN:
69-
if (fingerState == FINGER_RELEASED) {
70-
fingerState = FINGER_TOUCHED;
71-
} else {
72-
fingerState = FINGER_UNDEFINED;
73-
}
74-
break;
75-
76-
case MotionEvent.ACTION_UP:
77-
if (fingerState != FINGER_DRAGGING) {
78-
fingerState = FINGER_RELEASED;
79-
if (webViewClickListener != null) {
80-
webViewClickListener.onClick((View) view.getParent());
81-
}
82-
} else {
83-
fingerState = FINGER_RELEASED;
84-
}
85-
break;
86-
87-
case MotionEvent.ACTION_MOVE:
88-
if (fingerState == FINGER_TOUCHED || fingerState == FINGER_DRAGGING) {
89-
fingerState = FINGER_DRAGGING;
90-
} else {
91-
fingerState = FINGER_UNDEFINED;
92-
}
93-
break;
94-
95-
default:
96-
fingerState = FINGER_UNDEFINED;
97-
98-
}
99-
100-
return false;
55+
public boolean onSingleTapConfirmed(MotionEvent e) {
56+
performClick();
57+
return true;
10158
}
10259
});
60+
setOnTouchListener((view, event) -> {
61+
if (gestureDetector.onTouchEvent(event)) {
62+
return true;
63+
}
64+
return false;
65+
});
10366
setBackgroundColor(getResources().getColor(android.R.color.transparent));
10467
}
10568

69+
@Override
70+
public boolean performClick() {
71+
super.performClick();
72+
if (webViewClickListener != null) {
73+
webViewClickListener.onClick((View) getParent());
74+
}
75+
return true;
76+
}
77+
10678
public void loadWebData(String promoHtml, String remoteCssUrl, String typeface) {
10779
final String html = initialHtml(promoHtml, remoteCssUrl, typeface);
10880
loadDataWithBaseURL(null, html, TEXT_HTML, UTF_8, null);

0 commit comments

Comments
 (0)