Skip to content

Commit 4a33699

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

File tree

1 file changed

+22
-49
lines changed

1 file changed

+22
-49
lines changed

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

+22-49
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,32 @@ 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-
63-
@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;
53+
GestureDetector gestureDetector = new GestureDetector(context,
54+
new GestureDetector.SimpleOnGestureListener() {
55+
@Override
56+
public boolean onSingleTapConfirmed(MotionEvent e) {
57+
performClick();
58+
return true;
59+
}
60+
});
61+
setOnTouchListener((view, event) -> {
62+
if (gestureDetector.onTouchEvent(event)) {
63+
return true;
10164
}
65+
return false;
10266
});
10367
setBackgroundColor(getResources().getColor(android.R.color.transparent));
10468
}
10569

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

0 commit comments

Comments
 (0)