React-Native開發筆記 持續更新

一、css單位轉換px2dp
在作頁面開發的時候習慣了用rem去作css單位,處理各類尺寸數據,到了React-Native裏面作app開發時,rem就很差用了,這個時候就須要轉換成另一個單位,基本原理和rem轉換差很少,以下javascript

'use strict';

import { Dimensions } from 'react-native';

const deviceH = Dimensions.get('window').height;
const deviceW = Dimensions.get('window').width;

const basePx = 375;

export default function px2dp(px) {
    return px * deviceW / basePx;
}

二、RN中的Image標籤是沒法響應click/press事件的,須要的話在外面套一個TouchableOpacity吧css

三、header部分標題居中
ios下默認標題居中,可是android下因爲總體風格和ios不同,因此若是須要居中就要本身動手了。
網上有不少方案,好比設置java

headerTxt: { textAlign: 'center' }
或者
headerStyle: { textAlign: 'center' }

等等,不知道是我寫錯了仍是其餘緣由,並無生效。最終解決方案就是在header中添加一個text組件代替原有的title屬性。而後對text標籤設置居中。react

static navigationOptions={
    headerLeft: <TouchableOpacity onPress={_closeApp}>
      <Image source={{uri: 'https://img.aiyoumi.com/null/20181019/115051759/20181019115051_48x48.png?height=48&width=48'}} style={{width: 21, height: 21, marginLeft: 5}}/>
    </TouchableOpacity>,
    headerTintColor:'#000',                       //按鈕、標題顏色設置
    headerTitle: (
      <Text style={{ flex: 1, textAlign: 'center', color: '#222222', fontSize: px2dp(18) }}>個人客服</Text>
    ),
    headerRight: <View/>
  };

四、ScrollView不生效?
原諒個人無知,我實在不知道我寫的scrollView爲啥拖不動,肯意外的是加一段。。。ref={(scrollView) => { _scrollView = scrollView; }}這個就行了。。。就行了。。。android

<ScrollView ref={(scrollView) => { _scrollView = scrollView; }}>
  <View style={styles.container}>
    <Text>URL:{this.state.requestUrl}</Text>
    <Text>METHOD:{this.state.requestMethod}</Text>
  </View>
  <View style={styles.container}>
    <Text>開始時間: {this.state.startTime}</Text>
    <Text>結束時間: {this.state.endTime}</Text>
    <Text>消耗時間: {this.state.tiemCost}ms</Text>
  </View>
</ScrollView>

五、code-push -t參數誤解
-t參數後通常會跟一個版本號,乍一看可能就覺得是發佈的版本號,而後實際上並非的
-t 參數全稱是 --targetBinaryVersion指的是你的更新要針對的是哪一個版本,好比app中的版本是1.0.1的話,你每次codepush -t的應該都是1.0.1直到app中版本更新。ios

命令行解釋:--targetBinaryVersion, -t  Semver expression that specifies the binary app version(s) this release is targeting (e.g. 1.1.0, ~1.2.3). If omitted, the release will target the exact version specified in the "Info.plist" (iOS), "build.gradle" (Android) or "Package.appxmanifest" (Windows) files.  [字符串] [默認值: null]
相關文章
相關標籤/搜索