Skip to content

Commit

Permalink
fix: sdk 30 no styling nor touchListener
Browse files Browse the repository at this point in the history
  • Loading branch information
ath0mas committed Oct 28, 2021
1 parent 9414e69 commit a4aca43
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/android/nl/xservices/plugins/Toast.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class Toast extends CordovaPlugin {
private static final boolean IS_AT_LEAST_JELLY_BEAN = Build.VERSION.SDK_INT >= 16;
private static final boolean IS_AT_LEAST_LOLLIPOP = Build.VERSION.SDK_INT >= 21;
private static final boolean IS_AT_LEAST_PIE = Build.VERSION.SDK_INT >= 28;
private static final boolean IS_AT_LEAST_R = Build.VERSION.SDK_INT >= 30;

// note that webView.isPaused() is not Xwalk compatible, so tracking it poor-man style
private boolean isPaused;
Expand Down Expand Up @@ -106,7 +107,8 @@ public void run() {
}

// if one of the custom layout options have been passed in, draw our own shape
if (styling != null && IS_AT_LEAST_JELLY_BEAN) {
// (but disabled on Android >= 11 since custom toast views are deprecated)
if (styling != null && IS_AT_LEAST_JELLY_BEAN && !IS_AT_LEAST_R) {

// the defaults mimic the default toast as close as possible
final String backgroundColor = styling.optString("backgroundColor", "#333333");
Expand Down Expand Up @@ -138,9 +140,13 @@ public void run() {
}
}

// On Android >= 5 you can no longer rely on the 'toast.getView().setOnTouchListener',
// so created something funky that compares the Toast position to the tap coordinates.
if (IS_AT_LEAST_LOLLIPOP) {
if (IS_AT_LEAST_R) {
// On Android >= 11 the 'toast.getView()' will always return null
// so no touchListener can be used or mocked
// DO NOTHING
} else if (IS_AT_LEAST_LOLLIPOP) {
// On Android >= 5 you can no longer rely on the 'toast.getView().setOnTouchListener',
// so created something funky that compares the Toast position to the tap coordinates.
getViewGroup().setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
Expand Down

0 comments on commit a4aca43

Please sign in to comment.