Working login on mobile

This commit is contained in:
John Lyon-Smith
2018-03-12 19:11:13 -07:00
parent eeb3eb4947
commit e7aaa014ff
19 changed files with 10606 additions and 131 deletions

View File

@@ -0,0 +1,59 @@
import React from 'react'
import PropTypes from 'prop-types'
import { TextInput, Text, View } from 'react-native'
import { reactAutoBind } from 'auto-bind2'
export class BoundInput extends React.Component {
static propTypes = {
name: PropTypes.string.isRequired,
message: PropTypes.string,
label: PropTypes.string,
binder: PropTypes.object.isRequired,
password: PropTypes.bool,
placeholder: PropTypes.string
}
constructor(props) {
super(props)
reactAutoBind(this)
this.state = props.binder.getFieldState(props.name)
}
handleChangeText(newText) {
const { binder, name } = this.props
const state = binder.getFieldState(name)
if (!state.readOnly && !state.disabled) {
this.setState(binder.updateFieldValue(name, newText))
}
}
render() {
const { label, password, name, placeholder, message } = this.props
const { visible, disabled, value, valid } = this.state
if (!visible) {
return null
}
// TODO: Disabled
return (
<View style={{ width: '100%' }}>
<Text style={{ color: 'black', fontSize: 14, marginBottom: 5 }}>{label}</Text>
<TextInput style={{ width: '100%', paddingLeft: 5, paddingRight: 5, height: 40, borderColor: 'gray', borderWidth: 1, fontSize: 16 }}
autoCapitalize='none'
underlineColorAndroid='white'
value={value}
secureTextEntry={password}
onChangeText={this.handleChangeText}
placeholder={placeholder} />
<Text style={{
fontSize: 12,
display: valid ? 'none' : 'flex',
color: 'red',
}}>{message}</Text>
</View>
)
}
}