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, Text, TouchableHighlight } from 'react-native'
|
||||
import autobind from 'autobind-decorator'
|
||||
import React from "react"
|
||||
import PropTypes from "prop-types"
|
||||
import { View, Text, TouchableHighlight } from "react-native"
|
||||
import autobind from "autobind-decorator"
|
||||
|
||||
export class BoundButton extends React.Component {
|
||||
static propTypes = {
|
||||
@@ -9,7 +9,7 @@ export class BoundButton extends React.Component {
|
||||
title: PropTypes.string,
|
||||
binder: PropTypes.object.isRequired,
|
||||
onPress: PropTypes.func,
|
||||
width: PropTypes.oneOfType([ PropTypes.string, PropTypes.number ]),
|
||||
width: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
||||
}
|
||||
|
||||
constructor(props) {
|
||||
@@ -18,7 +18,7 @@ export class BoundButton extends React.Component {
|
||||
const { name, binder } = this.props
|
||||
|
||||
binder.addListener(name, this.updateValue)
|
||||
this.state = binder.getFieldState(name)
|
||||
this.state = binder.getBindingState(name)
|
||||
}
|
||||
|
||||
@autobind
|
||||
@@ -34,7 +34,7 @@ export class BoundButton extends React.Component {
|
||||
if (nextProps.binder !== this.props.binder) {
|
||||
this.props.binder.removeListener(this.props.name, this.updateValue)
|
||||
nextProps.binder.addListener(nextProps.name, this.updateValue)
|
||||
this.setState(nextProps.binder.getFieldState(nextProps.name))
|
||||
this.setState(nextProps.binder.getBindingState(nextProps.name))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,17 +48,31 @@ export class BoundButton extends React.Component {
|
||||
|
||||
if (disabled) {
|
||||
return (
|
||||
<View style={{ flexDirection: 'column', justifyContent: 'center', paddingHorizontal: 10, height: 40, width , backgroundColor: '#E0E0E0' }}>
|
||||
<Text style={{ alignSelf: 'center', color: '#AAAAAA' }}>{title}</Text>
|
||||
<View
|
||||
style={{
|
||||
flexDirection: "column",
|
||||
justifyContent: "center",
|
||||
paddingHorizontal: 10,
|
||||
height: 40,
|
||||
width,
|
||||
backgroundColor: "#E0E0E0",
|
||||
}}>
|
||||
<Text style={{ alignSelf: "center", color: "#AAAAAA" }}>{title}</Text>
|
||||
</View>
|
||||
)
|
||||
} else {
|
||||
return (
|
||||
<TouchableHighlight
|
||||
onPress={onPress}
|
||||
style={{ justifyContent: 'center', paddingHorizontal: 10, height: 40, width, backgroundColor: '#3BB0FD' }}
|
||||
underlayColor='#1A72AC'>
|
||||
<Text style={{ alignSelf: 'center', color: 'black' }}>{title}</Text>
|
||||
style={{
|
||||
justifyContent: "center",
|
||||
paddingHorizontal: 10,
|
||||
height: 40,
|
||||
width,
|
||||
backgroundColor: "#3BB0FD",
|
||||
}}
|
||||
underlayColor="#1A72AC">
|
||||
<Text style={{ alignSelf: "center", color: "black" }}>{title}</Text>
|
||||
</TouchableHighlight>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
import React from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
import { Header } from '.'
|
||||
import autobind from 'autobind-decorator'
|
||||
import React from "react"
|
||||
import PropTypes from "prop-types"
|
||||
import { Header } from "."
|
||||
import autobind from "autobind-decorator"
|
||||
|
||||
const headerButtonShape = { icon: PropTypes.string.isRequired, onPress: PropTypes.func }
|
||||
const headerButtonShape = {
|
||||
icon: PropTypes.string.isRequired,
|
||||
onPress: PropTypes.func,
|
||||
}
|
||||
|
||||
export class BoundHeader extends React.Component {
|
||||
static propTypes = {
|
||||
@@ -20,7 +23,7 @@ export class BoundHeader extends React.Component {
|
||||
const { name, binder } = this.props
|
||||
|
||||
binder.addListener(name, this.updateValue)
|
||||
this.state = binder.getFieldState(name)
|
||||
this.state = binder.getBindingState(name)
|
||||
}
|
||||
|
||||
@autobind
|
||||
@@ -36,7 +39,7 @@ export class BoundHeader extends React.Component {
|
||||
if (nextProps.binder !== this.props.binder) {
|
||||
this.props.binder.removeListener(this.props.name, this.updateValue)
|
||||
nextProps.binder.addListener(nextProps.name, this.updateValue)
|
||||
this.setState(nextProps.binder.getFieldState(nextProps.name))
|
||||
this.setState(nextProps.binder.getBindingState(nextProps.name))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,7 +57,8 @@ export class BoundHeader extends React.Component {
|
||||
title={title}
|
||||
disabled={disabled}
|
||||
leftButton={leftButton}
|
||||
rightButton={rightButton} />
|
||||
rightButton={rightButton}
|
||||
/>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,13 +23,13 @@ export class BoundInput extends React.Component {
|
||||
|
||||
const { name, binder } = this.props
|
||||
|
||||
this.state = binder.getFieldState(name)
|
||||
this.state = binder.getBindingState(name)
|
||||
this.handleChangeText = this.handleChangeText.bind(this)
|
||||
}
|
||||
|
||||
componentWillReceiveProps(nextProps) {
|
||||
if (nextProps.binder !== this.props.binder) {
|
||||
this.setState(nextProps.binder.getFieldState(nextProps.name))
|
||||
this.setState(nextProps.binder.getBindingState(nextProps.name))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ export class BoundInput extends React.Component {
|
||||
const { binder, name } = this.props
|
||||
|
||||
if (binder) {
|
||||
this.setState(binder.updateFieldValue(name, newText))
|
||||
this.setState(binder.updateBindingValue(name, newText))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,17 +17,19 @@ export class BoundOptionStrip extends React.Component {
|
||||
|
||||
constructor(props) {
|
||||
super(props)
|
||||
this.state = props.binder.getFieldState(props.name)
|
||||
this.state = props.binder.getBindingState(props.name)
|
||||
}
|
||||
|
||||
@autobind
|
||||
handleValueChanged(newValue) {
|
||||
this.setState(this.props.binder.updateFieldValue(this.props.name, newValue))
|
||||
this.setState(
|
||||
this.props.binder.updateBindingValue(this.props.name, newValue)
|
||||
)
|
||||
}
|
||||
|
||||
componentWillReceiveProps(nextProps) {
|
||||
if (nextProps.binder !== this.props.binder) {
|
||||
this.setState(nextProps.binder.getFieldState(nextProps.name))
|
||||
this.setState(nextProps.binder.getBindingState(nextProps.name))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -38,12 +38,12 @@ export class BoundPhotoPanel extends Component {
|
||||
|
||||
const { name, binder } = this.props
|
||||
|
||||
this.state = binder.getFieldState(name)
|
||||
this.state = binder.getBindingState(name)
|
||||
}
|
||||
|
||||
componentWillReceiveProps(nextProps) {
|
||||
if (nextProps.binder !== this.props.binder) {
|
||||
this.setState(nextProps.binder.getFieldState(nextProps.name))
|
||||
this.setState(nextProps.binder.getBindingState(nextProps.name))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,12 +80,12 @@ export class BoundPhotoPanel extends Component {
|
||||
const { binder, name } = this.props
|
||||
|
||||
if (binder) {
|
||||
const value = binder.getFieldValue(name)
|
||||
const value = binder.getBindingValue(name)
|
||||
let newValue = value instanceof Array ? value.slice(0) : []
|
||||
|
||||
newValue[index] = uploadData.assetId
|
||||
|
||||
this.setState(binder.updateFieldValue(name, newValue))
|
||||
this.setState(binder.updateBindingValue(name, newValue))
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
|
||||
@@ -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