I've been trying to get redux-form working with react-native, but I can't get the simplest form working.
I have 2 problems:
If I bind props.input to the TextInput component, every keypress gets eaten. You see the typed character for a brief moment and it disappears. By trial and error, I found that if you don't bind props.input.value, it will allow the field to show the characters you type.
My submit function is always passed an empty values argument.
// @flow
import React, { PropTypes } from 'react'
import {
StyleSheet,
Text,
TextInput,
TouchableHighlight,
View,
} from 'react-native'
import { reduxForm, Field } from 'redux-form'
const styles = StyleSheet.create({
form: {
flex: 1,
flexDirection: 'column',
paddingLeft: 16,
paddingRight: 16,
},
submitbutton: {
height: 48,
marginTop: 32,
},
textfield: {
height: 28,
},
});
class TextInputField extends React.Component {
render() {
const { input, placeholder, style, input: { onChange } } = this.props
console.log(this.props)
return (
<TextInput
onChange={onChange}
placeholder={placeholder}
style={style}
/>
)
}
}
class SigninScene extends React.Component {
render() {
const { handleSubmit, submitting } = this.props
return (
<View style={styles.form}>
<Field name="email" component={TextInputField} placeholder="email" style={styles.textfield}/>
<Field name="password" component={TextInputField} placeholder="password" style={styles.textfield}/>
<TouchableHighlight
onPress={handleSubmit((values, dispatch, props) => {
console.log("handling submit")
console.log(values)
})}
>
<Text style={styles.submitbutton}>Signin</Text>
</TouchableHighlight>
</View>
)
}
}
export default reduxForm({ form: 'signin' })(SigninScene)
Field
fromredux-form
instead of fromredux-form/immutable
– sfridman