react手机端

ReactNative的常用组件

2017-02-27  本文已影响438人  45b645c5912e

View

render() {
    return (
      <View style={[styles.flex]}>
        <View style={styles.container}>
          <View style={[styles.item,styles.center]}>
            <Text style={styles.font}>酒店</Text>
          </View>
          <View style={[styles.item,styles.lineLeft]}>
            <View style={[styles.flex,styles.center,styles.lineBottom]}>
              <Text style={styles.font}>机票</Text>
            </View>
            <View style={[styles.flex,styles.center]}>
              <Text style={styles.font}>火车票</Text>
            </View>
          </View>
          <View style={[styles.item,styles.lineLeft]}>
            <View style={[styles.flex,styles.center,styles.lineBottom]}>
              <Text style={styles.font}>旅游</Text>
            </View>
            <View style={[styles.flex,styles.center]}>
              <Text style={styles.font}>攻略</Text>
            </View>
          </View>
        </View>
      </View>

    );

Text

<View style={styles.headBox}>
        <Text style = {styles.font}>
          <Text style = {styles.titleStyle1}>网易</Text>
          <Text style = {styles.titleStyle2}>新闻</Text>
          <Text style = {styles.titleStyle3}>有态度"</Text>
        </Text>
      </View>

Navigator

render() {
    let rootViewName = 'FirstView';
    let rootComponent = FirstView;

    return (
      <Navigator
        initialRoute = {{ name: rootViewName, component: rootComponent }}
        configureScene = {(route) => {
          return Navigator.SceneConfigs.HorizontalSwipeJump ;
        }}
        renderScene = {(route, navigator) => {
          let Component = route.component;
          return <Component {...route.params} navigator = {navigator} />
        }} />
    );
  }
push = (Id) =>{
    var _this = this;
    const navigator = this.props.navigator;
    if (navigator) {
      navigator.push({
        name: 'SecondView',
        component: SecondView,
        params: {
          id: Id,
          getUser: function(user) {
            _this.setState({
              user: user
            })

          }
        }
      });
    }

  }
pop = () =>{
    if (this.props.navigator) {
      this.props.navigator.pop();
      let user = USER_MODELS[this.state.Id];
      this.props.getUser(user);
    }

  }

TextInput

Touchable类组件

Image

Picker

<View style={styles.container}>
        <Text >
          Picker选择器实例
        </Text>
        <Picker
          style={{width:200}}
          selectedValue={this.state.language}
          onValueChange={(value) => this.setState({language: value})}>
          <Picker.Item label="Java" value="java" />
          <Picker.Item label="JavaScript" value="javaScript" />
        </Picker>
        <Text>当前选择的是:{this.state.language}</Text>
      </View>

Switch

<View style={styles.container}>
        <Text>
           Swtich实例
        </Text>
        <Switch
          onValueChange={(value) => this.setState({falseSwitchIsOn: value})}
          style={{marginBottom:10,marginTop:10}}
          value={this.state.falseSwitchIsOn} />
        <Switch
          onValueChange={(value) => this.setState({trueSwitchIsOn: value})}
          value={this.state.trueSwitchIsOn} />
      </View>

ProgressBar

<View style={styles.container}>
            <ProgressViewIOS style={styles.progressView} progress={this.getProgress(0)}/>
            <ProgressViewIOS style={styles.progressView} progressTintColor="purple" progress={this.getProgress(0.2)}/>
            <ProgressViewIOS style={styles.progressView} progressTintColor="red" progress={this.getProgress(0.4)}/>
            <ProgressViewIOS style={styles.progressView} progressTintColor="orange" progress={this.getProgress(0.6)}/>
            <ProgressViewIOS style={styles.progressView} progressTintColor="yellow" progress={this.getProgress(0.8)}/>
          </View>
componentDidMount() {
      this.updateProgress();
  }
  updateProgress() {
    var progress = this.state.progress + 0.01;
    this.setState({ progress });
    this.timer = requestAnimationFrame(() => this.updateProgress());
  }
  getProgress(offset) {
    console.log('11');
    var progress = this.state.progress + offset;
    return Math.sin(progress % Math.PI) % 1;
  }
<View style={styles.container}>
          <ProgressBarAndroid progress={this.state.progress} {...this.props} />
        </View>

WebView

ListView

  <ListView
                dataSource={this.dataSource.cloneWithRows(this.state.dataArr)}
                renderRow={this.renderRow} //设置cell
                style={{width:screenWidth}}
                onEndReached={ this._toEnd }
                onEndReachedThreshold={20}
                renderFooter={ this._renderFooter }
                enableEmptySections = {true}
                refreshControl={
                        <RefreshControl
                            refreshing={this.state.isRefresh}
                            onRefresh={this._onRefresh}
                            tintColor="gray"
                            title="Loading..."
                            titleColor="gray"
                            colors={['#ff0000', '#00ff00', '#0000ff']}
                            progressBackgroundColor="#ffff00"
                        />}
            />
<ListView //创建ListView
                dataSource={this.dataSource.cloneWithRows(this.state.car)} //设置数据源
                renderRow={this.renderRow} //设置cell
                contentContainerStyle={styles.listViewStyle}//设置cell的样式
                onEndReached={ this._toEnd }
                onEndReachedThreshold={10}
                renderFooter={ this._renderFooter }
                enableEmptySections = {true}
                removeClippedSubviews={false}
                refreshControl={
                        <RefreshControl
                            refreshing={this.isRefreshing}
                            onRefresh={this._onRefresh}
                            tintColor="gray"
                            title="Loading..."
                            titleColor="gray"
                            colors={['#ff0000', '#00ff00', '#0000ff']}
                            progressBackgroundColor="#ffff00"
                        />}
            />
render(){
        const { brand} = this.props;
        var  Arr = brand ,
            sectionIDs =[],//所有区ID的数组
            rowIDs =[];//行ID数组
        for (let i in brand ) {
            sectionIDs.push(i);
            rowIDs.push(brand[i])
        }
        return(
                <ListView//创建表,并设置返回section和cell的方法
                    dataSource={this.dataSource.cloneWithRowsAndSections(Arr,sectionIDs,rowIDs)}
                    renderRow={this.renderRow}
                    renderSectionHeader={this.renderSectionHeader}
                    renderHeader={this.renderHeader }
                />
        )
    }
上一篇 下一篇

猜你喜欢

热点阅读