Cocina

Cocina

  • 文档
  • UI组件
  • API
  • 帮助
  • 博客

›组件

起步

  • 集合

组件

  • 结构
  • 手风琴
  • 浮动弹层
  • 角标
  • 按钮
  • 卡片
  • 复选框
  • 日期选择
  • 滑动的卡片
  • 浮动按钮
  • 底部选项卡
  • 表单
  • 顶部栏
  • 图标
  • 列表
  • 选择器
  • 单选
  • 搜索栏
  • 分段器
  • 加载器
  • 缩略图
  • 吐司
  • 标题大小
  • 抽屉滑动
  • 关联组件

列表

List 列表

用于指定信息列表的基本组件。

属性:

属性默认值选项描述
button-booleanTo navigate on click of a list item.
dataArrayArrayuser-defined arrayArray of data chunks to render iteratively.
selectedtruebooleanHighlights the selected item
noIndenttruebooleanRemoves margin from left Useful incase of setting backgroundColor for ListItem.
itemDivider-booleanHelps to organize and group the list items.
itemHeader--Style the item as header for ListItems
first--Adds style of first ListItem
last--Adds style of last ListItem
icon--To have list styling of icons
avatar--Style the list to have Avatars
thumbnail--Style the list to have Thumbnails
renderRowFunction-Callback which takes a chunk of data from dataArray and return as a component
enableEmptySections-booleanFlag indicating whether empty section headers should be rendered

注意:不鼓励使用List进行动态列表生成。请改用Flatlist。

列表分割符

List Divider组件创建一个列表分隔符,可用于对列表项进行分组。要为列表的任何子元素创建分隔符,请包含itemDividerprop with ListItemcomponent。 NativeBase的List Divider带有默认样式,可以轻松定制。

代码示例:

import React, { Component } from 'react';
import { Container, Header, Content, List, ListItem, Text } from 'native-base';
export default class ListDividerExample extends Component {
  render() {
    return (
      <Container>
        <Header />
        <Content>
          <List>
            <ListItem itemDivider>
              <Text>A</Text>
            </ListItem>                    
            <ListItem>
              <Text>Aaron Bennet</Text>
            </ListItem>
            <ListItem>
              <Text>Ali Connors</Text>
            </ListItem>
            <ListItem itemDivider>
              <Text>B</Text>
            </ListItem>  
            <ListItem>
              <Text>Bradley Horowitz</Text>
            </ListItem>
          </List>
        </Content>
      </Container>
    );
  }
}

列表标题

List Header组件创建一个列表标题,可用于对列表项进行分组。要为列表的任何子元素创建标题,请包含itemHeaderprop with ListItemcomponent。NativeBase的List Header带有默认样式,可以轻松定制。

代码示例:

import React, { Component } from 'react';
import { Container, Header, Content, List, ListItem, Text } from 'native-base';
export default class ListHeaderExample extends Component {
  render() {
    return (
      <Container>
        <Header />
        <Content>
          <List>
            <ListItem itemHeader first>
              <Text>COMEDY</Text>
            </ListItem>
            <ListItem >
              <Text>Hangover</Text>
            </ListItem>
            <ListItem last>
              <Text>Cop Out</Text>
            </ListItem>
            <ListItem itemHeader>
              <Text>ACTION</Text>
            </ListItem>
            <ListItem>
              <Text>Terminator Genesis</Text>
            </ListItem>
          </List>
        </Content>
      </Container>
    );
  }
}

ListItem已选中

ListItem的Selected组件突出显示所选的当前listitem。包括selected道具与ListItem组件。此道具带有默认样式,可轻松定制。

代码示例:

import React, { Component } from 'react';
import { Container, Header, Content, List, ListItem, Text, Left, Right, Icon } from 'native-base';
export default class ListItemSelectedExample extends Component {
  render() {
    return (
      <Container>
        <Header />
        <Content>
          <List>
            <ListItem selected>
              <Left>
                <Text>Simon Mignolet</Text>
              </Left>
              <Right>
                <Icon name="arrow-forward" />
              </Right>
            </ListItem>
            <ListItem>
             <Left>
                <Text>Nathaniel Clyne</Text>
              </Left>
              <Right>
                <Icon name="arrow-forward" />
              </Right>
            </ListItem>
            <ListItem>
              <Left>
                <Text>Dejan Lovren</Text>
              </Left>
              <Right>
                <Icon name="arrow-forward" />
              </Right>
            </ListItem>
          </List>
        </Content>
      </Container>
    );
  }
}

ListItem NoIndent

import React, { Component } from 'react';
import { Container, Header, Content, List, ListItem, Text, Left, Right, Icon } from 'native-base';
export default class ListItemNoIndentExample extends Component {
  render() {
    return (
      <Container>
        <Header />
        <Content>
          <List>
            <ListItem noIndent style={{ backgroundColor: "#cde1f9" }}>
              <Left>
                <Text>Simon Mignolet</Text>
              </Left>
              <Right>
                <Icon name="arrow-forward" />
              </Right>
            </ListItem>
            <ListItem >
             <Left>
                <Text>Nathaniel Clyne</Text>
              </Left>
              <Right>
                <Icon name="arrow-forward" />
              </Right>
            </ListItem>
            <ListItem>
              <Left>
                <Text>Dejan Lovren</Text>
              </Left>
              <Right>
                <Icon name="arrow-forward" />
              </Right>
            </ListItem>
          </List>
        </Content>
      </Container>
    );
  }
}

列表图标

import React, { Component } from 'react';
import { Container, Header, Content, List, ListItem, Text, Icon, Left, Body, Right, Switch } from 'native-base';
export default class ListIconExample extends Component {
  render() {
    return (
      <Container>
        <Header />
        <Content>
          <ListItem icon>
            <Left>
              <Button style={{ backgroundColor: "#FF9501" }}>
                <Icon active name="plane" />
              </Button>
            </Left>
            <Body>
              <Text>Airplane Mode</Text>
            </Body>
            <Right>
              <Switch value={false} />
            </Right>
          </ListItem>
          <ListItem icon>
            <Left>
              <Button style={{ backgroundColor: "#007AFF" }}>
                <Icon active name="wifi" />
              </Button>
            </Left>
            <Body>
              <Text>Wi-Fi</Text>
            </Body>
            <Right>
              <Text>GeekyAnts</Text>
              <Icon active name="arrow-forward" />
            </Right>
          </ListItem>
          <ListItem icon>
            <Left>
              <Button style={{ backgroundColor: "#007AFF" }}>
                <Icon active name="bluetooth" />
              </Button>
            </Left>
            <Body>
              <Text>Bluetooth</Text>
            </Body>
            <Right>
              <Text>On</Text>
              <Icon active name="arrow-forward" />
            </Right>
          </ListItem>
        </Content>
      </Container>
    );
  }
}

列表头像

列表头像是中等的,用于显示包含图标和缩略图之间维度的列表项的图像。要创建头像列表,请使用prop 在组件内嵌套组件avatar。

import React, { Component } from 'react';
import { Container, Header, Content, List, ListItem, Left, Body, Right, Thumbnail, Text } from 'native-base';
export default class ListAvatarExample extends Component {
  render() {
    return (
      <Container>
        <Header />
        <Content>
          <List>
            <ListItem avatar>
              <Left>
                <Thumbnail source={{ uri: 'Image URL' }} />
              </Left>
              <Body>
                <Text>Kumar Pratik</Text>
                <Text note>Doing what you like will always keep you happy . .</Text>
              </Body>
              <Right>
                <Text note>3:43 pm</Text>
              </Right>
            </ListItem>
          </List>
        </Content>
      </Container>
    );
  }
}

列表缩略图

列表缩略图是显示列表项目图像的媒介。要创建缩略图列表,请在组件中嵌套具有少量道具和样式的组件。

import React, { Component } from 'react';
import { Container, Header, Content, List, ListItem, Thumbnail, Text, Left, Body, Right, Button } from 'native-base';
export default class ListThumbnailExample extends Component {
  render() {
    return (
      <Container>
        <Header />
        <Content>
          <List>
            <ListItem thumbnail>
              <Left>
                <Thumbnail square source={{ uri: 'Image URL' }} />
              </Left>
              <Body>
                <Text>Sankhadeep</Text>
                <Text note numberOfLines={1}>Its time to build a difference . .</Text>
              </Body>
              <Right>
                <Button transparent>
                  <Text>View</Text>
                </Button>
              </Right>
            </ListItem>
          </List>
        </Content>
      </Container>
    );
  }
}

动态列表

设计用于有效表示垂直滚动的变化数据列表的中心方面。最简单的方法是创建一个List dataArray,用一组数据块填充它,并使用该数据块实例化一个ListItem组件,并从一个renderRow回调中获取整个数据数组中的一个块并返回一个可渲染组件。

import React, { Component } from 'react';
import { Container, Header, Content, List, ListItem, Text } from 'native-base';
export default class DynamicListExample extends Component {
  render() {
    var items = [
      'Simon Mignolet',
      'Nathaniel Clyne',
      'Dejan Lovren',
      'Mama Sakho',
      'Emre Can'
    ];
    return (
      <Container>
        <Header />
        <Content>
          <List dataArray={items}
            renderRow={(item) =>
              <ListItem>
                <Text>{item}</Text>
              </ListItem>
            }>
          </List>
        </Content>
      </Container>
    );
  }
}

列表分隔符

分隔符组件是列表中通常使用的分隔符,可用于对列表项进行分组。虽然它与List一起使用,但您可以在应用中的任何位置使用它。

import React, { Component } from 'react';
import { Container, Header, Content, List, ListItem, Text, Separator } from 'native-base';
export default class ListSeparatorExample extends Component {
  render() {
    return (
      <Container>
        <Header />
        <Content>
          <Separator bordered>
            <Text>MIDFIELD</Text>
          </Separator>
          <ListItem>
            <Text>Caroline Aaron</Text>
          </ListItem>
          <ListItem last>
            <Text>Lee Allen</Text>
          </ListItem>
          <Separator bordered>
            <Text>MIDFIELD</Text>
          </Separator>
          <ListItem>
            <Text>Caroline Aaron</Text>
          </ListItem>
          <ListItem last>
            <Text>Lee Allen</Text>
          </ListItem>
        </Content>
      </Container>
    );
  }
}
属性默认值选项描述
bordered--Adds border to top and bottom of the separator
← PreviousNext →
  • List 列表
  • 列表分割符
  • 列表标题
  • ListItem已选中
  • ListItem NoIndent
  • 列表图标
  • 列表头像
  • 列表缩略图
  • 动态列表
  • 列表分隔符
Cocina
Docs
Getting Started (or other categories)Guides (or other categories)API Reference (or other categories)
Community
User ShowcaseStack OverflowProject ChatTwitter
More
BlogGitHubStar
Facebook Open Source
Copyright © 2019 Your Name or Your Company Name