Skip to content

Commit

Permalink
Fix the issue where the promo WebView does not respond to click events
Browse files Browse the repository at this point in the history
  • Loading branch information
quanquan1 committed Mar 19, 2024
1 parent 09714fb commit a0d6fe2
Showing 1 changed file with 20 additions and 48 deletions.
68 changes: 20 additions & 48 deletions affirm/src/main/java/com/affirm/android/PromotionWebView.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.content.Context;
import android.os.Build;
import android.util.AttributeSet;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
import android.webkit.CookieManager;
Expand Down Expand Up @@ -49,60 +50,31 @@ public PromotionWebView(Context context, AttributeSet attrs) {
AffirmUtils.debuggableWebView(getContext());
setWebViewClient(new PromoWebViewClient(this));
setWebChromeClient(new AffirmWebChromeClient(this));


setOnTouchListener(new View.OnTouchListener() {

private static final int FINGER_RELEASED = 0;
private static final int FINGER_TOUCHED = 1;
private static final int FINGER_DRAGGING = 2;
private static final int FINGER_UNDEFINED = 3;

private int fingerState = FINGER_RELEASED;

GestureDetector gestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {

switch (motionEvent.getAction()) {

case MotionEvent.ACTION_DOWN:
if (fingerState == FINGER_RELEASED) {
fingerState = FINGER_TOUCHED;
} else {
fingerState = FINGER_UNDEFINED;
}
break;

case MotionEvent.ACTION_UP:
if (fingerState != FINGER_DRAGGING) {
fingerState = FINGER_RELEASED;
if (webViewClickListener != null) {
webViewClickListener.onClick((View) view.getParent());
}
} else {
fingerState = FINGER_RELEASED;
}
break;

case MotionEvent.ACTION_MOVE:
if (fingerState == FINGER_TOUCHED || fingerState == FINGER_DRAGGING) {
fingerState = FINGER_DRAGGING;
} else {
fingerState = FINGER_UNDEFINED;
}
break;

default:
fingerState = FINGER_UNDEFINED;

}

return false;
public boolean onSingleTapConfirmed(MotionEvent e) {
performClick();
return true;
}
});
setOnTouchListener((view, event) -> {
if (gestureDetector.onTouchEvent(event)) {
return true;
}
return false;
});
setBackgroundColor(getResources().getColor(android.R.color.transparent));
}

@Override
public boolean performClick() {
super.performClick();
if (webViewClickListener != null) {
webViewClickListener.onClick((View) getParent());
}
return true;
}

public void loadWebData(String promoHtml, String remoteCssUrl, String typeface) {
final String html = initialHtml(promoHtml, remoteCssUrl, typeface);
loadDataWithBaseURL(null, html, TEXT_HTML, UTF_8, null);
Expand Down

0 comments on commit a0d6fe2

Please sign in to comment.