SegmentedControl
使用SegmentedControl
来在设备上渲染一个UISegmentedControl组件。这是一个分段显示多个选项的组件。
截图
属性
renderTabBar
(Function:ReactComponent)- accept 1 argument
props
and should return a component to use as the tab bar. The component hasgoToPage
,tabs
,activeTab
andref
added to the props, and should implementsetAnimationValue
to be able to animate itself along with the tab content. You can manually pass theprops
to the TabBar component.
- accept 1 argument
tabBarPosition
(String) Defaults to"top"
."bottom"
to position the tab bar below content."overlayTop"
or"overlayBottom"
for a semitransparent tab bar that overlays content. Custom tab bars must consume a style prop on their outer element to support this feature:style={this.props.style}
.
onChangeTab
(Function)- function to call when tab changes, should accept 1 argument which is an Object containing two keys:
i
: the index of the tab that is selected,ref
: the ref of the tab that is selected
- function to call when tab changes, should accept 1 argument which is an Object containing two keys:
onScroll
(Function)- function to call when the pages are sliding, should accept 1 argument which is an Float number representing the page position in the slide frame.
locked
(Bool)- disables horizontal dragging to scroll between tabs, default is false.
initialPage
(Integer)- the index of the initially selected tab, defaults to 0 === first tab.
page
(Integer)- set selected tab
children
(ReactComponents)- each top-level child component should have a
tabLabel
prop that can be used by the tab bar component to render out the labels. The default tab bar expects it to be a string, but you can use anything you want if you make a custom tab bar.
- each top-level child component should have a
tabBarUnderlineColor
(String)- color of the default tab bar's underline, defaults to
navy
- color of the default tab bar's underline, defaults to
tabBarBackgroundColor
(String)- color of the default tab bar's background, defaults to
white
- color of the default tab bar's background, defaults to
tabBarActiveTextColor
(String)- color of the default tab bar's text when active, defaults to
navy
- color of the default tab bar's text when active, defaults to
tabBarInactiveTextColor
(String)- color of the default tab bar's text when inactive, defaults to
black
- color of the default tab bar's text when inactive, defaults to
tabBarTextStyle
(Object)- Additional styles to the tab bar's text. Example:
{fontFamily: 'Roboto', fontSize: 15}
- Additional styles to the tab bar's text. Example:
style
( View.propTypes.style )contentProps
(Object)- props that are applied to root
ScrollView
/ViewPagerAndroid
. Note that overriding defaults set by the library may break functionality; see the source for details.
- props that are applied to root
scrollWithoutAnimation
(Bool)- on tab press change tab without animation.
prerenderingSiblingsNumber
(Integer)- pre-render nearby # sibling,
Infinity
=== render all the siblings, default to 0 === render current page.
- pre-render nearby # sibling,
例子
import React,{Component} from 'react';
import {StyleSheet,Text,UIManager,View,AppRegistry,ScrollView,Image} from 'react-native';
import {
SegmentedControl,
DefaultTabBar,
ScrollableTabBar
} from '@ctrip/crn';
class AwesomeProject extends Component {
constructor(props){
super(props);
this.state = {
}
}
render() {
return (
<
View style={styles.container}
>
<
Text style={styles.text}
>
1、SimpleExample
<
/Text
>
<
SegmentedControl
style={{marginTop: 20, }}
renderTabBar={() =
>
<
DefaultTabBar /
>
}
>
<
Text tabLabel='Tab #1'
>
My
<
/Text
>
<
Text tabLabel='Tab #2'
>
favorite
<
/Text
>
<
Text tabLabel='Tab #3'
>
project
<
/Text
>
<
/SegmentedControl
>
<
Text style={styles.text}
>
2、ScrollableTabsExample
<
/Text
>
<
SegmentedControl
style={{marginTop: 20, }}
initialPage={1}
renderTabBar={() =
>
<
ScrollableTabBar /
>
}
>
<
Text tabLabel='Tab #1'
>
My
<
/Text
>
<
Text tabLabel='Tab #2 word word'
>
favorite
<
/Text
>
<
Text tabLabel='Tab #3 word word word'
>
project
<
/Text
>
<
Text tabLabel='Tab #4 word word word word'
>
favorite
<
/Text
>
<
Text tabLabel='Tab #5'
>
project
<
/Text
>
<
/SegmentedControl
>
<
Text style={styles.text}
>
3、OverlayExample
<
/Text
>
<
SegmentedControl
style={styles.container}
renderTabBar={()=
>
<
DefaultTabBar backgroundColor='rgba(255, 255, 255, 0.7)' /
>
}
tabBarPosition='overlayTop'
>
<
ScrollView tabLabel='iOS'
>
<
Image
style={styles.logo}
source={require('./imgs/IOS.png')}
/
>
<
Image
style={styles.logo}
source={require('./imgs/IOS.png')}
/
>
<
Image
style={styles.logo}
source={require('./imgs/IOS.png')}
/
>
<
/ScrollView
>
<
ScrollView tabLabel='Android'
>
<
Image
style={styles.logo}
source={require('./imgs/android.png')}
/
>
<
Image
style={styles.logo}
source={require('./imgs/android.png')}
/
>
<
Image
style={styles.logo}
source={require('./imgs/android.png')}
/
>
<
/ScrollView
>
<
/SegmentedControl
>
<
/View
>
);
}
}
var styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
marginTop:40
},
logo:{
width:300,
height:300
},
text:{
color: 'red'
}
});
AppRegistry.registerComponent('AwesomeProject', () =
>
AwesomeProject);