ENEI2019-Public/App/app/App.js

543 lines
12 KiB
JavaScript
Raw Normal View History

2019-01-15 10:06:33 +00:00
import React, {Component} from 'react';
2019-02-12 23:07:19 +00:00
import {
Platform,
StyleSheet,
Text,
View,
StatusBar,
Dimensions,
Image,
ActivityIndicator,
Button,
TouchableHighlight,
2019-02-16 11:39:08 +00:00
Keyboard,
ImageBackground,
LinearGradient,
2019-02-16 16:14:27 +00:00
TouchableOpacity,
2019-02-16 22:16:41 +00:00
TextInput,
2019-02-22 23:38:34 +00:00
NetInfo,
Animated
2019-02-12 23:07:19 +00:00
} from 'react-native';
2019-01-08 19:09:50 +00:00
2019-01-31 00:46:49 +00:00
import {bindActionCreators} from 'redux';
2019-02-08 18:56:38 +00:00
import {connect} from 'react-redux';
2019-01-15 10:06:33 +00:00
2019-01-31 00:46:49 +00:00
import QRCodeScanner from 'react-native-qrcode-scanner';
import {UtilStyles} from './assets/styles'
2019-02-12 23:07:19 +00:00
2019-02-22 23:38:34 +00:00
import * as Actions from './store/actions';
2019-02-12 23:07:19 +00:00
2019-02-11 19:47:52 +00:00
import {RkButton, RkTheme, RkText, RkTextInput} from 'react-native-ui-kitten';
import Modal from "react-native-modal";
2019-01-15 10:06:33 +00:00
2019-02-03 20:54:27 +00:00
import Router from './Router'
2019-01-30 14:32:25 +00:00
2019-02-11 19:47:52 +00:00
import Icon from "react-native-vector-icons/Ionicons"
2019-01-31 00:46:49 +00:00
const SCREEN_HEIGHT = Dimensions.get("window").height;
const SCREEN_WIDTH = Dimensions.get("window").width;
2019-01-30 14:32:25 +00:00
2019-02-16 11:39:08 +00:00
import Swiper from 'react-native-swiper';
2019-01-30 14:32:25 +00:00
2019-02-22 23:38:34 +00:00
function handleConnectivityChange() {
console.log("asdasd");
}
2019-02-08 18:56:38 +00:00
class App extends Component {
2019-02-11 19:47:52 +00:00
_activate=()=>{
this.setState({ isModalVisible: !this.state.isModalVisible});
this.scanner.reactivate();
}
2019-02-16 18:29:23 +00:00
_scanQr=()=>{
this.props.openScannerLogin()
console.log(this.props.UI_loginScannerActive)
}
2019-02-11 19:47:52 +00:00
_tryLogin=()=>{
2019-02-16 18:29:23 +00:00
//console.log(this.state.text)
//this.scanner.reactivate();
2019-02-11 19:47:52 +00:00
this.props.login(this.state.username, this.state.text);
2019-02-16 18:29:23 +00:00
2019-02-12 19:39:11 +00:00
2019-02-11 19:47:52 +00:00
}
_toggleModal = () =>
this.setState({ isModalVisible: !this.state.isModalVisible });
2019-01-08 19:09:50 +00:00
2019-01-15 10:06:33 +00:00
constructor(props) {
2019-02-08 18:56:38 +00:00
2019-01-15 10:06:33 +00:00
super(props);
2019-02-12 19:39:11 +00:00
2019-01-15 10:06:33 +00:00
this.state = {
2019-02-08 18:56:38 +00:00
token: {valid: false},
2019-02-03 20:54:27 +00:00
tokenData: '',
onHold: true,
2019-02-11 19:47:52 +00:00
logged: false,
isModalVisible: false,
state : {text: ''},
2019-02-16 18:29:23 +00:00
username:'QR code',
2019-02-12 23:07:19 +00:00
failedAttempt: false,
2019-02-16 18:29:23 +00:00
push:4,
UI_loginScannerActive:false
2019-01-31 00:46:49 +00:00
2019-01-15 10:06:33 +00:00
};
2019-01-31 00:46:49 +00:00
2019-01-15 10:06:33 +00:00
}
2019-02-12 23:07:19 +00:00
_print=()=>{
console.log("hello")
this.setState({push:0})
}
2019-02-12 19:39:11 +00:00
checkValue=(e)=>{
console.log("check"+e)
}
2019-02-22 23:38:34 +00:00
_handleConnectionChange = (isConnected) => {
this.props.connectionState(true);
};
2019-01-31 00:46:49 +00:00
componentDidMount() {
2019-02-22 23:38:34 +00:00
NetInfo.isConnected.addEventListener('connectionChange', this.handleConnectivityChange);
2019-02-12 19:39:11 +00:00
this.setState({isModalVisible: false})
2019-01-31 00:46:49 +00:00
//verifica se o utilizador tem token guardado
2019-02-03 20:54:27 +00:00
this.props.checkUser();
2019-02-12 23:07:19 +00:00
this.keyboardDidShowListener = Keyboard.addListener('keyboardDidShow', this._keyboardDidShow);
this.keyboardDidHideListener = Keyboard.addListener('keyboardDidHide', this._keyboardDidHide);
2019-02-08 18:56:38 +00:00
}
2019-02-22 23:38:34 +00:00
componentWillUnmount() {
NetInfo.isConnected.removeEventListener('connectionChange', this.handleConnectivityChange);
}
2019-02-12 23:07:19 +00:00
_keyboardDidShow () {
//alert('Keyboard Shown');
// this.setState({push:0})
}
_keyboardDidHide () {
//this.setState({push:4})
2019-01-31 00:46:49 +00:00
2019-02-12 23:07:19 +00:00
}
2019-01-31 00:46:49 +00:00
onSuccess = (e) => {
2019-02-16 18:29:23 +00:00
// this.setState({ isModalVisible: !this.state.isModalVisible });
2019-02-11 19:47:52 +00:00
// this.props.login(e.data, 'f8908cc0');
2019-02-16 18:29:23 +00:00
this.props.closeLoginQRScan();
2019-02-11 19:47:52 +00:00
this.setState({username:e.data})
2019-01-31 00:46:49 +00:00
2019-02-22 23:38:34 +00:00
console.log("QR code lido");
2019-02-03 20:54:27 +00:00
2019-02-08 18:56:38 +00:00
2019-02-16 18:29:23 +00:00
2019-02-08 18:56:38 +00:00
};
2019-01-31 00:46:49 +00:00
2019-02-03 20:54:27 +00:00
render() {
2019-02-22 23:38:34 +00:00
if (!this.props.logged) {
2019-02-08 18:56:38 +00:00
2019-01-31 00:46:49 +00:00
return (
2019-02-08 18:56:38 +00:00
<View style={UtilStyles.containerLoading}>
2019-02-22 23:38:34 +00:00
<ActivityIndicator size="large" color="red"/>
2019-02-03 20:54:27 +00:00
</View>
2019-02-08 18:56:38 +00:00
)
2019-01-31 00:46:49 +00:00
}
2019-02-22 23:38:34 +00:00
else
2019-02-03 20:54:27 +00:00
{
2019-02-22 23:38:34 +00:00
// console.log('token... '+ this.props.logged)
2019-02-08 18:56:38 +00:00
2019-02-03 20:54:27 +00:00
//se existir token
2019-02-22 23:38:34 +00:00
if (this.props.logged ) {
2019-01-31 00:46:49 +00:00
2019-02-03 20:54:27 +00:00
return (
2019-01-31 00:46:49 +00:00
2019-02-03 20:54:27 +00:00
<Router></Router>
)
}
2019-02-16 11:39:08 +00:00
return (
2019-02-22 23:38:34 +00:00
2019-02-16 11:39:08 +00:00
<View style={styles.slide2}>
2019-02-16 18:29:23 +00:00
<Modal isVisible={this.props.UI_loginScannerActive}>
<View style={{ flex: 1 , backgroundColor:'white'}}>
<Button onPress={this.props.closeLoginQRScan} title={"Fechar scanner"}> </Button>
<QRCodeScanner
2019-02-18 17:44:02 +00:00
onRead={this.onSuccess}
2019-02-16 18:29:23 +00:00
cameraStyle={ styles.cameraContainer}
/>
</View>
</Modal>
2019-02-16 11:39:08 +00:00
<View style={{ width:'100%',
justifyContent: 'center',
alignItems: 'center',}}>
<Image style={styles.logo2} source={require('./assets/img/logo2.png')}/>
</View>
2019-02-16 16:14:27 +00:00
<View styles={styles.loginContainer}>
<View style={styles.inputSection}>
<TextInput
style={styles.input}
2019-02-16 18:29:23 +00:00
placeholder={this.state.username}
2019-02-16 16:14:27 +00:00
onChangeText={(searchString) => {this.setState({searchString})}}
maxLength={15}
underlineColorAndroid="transparent"
/>
2019-02-16 18:29:23 +00:00
<TouchableOpacity onPress={this._scanQr}>
2019-02-16 16:14:27 +00:00
<View style={styles.scanQR}>
2019-02-16 18:29:23 +00:00
<Icon style={styles.searchIcon} name="ios-qr-scanner" size={30} color="#000"/>
2019-02-16 16:14:27 +00:00
<Text>Scan QR</Text>
</View>
</TouchableOpacity>
2019-02-22 23:38:34 +00:00
</View>
2019-02-16 16:14:27 +00:00
<TextInput style={styles.passwordInput}
onFocus={this._print}
maxLength={10}
blurOnSubmit ={true}
secureTextEntry={true}
2019-02-16 18:29:23 +00:00
2019-02-16 16:14:27 +00:00
onChangeText={(text) => this.setState({text})}
clearButtonMode='always'
value={this.state.text}
clearTextOnFocus={true}
onSubmitEditing={Keyboard.dismiss}
placeholder='Password' />
2019-02-16 18:29:23 +00:00
<RkButton rkType='dark' style={styles.loginBtn} onPress={this._tryLogin}>Entrar</RkButton>
2019-02-16 16:14:27 +00:00
</View>
2019-02-16 11:39:08 +00:00
<View style={ styles.buttons }>
<TouchableOpacity
style={styles.button}>
<Icon name="logo-facebook" size={40}/>
</TouchableOpacity>
<TouchableOpacity
style={styles.button}>
<Icon name="logo-instagram" size={40}/>
</TouchableOpacity>
<TouchableOpacity
style={styles.button}>
<Icon name="md-heart" size={40}/>
</TouchableOpacity>
</View>
<View style={styles.footer}>
<View style={styles.textRow}>
2019-02-16 18:29:23 +00:00
<RkText rkType='primary3'>Não sabes a password?</RkText>
<RkButton rkType='clear' onPress={this.onSignUpButtonPressed}>
2019-02-16 11:39:08 +00:00
<TouchableOpacity>
<RkText style={{color:'red'}} kType='header6'>Recuperar Password</RkText>
</TouchableOpacity>
</RkButton>
</View>
</View>
</View>
2019-02-22 23:38:34 +00:00
2019-02-16 11:39:08 +00:00
);
2019-02-17 00:46:36 +00:00
2019-02-08 18:56:38 +00:00
}
}
2019-01-31 00:46:49 +00:00
}
2019-01-31 00:46:49 +00:00
RkTheme.setType('RkButton', 'dark', {
container: {
2019-02-08 18:56:38 +00:00
paddingTop: 10,
backgroundColor: 'gray',
borderRadius: 90,
2019-01-31 00:46:49 +00:00
}
2019-02-08 18:56:38 +00:00
});
2019-01-08 19:09:50 +00:00
2019-01-31 00:46:49 +00:00
const rectDimensions = SCREEN_WIDTH * 0.85; // this is equivalent to 255 from a 393 device width
2019-01-31 00:46:49 +00:00
const overlayColor = 'rgba(0,0,0,0.30)';
2019-01-31 00:46:49 +00:00
const styles = {
2019-02-16 18:29:23 +00:00
cameraContainer:{
// height: Dimensions.get('window').height ,
},
2019-02-16 16:14:27 +00:00
passwordInput:{
borderRadius: 90,
borderColor:'#bfbdbd',
borderWidth: 1,
marginTop:20,
marginBottom:20,
width:SCREEN_WIDTH*0.8,
backgroundColor: 'white',
borderRadius: 90,
height: SCREEN_HEIGHT*0.08,
borderColor:'#bfbdbd',
borderWidth: 1,
paddingLeft:SCREEN_WIDTH*0.05,
},
scanQRText:{
2019-02-16 18:29:23 +00:00
paddingTop:50
2019-02-16 16:14:27 +00:00
// paddingTop:20,
},
scanQR:{
2019-02-22 23:38:34 +00:00
2019-02-16 18:29:23 +00:00
//flexDirection: 'row',
2019-02-16 16:14:27 +00:00
paddingTop:5,
backgroundColor:10,
2019-02-16 18:29:23 +00:00
width:80,
2019-02-16 16:14:27 +00:00
paddingLeft:10,
backgroundColor:'#f24b4b',
borderBottomRightRadius:90,
borderTopRightRadius:90,
height:'100%',
},
inputSection: {
flexDirection: 'row',
backgroundColor: '#fff',
backgroundColor: 'white',
borderRadius: 90,
height: SCREEN_HEIGHT*0.08,
borderColor:'#bfbdbd',
borderWidth: 1,
},
searchIcon: {
paddingLeft:10
},
input: {
2019-02-22 23:38:34 +00:00
2019-02-16 16:14:27 +00:00
flex: 1,
paddingRight: 10,
paddingLeft: 0,
paddingLeft:SCREEN_WIDTH*0.05,
color: '#424242',
},
textRow:{
marginBottom:40
},
loginContainer:{
width: '100%',
height: '30%',
justifyContent: 'center',
alignItems: 'center'
},
loginBtn:{
marginTop:10,
marginBottom:20,
marginLeft: '25%',
},
2019-02-16 11:39:08 +00:00
button: {
borderWidth:1,
borderColor:'rgba(0,0,0,0.2)',
alignItems:'center',
justifyContent:'center',
width:60,
height:60,
backgroundColor:'#fff',
borderRadius:100,
marginRight: 10,
marginLeft:10
},
footer: {},
buttons: {
flexDirection: 'row',
marginBottom: 24,
marginHorizontal: 24,
marginTop:24,
justifyContent: 'space-around',
},
2019-02-16 16:14:27 +00:00
2019-02-16 11:39:08 +00:00
logoContainer:{
2019-02-16 16:14:27 +00:00
2019-02-16 11:39:08 +00:00
width:'100%',
justifyContent: 'center',
alignItems: 'center',
marginTop:200
},
2019-02-08 18:56:38 +00:00
2019-02-16 11:39:08 +00:00
logo2:{
// flex: 1,
// resizeMode: 'contain',
width: 200, height: 200,
},
wrapper: {
},
slide1: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: 'white',
},
slide2: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: 'white',
},
slide3: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
2019-02-16 16:14:27 +00:00
color:'black',
backgroundColor: 'white',
2019-02-16 11:39:08 +00:00
},
text: {
color: '#fff',
fontSize: 30,
fontWeight: 'bold',
},
2019-02-08 18:56:38 +00:00
recover: {
paddingTop: 10,
2019-01-31 00:46:49 +00:00
color: "red",
2019-02-08 18:56:38 +00:00
paddingBottom: 10
2019-01-31 00:46:49 +00:00
},
2019-02-08 18:56:38 +00:00
manual: {},
2019-01-15 10:06:33 +00:00
2019-02-08 18:56:38 +00:00
logo: {
2019-01-15 10:06:33 +00:00
2019-02-08 18:56:38 +00:00
height: SCREEN_HEIGHT * 0.35,
width: SCREEN_WIDTH,
2019-01-31 00:46:49 +00:00
backgroundColor: overlayColor,
},
rectangleContainer: {
2019-02-08 18:56:38 +00:00
2019-01-31 00:46:49 +00:00
flex: 1,
alignItems: "center",
justifyContent: "center",
backgroundColor: "transparent",
2019-02-08 18:56:38 +00:00
2019-01-31 00:46:49 +00:00
},
2019-01-15 10:06:33 +00:00
2019-01-31 00:46:49 +00:00
rectangle: {
2019-02-08 18:56:38 +00:00
2019-01-31 00:46:49 +00:00
height: rectDimensions,
width: rectDimensions,
alignItems: "center",
justifyContent: "center",
backgroundColor: "transparent"
},
2019-01-15 10:06:33 +00:00
2019-01-31 00:46:49 +00:00
topOverlay: {
flex: 1,
backgroundColor: overlayColor,
justifyContent: "center",
alignItems: "center"
},
bottomOverlay: {
flex: 1,
height: SCREEN_HEIGHT,
width: SCREEN_WIDTH,
backgroundColor: overlayColor,
paddingBottom: SCREEN_WIDTH * 0.2
},
2019-01-15 10:06:33 +00:00
2019-01-31 00:46:49 +00:00
leftAndRightOverlay: {
height: rectDimensions,
width: SCREEN_WIDTH,
backgroundColor: overlayColor
},
};
2019-02-11 19:47:52 +00:00
RkTheme.setType('RkTextInput', 'frame', {
input: {
backgroundColor: 'white',
marginLeft: 0,
marginHorizontal: 0,
borderRadius: 5
},
color: 'gray',
backgroundColor: 'gray',
borderRadius: 10,
container: {
paddingHorizontal: 20
}
});
2019-02-08 18:56:38 +00:00
mapStateToProps = (state, props) => {
2019-01-31 00:46:49 +00:00
return {
2019-02-08 18:56:38 +00:00
token: state.apiReducer.token,
2019-01-31 00:46:49 +00:00
loggedIn: state.apiReducer.loggedIn,
2019-02-03 20:54:27 +00:00
onHold: state.apiReducer.onHold,
2019-02-11 19:47:52 +00:00
logged: state.apiReducer.logged,
failedAttempt:state.apiReducer.failedAttempt,
2019-02-16 18:29:23 +00:00
UI_loginScannerActive: state.uiReducer.UI_loginScannerActive
2019-01-15 10:06:33 +00:00
}
2019-02-08 18:56:38 +00:00
};
2019-01-08 19:09:50 +00:00
2019-02-08 18:56:38 +00:00
mapDispatchToProps = (dispatch) => {
2019-01-31 00:46:49 +00:00
return bindActionCreators(Actions, dispatch);
2019-02-08 18:56:38 +00:00
};
2019-01-15 10:06:33 +00:00
2019-01-31 00:46:49 +00:00
export default connect(mapStateToProps, mapDispatchToProps)(App);