落叶随风将要去何方

React Native Android随笔日记

1、以前做Listview 的时候都会有一个滚动条,不由分说,很丑,以前想要去掉却无从下手,

今日偶然发现Scrollview有两个属性

showsHorizontalScrollIndicator bool 

当此属性为true的时候,显示一个水平方向的滚动条。

showsVerticalScrollIndicator bool 

当此属性为true的时候,显示一个垂直方向的滚动条。

一定要记得试一下。果然有用,验证成功。

2、一些简洁的代码语法老会忘记怎么写,现发现一条就记录一条

<View style={[styles.innerContainer, {marginBottom:47}]}></View>
<Text style={{color:'red'}}>{this.state.second>=0?this.state.second:'重发验证码'}</Text>
<Text style={this.state.selectstate==0?styles.presstextnianfen:styles.textnianfen}>全部</Text>
<Image  source={rowData.currentscore>1?require('../home/icon_star_yellow.png'):require('../home/icon_star_grey.png')}
              style={{width:15,height:15,marginRight:2}}/>

 

  <View style={{width:150,height:150,backgroundColor:this.state.selectcenterstate[rowID]==0? "#E9E6E6":"#D2EDF6",borderRadius:5,flexDirection:'column'}}>

 3、关于如何在pop页面后触动更新的问题

一个很好的解决办法从A页面push到B页面,传一个刷新的函数过去,这样从B页面pop回A页面的同时,调用该函数。

例如A页面代码:回调函数中传一个刷新的函数fetchstorise()

pusheditcenter(talkmsg){
   let _this = this;
  this.props.navigator.push({
    name:'editcenter',
    component:TrainerselfCenterEdit,
    params:{
      talkmsg:talkmsg,
      getparams: function(){
      _this.fetchStories();
      }

    }
  })
}

B页面代码,在pop的时候调用该回调函数

pushback(){
    const { navigator } = this.props;
    if(this.props.getparams) {
       this.props.getparams();
    }
    if(navigator) {
//出栈,返回到上一页
        navigator.pop();
    }
  }

 4、关于如何使用定时器

写这个的原因是因为RN的发展速度过快,语法变,使用方法也相应改变,现在这里使用最新的es6的语法

componentDidMount(){
   this.timer=setTimeout(
        ()=>{
          this.setState({content:'这是定时器打印的内容'  })
           },2000
          ); 
   this.timer_two=setTimeout(
        ()=>{
             this.setState({msg:'这是定时器打印的第二段内容'})
         },4000     
       );       
}
 componentWillUnmount(){
     this.timer&&clearTimeout(this.timer);
     this.timer_two&&clearTimeout(this.timer_two);
   }
   render() {
         return (
       <View style={{margin:20}}>
        <Text>{this.state.content}</Text>
        <Text>{this.state.msg}</Text>
       </View>
      );

     }

注意:定时器功能比较简单,注意在es6中使用时,需铭记在unmount组件时清除(clearTimeout/clearInterval)所有用到的定时器。

5、关于如何将ActivityIndicator与定时器结合使用

ActivityIndicator就是一个圆形的显示指示器

属性如下:

animating (bool) 

是否要显示指示器,默认为true,表示显示。

color (string)

滚轮的前景颜色(默认为灰色)。

size enum('small', 'large') 

指示器的大小。small的高度为20,large为36。

实现大概思路:将是否显示指示器anitmating属性从false变成true的过程中通过定时器延迟几秒。

constructor(props) {
        super(props);
        this.state = {
            loading: true
        };
    }
    componentDidMount() {
   
        this.timer = setTimeout(() => {
                this.setState({loading: false})
            },
            6000)
    }
    componentWillUnMount() {
        this.timer && clearTimeout(this.timer)
    }
    render() {
        return (
            <ActivityIndicator
                size='large'
                animating={this.state.loading}
            />
        )
    }

 

posted @ 2016-11-24 10:36  木子飞2  阅读(351)  评论(0编辑  收藏  举报

只留给天空美丽一场