iis服务器助手广告广告
返回顶部
首页 > 资讯 > 精选 >React-Native中一些常用组件的用法详解(一)
  • 183
分享到

React-Native中一些常用组件的用法详解(一)

react-native常用组件用法 2023-05-31 00:05:48 183人浏览 独家记忆
摘要

前言本文为大家介绍一下React-Native中一些常用的组件,由于对es6的语法并没有完全掌握,这里暂时用ES5和ES6混用的语法。View组件View是一个支持Flexbox布局、样式、一些触摸处理、和一些无障碍功能的容器,并且它可以放

前言

本文为大家介绍一下React-Native中一些常用的组件,由于对es6的语法并没有完全掌握,这里暂时用ES5和ES6混用的语法。

View组件

View是一个支持Flexbox布局、样式、一些触摸处理、和一些无障碍功能的容器,并且它可以放到其它的视图里,也可以有任意多个任意类型的子视图。

View的设计初衷是和StyleSheet搭配使用,这样可以使代码更清晰并且获得更高的性能。尽管内联样式也同样可以使用。

View的常用样式设置

  • flex布局样式
  • backgroundColor:背景颜色
  • borderColor:边框颜色
  • borderWidth:边框大小
  • borderRadius:圆角

以手机端携程官网为示例

import React, { Component } from 'react';import { AppReGIStry, StyleSheet, Text, View} from 'react-native';var ViewTest = React.createClass({ render () { return ( <View style={styles.container}> <View style={[styles.flex, styles.center]}>  <Text style={styles.white}>酒店</Text> </View> <View style={styles.flex}>  <View style={[styles.flex, styles.leftRightLine, styles.bottomLine, styles.center]}>  <Text style={styles.white}>海外酒店</Text>  </View>  <View style={[styles.flex, styles.leftRightLine, styles.center]}>  <Text style={styles.white}>特价酒店</Text>  </View> </View> <View style={styles.flex}>  <View style={[styles.flex, styles.bottomLine, styles.center]}>  <Text style={styles.white}>团购</Text>  </View>  <View style={[styles.flex, styles.center]}>  <Text style={styles.white}>民宿•网</Text>  </View> </View> </View> ) }});var styles = StyleSheet.create({ container: { margin: 10, marginTop: 25, height: 75, flexDirection: "row", backgroundColor: "#ff607c", borderRadius: 5 }, flex: { flex: 1 }, white: { color: "white", fontWeight: "900", textShadowColor: "#ccc", textShadowOffset: {width: 1, height: 1} }, center: { justifyContent: "center", alignItems: "center" }, leftRightLine: { borderLeftWidth: 1, borderRightWidth: 1, borderColor: "white" }, bottomLine: { borderBottomWidth: 1, borderColor: "white" }});AppRegistry.registerComponent('HelloReact', () => ViewTest);

--结束END--

本文标题: React-Native中一些常用组件的用法详解(一)

本文链接: https://www.lsjlt.com/news/222583.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作