doin / blog

blog
4 stars 0 forks source link

React Native笔记 #21

Open doin opened 6 years ago

doin commented 6 years ago

安装环境

测试环境

HELLO WORLD

学习参考

doin commented 6 years ago
doin commented 6 years ago

navigation + router处理

doin commented 6 years ago

tabbar使用

doin commented 6 years ago

动态设置navigationOptions的title

doin commented 6 years ago

TOAST使用

doin commented 6 years ago

React Native 项目常用第三方组件汇总

doin commented 6 years ago

fetch如何使用, 封装库

doin commented 6 years ago

警告: debug一直在警告, 看翻译就知道需要把浏览器进程放在前面

warning encountered 1 time. remote debugger is in a background tab which may cause apps to perform slowly. fix this by foregrounding the tab (or opening it in a separate window)

翻译: 远程调试器处于后台选项卡,可能会导致应用程序执行缓慢。 通过前面的选项卡(或在单独的窗口中打开它)来解决这个问题

doin commented 6 years ago

真机调试

打开"RCTWebSocketExecutor.m "文件,将“localhost”改为你的电脑的ip,然后在Developer Menu下单击"Debug JS Remotely" 启动JS远程调试功能。

方式一: 在Android5.0以上设备上,将手机通过usb连接到你的电脑,然后通过adb命令行工具运行如下命令来设置端口转发。 adb reverse tcp:8081 tcp:8081

方式二: 你也可以通过在“Developer Menu”下的“Dev Settings”中设置你的电脑ip来进行调试。

心得:在使用真机调试时,你需要确保你的手机和电脑处在同一个网段内,即它们实在同一个路由器下。

doin commented 6 years ago

怎么查看调试网络请求,chorme面板里没有看到

doin commented 6 years ago

webpack打包react文件过大的问题

  1. 生产环境禁用 source-map devtool: shouldUseSourceMap ? false : false
  2. 合并公用文件 vendor: [require.resolve('./polyfills'), "react", "react-dom", "react-router"]

参考

doin commented 6 years ago

图片背景如何实现

通过嵌套来实现背景图片
开发者们常面对的一种需求就是类似web中的背景图(background-image)。要实现这一用例,只需简单地创建一个<Image>组件,然后把需要背景图的子组件嵌入其中即可。

return (
  <Image source={...}>
    <Text>Inside</Text>
  </Image>
);
doin commented 6 years ago

react-native 填坑之Image "unexpected character 乱码"

doin commented 6 years ago

打包IPA给测试人使用教程

  1. 命令编译: react-native bundle --entry-file index.ios.js --platform ios --dev false --bundle-output ios/ios.jsbundle
  2. 修改文件:
    //jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index.ios" fallbackResource:nil];
    jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"ios" withExtension:@"jsbundle"];
doin commented 6 years ago

网络加载的Loading

doin commented 6 years ago

设置IOS的应用名称

设置IOS的图标ICON

doin commented 6 years ago

安卓真机调试

报错 模拟器可以安装 真机无法安装

Installing APK 'app-debug.apk' on 'm2 note - 5.1' for app:debug
09:03:40 E/341473558: Error while uploading app-debug.apk : Unknown failure ([CDS]close[0])
Unable to install /Users/doin/Desktop/coding/DoctorRN/android/app/build/outputs/apk/app-debug.apk
com.android.ddmlib.InstallException: Failed to install all
        at com.android.ddmlib.SplitApkInstaller.install(SplitApkInstaller.java:89)
        at com.android.ddmlib.Device.installPackages(Device.java:904)
        at com.android.builder.testing.ConnectedDevice.installPackages(ConnectedDevice.java:137)
        at com.android.build.gradle.internal.tasks.InstallVariantTask.install(InstallVariantTask.java:134)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:75)
  1. 报错: 安卓真机上启动后白屏

  2. 报错: 真机红屏(同网段不需要)

  3. 摇一摇DEBUG窗不显示:

  4. 5.0和5.0以下真机调试的不同方式

doin commented 6 years ago

使用react navigation关于goBack返回指定页面的问题

doin commented 6 years ago

ScrollView使用RefreshControl完成下拉刷新

doin commented 6 years ago

安卓打包bundle.js文件

react-native bundle --entry-file index.android.js --bundle-output ./android/app/src/main/assets/index.android.jsbundle --platform android --assets-dest ./android/app/src/main/res/ --dev false 

安卓生成key,配置key

// 生成key,把文件拉到APP文件夹DoctorRN-release-key.keystore
$ keytool -genkey -v -keystore DoctorRN-release-key.keystore -alias DoctorRN-key-alias -keyalg RSA -keysize 2048 -validity 10000

// 配置build.gradle
signingConfigs { 
        release { 
            storeFile file("./DoctorRN-release-key.keystore") 
            storePassword "starfish" 
            keyAlias "DoctorRN-key-alias" 
            keyPassword "starfish" 
        } 
    } 

打包安卓的离线包 在output文件里的APK

cd android && ./gradlew assembleRelease

doin commented 6 years ago

使用react-native-root-toast报错

image

解决

image

doin commented 6 years ago

React-native-router-flux

http://blog.csdn.net/fsf_snail/article/details/71080827

webview怎么动态的改变Scene上面的title/状态栏上面的button?

onNavigationStateChange = (navState) => {
        console.log("navState", navState);
        Actions.refresh({title:navState.title});
        this.setState({
          backButtonEnabled: navState.canGoBack,
          forwardButtonEnabled: navState.canGoForward,
          url: navState.url,
          status: navState.title,
          loading: navState.loading,
          scalesPageToFit: true
        });
      };
doin commented 6 years ago

react native 数字键盘没有确认键

doin commented 6 years ago

react-native-xcode.sh: No such file or directory

I was able to solve this error by:

Opening the project in XCode
Navigate to Build Phases > Bundle React Native code and images
Change export NODE_BINARY=node
../node_modules/react-native/packager/react-native-xcode.sh to export NODE_BINARY=node
../node_modules/react-native/scripts/react-native-xcode.sh
Notice how packager is now scripts, which is where that file actually lives in latest version of RN

https://stackoverflow.com/questions/33650380/react-native-error-react-native-xcode-sh-line-45-react-native-command-not-f

doin commented 5 years ago

What is the meaning of 'No bundle URL present' in react-native? https://github.com/facebook/react-native/issues/12754 image

doin commented 5 years ago

https://blog.csdn.net/shalyf/article/details/71629617 apple mach-o linker error 报错解决 https://blog.csdn.net/mushaofeng1990/article/details/53159147 只要在电脑上找到这个文件夹,删除下面所有的缓存文件,然后clean一下项目,再编译运行,就没有问题了。

上图中的 /Users/apple/Library/Developer/Xcode/DerivedData 中的apple 是我本机的用户名,替换成自己的用户名就可以了。

doin commented 5 years ago

found 'config.h'

https://www.jianshu.com/p/cf0ec5469522