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]
相关文章
相关标签/搜索