We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
本教程适合已有React开发经验的朋友阅读
可以通过npm run android或npm run ios启动并在模拟器查看效果。
示例代码:/lesson01/App.js
<View> <Image source={require('/react-native/img/favicon.png')} /> <Image source={{ uri: 'https://facebook.github.io/react-native/docs/assets/favicon.png' }} /> <Image source={{ uri: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADMAAAAzCAYAAAA6oTAqAAAAEXRFWHRTb2Z0d2FyZQBwbmdjcnVzaEB1SfMAAABQSURBVGje7dSxCQBACARB+2/ab8BEeQNhFi6WSYzYLYudDQYGBgYGBgYGBgYGBgYGBgZmcvDqYGBgmhivGQYGBgYGBgYGBgYGBgYGBgbmQw+P/eMrC5UTVAAAAABJRU5ErkJggg==' }} /> </View>
// 引入Dimensions,用于获取设备的尺寸 import { Dimensions } from 'react-native'; // 设置基础宽度为750 const BASE_WIDTH=750; export function calc(size){ // 获取当前窗口宽度,支持参数为window和screen let { width } = Dimensions.get('window'); // 换算出当前需要显示的尺寸 return size * width / BASE_WIDTH; }
The text was updated successfully, but these errors were encountered:
内容和标题不符……
Sorry, something went wrong.
No branches or pull requests
阅读更多系列文章请访问我的GitHub博客,示例代码请访问这里。
可以通过npm run android或npm run ios启动并在模拟器查看效果。
React Native基础组件
值得注意的是,在React Native中所有的文本都必须放在Text中,而不能单独显示。
若是需要渲染长列表,如一个商品列表,则可以使用FlatList组件,因为ScrollView会将列表组件一次性渲染出,这样容易造成过多内存占用,而FlatList则只会渲染将要出现在屏幕中的元素。
虽然FlatList在使用上更加复杂,但为了提升性能,我们应该优先使用ScrollView。
如color,在Android中,它修改的是背景色,在iOS中,它修改的是字体颜色。
在开发中,若需要用到Button,在GitHub上搜索是一个好选择:https://github.com/search?utf8=%E2%9C%93&q=react+native+button&ref=simplesearch
React Native样式介绍
为了适配各尺寸屏幕,可以通过设定基础屏幕宽度,如750,与当前屏幕宽度换算出当前实际需要的尺寸。
The text was updated successfully, but these errors were encountered: