-
Notifications
You must be signed in to change notification settings - Fork 204
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Separated callbacks to onSuccess onFailure, modified native impl acco…
…rdingly
- Loading branch information
Showing
16 changed files
with
245 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,3 +57,6 @@ buck-out/ | |
|
||
# CocoaPods | ||
/ios/Pods/ | ||
|
||
#Secrets | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,16 @@ | ||
module.exports = { | ||
presets: ['module:metro-react-native-babel-preset'], | ||
}; | ||
presets: ["module:metro-react-native-babel-preset"], | ||
plugins: [ | ||
[ | ||
"module:react-native-dotenv", | ||
{ | ||
moduleName: "@env", | ||
path: ".env", | ||
blacklist: null, | ||
whitelist: null, | ||
safe: false, | ||
allowUndefined: true, | ||
}, | ||
], | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,105 @@ | ||
/* @flow weak */ | ||
|
||
import React from 'react'; | ||
import {View, Text, StyleSheet, ScrollView} from 'react-native'; | ||
import {ListItem, Avatar, Button} from 'react-native-elements' | ||
import {View, Text, StyleSheet, ScrollView, Alert} from 'react-native'; | ||
import {ListItem, Avatar, Button} from 'react-native-elements'; | ||
//import {InAppPurchase} from 'react-native-iap'; | ||
|
||
const Cart = ({route, navigation}) => { | ||
const {productList, removeProductFromCart, checkout} = route.params; | ||
const {productList, removeProductFromCart, checkout} = route.params; | ||
|
||
/* | ||
const productIds = [ | ||
'one1', | ||
'non.cons2', | ||
'auto.renew', | ||
'non.renew', | ||
'cons.test', | ||
'nonconsumable.purchase1', | ||
'autorenewable.purchase1', | ||
'nonrenewing.purchase1', | ||
]; | ||
const handleRemove = product => { | ||
removeProductFromCart(product); | ||
navigation.goBack(); | ||
} | ||
InAppPurchase.getProducts(productIds) | ||
.then(products => { | ||
console.log('Products:', products); | ||
}) | ||
.catch(error => { | ||
console.log('Error fetching products:', error); | ||
}); | ||
*/ | ||
|
||
const handleRemove = product => { | ||
removeProductFromCart(product); | ||
navigation.goBack(); | ||
}; | ||
|
||
const handleCheckout = () => { | ||
if (productList.length !== 0) { | ||
checkout(); | ||
navigation.goBack(); | ||
} | ||
} | ||
const handleCheckout = () => { | ||
if (productList.length !== 0) { | ||
checkout(); | ||
navigation.goBack(); | ||
} else { | ||
Alert.alert( | ||
'Cart Empty', // Alert Title | ||
'The cart is empty.', // Alert Message | ||
[ | ||
{ | ||
text: 'OK', | ||
onPress: () => console.log('OK Pressed'), | ||
style: 'cancel', | ||
}, | ||
], | ||
{ | ||
cancelable: true, // whether the alert can be dismissed by tapping outside of the alert box | ||
onDismiss: () => console.log('Alert dismissed'), // a callback that gets called when the alert is dismissed | ||
}, | ||
); | ||
} | ||
}; | ||
|
||
return (<View style={styles.container}> | ||
return ( | ||
<View style={styles.container}> | ||
<ScrollView> | ||
{ | ||
productList.map((product, index) => { | ||
return (<ListItem.Swipeable key={index} bottomDivider="bottomDivider" rightContent={<Button title = "Delete" buttonStyle = {{ minHeight: '100%', backgroundColor: 'red' }}onPress = { | ||
() => handleRemove(product) | ||
} | ||
/>}> | ||
<Avatar source={{ | ||
uri: product.image | ||
}}/> | ||
<ListItem.Content> | ||
<ListItem.Title>{product.name}</ListItem.Title> | ||
<ListItem.Subtitle>{`${product.price} USD`}</ListItem.Subtitle> | ||
</ListItem.Content> | ||
</ListItem.Swipeable>) | ||
}) | ||
} | ||
{productList.map((product, index) => { | ||
return ( | ||
<ListItem.Swipeable | ||
key={index} | ||
bottomDivider="bottomDivider" | ||
rightContent={ | ||
<Button | ||
title="Delete" | ||
buttonStyle={{minHeight: '100%', backgroundColor: 'red'}} | ||
onPress={() => handleRemove(product)} | ||
/> | ||
}> | ||
<Avatar | ||
source={{ | ||
uri: product.image, | ||
}} | ||
/> | ||
<ListItem.Content> | ||
<ListItem.Title>{product.name}</ListItem.Title> | ||
<ListItem.Subtitle>{`${product.price} USD`}</ListItem.Subtitle> | ||
</ListItem.Content> | ||
</ListItem.Swipeable> | ||
); | ||
})} | ||
</ScrollView> | ||
<Button buttonStyle={styles.checkoutButton} title='Checkout'onPress={handleCheckout}/> | ||
</View>); | ||
} | ||
<Button | ||
buttonStyle={styles.checkoutButton} | ||
title="Checkout" | ||
onPress={handleCheckout} | ||
/> | ||
</View> | ||
); | ||
}; | ||
export default Cart; | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
flex: 1 | ||
}, | ||
checkoutButton: { | ||
marginBottom: 10 | ||
} | ||
container: { | ||
flex: 1, | ||
}, | ||
checkoutButton: { | ||
height: 75, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.