Skip to content

Commit

Permalink
fix(sdk): prevent cancel until ready for interaction (#126)
Browse files Browse the repository at this point in the history
  • Loading branch information
CAMOBAP authored May 31, 2023
1 parent a2ba105 commit 022d95b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
13 changes: 8 additions & 5 deletions sdk/src/main/java/com/hcaptcha/sdk/HCaptchaDialogFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public final class HCaptchaDialogFragment extends DialogFragment implements IHCa

private float defaultDimAmount = 0.6f;

private boolean loaded = false;
private boolean readyForInteraction = false;

/**
* Creates a new instance
Expand Down Expand Up @@ -120,6 +120,7 @@ public View onCreateView(@Nullable LayoutInflater inflater,

webViewHelper = new HCaptchaWebViewHelper(new Handler(Looper.getMainLooper()),
requireContext(), config, internalConfig, this, listener, webView);
readyForInteraction = false;
return rootView;
} catch (BadParcelableException | InflateException | ClassCastException e) {
HCaptchaLog.w("Cannot create view. Dismissing dialog...");
Expand Down Expand Up @@ -191,10 +192,10 @@ public void onLoaded() {
assert webViewHelper != null;

if (webViewHelper.getConfig().getSize() != HCaptchaSize.INVISIBLE) {
// checkbox will be shown
readyForInteraction = true;
hideLoadingContainer();
}

loaded = true;
}

@Override
Expand All @@ -205,6 +206,8 @@ public void onOpen() {
hideLoadingContainer();
}

readyForInteraction = true;

webViewHelper.getListener().onOpen();
}

Expand Down Expand Up @@ -275,7 +278,7 @@ private View prepareRootView(@NonNull LayoutInflater inflater,
return false;
}

final boolean withoutLoadingUI = !loaded && Boolean.FALSE.equals(config.getLoading());
final boolean withoutLoadingUI = !readyForInteraction && Boolean.FALSE.equals(config.getLoading());
if (withoutLoadingUI) {
return true;
}
Expand All @@ -291,7 +294,7 @@ private HCaptchaWebView prepareWebView(@NonNull View rootView, @NonNull HCaptcha
final HCaptchaWebView webView = rootView.findViewById(R.id.webView);
if (Boolean.FALSE.equals(config.getLoading())) {
webView.setOnTouchListener((view, event) -> {
if (!loaded && isAdded()) {
if (!readyForInteraction && isAdded()) {
final Activity activity = getActivity();
if (activity != null) {
activity.dispatchTouchEvent(event);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
public interface OnOpenListener {

/**
* Called when the hCaptcha challenge is displayed on the html page
* Called when the hCaptcha visual challenge is displayed on the html page
*/
void onOpen();
}

0 comments on commit 022d95b

Please sign in to comment.