如何在tcomb中输入按钮反应本机

时间:2019-09-10 10:23:27

标签: react-native react-native-android tcomb-form-native tcomb

我想将按钮放在表单中以获取当前位置,然后将值放入坐标

我尝试了这个,但是没有用

const validForm = t.struct({
    coordinate: t.maybe(t.String),
    buttoncoordinate: t.maybe(t.String),
});

let options = {
    i18n: {
        optional: '',
        required: ' *'
    },
    fields: {
        coordinate: {
            label: 'coordinate',
            stylesheet : textInput,
        },
        buttoncoordinate:{
            label:'',
            stylesheet : textInput,
            factory: props => (<Button{...props} onPress={() => console.log('pressed')} />
            ),
        },
    }
};


render() {
        return (
                    <View style={styles.formInput}>
                        <Form
                            ref="form"
                            type={validForm}
                            options={options}
                            value={this.state.value}
                            onChange={this._onChange}
                        />
                    </View>
        );
    }

我只想将按钮放在表单中。怎么做?

2 个答案:

答案 0 :(得分:1)

这种方式:

 buttoncoordinate:{
            label:'',
            stylesheet : textInput,
            factory: YoutButtonComponent
           }

例如:

var options = {
  fields: {
    name: {
      factory: MyComponent
    }
  }
};

答案 1 :(得分:0)

更改代码。没有输入按钮,也不在选项中使用按钮。

<View style={styles.formInput}>
                        <Form
                            ref="form"
                            type={validForm}
                            options={options}
                            value={this.state.value}
                            onChange={this._onChange}
                        />
               <Button block onPress={() => this.login()}>
               <Text>Login</Text>
               </Button>
                    </View>