【问题标题】:How to input button in tcomb react native如何在tcomb中输入按钮反应原生
【发布时间】:2019-09-10 10:23:27
【问题描述】:

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

我试过了,但是没用

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>
        );
    }

我只想将按钮放入表单中。如何制作?

【问题讨论】:

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


    【解决方案1】:

    这样:

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

    例如:

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

    【讨论】:

      【解决方案2】:

      更改代码。按钮不输入,不用于选项。

      <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>
      

      【讨论】:

        猜你喜欢
        • 2021-08-04
        • 2016-09-19
        • 1970-01-01
        • 2021-10-20
        • 2018-05-07
        • 2016-01-29
        • 2022-01-19
        • 2022-06-17
        • 1970-01-01
        相关资源
        最近更新 更多