Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
R
react-native-learning
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Shahzad Bhatti
react-native-learning
Commits
fce2c627
Commit
fce2c627
authored
Feb 27, 2023
by
Shahzad Bhatti
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test google sign in working
parent
98f3aef8
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
53 additions
and
19 deletions
+53
-19
Background.js
src/components/Background.js
+10
-2
Cart.js
src/components/screens/Cart.js
+16
-6
ProductDetail.js
src/components/screens/ProductDetail.js
+16
-4
AuthStack.js
src/navigation/AuthStack.js
+11
-7
No files found.
src/components/Background.js
View file @
fce2c627
import
React
from
'react'
;
import
React
from
'react'
;
import
{
View
}
from
'react-native'
;
import
{
StyleSheet
,
View
}
from
'react-native'
;
const
Background
=
({
children
})
=>
{
const
Background
=
({
children
})
=>
{
return
<
View
style
=
{
{
position
:
'absolute'
,
padding
:
16
}
}
>
{
children
}
<
/View>
;
return
<
View
style
=
{
styles
.
rootContainer
}
>
{
children
}
<
/View>
;
};
};
const
styles
=
StyleSheet
.
create
({
rootContainer
:
{
flex
:
1
,
position
:
'absolute'
,
padding
:
16
,
},
});
export
default
Background
;
export
default
Background
;
src/components/screens/Cart.js
View file @
fce2c627
import
React
,
{
useContext
,
useState
}
from
'react'
;
import
React
,
{
useContext
,
useState
}
from
'react'
;
import
{
View
,
Text
,
StyleSheet
,
Button
,
Image
}
from
'react-native'
;
import
{
View
,
Text
,
StyleSheet
,
Button
,
Image
}
from
'react-native'
;
import
{
Colors
}
from
'../../constants/Constants'
;
import
{
CartContext
}
from
'../../store/CartContext'
;
import
{
CartContext
}
from
'../../store/CartContext'
;
const
CartItem
=
({
item
})
=>
{
const
CartItem
=
({
item
})
=>
{
const
{
removeFromCart
,
updateQuantity
}
=
useContext
(
CartContext
);
const
{
removeFromCart
,
updateQuantity
}
=
useContext
(
CartContext
);
...
@@ -14,8 +14,6 @@ const CartItem = ({item}) => {
...
@@ -14,8 +14,6 @@ const CartItem = ({item}) => {
updateQuantity
(
item
.
product
,
newQuantity
);
updateQuantity
(
item
.
product
,
newQuantity
);
};
};
// setTotal(total + (item.product.price * item.quantity));
return
(
return
(
<
View
style
=
{
styles
.
itemContainer
}
>
<
View
style
=
{
styles
.
itemContainer
}
>
<
View
style
=
{
styles
.
imageContainer
}
>
<
View
style
=
{
styles
.
imageContainer
}
>
...
@@ -26,13 +24,14 @@ const CartItem = ({item}) => {
...
@@ -26,13 +24,14 @@ const CartItem = ({item}) => {
<
Text
style
=
{
styles
.
price
}
>
{
item
.
product
.
price
}
<
/Text
>
<
Text
style
=
{
styles
.
price
}
>
{
item
.
product
.
price
}
<
/Text
>
<
/View
>
<
/View
>
<
View
style
=
{
styles
.
qtyContainer
}
>
<
View
style
=
{
styles
.
qtyContainer
}
>
<
Button
title
=
"
-
"
onPress
=
{
handleRemoveFromCart
}
/
>
<
Button
title
=
"
X
"
onPress
=
{
handleRemoveFromCart
}
/
>
<
Button
<
Button
title
=
"-"
title
=
"-"
onPress
=
{()
=>
handleUpdateQuantity
(
item
.
quantity
-
1
)}
onPress
=
{()
=>
handleUpdateQuantity
(
item
.
quantity
-
1
)}
/
>
/
>
<
Text
>
{
item
.
product
.
quantity
}
<
/Text
>
<
Text
>
{
item
.
product
.
quantity
}
<
/Text
>
<
Button
<
Button
style
=
{
styles
.
inc_dec_btn
}
title
=
"+"
title
=
"+"
onPress
=
{()
=>
handleUpdateQuantity
(
item
.
quantity
+
1
)}
onPress
=
{()
=>
handleUpdateQuantity
(
item
.
quantity
+
1
)}
/
>
/
>
...
@@ -43,14 +42,21 @@ const CartItem = ({item}) => {
...
@@ -43,14 +42,21 @@ const CartItem = ({item}) => {
const
Cart
=
()
=>
{
const
Cart
=
()
=>
{
const
{
cart
}
=
useContext
(
CartContext
);
const
{
cart
}
=
useContext
(
CartContext
);
const
[
total
,
setTotal
]
=
useState
(
0
);
const
calculateTotalPrice
=
()
=>
{
let
total
=
0
;
cart
.
map
(
item
=>
{
total
+=
parseFloat
(
item
.
product
.
price
)
*
parseInt
(
item
.
product
.
quantity
);
});
return
parseFloat
(
total
);
};
return
(
return
(
<
View
style
=
{
styles
.
cartContiner
}
>
<
View
style
=
{
styles
.
cartContiner
}
>
{
cart
.
map
(
item
=>
(
{
cart
.
map
(
item
=>
(
<
CartItem
key
=
{
item
.
product
.
id
}
item
=
{
item
}
/
>
<
CartItem
key
=
{
item
.
product
.
id
}
item
=
{
item
}
/
>
))}
))}
<
Text
style
=
{
styles
.
title
}
>
Total
<
/Text
>
<
Text
style
=
{
styles
.
title
}
>
Total
:
{
calculateTotalPrice
()}
<
/Text
>
<
/View
>
<
/View
>
);
);
};
};
...
@@ -101,6 +107,10 @@ const styles = StyleSheet.create({
...
@@ -101,6 +107,10 @@ const styles = StyleSheet.create({
fontSize
:
14
,
fontSize
:
14
,
color
:
'#888'
,
color
:
'#888'
,
},
},
inc_dec_btn
:
{
borderRadius
:
25
,
backgroundColor
:
Colors
.
primary500
,
},
});
});
export
default
Cart
;
export
default
Cart
;
src/components/screens/ProductDetail.js
View file @
fce2c627
import
React
,
{
useContext
,
useState
}
from
'react'
;
import
React
,
{
useContext
,
useState
}
from
'react'
;
import
{
View
,
Text
,
Image
,
Button
,
StyleSheet
}
from
'react-native'
;
import
{
View
,
Text
,
Image
,
Button
,
StyleSheet
,
TouchableOpacity
}
from
'react-native'
;
import
{
useNavigation
}
from
'@react-navigation/native'
;
import
{
useNavigation
}
from
'@react-navigation/native'
;
import
{
CartContext
}
from
'../../store/CartContext'
;
import
{
CartContext
}
from
'../../store/CartContext'
;
import
FlatButton
from
'../ui/FlatButton'
;
import
{
Colors
}
from
'../../constants/Constants'
;
const
ProductDetail
=
porps
=>
{
const
ProductDetail
=
porps
=>
{
const
item
=
porps
.
route
.
params
.
item
;
const
item
=
porps
.
route
.
params
.
item
;
...
@@ -56,8 +57,12 @@ const ProductDetail = porps => {
...
@@ -56,8 +57,12 @@ const ProductDetail = porps => {
flexDirection
:
'row'
,
flexDirection
:
'row'
,
justifyContent
:
'space-evenly'
,
justifyContent
:
'space-evenly'
,
}}
>
}}
>
<
FlatButton
onPress
=
{
handleBuyNow
}
>
Buy
Now
<
/FlatButton
>
<
TouchableOpacity
style
=
{
styles
.
btnBuy
}
onPress
=
{
handleBuyNow
}
>
<
FlatButton
onPress
=
{
handleAddToCart
}
>
Add
to
Cart
<
/FlatButton
>
<
Text
>
Buy
Now
<
/Text
>
<
/TouchableOpacity
>
<
TouchableOpacity
onPress
=
{
handleAddToCart
}
>
<
Text
>
Add
to
Cart
<
/Text
>
<
/TouchableOpacity
>
<
/View
>
<
/View
>
<
/View
>
<
/View
>
<
/View
>
<
/View
>
...
@@ -65,11 +70,18 @@ const ProductDetail = porps => {
...
@@ -65,11 +70,18 @@ const ProductDetail = porps => {
};
};
const
styles
=
StyleSheet
.
create
({
const
styles
=
StyleSheet
.
create
({
btnBuy
:
{
// backgroundColor: Colors.primary100,
// borderRadius: 100,
alignItems
:
'center'
,
width
:
80
,
},
container
:
{
container
:
{
flex
:
1
,
flex
:
1
,
alignItems
:
'center'
,
alignItems
:
'center'
,
justifyContent
:
'center'
,
justifyContent
:
'center'
,
padding
:
1
,
padding
:
1
,
background
:
'linear-gradient(to bottom right, #ccc, #red)'
,
},
},
productContainer
:
{
productContainer
:
{
flex
:
1
,
flex
:
1
,
...
...
src/navigation/AuthStack.js
View file @
fce2c627
import
React
,
{
useContext
}
from
'react'
;
import
React
,
{
useContext
}
from
'react'
;
import
{
NavigationContainer
}
from
'@react-navigation/native'
;
import
{
NavigationContainer
,
useNavigation
}
from
'@react-navigation/native'
;
import
{
createNativeStackNavigator
}
from
'@react-navigation/native-stack'
;
import
{
createNativeStackNavigator
}
from
'@react-navigation/native-stack'
;
import
Cart
from
'../components/screens/Cart'
;
import
Cart
from
'../components/screens/Cart'
;
import
MedicineList
from
'../components/screens/MedicineList'
;
import
MedicineList
from
'../components/screens/MedicineList'
;
...
@@ -41,12 +41,16 @@ export default function AuthStack() {
...
@@ -41,12 +41,16 @@ export default function AuthStack() {
component
=
{
ProductDetail
}
component
=
{
ProductDetail
}
options
=
{{
options
=
{{
title
:
'Product Detail'
,
title
:
'Product Detail'
,
headerRight
:
()
=>
(
headerRight
:
()
=>
{
<
Icon
return
(
name
=
"shopping-cart"
<
Icon
size
=
{
30
}
onPress
=
{
authCtx
.
logout
}
color
=
{
Colors
.
primary500
}
><
/Icon
>
// name="shopping-cart"
),
name
=
"sign-out"
size
=
{
30
}
color
=
{
Colors
.
primary500
}
><
/Icon
>
);
},
}}
}}
/
>
/
>
<
Stack
.
Screen
name
=
"Cart"
component
=
{
Cart
}
/
>
<
Stack
.
Screen
name
=
"Cart"
component
=
{
Cart
}
/
>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment