1- import { StyleSheet , Pressable } from 'react-native' ;
1+ import { StyleSheet , Pressable , View } from 'react-native' ;
22import type { ViewProps , StyleProp , ViewStyle } from 'react-native' ;
3+ import type { ReactNode } from 'react' ;
34import GooglePayButtonComponent from './specs/NativeGooglePayButtonComponent' ;
45import GooglePayButtonConstantsModule from './specs/NativeGooglePayButtonConstantsModule' ;
5- import type { GooglePayPaymentMethod } from './specs/NativeGooglePayButtonComponent'
6+ import type { GooglePayPaymentMethod } from './specs/NativeGooglePayButtonComponent' ;
7+ import { Loader } from './Loader' ;
8+
9+ const GooglePayButtonConstants =
10+ GooglePayButtonConstantsModule ?. loadConstants ( ) ;
611
712export interface Props extends ViewProps {
813 allowedPaymentMethods : GooglePayPaymentMethod [ ] ;
@@ -12,6 +17,8 @@ export interface Props extends ViewProps {
1217 onPress : ( ) => void ;
1318 disabled : boolean ;
1419 style : StyleProp < ViewStyle > ;
20+ loading ?: boolean ;
21+ loader ?: ReactNode ;
1522}
1623
1724const GooglePayButton = ( {
@@ -22,13 +29,15 @@ const GooglePayButton = ({
2229 type,
2330 radius,
2431 style,
32+ loading,
33+ loader,
2534} : Props ) => {
2635 return (
2736 < Pressable
2837 onPress = { onPress }
29- disabled = { disabled }
38+ disabled = { disabled || loading }
3039 style = { [
31- disabled ? styles . disabled : styles . enabled ,
40+ disabled || loading ? styles . disabled : styles . enabled ,
3241 styles . overridable ,
3342 style ,
3443 styles . fixed ,
@@ -40,8 +49,13 @@ const GooglePayButton = ({
4049 type = { type }
4150 theme = { theme }
4251 radius = { radius }
43- style = { [ styles . button , styles . nobg ] }
52+ style = { [ styles . button , styles . nobg , loading && styles . hidden ] }
4453 />
54+ { loading && (
55+ < View style = { styles . loaderContainer } >
56+ { loader || < Loader theme = { theme } /> }
57+ </ View >
58+ ) }
4559 </ Pressable >
4660 ) ;
4761} ;
@@ -67,8 +81,14 @@ const styles = StyleSheet.create({
6781 nobg : {
6882 backgroundColor : 'rgba(0, 0, 0, 0)' ,
6983 } ,
84+ hidden : {
85+ opacity : 0 ,
86+ } ,
87+ loaderContainer : {
88+ ...StyleSheet . absoluteFillObject ,
89+ justifyContent : 'center' ,
90+ alignItems : 'center' ,
91+ } ,
7092} ) ;
7193
72- const GooglePayButtonConstants = GooglePayButtonConstantsModule ?. loadConstants ( ) ;
73-
7494export { GooglePayButton , GooglePayButtonConstants } ;
0 commit comments