Skip to content

Commit 69c83e3

Browse files
committed
feat: add alert at onGeolocationPermissionsShowPrompt
1 parent bddf099 commit 69c83e3

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

android/src/main/java/com/reactnativecommunity/webview/RNCWebChromeClient.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,22 @@ public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermiss
228228
requestPermissions(Collections.singletonList(Manifest.permission.ACCESS_FINE_LOCATION));
229229

230230
} else {
231-
callback.invoke(origin, true, false);
231+
String alertMessage = String.format("Allow %s to use your location?", origin);
232+
AlertDialog.Builder builder = new AlertDialog.Builder(this.mWebView.getContext());
233+
builder.setMessage(alertMessage);
234+
builder.setCancelable(false);
235+
builder.setPositiveButton("Allow", (dialog, which) -> {
236+
callback.invoke(origin, true, false);
237+
});
238+
builder.setNegativeButton("Don't allow", (dialog, which) -> {
239+
callback.invoke(origin, false, false);
240+
});
241+
AlertDialog alertDialog = builder.create();
242+
alertDialog.show();
243+
//Delay making `allow` clickable for 500ms to avoid unwanted presses.
244+
Button posButton = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
245+
posButton.setEnabled(false);
246+
this.runDelayed(() -> posButton.setEnabled(true), 500);
232247
}
233248
}
234249

0 commit comments

Comments
 (0)