React Native 中文文档 iOS 选项卡

2024-02-25 开发教程 React Native 中文文档 匿名 2

属性

Edit on GitHub

style View#style

例子

Edit on GitHub

'use strict';var React = require('react-native');var {
  StyleSheet,
  TabBarIOS,
  Text,
  View,
} = React;var TabBarExample = React.createClass({  statics: {    title: '<TabBarIOS>',    description: 'Tab-based navigation.'
  },  getInitialState: function() {    return {      selectedTab: 'redTab',      notifCount: 0,      presses: 0,
    };
  },  _renderContent: function(color: string, pageText: string) {    return (
      <View style={[styles.tabContent, {backgroundColor: color}]}>
        <Text style={styles.tabText}>{pageText}</Text>
        <Text style={styles.tabText}>{this.state.presses} re-renders of the More tab</Text>
      </View>
    );
  },  render: function() {    return (
      <TabBarIOS>
        <TabBarIOS.Item
          title="Blue Tab"
          selected={this.state.selectedTab === 'blueTab'}
          onPress={() => {            this.setState({              selectedTab: 'blueTab',
            });
          }}>
          {this._renderContent('#414A8C', 'Blue Tab')}
        </TabBarIOS.Item>
        <TabBarIOS.Item
          systemIcon="history"
          badge={this.state.notifCount > 0 ? this.state.notifCount : undefined}
          selected={this.state.selectedTab === 'redTab'}
          onPress={() => {            this.setState({              selectedTab: 'redTab',              notifCount: this.state.notifCount + 1,
            });
          }}>
          {this._renderContent('#783E33', 'Red Tab')}
        </TabBarIOS.Item>
        <TabBarIOS.Item
          systemIcon="more"
          selected={this.state.selectedTab === 'greenTab'}
          onPress={() => {            this.setState({              selectedTab: 'greenTab',              presses: this.state.presses + 1
            });
          }}>
          {this._renderContent('#21551C', 'Green Tab')}
        </TabBarIOS.Item>
      </TabBarIOS>
    );
  },
});var styles = StyleSheet.create({  tabContent: {    flex: 1,    alignItems: 'center',
  },  tabText: {    color: 'white',    margin: 50,
  },
});module.exports = TabBarExample;