zoukankan      html  css  js  c++  java
  • React Native入坑记录

    1.render中如果使用props,直接用this.props.xxx,如果是在JSX中,用{this.props.xxx}

     

     

     

    2.警告each child in an array or iterator should have a unique "key" prop.

     

    在<PickerItem ... /> 加一个 key="";

     

     

     

    3.组件id:增加ref="xxx".使用时this.refs.xxx.state.yyyy

     

     

     

    4.android发布后白屏

     

    重新生成asset

     

     

     

    5.生成asset时报错:A problem occurred starting process 'command 'node''

     

    先执行./gradlew --stop

     

     

    6.判断系统

     

    import {

    Platform,

    } from 'react-native';

     

    console.warn(Platform.OS);

     

     

    7.Android发布后闪退深坑

    首先手动在android目录下创建react.grandle,内容为:

    def config = project.hasProperty("react") ? project.react : [];
    
    def bundleAssetName = config.bundleAssetName ?: "index.android.bundle"
    def entryFile = config.entryFile ?: "index.android.js"
    
    // because elvis operator
    def elvisFile(thing) {
        return thing ? file(thing) : null;
    }
    
    def reactRoot = elvisFile(config.root) ?: file("../../")
    def jsBundleDirDebug = elvisFile(config.jsBundleDirDebug) ?:
            file("$buildDir/intermediates/assets/debug")
    def jsBundleDirRelease = elvisFile(config.jsBundleDirRelease) ?:
            file("$buildDir/intermediates/assets/release")
    def resourcesDirDebug = elvisFile(config.resourcesDirDebug) ?:
            file("$buildDir/intermediates/res/merged/debug")
    def resourcesDirRelease = elvisFile(config.resourcesDirRelease) ?:
            file("$buildDir/intermediates/res/merged/release")
    def inputExcludes = config.inputExcludes ?: ["android/**", "ios/**"]
    
    def jsBundleFileDebug = file("$jsBundleDirDebug/$bundleAssetName")
    def jsBundleFileRelease = file("$jsBundleDirRelease/$bundleAssetName")
    
    task bundleDebugJsAndAssets(type: Exec) {
        // create dirs if they are not there (e.g. the "clean" task just ran)
        doFirst {
            jsBundleDirDebug.mkdirs()
            resourcesDirDebug.mkdirs()
        }
    
        // set up inputs and outputs so gradle can cache the result
        inputs.files fileTree(dir: reactRoot, excludes: inputExcludes)
        outputs.dir jsBundleDirDebug
        outputs.dir resourcesDirDebug
    
        // set up the call to the react-native cli
        workingDir reactRoot
        commandLine "react-native", "bundle", "--platform", "android", "--dev", "true", "--entry-file",
                entryFile, "--bundle-output", jsBundleFileDebug, "--assets-dest", resourcesDirDebug
    
        enabled config.bundleInDebug ?: false
    }
    
    task bundleReleaseJsAndAssets(type: Exec) {
        // create dirs if they are not there (e.g. the "clean" task just ran)
        doFirst {
            jsBundleDirRelease.mkdirs()
            resourcesDirRelease.mkdirs()
        }
    
        // set up inputs and outputs so gradle can cache the result
        inputs.files fileTree(dir: reactRoot, excludes: inputExcludes)
        outputs.dir jsBundleDirRelease
        outputs.dir resourcesDirRelease
    
        // set up the call to the react-native cli
        workingDir reactRoot
        commandLine "react-native", "bundle", "--platform", "android", "--dev", "false", "--entry-file",
                entryFile, "--bundle-output", jsBundleFileRelease, "--assets-dest", resourcesDirRelease
    
        enabled config.bundleInRelease ?: true
    }
    
    gradle.projectsEvaluated {
        // hook bundleDebugJsAndAssets into the android build process
        bundleDebugJsAndAssets.dependsOn mergeDebugResources
        bundleDebugJsAndAssets.dependsOn mergeDebugAssets
        processDebugResources.dependsOn bundleDebugJsAndAssets
    
        // hook bundleReleaseJsAndAssets into the android build process
        bundleReleaseJsAndAssets.dependsOn mergeReleaseResources
        bundleReleaseJsAndAssets.dependsOn mergeReleaseAssets
        processReleaseResources.dependsOn bundleReleaseJsAndAssets
    }
    

    然后在根目录下执行:

    react-native bundle --platform android --dev false --entry-file index.android.js --bundle-output ./android/app/build/intermediates/assets/release/index.android.bundle --assets-dest ./android/app/build/intermediates/res/merged/release

  • 相关阅读:
    POJ 1681 Painter's Problem(高斯消元法)
    HDU 3530 Subsequence(单调队列)
    HDU 4302 Holedox Eating(优先队列或者线段树)
    POJ 2947 Widget Factory(高斯消元法,解模线性方程组)
    HDU 3635 Dragon Balls(并查集)
    HDU 4301 Divide Chocolate(找规律,DP)
    POJ 1753 Flip Game(高斯消元)
    POJ 3185 The Water Bowls(高斯消元)
    克琳:http://liyu.eu5.org
    WinDbg使用
  • 原文地址:https://www.cnblogs.com/punkrocker/p/6373127.html
Copyright © 2011-2022 走看看