From 3d71935eb7c7e44a37800f418cf423fb5c1a3e7a Mon Sep 17 00:00:00 2001 From: pinpong Date: Sat, 30 Nov 2024 12:31:01 +0100 Subject: [PATCH 1/3] fix: Tried to register two views with the same name GooglePayButton --- src/GooglePayButton.jsx | 92 ++++++++++++++++++++++++----------------- 1 file changed, 53 insertions(+), 39 deletions(-) diff --git a/src/GooglePayButton.jsx b/src/GooglePayButton.jsx index 23a647c..b9f198d 100644 --- a/src/GooglePayButton.jsx +++ b/src/GooglePayButton.jsx @@ -14,50 +14,64 @@ * limitations under the License. */ -import * as React from 'react' -import {NativeModules, requireNativeComponent, TouchableOpacity, StyleSheet} from 'react-native' +import * as React from 'react'; +import { + NativeModules, + requireNativeComponent, + TouchableOpacity, + StyleSheet, + UIManager, +} from 'react-native'; -const NativeGooglePayButton = requireNativeComponent('GooglePayButton') +const ComponentName = 'GooglePayButton'; +const NativeGooglePayButton = + UIManager.getViewManagerConfig(ComponentName) != null + ? requireNativeComponent(ComponentName) + : () => { + throw new Error( + `The package 'react-native-make-payment' doesn't seem to be linked.` + ); + }; -const GooglePayButtonConstants = NativeModules.GooglePayButtonConstants?.getConstants(); +const GooglePayButtonConstants = + NativeModules.GooglePayButtonConstants?.getConstants(); const GooglePayButton = ({ - onPress, - disabled, - allowedPaymentMethods, - theme, - type, - radius, - style - }) => { - return ( - - - - - ); - }; + onPress, + disabled, + allowedPaymentMethods, + theme, + type, + radius, + style, +}) => { + return ( + + + + ); +}; const styles = StyleSheet.create({ - disabled: { - flex: 0, - opacity: 0.4, - }, - notDisabled: { - flex: 0, - }, - nativeButtonStyle: { flex: 1 }, + disabled: { + flex: 0, + opacity: 0.4, + }, + notDisabled: { + flex: 0, + }, + nativeButtonStyle: { flex: 1 }, }); -module.exports = { GooglePayButton, GooglePayButtonConstants }; \ No newline at end of file +module.exports = { GooglePayButton, GooglePayButtonConstants }; From 5ea390b7eba3b67c584ca73857a9c2a2c5f39ebe Mon Sep 17 00:00:00 2001 From: pinpong Date: Sat, 30 Nov 2024 12:32:16 +0100 Subject: [PATCH 2/3] chore: prettier --- README.md | 4 +++- example/src/App.jsx | 15 +++++++++------ src/index.jsx | 5 ++++- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 9fb75ae..aab83c2 100644 --- a/README.md +++ b/README.md @@ -82,6 +82,7 @@ paymentRequest.canMakePayment().then((canMakePayment) => { ``` ### Google Pay Button + Example of adding a native Google Pay button: ```xml @@ -91,5 +92,6 @@ Example of adding a native Google Pay button: allowedPaymentMethods={googlePayRequest.allowedPaymentMethods} theme={GooglePayButtonConstants.Themes.Dark} type={GooglePayButtonConstants.Types.Buy} - radius={4} + radius={4} /> +``` diff --git a/example/src/App.jsx b/example/src/App.jsx index e74d834..2212dfe 100644 --- a/example/src/App.jsx +++ b/example/src/App.jsx @@ -16,7 +16,11 @@ import React, { useState } from 'react'; import { Text, StyleSheet, ScrollView } from 'react-native'; -import { PaymentRequest, GooglePayButton, GooglePayButtonConstants } from '@google/react-native-make-payment'; +import { + PaymentRequest, + GooglePayButton, + GooglePayButtonConstants, +} from '@google/react-native-make-payment'; const paymentDetails = { total: { @@ -116,7 +120,7 @@ export default function App() { scrollView: { flexGrow: 1, justifyContent: 'center', - alignItems: 'center' + alignItems: 'center', }, googlepaybutton: { height: 100, @@ -124,21 +128,20 @@ export default function App() { }, }); - return ( + return ( - {/* Showing the Google Pay button in any case. You might want to do a paymentRequest.canMakePayment() check upfront and only conditionally show the button - */} + */} {text} diff --git a/src/index.jsx b/src/index.jsx index 2dfdbdd..a8654b8 100644 --- a/src/index.jsx +++ b/src/index.jsx @@ -38,7 +38,10 @@ class PaymentRequest { this.#version = pkg.version; } catch (_) {} - if (this.paymentMethods[GOOGLE_PAY_PMI] && !this.paymentMethods[GOOGLE_PAY_PMI].merchantInfo.softwareInfo) { + if ( + this.paymentMethods[GOOGLE_PAY_PMI] && + !this.paymentMethods[GOOGLE_PAY_PMI].merchantInfo.softwareInfo + ) { this.paymentMethods[GOOGLE_PAY_PMI].merchantInfo.softwareInfo = { id: this.#name.split('/').pop(), version: this.#version, From 958ee0feab888ebf76acc7613aec6bcdac76539a Mon Sep 17 00:00:00 2001 From: pinpong Date: Sat, 30 Nov 2024 14:26:17 +0100 Subject: [PATCH 3/3] getViewManagerConfig --- src/GooglePayButton.jsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/GooglePayButton.jsx b/src/GooglePayButton.jsx index b9f198d..d5569e6 100644 --- a/src/GooglePayButton.jsx +++ b/src/GooglePayButton.jsx @@ -33,8 +33,10 @@ const NativeGooglePayButton = ); }; -const GooglePayButtonConstants = - NativeModules.GooglePayButtonConstants?.getConstants(); +export const GooglePayButtonConstants = + NativeModules.GooglePayButtonConstants.getViewManagerConfig?.( + 'getConstants' + ) ?? NativeModules.GooglePayButtonConstants.getConstants?.(); const GooglePayButton = ({ onPress,