React Native Listview留空间

ila*_*sas 40 javascript listview ios react-native

我正在尝试在React Native中实现listview.当我刚刚调用组件时,一切都很好Accounts但是因为我把它放到NavigatorIOS中,Listview在第一个项目之前留下了一些空间:看到这里,当我在这里滚动时.

这是我的代码:

index.ios.js

var RemoteX1 = React.createClass({

  render: function() {
    return (
      <NavigatorIOS
        style={styles.container}
        initialRoute={{
          title: 'Accounts',
          component: Accounts,
        }}/>
    );
  }
});

var styles = StyleSheet.create({
  container: {
    flex: 1,
  },
});
Run Code Online (Sandbox Code Playgroud)

accounts.js

var people = [
  {
    title: "Papa",
    favouriteChannels: []
  },
  {
    title: "Maman",
    favouriteChannels: []
  },
  {
    title: "Kids",
    favouriteChannels: []
  },
  {
    title: "Invité",
    favouriteChannels: []
  }
];

var Accounts = React.createClass({
  getInitialState: function() {
    var ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
    return {
      dataSource: ds.cloneWithRows(people),
    }
  },
  renderRow: function(person) {
    return (
      <TouchableHighlight onPress={this.onPressRow}>
        <Text style={styles.account}>{person.title}</Text>
      </TouchableHighlight>
    );
  },
  render: function() {
    return (
      <View style={styles.container}>
        <View style={styles.panel}>
          <Text style={styles.icon}>&#xF0C6;</Text>
          <Text style={styles.welcome}>BIENVENUE</Text>
          <ListView 
            dataSource={this.state.dataSource}
            renderRow={this.renderRow}
            style={styles.listView} />
        </View>
      </View>
    );
  }
});

var styles = StyleSheet.create({
  container: {
    flex: 1,
    alignItems: 'center',
    justifyContent: 'center'
  },
  panel: {
    backgroundColor: '#67F072',
    alignItems: 'center',
    justifyContent: 'center',
    paddingLeft: 50,
    paddingRight: 50,
  },
  icon: {
    color: '#67B7F0',
    fontFamily: 'CanalDemiRomainG7',
    fontSize: 40
  },
  welcome: {
    color: '#67B7F0',
    fontFamily: 'CanalDemiRomainG7'
  },
  account: {
    color: '#000000',
    height: 30,
    alignSelf: 'center',
    fontFamily: 'CanalDemiRomainG7'
  },
})
Run Code Online (Sandbox Code Playgroud)

有没有人知道发生了什么?谢谢

ila*_*sas 87

好的,我找到了答案,我在这里发布给遇到同样问题的人.

这里已经在Github上发布了一个问题.有必要添加ListView参数automaticallyAdjustContentInsets={false}.问题解决了.


dri*_*oda 32

只有当您使用带有TabBarIOS的ScrollView或ListView时才会发生这种情况.如果放置,您可以删除顶部的额外空间automaticallyAdjustContentInsets={false}

但是,ScrollView将无法完全显示,因为它的底部将隐藏在TabBarIOS下.要修复此添加contentInset={{bottom:49}},请根据需要调整高度.

这是代码:

<ListView
  contentInset={{bottom:49}}
  automaticallyAdjustContentInsets={false}
>
Run Code Online (Sandbox Code Playgroud)


Tom*_*Tom 9

如果你想在android..contentInset中尝试实现这一点是iOS特定的,要在android上管理这个你需要在里面设置属性 <ListView contentContainerStyle={styles.contentContainer}> </ListView>

然后在你的stylesheets.create中

var styles = StyleSheet.create({
  contentContainer: {
    paddingBottom: 100 
  }
Run Code Online (Sandbox Code Playgroud)

*我意识到op正在寻求一个iOS解决方案,只是为人们传递的Android解决方案,如果op决定他厌倦了iOS