React Native - 在当地自定义底部导航栏中激活当前页面

时间:2018-04-23 06:11:58

标签: css react-native

我做了一个自定义的底部导航栏。代码如下。我想浏览导航栏中的页面,当在特定页面上时,导航栏中图标(.png)应该处于活动状态以指示当前页面。帮助我在底部导航栏上显示活动页面。

import React from 'react';
    import {
      Dimensions,
      View,
      Image,
      TouchableOpacity,
      Text,
      Platform,
    } from 'react-native';
    const { width, height } = Dimensions.get("window");
    import images from '../../images';
    import NormalizeSize from '../../styles/NormalizeSize'
    import common from '../../css/common'
    import NavigatorService from '../../lib/NavigatorService';
    const {normalize}=NormalizeSize;
    const Bottom=(props)=>{
      const {navigate, state}=props.navigation;

      const {isDrawer,isRightButton,isNotificationButton,title,navigation, isFilterButton, isDummyButton}=props;
      return(
        <View style={{position:'absolute', bottom: 0}}>
          <View>

            <TouchableOpacity
              onPress={() => { NavigatorService.navigate('ExcerciseList') }}
              hitSlop={{ top: 20, bottom: 20, left: 20, right: 20 }} style={common.bottomNavBlock}>
              <Image
                resizeMode='contain'
                style={{ height: 20, width: 20 }}
                source={images.excercise_icon} />

            </TouchableOpacity>
            ...........

          </View>
        </View>
      )
    }

    export default Bottom;

1 个答案:

答案 0 :(得分:0)

只需像这样更改代码即可。您需要两个图像:非活动和活动图标。

 <TouchableOpacity
          onPress={() => { NavigatorService.navigate('ExcerciseList') }}
          hitSlop={{ top: 20, bottom: 20, left: 20, right: 20 }} style={common.bottomNavBlock}>
          {state.routeName==='ExcerciseList'?<Image
            resizeMode='contain'
            style={{ height: 20, width: 20 }}
            source={images.excercise_active} />:<Image
            resizeMode='contain'
            style={{ height: 20, width: 20 }}
            source={images.excercise_icon} />}
        </TouchableOpacity>