Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update webview to grant location #8840

Merged
merged 2 commits into from
Mar 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 40 additions & 16 deletions patches/react-native-webview+11.13.0.patch
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ index 0000000..f4a6af9
+ }
+}
diff --git a/node_modules/react-native-webview/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java b/node_modules/react-native-webview/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java
index f743bbc..06d172f 100644
index f743bbc..b520532 100644
--- a/node_modules/react-native-webview/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java
+++ b/node_modules/react-native-webview/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java
@@ -5,6 +5,7 @@ import android.annotation.TargetApi;
Expand Down Expand Up @@ -1022,7 +1022,31 @@ index f743bbc..06d172f 100644

@Override
public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback) {
@@ -1402,6 +1756,15 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
@@ -1266,7 +1620,22 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
requestPermissions(Collections.singletonList(Manifest.permission.ACCESS_FINE_LOCATION));

} else {
- callback.invoke(origin, true, false);
+ String alertMessage = String.format("Allow this app to use your location?");
+ AlertDialog.Builder builder = new AlertDialog.Builder(this.mWebView.getContext());
+ builder.setMessage(alertMessage);
+ builder.setCancelable(false);
+ builder.setPositiveButton("Allow", (dialog, which) -> {
+ callback.invoke(origin, true, false);
+ });
+ builder.setNegativeButton("Don't allow", (dialog, which) -> {
+ callback.invoke(origin, false, false);
+ });
+ AlertDialog alertDialog = builder.create();
+ alertDialog.show();
+ //Delay making `allow` clickable for 500ms to avoid unwanted presses.
+ Button posButton = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
+ posButton.setEnabled(false);
+ this.runDelayed(() -> posButton.setEnabled(true), 500);
}
}

@@ -1402,6 +1771,15 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
}
}

Expand All @@ -1038,7 +1062,7 @@ index f743bbc..06d172f 100644
@Override
public void onHostPause() { }

@@ -1447,6 +1810,13 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
@@ -1447,6 +1825,13 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
protected boolean nestedScrollEnabled = false;
protected ProgressChangedFilter progressChangedFilter;

Expand All @@ -1052,7 +1076,7 @@ index f743bbc..06d172f 100644
/**
* WebView must be created with an context of the current activity
* <p>
@@ -1475,6 +1845,42 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
@@ -1475,6 +1860,42 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
this.nestedScrollEnabled = nestedScrollEnabled;
}

Expand Down Expand Up @@ -1095,7 +1119,7 @@ index f743bbc..06d172f 100644
@Override
public void onHostResume() {
// do nothing
@@ -1533,6 +1939,8 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
@@ -1533,6 +1954,8 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
}
}

Expand All @@ -1104,7 +1128,7 @@ index f743bbc..06d172f 100644
public @Nullable
RNCWebViewClient getRNCWebViewClient() {
return mRNCWebViewClient;
@@ -1609,8 +2017,8 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
@@ -1609,8 +2032,8 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {

public void callInjectedJavaScriptBeforeContentLoaded() {
if (getSettings().getJavaScriptEnabled() &&
Expand All @@ -1115,7 +1139,7 @@ index f743bbc..06d172f 100644
evaluateJavascriptWithFallback("(function() {\n" + injectedJSBeforeContentLoaded + ";\n})();");
}
}
@@ -1672,16 +2080,16 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
@@ -1672,16 +2095,16 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {

if (mOnScrollDispatchHelper.onScrollChanged(x, y)) {
ScrollEvent event = ScrollEvent.obtain(
Expand Down Expand Up @@ -1174,39 +1198,39 @@ diff --git a/node_modules/react-native-webview/apple/RNCWebView.m b/node_modules
index 28c078a..9bb5368 100644
--- a/node_modules/react-native-webview/apple/RNCWebView.m
+++ b/node_modules/react-native-webview/apple/RNCWebView.m
@@ -105,6 +105,7 @@ @implementation RNCWebView
@@ -105,6 +105,7 @@ static NSDictionary* customCertificatesForHost;
UIStatusBarStyle _savedStatusBarStyle;
#endif // !TARGET_OS_OSX
BOOL _savedStatusBarHidden;
+ BOOL _disablePromptDuringLoading; //Disables the display of prompts during site navigation/loading

#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000 /* __IPHONE_11_0 */
UIScrollViewContentInsetAdjustmentBehavior _savedContentInsetAdjustmentBehavior;
@@ -139,6 +140,7 @@ - (instancetype)initWithFrame:(CGRect)frame
@@ -139,6 +140,7 @@ static NSDictionary* customCertificatesForHost;
_injectedJavaScriptForMainFrameOnly = YES;
_injectedJavaScriptBeforeContentLoaded = nil;
_injectedJavaScriptBeforeContentLoadedForMainFrameOnly = YES;
+ _disablePromptDuringLoading = YES;

#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000 /* __IPHONE_11_0 */
_savedContentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
@@ -417,6 +419,7 @@ -(void)keyboardDisplacementFix
@@ -417,6 +419,7 @@ static NSDictionary* customCertificatesForHost;
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context{
if ([keyPath isEqual:@"estimatedProgress"] && object == self.webView) {
if(_onLoadingProgress){
+ _disablePromptDuringLoading = YES;
NSMutableDictionary<NSString *, id> *event = [self baseEvent];
[event addEntriesFromDictionary:@{@"progress":[NSNumber numberWithDouble:self.webView.estimatedProgress]}];
_onLoadingProgress(event);
@@ -492,6 +495,7 @@ - (void)userContentController:(WKUserContentController *)userContentController
@@ -492,6 +495,7 @@ static NSDictionary* customCertificatesForHost;
NSMutableDictionary<NSString *, id> *event = [self baseEvent];
[event addEntriesFromDictionary: @{@"navigationType": message.body}];
_onLoadingFinish(event);
+ _disablePromptDuringLoading = NO;
}
} else if ([message.name isEqualToString:MessageHandlerName]) {
if (_onMessage) {
@@ -851,11 +855,13 @@ - (void) webView:(WKWebView *)webView
@@ -851,11 +855,13 @@ static NSDictionary* customCertificatesForHost;
- (void)webView:(WKWebView *)webView runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(void))completionHandler
{
#if !TARGET_OS_OSX
Expand All @@ -1225,7 +1249,7 @@ index 28c078a..9bb5368 100644
#else
NSAlert *alert = [[NSAlert alloc] init];
[alert setMessageText:message];
@@ -868,6 +874,51 @@ - (void)webView:(WKWebView *)webView runJavaScriptAlertPanelWithMessage:(NSStrin
@@ -868,6 +874,51 @@ static NSDictionary* customCertificatesForHost;
/**
* confirm
*/
Expand Down Expand Up @@ -1277,7 +1301,7 @@ index 28c078a..9bb5368 100644
- (void)webView:(WKWebView *)webView runJavaScriptConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(BOOL))completionHandler{
#if !TARGET_OS_OSX
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"" message:message preferredStyle:UIAlertControllerStyleAlert];
@@ -894,44 +945,49 @@ - (void)webView:(WKWebView *)webView runJavaScriptConfirmPanelWithMessage:(NSStr
@@ -894,44 +945,49 @@ static NSDictionary* customCertificatesForHost;
* prompt
*/
- (void)webView:(WKWebView *)webView runJavaScriptTextInputPanelWithPrompt:(NSString *)prompt defaultText:(NSString *)defaultText initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(NSString *))completionHandler{
Expand Down Expand Up @@ -1362,15 +1386,15 @@ index 28c078a..9bb5368 100644
}

#if !TARGET_OS_OSX
@@ -1157,6 +1213,7 @@ - (void)webView:(WKWebView *)webView
@@ -1157,6 +1213,7 @@ static NSDictionary* customCertificatesForHost;
}

if (_onLoadingFinish) {
+ _disablePromptDuringLoading = NO;
_onLoadingFinish([self baseEvent]);
}
}
@@ -1446,3 +1503,4 @@ - (void)userContentController:(WKUserContentController *)userContentController d
@@ -1446,3 +1503,4 @@ static NSDictionary* customCertificatesForHost;
}

@end
Expand Down
Loading