Skip to content

Commit

Permalink
Add navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
danielmark0116 committed Mar 27, 2020
1 parent ac1df86 commit 80c2add
Show file tree
Hide file tree
Showing 9 changed files with 663 additions and 50 deletions.
75 changes: 28 additions & 47 deletions App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,61 +7,42 @@
*
* @format
*/

import React, {useState, useEffect} from 'react';
import {StyleSheet, StatusBar} from 'react-native';
import {ApplicationProvider, Layout, Text, Button} from '@ui-kitten/components';
import 'react-native-gesture-handler';
import React from 'react';
import {StatusBar, SafeAreaView, StyleSheet} from 'react-native';
import {ApplicationProvider, Layout} from '@ui-kitten/components';
import {mapping, dark as darkTheme} from '@eva-design/eva';
import {getUser, updateUser} from './src/data/Api';
import {UserData} from './src/types/UserData.types';

const App = () => {
const [user, setUser] = useState<UserData | null>(null);
import {NavigationContainer} from '@react-navigation/native';
import {createStackNavigator} from '@react-navigation/stack';
import Home from './src/screens/Home';
import FormName from './src/screens/FormName';
import FormAddress from './src/screens/FormAddress';
import FormPayment from './src/screens/FormPayment';

useEffect(() => {
console.log(user);
}, [user]);

const fetchData = async () => {
setUser(user ? await getUser({...user}) : await getUser());
};

const updateData = async () => {
if (user) {
setUser(await updateUser({...user, name: 'Kathy'}));
}
};
const Stack = createStackNavigator();

const App = () => {
return (
<ApplicationProvider mapping={mapping} theme={darkTheme}>
<StatusBar barStyle="light-content" />
<Layout style={styles.container}>
<Text category="h1">Form App</Text>
<Button
size="large"
appearance="ghost"
status="basic"
onPress={fetchData}>
Get user
</Button>
<Button
size="large"
appearance="ghost"
status="success"
onPress={updateData}>
Update user
</Button>
</Layout>
</ApplicationProvider>
<NavigationContainer>
<ApplicationProvider mapping={mapping} theme={darkTheme}>
<Layout style={styles.wrapper}>
<SafeAreaView style={styles.wrapper}>
<StatusBar barStyle="light-content" />
<Stack.Navigator screenOptions={{headerShown: false}}>
<Stack.Screen name="Home" component={Home} />
<Stack.Screen name="FormName" component={FormName} />
<Stack.Screen name="FormAddress" component={FormAddress} />
<Stack.Screen name="FormPayment" component={FormPayment} />
</Stack.Navigator>
</SafeAreaView>
</Layout>
</ApplicationProvider>
</NavigationContainer>
);
};

const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
wrapper: {flex: 1},
});

export default App;
30 changes: 30 additions & 0 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ PODS:
- React-cxxreact (= 0.61.5)
- React-jsi (= 0.61.5)
- React-jsinspector (0.61.5)
- react-native-safe-area-context (0.7.3):
- React
- React-RCTActionSheet (0.61.5):
- React-Core/RCTActionSheetHeaders (= 0.61.5)
- React-RCTAnimation (0.61.5):
Expand Down Expand Up @@ -217,6 +219,14 @@ PODS:
- React-cxxreact (= 0.61.5)
- React-jsi (= 0.61.5)
- ReactCommon/jscallinvoker (= 0.61.5)
- RNCMaskedView (0.1.7):
- React
- RNGestureHandler (1.6.1):
- React
- RNReanimated (1.7.1):
- React
- RNScreens (2.4.0):
- React
- RNSVG (12.0.3):
- React
- Yoga (1.14.0)
Expand All @@ -238,6 +248,7 @@ DEPENDENCIES:
- React-jsi (from `../node_modules/react-native/ReactCommon/jsi`)
- React-jsiexecutor (from `../node_modules/react-native/ReactCommon/jsiexecutor`)
- React-jsinspector (from `../node_modules/react-native/ReactCommon/jsinspector`)
- react-native-safe-area-context (from `../node_modules/react-native-safe-area-context`)
- React-RCTActionSheet (from `../node_modules/react-native/Libraries/ActionSheetIOS`)
- React-RCTAnimation (from `../node_modules/react-native/Libraries/NativeAnimation`)
- React-RCTBlob (from `../node_modules/react-native/Libraries/Blob`)
Expand All @@ -249,6 +260,10 @@ DEPENDENCIES:
- React-RCTVibration (from `../node_modules/react-native/Libraries/Vibration`)
- ReactCommon/jscallinvoker (from `../node_modules/react-native/ReactCommon`)
- ReactCommon/turbomodule/core (from `../node_modules/react-native/ReactCommon`)
- "RNCMaskedView (from `../node_modules/@react-native-community/masked-view`)"
- RNGestureHandler (from `../node_modules/react-native-gesture-handler`)
- RNReanimated (from `../node_modules/react-native-reanimated`)
- RNScreens (from `../node_modules/react-native-screens`)
- RNSVG (from `../node_modules/react-native-svg`)
- Yoga (from `../node_modules/react-native/ReactCommon/yoga`)

Expand Down Expand Up @@ -285,6 +300,8 @@ EXTERNAL SOURCES:
:path: "../node_modules/react-native/ReactCommon/jsiexecutor"
React-jsinspector:
:path: "../node_modules/react-native/ReactCommon/jsinspector"
react-native-safe-area-context:
:path: "../node_modules/react-native-safe-area-context"
React-RCTActionSheet:
:path: "../node_modules/react-native/Libraries/ActionSheetIOS"
React-RCTAnimation:
Expand All @@ -305,6 +322,14 @@ EXTERNAL SOURCES:
:path: "../node_modules/react-native/Libraries/Vibration"
ReactCommon:
:path: "../node_modules/react-native/ReactCommon"
RNCMaskedView:
:path: "../node_modules/@react-native-community/masked-view"
RNGestureHandler:
:path: "../node_modules/react-native-gesture-handler"
RNReanimated:
:path: "../node_modules/react-native-reanimated"
RNScreens:
:path: "../node_modules/react-native-screens"
RNSVG:
:path: "../node_modules/react-native-svg"
Yoga:
Expand All @@ -326,6 +351,7 @@ SPEC CHECKSUMS:
React-jsi: cb2cd74d7ccf4cffb071a46833613edc79cdf8f7
React-jsiexecutor: d5525f9ed5f782fdbacb64b9b01a43a9323d2386
React-jsinspector: fa0ecc501688c3c4c34f28834a76302233e29dc0
react-native-safe-area-context: e200d4433aba6b7e60b52da5f37af11f7a0b0392
React-RCTActionSheet: 600b4d10e3aea0913b5a92256d2719c0cdd26d76
React-RCTAnimation: 791a87558389c80908ed06cc5dfc5e7920dfa360
React-RCTBlob: d89293cc0236d9cb0933d85e430b0bbe81ad1d72
Expand All @@ -336,6 +362,10 @@ SPEC CHECKSUMS:
React-RCTText: 9ccc88273e9a3aacff5094d2175a605efa854dbe
React-RCTVibration: a49a1f42bf8f5acf1c3e297097517c6b3af377ad
ReactCommon: 198c7c8d3591f975e5431bec1b0b3b581aa1c5dd
RNCMaskedView: 76c40a1d41c3e2535df09246a2b5487f04de0814
RNGestureHandler: 8f09cd560f8d533eb36da5a6c5a843af9f056b38
RNReanimated: 4e102df74a9674fa943e05f97f3362b6e44d0b48
RNScreens: b5c0e1b2b04512919e78bd3898e144a157ce2363
RNSVG: 7e16ddfc6e00d5aa69c9eb83e699bcce5dcb85d4
Yoga: f2a7cd4280bfe2cca5a7aed98ba0eb3d1310f18b

Expand Down
7 changes: 7 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,16 @@
},
"dependencies": {
"@eva-design/eva": "^1.4.0",
"@react-native-community/masked-view": "^0.1.7",
"@react-navigation/native": "^5.1.3",
"@react-navigation/stack": "^5.2.6",
"@ui-kitten/components": "^4.4.1",
"react": "16.9.0",
"react-native": "0.61.5",
"react-native-gesture-handler": "^1.6.1",
"react-native-reanimated": "^1.7.1",
"react-native-safe-area-context": "^0.7.3",
"react-native-screens": "^2.4.0",
"react-native-svg": "^12.0.3"
},
"devDependencies": {
Expand Down
119 changes: 119 additions & 0 deletions src/screens/FormAddress.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
import React, {useCallback} from 'react';
import {StyleSheet, View, KeyboardAvoidingView, ScrollView} from 'react-native';
import {Layout, Text, Button, Input} from '@ui-kitten/components';
import {theme} from '../utils/Theme';
import {useNavigation} from '@react-navigation/native';

const FormAddress = () => {
const {goBack, navigate} = useNavigation();

const backBtn = useCallback(() => goBack(), [goBack]);
const goNext = useCallback(() => navigate('FormPayment'), [navigate]);

return (
<>
<Layout style={styles.container}>
<Text style={styles.title} category="h2">
Address
</Text>
<KeyboardAvoidingView
keyboardVerticalOffset={theme.spacing.value * 4}
style={[styles.container]}
behavior="height">
<View style={styles.top}>
<ScrollView showsVerticalScrollIndicator={false}>
<View style={styles.form}>
<Input
style={styles.input}
label="Street"
value=""
placeholder="18th Dev Avenue"
onChangeText={() => null}
/>
<Input
style={styles.input}
label="City"
value=""
placeholder="South Dev City"
onChangeText={() => null}
/>
<Input
style={styles.input}
label="Post code"
value=""
placeholder="9932"
onChangeText={() => null}
/>
<Input
style={styles.input}
label="Country"
value=""
placeholder="Devland"
onChangeText={() => null}
/>
</View>
</ScrollView>
</View>
<View style={styles.bottom}>
<Button
style={styles.next}
size="medium"
appearance="ghost"
status="basic"
onPress={backBtn}>
Back
</Button>
<Button
style={styles.next}
size="medium"
appearance="outline"
status="success"
onPress={goNext}>
Next
</Button>
</View>
</KeyboardAvoidingView>
</Layout>
</>
);
};

const styles = StyleSheet.create({
container: {
flex: 1,
},
title: {
paddingHorizontal: theme.spacing.value * 2,
paddingTop: theme.spacing.value * 2,
},
top: {
flex: 20,
width: '100%',
paddingHorizontal: theme.spacing.value * 2,
},
bottom: {
flex: 2,
width: '100%',
flexDirection: 'row',
justifyContent: 'space-between',
paddingHorizontal: theme.spacing.value * 2,
backgroundColor: 'transparent',
position: 'absolute',
bottom: 0,
paddingBottom: 20,
},
form: {
marginTop: theme.spacing.value * 4,
},
input: {
marginBottom: theme.spacing.value * 2,
},
next: {
alignSelf: 'flex-end',
},
prev: {
alignSelf: 'flex-start',
},
});

export default FormAddress;
Loading

0 comments on commit 80c2add

Please sign in to comment.