反应本机元素未按预期呈现

时间:2019-10-05 16:56:59

标签: javascript reactjs react-native expo react-native-elements

我刚开始使用React Native。我使用expo.io创建了一个新应用,目前正在测试https://react-native-elements.github.io

提供的组件

我正在尝试输入表单和按钮,目前我的代码如下:

class EnterNewPasswordComp extends React.Component {

    constructor(props) {
        super(props);
        this.state = {
            pass : ''
        }
    }

    render() {
        return <View style={styles.container}>
            <Text style={styles.label}>{pass_label}</Text>
            <Input placeholder='Password' />
            <Text style={styles.note}>{pass_desc}</Text>
            <Button title="Submit" type="outline" />
        </View>;
    }
}

const styles = {
  container : {
      flex : 1,
      justifyContent: 'center',
      alignItems: 'center',
  },
  label : {
      fontSize: 20,
  },
  note : {
      fontSize: 12,
      marginBottom: 20
  },
  input : {
      color : style.txtcolor
  },
  btn : {
      width : '50%'
  }
};

该组件(当前)仅返回EnterNewPasswordComp

class IndexComponent extends React.Component {

    constructor(props) {
        super(props);
        this.passDao = Factory.getPasswordDao();
        this.state = {
            status: 'initializing'
        }
    }

    async componentDidMount() {
        try {
            const pass = await this.passDao.getPassword();
            logger.info(pass);
            const setupNeeded = pass === null;
            if( setupNeeded ) {
                this.setState({
                    status : 'setup'
                });
            }
            else {
                this.setState({
                    status : 'ready'
                })
            }
        } catch (e) {
            logger.error("Error during db query", e);
            this.setState({
                status: 'corrupted'
            });
        }
    }

    render() {
        let msg = "initializing";

        switch (this.state.status) {
            case 'initializing':
                msg = 'initializing';
                break;
            case 'corrupted':
            default:
                msg = 'corrupted';
                break;
            case 'ready':
                msg = 'ready';
                break;
            case 'setup':
                return <EnterNewPasswordComp/>
        }

        return <Text>{msg}</Text>
    }
}

,此组件在App.js中的使用方式如下:

export default class App extends Component {

  render() {
    return (
      <View style={styles.container}>
        <IndexComponent/>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  }
});

这是我的输出在Android手机上的样子:

Application Screenshot

请注意:

  • 输入字段根本不呈现
  • 未正确选择按钮类型轮廓
  • 未正确拾取按钮宽度

我玩弄了各种样式(例如设置输入表单的颜色,怀疑它可能与背景相同),但没有任何改变。我想知道我是否在做一些根本上错误的事情来产生这些问题。

0 个答案:

没有答案
相关问题