RN 经验文档(Android)

发布时间:2019-06-15 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了RN 经验文档(Android)脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

React Native 路由跳转

  • 发送广播和接受事件通知DeviceEventEmitter
    A/B页面之间进行"通信"

    //A页面 导入组件:
    import { DeviceEventEmITter } From 'react-native';//添加监听
    
    //A页面 添加广播事件
    DeviceEventEmitter.emit('setTitle', result.data);
    //B页面 导入组件
    import { DeviceEventEmitter } from 'react-native';//添加监听
    
    componentWillMount() {
        this.setTitle = DeviceEventEmitter.addListener('setTitle', (title)=>{
            this.setState({
                title,
            })
        });
    }
    //最后不要忘了,卸载接受广播的方法
    componentWillUnmount(){
        // DeviceEventEmitter.removeListener();
        this.setTitle.remove();
    }
  • 返回并刷新页面,
    this.PRops.navigation.goBack()并不会触发前一个页面的生命钩子,然而有时我们在新页面进行了修改操作,
    同时之前的页面也发生了相应的改变

    this.props.navigation.navigate("newPage", {
        id: this.state.id,
        refresh: function () {
            this._init();
        }
    });
    //newPage页面返回操作执行后会执行 refresh 方法里的 _init();
    <View onPress={() => {
        this.props.navigation.state.params.refresh();
        this.props.navigation.goBack();
    }}>
        <Text>goback</Text>
    </View>

React Native 项目名称修改

  • 修改应用显示名(手机上的APP名称)
androidappsrcmainresvaluesstrings.XMl //IOS下可以在 ios{project}Info.plist中直接更改
  • 修改包名
package.json
index.{os}.js
androidsettings.gradle
andROIdappbuild.gradle
androidappsrcmainjavacom{project}
androidappsrcmainjavacom{project}MainActivity.java
androidappsrcmainjavacom{project}MainApplication.java
<key>CFBundleidentifier</key>
<key>CFBundleName</key>
//下的string直接更改项目名称。
//不过xcode下更方便,开发IOS的话,还是来台MAC吧 - -

React Native 应用图标修改

替换android/app/src/main/res/mipmap-XXX文件夹里面的图片,名字不能修改

RN 经验文档(Android)

React Native 启动页设置

替换android/app/src/main/res/drawable-XXX文件夹里面的图片,名字不能修改

RN 经验文档(Android)

注:gradlew asSEMbleRelease或者react-native run-android之前最好先gradlew clean

Android如何查看应用签名信息

打开密钥放置文件夹(android/app/),输入以下命令,my-release-key.jks为密钥文件名

keytool -list -keyStore my-release-key.jks

脚本宝典总结

以上是脚本宝典为你收集整理的RN 经验文档(Android)全部内容,希望文章能够帮你解决RN 经验文档(Android)所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。