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

标签 css react-native

我在 React Native 中制作了一个自定义底部导航栏。代码如下。我想浏览导航栏中的页面,当在特定页面上时,导航栏中的图标 image(.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;

最佳答案

只需像这样更改代码。为此,您需要两个图像:非事件图标和事件图标。

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

关于css - React Native - 在 React Native 自定义底部导航栏中激活当前页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49974469/

相关文章:

css - 在 React App 中调用 API 后不透明度转换的时间

html - 滚动内容层在位置 :absolute Layer? 下方

react-native - react native 如何通过导航器将 Prop 传递到另一个事件/ View

android - React Native 'yarn android' 失败,出现 'Task :app:compileDebugJavaWithJavac FAILED' 和 'package org.unimodules.core.interfaces does not exist'

javascript - '错误 : Unknown named module', 从动态路径加载 react-native 图像

javascript - 无法在 React Native 中导出(目前无法)

html - 100% 高度的图像,带有固定的顶栏和页脚(不固定)

html - 如何使方形图像适合矩形 div 的内部?

关于网格系统、媒体查询、响应式网页设计的 CSS 问题

javascript - React/Redux 如何传递参数来修改 API