Upgrade to new form binder
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import React from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
import { View, Switch, Text } from 'react-native'
|
||||
import autobind from 'autobind-decorator'
|
||||
import React from "react"
|
||||
import PropTypes from "prop-types"
|
||||
import { View, Switch, Text } from "react-native"
|
||||
import autobind from "autobind-decorator"
|
||||
|
||||
export class BoundSwitch extends React.Component {
|
||||
static propTypes = {
|
||||
@@ -12,22 +12,22 @@ export class BoundSwitch extends React.Component {
|
||||
|
||||
constructor(props) {
|
||||
super(props)
|
||||
this.state = props.binder.getFieldState(props.name)
|
||||
this.state = props.binder.getBindingState(props.name)
|
||||
}
|
||||
|
||||
@autobind
|
||||
handleValueChange(newValue) {
|
||||
const { binder, name } = this.props
|
||||
const state = binder.getFieldState(name)
|
||||
const state = binder.getBindingState(name)
|
||||
|
||||
if (!state.readOnly && !state.disabled) {
|
||||
this.setState(binder.updateFieldValue(name, newValue))
|
||||
this.setState(binder.updateBindingValue(name, newValue))
|
||||
}
|
||||
}
|
||||
|
||||
componentWillReceiveProps(nextProps) {
|
||||
if (nextProps.binder !== this.props.binder) {
|
||||
this.setState(nextProps.binder.getFieldState(nextProps.name))
|
||||
this.setState(nextProps.binder.getBindingState(nextProps.name))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,16 +36,22 @@ export class BoundSwitch extends React.Component {
|
||||
const { visible, disabled, value } = this.state
|
||||
|
||||
return (
|
||||
<View style={{
|
||||
display: visible ? 'flex' : 'none',
|
||||
flexDirection: 'row',
|
||||
<View
|
||||
style={{
|
||||
display: visible ? "flex" : "none",
|
||||
flexDirection: "row",
|
||||
}}>
|
||||
<Switch disabled={disabled} value={value} onValueChange={this.handleValueChange} />
|
||||
<Text style={{
|
||||
color: disabled ? 'gray' : 'black',
|
||||
<Switch
|
||||
disabled={disabled}
|
||||
value={value}
|
||||
onValueChange={this.handleValueChange}
|
||||
/>
|
||||
<Text
|
||||
style={{
|
||||
color: disabled ? "gray" : "black",
|
||||
fontSize: 16,
|
||||
paddingLeft: 8,
|
||||
alignSelf: 'center'
|
||||
alignSelf: "center",
|
||||
}}>
|
||||
{label}
|
||||
</Text>
|
||||
|
||||
Reference in New Issue
Block a user