Skip to content

Commit 7872dfe

Browse files
authored
Merge pull request #69 from MetaMask/chore/cherry-pick-android-payment-api
2 parents 153c60b + f766685 commit 7872dfe

File tree

11 files changed

+101
-3
lines changed

11 files changed

+101
-3
lines changed

android/gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
ReactNativeWebView_kotlinVersion=1.6.0
2-
ReactNativeWebView_webkitVersion=1.4.0
2+
ReactNativeWebView_webkitVersion=1.14.0
33
ReactNativeWebView_compileSdkVersion=31
44
ReactNativeWebView_targetSdkVersion=31
55
ReactNativeWebView_minSdkVersion=21

android/src/main/AndroidManifest.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
22
package="com.reactnativecommunity.webview">
33

4+
<queries>
5+
<intent>
6+
<action android:name="org.chromium.intent.action.PAY"/>
7+
</intent>
8+
<intent>
9+
<action android:name="org.chromium.intent.action.IS_READY_TO_PAY"/>
10+
</intent>
11+
<intent>
12+
<action android:name="org.chromium.intent.action.UPDATE_PAYMENT_DETAILS"/>
13+
</intent>
14+
</queries>
15+
416
<application>
517
<provider
618
android:name=".RNCWebViewFileProvider"

android/src/main/AndroidManifestNew.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,17 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
2+
3+
<queries>
4+
<intent>
5+
<action android:name="org.chromium.intent.action.PAY"/>
6+
</intent>
7+
<intent>
8+
<action android:name="org.chromium.intent.action.IS_READY_TO_PAY"/>
9+
</intent>
10+
<intent>
11+
<action android:name="org.chromium.intent.action.UPDATE_PAYMENT_DETAILS"/>
12+
</intent>
13+
</queries>
14+
215
<application>
316
<provider
417
android:name=".RNCWebViewFileProvider"

android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManagerImpl.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,4 +761,11 @@ class RNCWebViewManagerImpl(private val newArch: Boolean = false) {
761761
fun setWebviewDebuggingEnabled(viewWrapper: RNCWebViewWrapper, enabled: Boolean) {
762762
RNCWebView.setWebContentsDebuggingEnabled(enabled)
763763
}
764+
765+
fun setPaymentRequestEnabled(viewWrapper: RNCWebViewWrapper, enabled: Boolean) {
766+
val view = viewWrapper.webView
767+
if (WebViewFeature.isFeatureSupported(WebViewFeature.PAYMENT_REQUEST)) {
768+
WebSettingsCompat.setPaymentRequestEnabled(view.settings, enabled)
769+
}
770+
}
764771
}

android/src/newarch/com/reactnativecommunity/webview/RNCWebViewManager.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,12 @@ public void setWebviewDebuggingEnabled(RNCWebViewWrapper view, boolean value) {
331331
mRNCWebViewManagerImpl.setWebviewDebuggingEnabled(view, value);
332332
}
333333

334+
@Override
335+
@ReactProp(name = "paymentRequestEnabled")
336+
public void setPaymentRequestEnabled(RNCWebViewWrapper view, boolean value) {
337+
mRNCWebViewManagerImpl.setPaymentRequestEnabled(view, value);
338+
}
339+
334340
/* iOS PROPS - no implemented here */
335341
@Override
336342
public void setAllowingReadAccessToURL(RNCWebViewWrapper view, @Nullable String value) {}

android/src/oldarch/com/reactnativecommunity/webview/RNCWebViewManager.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,11 @@ public void setUserAgent(RNCWebViewWrapper view, @Nullable String value) {
273273
mRNCWebViewManagerImpl.setUserAgent(view, value);
274274
}
275275

276+
@ReactProp(name = "paymentRequestEnabled")
277+
public void setPaymentRequestEnabled(RNCWebViewWrapper view, boolean value) {
278+
mRNCWebViewManagerImpl.setPaymentRequestEnabled(view, value);
279+
}
280+
276281
@Override
277282
protected void addEventEmitters(@NonNull ThemedReactContext reactContext, RNCWebViewWrapper viewWrapper) {
278283
// Do not register default touch emitter and let WebView implementation handle touches

docs/Reference.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ This document lays out the current public properties and methods for the React N
9393
- [`lackPermissionToDownloadMessage`](Reference.md#lackPermissionToDownloadMessage)
9494
- [`allowsProtectedMedia`](Reference.md#allowsProtectedMedia)
9595
- [`webviewDebuggingEnabled`](Reference.md#webviewDebuggingEnabled)
96+
- [`paymentRequestEnabled`](Reference.md#paymentRequestEnabled)
9697

9798
## Methods Index
9899

@@ -1026,8 +1027,8 @@ Boolean value that indicates whether HTML5 videos can play Picture in Picture. T
10261027

10271028
> **NOTE**
10281029
>
1029-
> In order to restrict playing video in picture in picture mode this props need to be set to `false`
1030-
.
1030+
> In order to restrict playing video in picture in picture mode this props need to be set to `false`.
1031+
10311032
| Type | Required | Platform |
10321033
| ---- | -------- | -------- |
10331034
| bool | No | iOS |
@@ -1718,6 +1719,15 @@ Default is `false`. Supported on iOS as of 16.4, previous versions always allow
17181719
| ------- | -------- | -------- |
17191720
| boolean | No | iOS & Android |
17201721

1722+
### `paymentRequestEnabled`[](#props-index)
1723+
1724+
Whether or not the webview has the Payment Request API enabled. Default is `false`.
1725+
This is needed for Google Pay to work within the WebView.
1726+
1727+
| Type | Required | Platform |
1728+
| ------- | -------- | -------- |
1729+
| boolean | No | Android |
1730+
17211731
## Methods
17221732

17231733
### `goForward()`[](#methods-index)

example/App.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import Messaging from './examples/Messaging';
2121
import MultiMessaging from './examples/MultiMessaging';
2222
import NativeWebpage from './examples/NativeWebpage';
2323
import ApplePay from './examples/ApplePay';
24+
import GooglePay from './examples/GooglePay';
2425
import CustomMenu from './examples/CustomMenu';
2526
import OpenWindow from './examples/OpenWindow';
2627
import SuppressMenuItems from './examples/Suppress';
@@ -123,6 +124,14 @@ const TESTS = {
123124
return <ApplePay />;
124125
},
125126
},
127+
GooglePay: {
128+
title: 'Google Pay ',
129+
testId: 'GooglePay',
130+
description: 'Test to open a Google Pay supported page',
131+
render() {
132+
return <GooglePay />;
133+
},
134+
},
126135
CustomMenu: {
127136
title: 'Custom Menu',
128137
testId: 'CustomMenu',
@@ -250,6 +259,13 @@ export default class App extends Component<Props, State> {
250259
onPress={() => this._changeTest('ApplePay')}
251260
/>
252261
)}
262+
{Platform.OS === 'android' && (
263+
<Button
264+
testID="testType_googlePay"
265+
title="GooglePay"
266+
onPress={() => this._changeTest('GooglePay')}
267+
/>
268+
)}
253269
<Button
254270
testID="testType_customMenu"
255271
title="CustomMenu"

example/examples/GooglePay.tsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import React, {Component} from 'react';
2+
import {View} from 'react-native';
3+
4+
import WebView from 'react-native-webview';
5+
6+
type Props = {};
7+
type State = {};
8+
9+
export default class Alerts extends Component<Props, State> {
10+
state = {};
11+
12+
render() {
13+
return (
14+
<View style={{ flex: 1 }}>
15+
<WebView
16+
source={{uri: "https://rsolomakhin.github.io/pr/gp2-test"}}
17+
paymentRequestEnabled={true}
18+
/>
19+
</View>
20+
);
21+
}
22+
}

src/RNCWebViewNativeComponent.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ export interface NativeProps extends ViewProps {
292292
}>;
293293
userAgent?: string;
294294
injectedJavaScriptObject?: string;
295+
paymentRequestEnabled?: boolean;
295296
}
296297

297298
export interface NativeCommands {

0 commit comments

Comments
 (0)