zoukankan      html  css  js  c++  java
  • React-Native开发笔记 持续更新

    1、css单位转换px2dp
    在做页面开发的时候习惯了用rem去做css单位,处理各种尺寸数据,到了React-Native里面做app开发时,rem就不好用了,这个时候就需要转换成另外一个单位,基本原理和rem转换差不多,如下

    '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;
    }
    

    2、RN中的Image标签是无法响应click/press事件的,需要的话在外面套一个TouchableOpacity吧

    3、header部分标题居中
    ios下默认标题居中,但是android下由于整体风格和ios不一样,所以如果需要居中就要自己动手了。
    网上有很多方案,比如设置

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

    等等,不知道是我写错了还是其他原因,并没有生效。最终解决方案就是在header中添加一个text组件代替原有的title属性。然后对text标签设置居中。

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

    4、ScrollView不生效?
    原谅我的无知,我实在不知道我写的scrollView为啥拖不动,肯意外的是加一段。。。ref={(scrollView) => { _scrollView = scrollView; }}这个就好了。。。就好了。。。

    <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>
    

    5、code-push -t参数误解
    -t参数后一般会跟一个版本号,乍一看可能就以为是发布的版本号,然后实际上并不是的
    -t 参数全称是 --targetBinaryVersion指的是你的更新要针对的是哪个版本,比如app中的版本是1.0.1的话,你每次codepush -t的应该都是1.0.1直到app中版本更新。

    命令行解释:--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]
    
    
  • 相关阅读:
    数组的学习(一)
    Servlet是线程安全吗?
    MySql用户管理:添加用户、授权、删除用户
    泛型(二)
    泛型(一)
    Spring MVC
    spring框架
    mybatis基础
    Hibernate 基础
    Java局部类
  • 原文地址:https://www.cnblogs.com/heioray/p/9907653.html
Copyright © 2011-2022 走看看