React Native NavigatorIOS不渲染组件

时间:2016-01-08 04:22:00

标签: css react-native

我在navigatorIOS内部渲染我的组件时遇到问题,我确信这是一个样式问题,但我无法确定在哪里。

我给了flex:1 删除backgroundColor 我给了一个保证金

正如其他堆栈溢出问题所示。

如果我将MessageBoardTopics扔到导航器之外,它会很好。

    import MessageBoardTopics from './messageBoardTopics.js';

    class MessageBoards extends React.Component{

        constructor(props){
            super(props);

        }

        componentDidMount(){

        }

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

            <NavigatorIOS
             style={{flex: 1}}
              initialRoute={{
                component: MessageBoardTopics,
                title: 'Forum',
              }}/>  
        </View> 
        );
      }
    };

    module.exports = MessageBoards;

    var styles = StyleSheet.create({
      container: {
        flex: 1,
        justifyContent: 'center',
        alignItems: 'center',
      },
    });





var screenWidth = Dimensions.get('window').width;


class MessageBoardTopics extends React.Component{
    constructor(props){
        super(props);

        var ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
        var data = PostStore.getState().posts;
        this.state={sortText: 'Sort by: Old',
        dataSource: ds.cloneWithRows(data)};
    }

    componentDidMount() {
      PostStore.listen(this.onChange);
    }

    componentWillUnmount() {
      PostStore.unlisten(this.onChange);
    }

    onChange(state) {
     this.setState(state);
   }

    replyToMessage(){

    }

    removeMessage(){

    }

    sortMessages(){

    }

    editMessage(){

    }


    pressRow(rowData){  
        this.props.navigator.push({
            title: rowData.title,
            component: Topic
        });
    }

  render() {
    return (        
      <View style={styles.container}>
<Text>fasfasdfafasdf</Text>

        <View style={{flex: .2}}></View>
            <View style={styles.buttonBar}>
                <TouchableHighlight style={styles.centerButton} underlayColor={"lightred"} onPress={this.sortMessages}>
                    <Text>{this.state.sortText}</Text>
                </TouchableHighlight>
                <View style={styles.centerButton} underlayColor={"lightred"} onPress={this.newMessage}> 

                    <ComposeModal reply={this.replyToMessage} index={null}/>
                </View>
            </View> 

        <ListView
          dataSource={this.state.dataSource}
          style={{borderTopWidth: 2}}
          renderRow={(rowData) =>
            <TouchableHighlight underlayColor="lightgrey" onPress={()=>this.pressRow(rowData)}>
                <View style={styles.message}>
                    <Text style={styles.messageTitle}>{rowData.title}</Text>
                    <Text style={styles.messageAuthor}>By: <Text style={{color: 'blue', fontStyle: 'italic'}}>{rowData.author}</Text></Text>
                </View>
            </TouchableHighlight>}/>

     </View>
    );
  }
};

module.exports = MessageBoardTopics;

var styles = StyleSheet.create({
  container: {
    flex: 1,
    marginTop: 80,
  },
  message: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: 'white',   
    borderWidth: 1,
    borderColor: "lightblue",
    padding: 15,
},
 messageTitle: {
    color: 'grey',
    textDecorationLine: 'underline',
    fontWeight: 'bold',
},
 messageAuthor: {
    fontSize: 10,
},
buttonBar: {
    flex: .1,
    alignSelf: 'stretch',
    alignItems: 'center',
    flexDirection: 'row',
},
centerButton: {
    flex: 1,
    width: (screenWidth/2),
    alignItems: 'center',
    },
button: {
    flex: 1,
    textAlign: 'center',
},
});

1 个答案:

答案 0 :(得分:0)

我需要将width设置为navigatorIOS的包装器组件 编辑:当我从react-native 0.16升级到0.17 flex时:1在navigatorIOS上无效。我必须创建一个包装器组件,并给它一个flex

这不起作用。这是在我的index.ios.js文件中,它将navigatorIOS渲染为0.16。

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

        <NavigatorIOS
         style={{flex: 1, alignSelf: 'stretch'}}
          initialRoute={{
            component: MessageBoardTopics,
            title: 'Forum',
          }}/>  
    </View> 
    );
  }
};

on react-native 0.17我必须创建一个包装器组件并赋予flex属性。我不得不改变我的index.ios.js来代替它。

var forumComponent = React.createClass({
  render: function() {
    return (
      <View style={styles.container}>
    <MessageBoards style={{flex: 1}}/>
      </View>
    );
  }
});