react-native errors

持续更新中...


在ScrollView中切换输入框,为什么需要点击两次才能实现?

答:这是由于ScrollView也会相应点击事件,解决这个问题,只需要在ScrollView组件中添加两个属性:
keyboardShouldPersistTaps={true}
keyboardDismissMode={'on-drag'}
即可。


Application 应用名 has not been registered.

Application 应用名 has not been registered.

Hint: This error often happens when you're running the packager (local dev server) from a wrong folder. For example you have multiple apps and the packager is still running for the app you were working on before.
If this is the case, simply kill the old packager instance (e.g. close the packager terminal window) and start the packager in the correct app folder (e.g. cd into app folder and run 'npm start').

This error can also happen due to a require() error during initialization or failure to call AppRegistry.registerComponent.
答:This error can also happen due to a require() error during initialization or failure to call AppRegistry.registerComponent.

一定要注意检查最近修改的文件,看看require和import的引用方式是否正确。

eg:
import * as Linking from "react-native";  //error
import { Linking } from "react-native";     //ok


点击列表页中的Item ,传递不同的参数到详情页,显示不同的内容,再点击慢的情况下没有问题,再点击快的时候会出现数据不更新的情况,导致数据显示错误,怎么解决?

答:这是因为原有的详情页还没有卸载,然后就点击了列表页的item,然后传参数到详情页,
此时不会创建新的详情页,原有详情页会接收传过来的参数通过 componentWillReceiveProps
 方法,此时需要判断相关数据是不是需要重新渲染(或者说现在的详情页需要显示的数据和上
一次的详情页显示的数据是不是一致),如果需要重新渲染,则重新初始化数据,重新调接口,
重新渲染界面。


    // 1. 必须在componentWillReceiveProps(nextProps)生命周期中接受传递的参数
    // 2. 该生命周期方法中的参数必须叫做nextProps
    // 3. 所有传递过来的参数都包含在nextProps参数中
    // 4. 以nextProps.PARAM_NAME的方式获取指定的参数
    componentWillReceiveProps(nextProps) {
        /**
         * todo 判断是不是第一次进入该界面或者说该界面需要重新渲染,
         * todo 主要用于组件还没有卸载,就又调用了该组件,因此会走componentWillReceiveProps方法。
         */
        let isFirstComeIn = nextProps.rowData.order_id != this.props.rowData.order_id;//im

        InteractionManager.runAfterInteractions(() => {
            if (isFirstComeIn) {
                this.onFirstComeIn();
                return;
            }
        });

    }




在react-native中,如果一个组件数据的刷新需要联网,在网络数据返回后更新页面,这个时候,需要在刷新页面的时候判断一下该组件是否处于加载状态,如果不在加载状态,那么不应该调用this.setState()去更新state,可以按以下方法来进行处理:

工具类:BaseCommon.js

/**
 * BaseCommon
 * 公共逻辑处理
 */
'use strict';

import React from "react";

export default class BaseCommon {
    constructor(props) {
    }

    componentWillMount() {
    }

    componentDidMount() {
        this.mounted = true;
    }

    componentWillUnmount() {
        this.mounted = false;
    }

}


通过BaseCommon.js 来对当前组件进行加载状态判断,

export default class IndexScreen extends BaseComponent {
    // 构造
    constructor(props) {
        super(props);
        this.baseCommon = new BaseCommon({ ...props, });

        // 初始状态
        this.state = {
        };
    }

    componentDidMount() {
        this.baseCommon.componentDidMount();

        fetch().then((response) => {
                this.baseCommon.mounted && this.setState({});
            })
    }

    componentWillMount() {
        this.baseCommon.componentWillMount();
    }

    componentWillUnmount() {
        this.baseCommon.componentWillUnmount();
    }
}

I'm having an issue with react-native-camera on Android. It was working fine for about a week now and suddenly, gradle won't build giving the following error:

Error:Execution failed for task ':react-native-camera:processReleaseResources'.
> Error: more than one library with package name 'com.google.android.gms.license'

答: https://stackoverflow.com/questions/49418193/react-native-camera-causing-gradle-build-error/49418244#


Types are not supported by current JavaScript version

changing to "Flow" solved it

参考:
https://intellij-support.jetbrains.com/hc/en-us/community/posts/207764165--Types-are-not-supported-by-current-JavaScript-version-after-update-to-2016-2



Package not compatible with React Native 0.56 (Android)


subprojects { subproject ->
    afterEvaluate {
        if ((subproject.plugins.hasPlugin('android') || subproject.plugins.hasPlugin('android-library'))) {
            android {
                compileSdkVersion rootProject.ext.compileSdkVersion
                buildToolsVersion rootProject.ext.buildToolsVersion
            }
        }
    }
}

ext {
    buildToolsVersion = "26.0.3"
    minSdkVersion = 16
    compileSdkVersion = 26
    targetSdkVersion = 26
    supportLibVersion = "26.1.0"
}

参考:
Package not compatible with React Native 0.56 (Android) https://github.com/react-native-community/react-native-svg/issues/730



界面出现卡死现象,查看内存显示已被占满。

原因:console.log() 打印了不应该被打印的内容,尤其是在非 Debug JS Remotely,模式下,发现不了这个问题,取消该模式,界面会出现卡死现象。

解决方案:将不必要的console.log() 取消掉。


Xcode10 Multiple commands produced error https://www.jianshu.com/p/bb80d6d3724a




ios build failed : build/Script-00DD1BFF1BD5951E006B06BC.sh env: node: No such file or directory

xcode and nvm 兼容性问题
Using node with nvm
If you are using nvm, Xcode seems to have problems locating the default node binary. In that case you should change the scripts to this:

解决方案:(以sentry为例)

#!/bin/bash
# Copyright (c) 2015-present, Facebook, Inc.
# 参考 https://docs.sentry.io/clients/react-native/manual-setup/#ios
# https://github.com/getsentry/react-native-sentry/issues/141
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

# Bundle React Native app's code and image assets.
# This script is supposed to be invoked as part of Xcode build process
# and relies on environment variables (including PWD) set by Xcode


# Setup nvm and set node
[ -z "$NVM_DIR" ] && export NVM_DIR="$HOME/.nvm"

if [[ -s "$HOME/.nvm/nvm.sh" ]]; then
. "$HOME/.nvm/nvm.sh"
elif [[ -x "$(command -v brew)" && -s "$(brew --prefix nvm)/nvm.sh" ]]; then
. "$(brew --prefix nvm)/nvm.sh"
fi

# Set up the nodenv node version manager if present
if [[ -x "$HOME/.nodenv/bin/nodenv" ]]; then
eval "$("$HOME/.nodenv/bin/nodenv" init -)"
fi

[ -z "$NODE_BINARY" ] && export NODE_BINARY="node"

# Run sentry cli script to upload debug symbols
#$NODE_BINARY ../node_modules/@sentry/cli/bin/sentry-cli upload-dsym

# OR

#$NODE_BINARY ../node_modules/@sentry/cli/bin/sentry-cli react-native xcode \
#  ../node_modules/react-native/scripts/react-native-xcode.sh


解决方案:
https://docs.sentry.io/clients/react-native/manual-setup/#ios
https://github.com/getsentry/react-native-sentry/issues/141



No resource identifier found for attribute 'appComponentFactory' in package 'android'

原因是 Androidx和Android support库不能共存

解决方案:
Androidx和Android support库共存问题解决 https://www.jianshu.com/p/f7a7a8765294





你可能感兴趣的:(react-native errors)