React Native 踩坑记

969 阅读1分钟

一、rn上遇到的各类安卓打包bug解决方法

  • Could not list contents of '/Users/xxxx/Downloads/xxxx/node_modules/node-pre-gyp /node_modules/.bin/needle'. Couldn't follow symbolic link.

重新npm install node-pre-gyp
改变是否vpn

  • 全局设置react-navigation样式,使顶部标题栏居中

createStackNavigator( { xxxxx }, { headerLayoutPreset: 'center' } );

  • 键盘将底部导航栏顶起解决方案

用react-navigation中设置tabBarVisible: false,但此方法在安卓中收起键盘后会出现留白,所以安卓下将android->app->sra->main->AndroidManifest.xml文件中android:windowSoftInputMode:值更改为stateAlwaysHidden|adjustPan

  • android 打包时报/fsevents/node_modules/node-pre-gyp/node_modules/.bin/needle

将此文件找到删除 ->没找到此文件 重新 npm install node-pre-gyp -> 迷之解决问题了,但是每次打包都要重新安装一次

  • 实现高度自适应的Text

www.hangge.com/blog/cache/…

  • 写组件时注意不要使用关键字,如key等
  • 从config里拿的时候要注意,因为编译方式不一样,所以可能导致

二、ios pod时出现的问题 当我使用react-native-permissions,执行到pod install遇到下列报错

[!] Unable to find a specification for "RNPermissions" depended upon by "Permission-LocationWhenInUse"

You have either:
 * out-of-date source repos which you can update with "pod repo update" or with "pod install --repo-update".
 * mistyped the name or version.
 * not added the source repo that hosts the Podspec to your Podfile.

原因为我使用的rn版本为0.59.1,0.60以下版本pod不能自动link,需要手动添加 pod 'RNPermissions', :path => '../node_modules/react-native-permissions' 则可pod install成功

三、可以尝试在android->app->src->main->res->values->styles.xml中添加如下代码 <style name="upsdkDlDialog" parent="@android:style/Theme.Holo.Light"> <item name="android:windowBackground">@android:color/transparent</item> <item name="android:windowNoTitle">true</item> <item name="android:windowIsTranslucent">true</item> </style>

希望对您有所帮助