Skip to content

Commit 8ef563d

Browse files
committed
Basic login form functionality with reusable input
1 parent b4426d7 commit 8ef563d

File tree

4 files changed

+94
-2
lines changed

4 files changed

+94
-2
lines changed

App.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import React, { Component } from "react";
22
import { AppRegistry, View, Text } from "react-native";
3-
import { Header } from "./src/components/common";
43
import firebase from "firebase";
4+
import { Header } from "./src/components/common";
5+
import LoginForm from "./src/components/LoginForm";
56

67
export default class App extends Component {
78
componentWillMount() {
@@ -20,7 +21,7 @@ export default class App extends Component {
2021
return (
2122
<View>
2223
<Header headerText="Authentication" />
23-
<Text>An app</Text>
24+
<LoginForm />
2425
</View>
2526
);
2627
}

src/components/LoginForm.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import React, { Component } from "react";
2+
import firebase from "firebase";
3+
import { Button, Card, CardSection, Input } from "./common";
4+
5+
class LoginForm extends Component {
6+
constructor(props) {
7+
super(props);
8+
this.state = {
9+
email: "",
10+
password: ""
11+
};
12+
}
13+
14+
onButtonPress = () => {
15+
const { email, password } = this.state;
16+
firebase.auth().signInAndRetrieveDataWithEmailAndPassword(email, password);
17+
};
18+
19+
render() {
20+
return (
21+
<Card>
22+
<CardSection>
23+
<Input
24+
value={this.state.email}
25+
onChangeText={email => this.setState({ email })}
26+
label="Email"
27+
placeholder="user@example.com"
28+
/>
29+
</CardSection>
30+
<CardSection>
31+
<Input
32+
value={this.state.password}
33+
onChangeText={password => this.setState({ password })}
34+
label="Password"
35+
placeholder="password"
36+
secureTextEntry
37+
/>
38+
</CardSection>
39+
<CardSection>
40+
<Button onPress={this.onButtonPress}>Login</Button>
41+
</CardSection>
42+
</Card>
43+
);
44+
}
45+
}
46+
47+
export default LoginForm;

src/components/common/Input.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import React from "react";
2+
import { TextInput, View, Text } from "react-native";
3+
4+
const Input = ({ label, value, onChangeText, placeholder, secureTextEntry }) => {
5+
const { inputStyle, labelStyle, containerStyle } = styles;
6+
return (
7+
<View style={containerStyle}>
8+
<Text style={labelStyle}>{label}</Text>
9+
<TextInput
10+
placeholder={placeholder}
11+
value={value}
12+
onChange={onChangeText}
13+
style={inputStyle}
14+
autoCorrect={false}
15+
secureTextEntry={secureTextEntry}
16+
/>
17+
</View>
18+
);
19+
};
20+
21+
const styles = {
22+
inputStyle: {
23+
color: "#000",
24+
paddingRight: 5,
25+
paddingLeft: 5,
26+
fontSize: 18,
27+
lineHeight: 23,
28+
flex: 2
29+
},
30+
labelStyle: {
31+
fontSize: 18,
32+
paddingLeft: 20,
33+
flex: 1
34+
},
35+
containerStyle: {
36+
flex: 1,
37+
height: 40,
38+
flexDirection: "row",
39+
alignItems: "center"
40+
}
41+
};
42+
43+
export { Input };

src/components/common/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ export * from "./Button";
22
export * from "./Card";
33
export * from "./CardSection";
44
export * from "./Header";
5+
export * from "./Input";

0 commit comments

Comments
 (0)