Dhi*_*iya 1 reactjs react-native react-native-tab-view react-native-scrollable-tab-view
我正在使用react-native-tab-view屏幕顶部的显示选项卡。如果屏幕数量将增加(超过 5 个),屏幕视图看起来会很拥挤
下面是我的代码片段
export default class CustomTabViewComponent extends React.Component{
state = {
index: 0,
routes: [
{ key: 'tab1', title: 'Tab1' },
{ key: 'tab2', title: 'Tab2' },
{ key: 'tab3', title: 'Tab3' },
{ key: 'tab4', title: 'Tab4' },
{ key: 'tab5', title: 'Tab5' },
],
};
render(){
return(
<TabView
navigationState={this.state}
renderScene={this.renderScene}
renderTabBar={this._renderTabBar}
onIndexChange={this.onIndexChange}
initialLayout={{
width: Dimensions.get('window').width,
height: 100,
}}
/>
)}
}
Run Code Online (Sandbox Code Playgroud)
我也发布图片以供参考。
是否有任何属性可以帮助我TabView使用单个选项卡固定宽度向右滚动?
PS:我尝试过,react-native-scrollable-tab-view但卡在同一个地方。
将renderTabBarprop传递给 TableView,它返回一个自定义的 React Element 并返回<TabBar>, addtabStyle和scrollEnabled={true}to TabBar。
renderTabBar - 返回一个自定义 React 元素以用作标签栏的回调
TabBar - 材料设计主题标签栏。
scrollEnabled - 布尔值,指示是否启用可滚动选项卡。
tabStyle - 应用于选项卡栏中各个选项卡项的样式。
import { TabView, SceneMap, TabBar } from 'react-native-tab-view';
<TabView
navigationState={this.state}
renderScene={this.renderScene}
renderTabBar={this._renderTabBar}
onIndexChange={this.onIndexChange}
renderTabBar={props => (
<TabBar
{...props}
indicatorStyle={{ backgroundColor: 'white' }}
tabStyle={{ width: 100 }}
scrollEnabled={true}
style={{ backgroundColor: 'blue' }}
/>
)}
initialLayout={{
width: Dimensions.get('window').width,
height: 100,
}}
/>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2848 次 |
| 最近记录: |