Skip to content

Commit

Permalink
Login and Alert
Browse files Browse the repository at this point in the history
  • Loading branch information
MengTo committed May 12, 2019
1 parent ae61dd7 commit 73945ec
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 7 deletions.
4 changes: 4 additions & 0 deletions App.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ const reducer = (state = initialState, action) => {
return { action: "openCard" };
case "CLOSE_CARD":
return { action: "closeCard" };
case "OPEN_LOGIN":
return { action: "openLogin" };
case "CLOSE_LOGIN":
return { action: "closeLogin" };
default:
return state;
}
Expand Down
81 changes: 75 additions & 6 deletions components/ModalLogin.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,23 @@ import {
import { BlurView } from "expo";
import Success from "./Success";
import Loading from "./Loading";
import { Alert, Animated, Dimensions } from "react-native";
import { connect } from "react-redux";

const screenHeight = Dimensions.get("window").height;

function mapStateToProps(state) {
return { action: state.action };
}

function mapDispatchToProps(dispatch) {
return {
closeLogin: () =>
dispatch({
type: "CLOSE_LOGIN"
})
};
}

class ModalLogin extends React.Component {
state = {
Expand All @@ -16,9 +33,41 @@ class ModalLogin extends React.Component {
iconEmail: require("../assets/icon-email.png"),
IconPassword: require("../assets/icon-password.png"),
isSuccessful: false,
isLoading: false
isLoading: false,
top: new Animated.Value(screenHeight),
scale: new Animated.Value(1.3),
translateY: new Animated.Value(0)
};

componentDidUpdate() {
if (this.props.action === "openLogin") {
Animated.timing(this.state.top, {
toValue: 0,
duration: 0
}).start();
Animated.spring(this.state.scale, { toValue: 1 }).start();
Animated.timing(this.state.translateY, {
toValue: 0,
duration: 0
}).start();
}

if (this.props.action === "closeLogin") {
setTimeout(() => {
Animated.timing(this.state.top, {
toValue: screenHeight,
duration: 0
}).start();
Animated.spring(this.state.scale, { toValue: 1.3 }).start();
}, 500);

Animated.timing(this.state.translateY, {
toValue: 1000,
duration: 500
}).start();
}
}

handleLogin = () => {
console.log(this.state.email, this.state.password);

Expand All @@ -27,6 +76,13 @@ class ModalLogin extends React.Component {
setTimeout(() => {
this.setState({ isLoading: false });
this.setState({ isSuccessful: true });

Alert.alert("Congrats", "You've logged successfully!");

setTimeout(() => {
this.props.closeLogin();
this.setState({ isSuccessful: false });
}, 1000);
}, 2000);
};

Expand All @@ -46,11 +102,12 @@ class ModalLogin extends React.Component {

tapBackground = () => {
Keyboard.dismiss();
this.props.closeLogin();
};

render() {
return (
<Container>
<AnimatedContainer style={{ top: this.state.top }}>
<TouchableWithoutFeedback onPress={this.tapBackground}>
<BlurView
tint="default"
Expand All @@ -62,7 +119,14 @@ class ModalLogin extends React.Component {
}}
/>
</TouchableWithoutFeedback>
<Modal>
<AnimatedModal
style={{
transform: [
{ scale: this.state.scale },
{ translateY: this.state.translateY }
]
}}
>
<Logo source={require("../assets/logo-dc.png")} />
<Text>Start Learning. Access Pro Content.</Text>
<TextInput
Expand All @@ -84,14 +148,17 @@ class ModalLogin extends React.Component {
<ButtonText>Log In</ButtonText>
</Button>
</TouchableOpacity>
</Modal>
</AnimatedModal>
<Success isActive={this.state.isSuccessful} />
<Loading isActive={this.state.isLoading} />
</Container>
</AnimatedContainer>
);
}
}
export default ModalLogin;
export default connect(
mapStateToProps,
mapDispatchToProps
)(ModalLogin);

const Container = styled.View`
position: absolute;
Expand All @@ -103,6 +170,7 @@ const Container = styled.View`
justify-content: center;
align-items: center;
`;
const AnimatedContainer = Animated.createAnimatedComponent(Container);
const Modal = styled.View`
width: 335px;
height: 370px;
Expand All @@ -111,6 +179,7 @@ const Modal = styled.View`
box-shadow: 0 20px 40px rgba(0, 0, 0, 0.15);
align-items: center;
`;
const AnimatedModal = Animated.createAnimatedComponent(Modal);
const Logo = styled.Image`
width: 44px;
height: 44px;
Expand Down
6 changes: 5 additions & 1 deletion screens/HomeScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ function mapDispatchToProps(dispatch) {
openMenu: () =>
dispatch({
type: "OPEN_MENU"
}),
openLogin: () =>
dispatch({
type: "OPEN_LOGIN"
})
};
}
Expand Down Expand Up @@ -131,7 +135,7 @@ class HomeScreen extends React.Component {
<ScrollView style={{ height: "100%" }}>
<TitleBar>
<TouchableOpacity
onPress={this.props.openMenu}
onPress={this.props.openLogin}
style={{ position: "absolute", top: 0, left: 20 }}
>
<Avatar />
Expand Down

0 comments on commit 73945ec

Please sign in to comment.