haibinyu / react-native-tricks Goto Github PK
View Code? Open in Web Editor NEWTips, Tricks, and Techniques on using React Native.
Tips, Tricks, and Techniques on using React Native.
在通过react-native init 新生成项时,有时候会挂起,无法成功,这时候很可能是watchman导致的,运行下面的命令重新安装watchman可以解决问题
rm -rf /usr/local/var/run/watchman/ && brew uninstall watchman && brew install watchman
在 app开发过程中,添加了新的图片之后,有时会出现如下错误:
Unexpected character '�' (1:0)
具体issue可参见这里
可能的原因是 npm start
的时候React Native会生成一份图片的map,新加入的图片导致map出现问题。
重启packager:
npm start
React Native app 启动后,在显示app landing view前会显示一段时间的白屏,随着app内容增加,白屏时间也会增加,非常影响用户体验。
React Native app打包后,所有的js文件会打包到js.bundle文件中,app启动时会load该文件到内存,然后显示第一个界面,如果js.bundle文件很大, load需要比较长的时间,在这段时间内就会出现白屏。
对于iOS, 解决方法是在load js.bundle的这段时间内显示一个loadingView, 幸运的是RCTRootView
已经提供了技术支持,具体方法是在 AppDelegate.m
的application:didFinishLaunchingWithOptions:
方法内添加如下代码,在load js.bundle 的时候显示LaunchScreen
UIView* launchScreen = [[[NSBundle mainBundle] loadNibNamed:@"LaunchScreen" owner:self options:nil] objectAtIndex:0];
launchScreen.frame = [UIScreen mainScreen].bounds;
rootView.loadingView = launchScreen;
return YES;
对于 Android,一个简单的解决方法是添加一个SplashScreen,方法如下:
splash_screen.xml
的 drawable作为SplashScreen:<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/background"/>
<item>
<bitmap android:gravity="center" android:src="@drawable/logo"/>
</item>
</layer-list>
SplashTheme
的Theme:<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
</style>
<style name="SplashTheme" parent="AppTheme">
<item name="android:windowBackground">@drawable/splash_screen</item>
</style>
</resources>
<application
android:theme="@style/SplashTheme">
</application>
该解决方案简单易用,虽然没有提高app的启动速度,但很好的解决了白屏问题,提高了app用户体验。
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.