2021-06-13 12:43:50 +02:00
import React , { useState , useEffect } from "react" ;
2021-05-24 13:19:19 +02:00
import {
StyleSheet ,
Text ,
View ,
TouchableOpacity ,
TextInput ,
2021-06-13 12:43:50 +02:00
Keyboard
2021-05-24 13:19:19 +02:00
} from "react-native" ;
import SetupView from '../components/SetupView' ;
import EvilIcon from "react-native-vector-icons/EvilIcons" ;
import MaterialIcon from "react-native-vector-icons/MaterialCommunityIcons" ;
import themeColors from '../components/themeColors' ;
function WifiPasswordView ( props ) {
2021-06-13 12:43:50 +02:00
props = { ... props , ... props . route . params } ;
useEffect ( ( ) => {
Keyboard . addListener ( "keyboardDidShow" , _keyboardDidShow ) ;
Keyboard . addListener ( "keyboardDidHide" , _keyboardDidHide ) ;
// cleanup function
return ( ) => {
Keyboard . removeListener ( "keyboardDidShow" , _keyboardDidShow ) ;
Keyboard . removeListener ( "keyboardDidHide" , _keyboardDidHide ) ;
} ;
} , [ ] ) ;
const [ keyboardStatus , setKeyboardStatus ] = useState ( undefined ) ;
const [ password1 , setPassword1 ] = useState ( "" ) ;
const [ password2 , setPassword2 ] = useState ( "" ) ;
const [ errorMsg , setErrorMsg ] = useState ( "" ) ;
const _keyboardDidShow = ( ) => setKeyboardStatus ( true ) ;
const _keyboardDidHide = ( ) => setKeyboardStatus ( false ) ;
2021-05-24 13:19:19 +02:00
let iconName = "wifi-strength-" + props . strength ;
if ( props . lock ) {
iconName += "-lock" ;
}
2021-06-13 12:43:50 +02:00
const onSubmit = ( ) => {
if ( props . confirmPwInput && password1 != password2 )
setErrorMsg ( "Passwords don't match" ) ;
else if ( password1 . length < 8 )
setErrorMsg ( "Password has to be at least 8 characters long" )
else if ( password1 . length > 128 )
setErrorMsg ( "Password too long" ) ;
else
setErrorMsg ( "" ) ;
} ;
2021-05-24 13:19:19 +02:00
return (
< SetupView
headerText = "WiFi Password"
lowerRightButtonText = "Need help?"
2021-06-13 12:43:50 +02:00
backButton = { true }
navigation = { props . navigation }
2021-05-24 13:19:19 +02:00
>
2021-06-13 12:43:50 +02:00
{ ! keyboardStatus &&
< Text style = { styles . subtext } >
{ props . subText }
< / T e x t >
}
2021-05-24 13:19:19 +02:00
< View style = { styles . formContainer } >
< View style = { [ styles . row , { backgroundColor : "rgba(155,155,155,0.8)" } ] } >
< MaterialIcon style = { styles . ssidIcon } name = { iconName } > < / M a t e r i a l I c o n >
< Text style = { styles . ssidLabel } > { props . ssid } < / T e x t >
< / V i e w >
< View style = { styles . row } >
< EvilIcon name = "lock" style = { styles . ssidIcon } > < / E v i l I c o n >
< TextInput style = { styles . passwordInput }
2021-06-13 12:43:50 +02:00
onChangeText = { setPassword1 }
2021-05-24 13:19:19 +02:00
autoCompleteType = "password"
placeholder = "Password"
placeholderTextColor = "rgba(255,255,255,0.5)"
secureTextEntry = { true }
> < / T e x t I n p u t >
< / V i e w >
{ props . confirmPwInput &&
< View style = { styles . row } >
< EvilIcon name = "lock" style = { styles . ssidIcon } > < / E v i l I c o n >
< TextInput style = { styles . passwordInput }
2021-06-13 12:43:50 +02:00
onChangeText = { setPassword2 }
2021-05-24 13:19:19 +02:00
autoCompleteType = "password"
placeholder = "Repeat Password"
placeholderTextColor = "rgba(255,255,255,0.5)"
secureTextEntry = { true }
> < / T e x t I n p u t >
< / V i e w >
}
2021-06-13 12:43:50 +02:00
{ errorMsg . length > 0 &&
< View >
< Text style = { { color : "red" , paddingTop : 10 , paddingLeft : 55 } } > { errorMsg } < / T e x t >
< / V i e w >
}
< TouchableOpacity style = { [ styles . row , styles . button ] } onPress = { onSubmit } >
2021-05-24 13:19:19 +02:00
< Text style = { [ styles . ssidLabel , { alignSelf : "center" , textAlign : "center" } ] } > { props . buttonText } < / T e x t >
< / T o u c h a b l e O p a c i t y >
< / V i e w >
< / S e t u p V i e w >
) ;
}
WifiPasswordView . defaultProps = {
lock : true ,
strength : 2 ,
ssid : "TheWLANName" ,
confirmPwInput : false ,
buttonText : "Set Password" ,
subText : "Please enter password for your home WiFi"
}
WifiPasswordView . defaultProps = {
lock : true ,
strength : 3 ,
ssid : "swimtracker-E2842S" ,
subText : "Use this option only if you're home WiFi doesn't reach the SwimTracker. The SwimTracker creates its own WiFi with the password you set here." ,
confirmPwInput : true ,
buttonText : "Set Password" ,
}
const styles = StyleSheet . create ( {
subtext : {
color : "rgba(255,255,255,1)" ,
textAlign : "left" ,
2021-06-13 12:43:50 +02:00
fontSize : 16 ,
2021-05-24 13:19:19 +02:00
lineHeight : 25 ,
width : "80%" ,
2021-06-13 12:43:50 +02:00
paddingBottom : 30 ,
2021-05-24 13:19:19 +02:00
} ,
formContainer : {
} ,
row : {
backgroundColor : "rgba(255,255,255,0.4)" ,
borderRadius : 5 ,
width : "100%" ,
height : 50 ,
flexDirection : "row" ,
alignItems : "center" ,
marginTop : 5 ,
marginBottom : 5 ,
} ,
ssidLabel : {
color : "rgba(255,255,255,1)" ,
fontSize : 18 ,
width : "100%"
} ,
button : {
marginTop : 20 ,
backgroundColor : themeColors [ "GREEN SEA" ] ,
justifyContent : "center"
} ,
ssidIcon : {
fontSize : 25 ,
color : "rgba(255,255,255,1)" ,
marginLeft : 15 ,
marginRight : 15 ,
} ,
passwordInput : {
height : 30 ,
color : "rgba(255,255,255,1)" ,
width : "100%" ,
fontSize : 18 ,
}
} ) ;
export default WifiPasswordView ;