A Custom Tab bar with two images in each tab using react navigation?

柔情痞子 提交于 2019-12-04 05:49:32

TABBAR

import React, { Component } from 'react';
import { View, Platform, StyleSheet, Image, TouchableOpacity } from 'react- 
native';
import {SafeAreaView} from 'react-navigation';
import IconTab from "./IconTab";

class TabBar extends Component {
  render() {
    const {
      navigation,
      jumpToIndex,
    } = this.props;
    const {
      routes
    } = navigation.state;
    return (
        <SafeAreaView style={{zIndex: 10}} forceInset={{ top: 'always' }}>
          <View style={styles.tabbarcontainer}>
                <Image
                   style={styles.bg}
                   source={require('./Assets/Header.png')}
                   resizeMode={'stretch'}/>
            <View style={styles.tabbar}>
              {routes && routes.map((route, index) => {
                const focused = index === navigation.state.index;
                const tabKey = route.key;
                return <View key={route.key} style={{ alignItems: 'center' }}>
                  <IconTab
                    press={() => jumpToIndex(index)}
                    key={route.key}
                    index={index}
                    focused={focused}
                  />
                  {focused && <Image source= {require('./Assets/Triangles.png')}
                                     style={{ position: 'absolute', top: 38 }} />}
                </View>;
              })}
            </View>
          </View>
      </SafeAreaView>
       );
    }
}

const styles = StyleSheet.create({
  tabbarcontainer: {
    height: 44,
  },
  bg: {
    position: 'absolute',
    width: '100%',
    height: 44,
    alignSelf: 'center',
  },
  tabbar: {
    margin: 5,
    height: 34,
    flexDirection: 'row',
    justifyContent: 'space-around',
    alignItems: 'center',
    alignContent: 'center',
    backgroundColor: 'transparent',
    borderTopColor: 'transparent',
  },

});

export default TabBar;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!