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 (<ActivityIndicatorsize='large'animating={this.state.loading}/> )}?
轉載于:https://www.cnblogs.com/lgp142332/p/6096753.html
總結
以上是生活随笔為你收集整理的React Native Android随笔日记的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: matlab 莫比乌斯曲面,『Rhino
- 下一篇: Asdasd