React Native组件 --Touchable类&Image&TabBarIOS&WebView

737 查看

1.Touchable类组件

a.TouchableHighlight组件: 高亮触摸,出现高亮效果

属性:

    - activeOpacity : 触摸时透明度的设置
    - onHideUnderlay:隐藏背景阴影时触发该事件
    - onShowUnderlay:出现背景阴影时触发该事件
    - underlayColor:点击时背景阴影效果的背景颜色
b.TouchableOpacity:透明触摸,出现透明过滤效果

属性:

     activeOpacity:触摸时透明度的设置
c.TouchableWitoutFeedback:无反馈性触摸,不会出现任何视图变化
事件:
 onLongPress:长按事件
 onPressIn:触摸进入事件
 onPressOut:触摸释放事件

2.Image组件

属性及事件
- resizeMode:枚举类型。cover、contain、stretch;表示图片适应的模式;
   - Image.resizeMode.cover:图片居中显示,没有被拉伸,超出部分被截断
   - Image.resizeMode.contain:容器完全容纳图片,图片等比例进拉伸
   - Image.resizeMode.stretch:图片被拉伸适应容器大小,有可能会发生变形
- source:图片的引用地址,{uri:string}如果是一个本地的静态资源;那么需要使用- require(’image!name’)包裹
- defaultSource:表示默认的图片地址。
- onLoad:加载成功时触发该事件
- onLoadEnd :不管加载失败还是加载成功,都会触发该事件
- onLoadStart:加载开始时触发
- onProgress:加载过程的进度事件

注:
本地图片:<Image source = { require(‘image!my-icon')}/> // 加载xcode中的图片

3.TabBarIOS组件

属性:
barTintColor :tab栏的背景颜色
tintColor:选中tab的图标颜色
translucent:tab栏是否透明
TabBarIOS.Item组件属性及事件:
badge:红色的提示数字
icon:tab图标
onPress:点击事件;注:其中一个tab被选中时,需要改变该组件的selected = {true}
selected:是否选中某个tab;
selectedIcon:选中状态的图标;如果为空图标变为蓝色;类似于iOS系统默认渲染图片;
systemIcon:系统图标;枚举类型:bookmarks,contacts,downloads,favorites,featured,history,more,most-recent,most-viewed,recents,search,top-rated;
title:标题;出现在图标底部;使用系统图标时,会忽略该标题;
      <TabBarIOS style = {styles.flex}>
           <TabBarIOS.Item
              title = "消息"
              icon = {require("image!message")}
              onPress = {this.select.bind(this,'message')}
              selected = {this.state.tab == 'message'}>
           </TabBarIOS.Item>
           <TabBarIOS.Item
              title = "联系人"
              icon = {require("image!phone")}
              onPress = {this.select.bind(this,'phonelist')}
              selected = {this.state.tab == 'phonelist'}>
        </TabBarIOS.Item>
      </TabBarIOS>

4.WebView组件

属性及事件
automaticallyAdjustContentInsets:表示是否自动调整内部内容,
bounces:回弹效果,默认为true;
contentInset:内部内容偏移值,{top:number,left:number,bottom:number,right:number}
html:html代码字符串
injectedJavaScript:注入的JavaScript代码,
onNavigationStateChange:监听导航状态变化的函数
renderError:监听渲染页面出错的函数
startInLoadingState:是否开启页面加载的状态
renderLoading:webview组件正在渲染页面时触发的函数,startInLoadingState为true时才起作用;
scrollEnabled:表示webview 页面是否能滚动;
onNavigationStateChange:按照页面比例和内容宽高比例自动缩放内容;
        <WebView
        injectedJavaScript = "alert('欢迎使用React Native')"
        bounces = {false}
        url = 'http://weibo.com'
        style = {{width:width,height:height}}>
        </WebView>
        <WebView
        contentInset = {{left:100,top:180}}
        scrollEnabled = {false}
        html = '<div> <img  src = "http://upload.jianshu.io/users/upload_avatars/1109379/e9bb0a950f29.jpg?imageMogr/thumbnail/90x90/quality/100"/></div>'
        style = {{width:width,height:height}}>
        </WebView>

注:
xcode访问HTTP时需要做一下配置


网络配置