Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tabs scrolling #50

Open
SobolRR opened this issue Mar 6, 2017 · 3 comments
Open

Tabs scrolling #50

SobolRR opened this issue Mar 6, 2017 · 3 comments

Comments

@SobolRR
Copy link

SobolRR commented Mar 6, 2017

Can we opportunity horizontally scroll tabs?

@powman
Copy link

powman commented Apr 19, 2017

Usage:

access folder node_modules/react-native-tabs/index.js and add code.

'use strict';

import React, {
Component
} from 'react';

import {
StyleSheet,
View,
Text,
ScrollView,
TouchableOpacity,
} from 'react-native';

class Tabs extends Component {
onSelect(el){
if (el.props.onSelect) {
el.props.onSelect(el);
} else if (this.props.onSelect) {
this.props.onSelect(el);
}
}

render(){
    const self = this;
    let selected = this.props.selected
    let horizontal = this.props.horizontal
    if (!selected){
        React.Children.forEach(this.props.children.filter(c=>c), el=>{
            if (!selected || el.props.initial){
                selected = el.props.name || el.key;
            }
        });
    }
    if(!horizontal){
        return (
            <View style={[styles.tabbarView, this.props.style]}>
                {React.Children.map(this.props.children.filter(c=>c),(el)=>
                    <TouchableOpacity key={el.props.name+"touch"}
                       style={[styles.iconView, this.props.iconStyle, (el.props.name || el.key) == selected ? this.props.selectedIconStyle || el.props.selectedIconStyle || {} : {} ]}
                       onPress={()=>!self.props.locked && self.onSelect(el)}
                       onLongPress={()=>self.onSelect(el)}
                       activeOpacity={el.props.pressOpacity}>
                         {selected == (el.props.name || el.key) ? React.cloneElement(el, {selected: true, style: [el.props.style, this.props.selectedStyle, el.props.selectedStyle]}) : el}
                    </TouchableOpacity>
                )}
            </View>
        );
    }else{
        return (
            <ScrollView 
                style={[styles.tabbarViewScroll, this.props.style]}
                contentContainerStyle={{width:500}}
                horizontal={true}
                showsHorizontalScrollIndicator={false}
                >
                {React.Children.map(this.props.children.filter(c=>c),(el)=>
                    <TouchableOpacity key={el.props.name+"touch"}
                       style={[styles.iconView, this.props.iconStyle, (el.props.name || el.key) == selected ? this.props.selectedIconStyle || el.props.selectedIconStyle || {} : {} ]}
                       onPress={()=>!self.props.locked && self.onSelect(el)}
                       onLongPress={()=>self.onSelect(el)}
                       activeOpacity={el.props.pressOpacity}>
                         {selected == (el.props.name || el.key) ? React.cloneElement(el, {selected: true, style: [el.props.style, this.props.selectedStyle, el.props.selectedStyle]}) : el}
                    </TouchableOpacity>
                )}
            </ScrollView>
        );
    }
}

}
var styles = StyleSheet.create({
tabbarView: {
position:'absolute',
bottom:0,
right:0,
left:0,
height:50,
opacity:1,
backgroundColor:'transparent',
flexDirection: 'row',
justifyContent: 'center',
alignItems: 'center'
},
tabbarViewScroll: {
position:'absolute',
bottom:0,
right:0,
left:0,
height:50,
opacity:1,
backgroundColor:'transparent',
flexDirection: 'row',
},
iconView: {
flex: 1,
height: 50,
justifyContent: 'center',
alignItems: 'center',
}
});

module.exports = Tabs;

@powman
Copy link

powman commented Apr 19, 2017

Param in tab horizontal={true}

@rajscet
Copy link

rajscet commented Sep 1, 2018

love you thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants