Support geolocation in android webview

Summary:
Makes sure request for geolocation use in the webview is handled.
This solves issue #7609

Currently use of geolocation in webview fails silently, as the permission request is never received by the native app.

**Test plan (required)**

1. Create new project with webview
2. Add javascript for geolocation:
```javascript
navigator.geolocation.getCurrentPosition(function (position) {
  console.log('success', position)
}, function (error) {
  console.log('could not determine position', error)
})
```
3. Run code and assert geolocation permission is requested, resulting in success (or error) callback being called
Closes https://github.com/facebook/react-native/pull/8305

Differential Revision: D3592887

fbshipit-source-id: 84fe2383fba8873431c5e89d154c0a4fd58ffb70
This commit is contained in:
Jon Vassbø 2016-07-20 05:41:32 -07:00 committed by Facebook Github Bot 9
parent 654e4bed2e
commit b7bf24bc7f

View File

@ -18,6 +18,7 @@ import java.util.Map;
import android.graphics.Bitmap;
import android.os.Build;
import android.text.TextUtils;
import android.webkit.GeolocationPermissions;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.webkit.WebChromeClient;
@ -259,7 +260,12 @@ public class ReactWebViewManager extends SimpleViewManager<WebView> {
@Override
protected WebView createViewInstance(ThemedReactContext reactContext) {
ReactWebView webView = new ReactWebView(reactContext);
webView.setWebChromeClient(new WebChromeClient());
webView.setWebChromeClient(new WebChromeClient() {
@Override
public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback) {
callback.invoke(origin, true, false);
}
});
reactContext.addLifecycleEventListener(webView);
mWebViewConfig.configWebView(webView);
webView.getSettings().setBuiltInZoomControls(true);