diff --git a/Libraries/Components/WebView/WebView.android.js b/Libraries/Components/WebView/WebView.android.js index a457298f96f65f..6f0ac9b57fb033 100644 --- a/Libraries/Components/WebView/WebView.android.js +++ b/Libraries/Components/WebView/WebView.android.js @@ -138,6 +138,12 @@ class WebView extends React.Component { */ domStorageEnabled: PropTypes.bool, + /** + * Sets whether Geolocation is enabled. The default is false. + * @platform android + */ + geolocationEnabled: PropTypes.bool, + /** * Sets the JS to be injected when the webpage loads. */ @@ -310,6 +316,7 @@ class WebView extends React.Component { onLoadingFinish={this.onLoadingFinish} onLoadingError={this.onLoadingError} testID={this.props.testID} + geolocationEnabled={this.props.geolocationEnabled} mediaPlaybackRequiresUserAction={this.props.mediaPlaybackRequiresUserAction} allowUniversalAccessFromFileURLs={this.props.allowUniversalAccessFromFileURLs} mixedContentMode={this.props.mixedContentMode} diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/webview/ReactWebViewManager.java b/ReactAndroid/src/main/java/com/facebook/react/views/webview/ReactWebViewManager.java index 3097beea5aadd6..a580a2bc4a18af 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/webview/ReactWebViewManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/webview/ReactWebViewManager.java @@ -384,6 +384,7 @@ public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermiss new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); + setGeolocationEnabled(webView, false); if (ReactBuildConfig.DEBUG && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { WebView.setWebContentsDebuggingEnabled(true); } @@ -538,6 +539,13 @@ public void setUrlPrefixesForDefaultIntent( } } + @ReactProp(name = "geolocationEnabled") + public void setGeolocationEnabled( + WebView view, + @Nullable Boolean isGeolocationEnabled) { + view.getSettings().setGeolocationEnabled(isGeolocationEnabled != null && isGeolocationEnabled); + } + @Override protected void addEventEmitters(ThemedReactContext reactContext, WebView view) { // Do not register default touch emitter and let WebView implementation handle touches