SegmentedControl

使用SegmentedControl来在设备上渲染一个UISegmentedControl组件。这是一个分段显示多个选项的组件。

截图

属性

  • renderTabBar (Function:ReactComponent)
    • accept 1 argument props and should return a component to use as the tab bar. The component has goToPage , tabs , activeTab and ref added to the props, and should implement setAnimationValue to be able to animate itself along with the tab content. You can manually pass the props to the TabBar component.
  • 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
  • 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.
  • tabBarUnderlineColor (String)
    • color of the default tab bar's underline, defaults to navy
  • tabBarBackgroundColor (String)
    • color of the default tab bar's background, defaults to white
  • tabBarActiveTextColor (String)
    • color of the default tab bar's text when active, defaults to navy
  • tabBarInactiveTextColor (String)
    • color of the default tab bar's text when inactive, defaults to black
  • tabBarTextStyle (Object)
    • Additional styles to the tab bar's text. Example: {fontFamily: 'Roboto', fontSize: 15}
  • 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.
  • 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.

例子

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);

results matching ""

    No results matching ""