热门标签 | HotTags
当前位置:  开发笔记 > Android > 正文

键盘显示时,createBottomTabNavigator空白(图标是自动隐藏)

如何解决《键盘显示时,createBottomTabNavigator空白(图标是自动隐藏)》经验,为你挑选了1个好方法。

React-native应用程序的版本:

react@16.9.0
react-native@0.61.2
react-navigation@^4.0.10
react-navigation-stack@^1.10.3
react-navigation-tabs@^2.5.6

我正在尝试使用createBottomTabs创建应用程序,当我尝试输入TextInput时,当键盘显示时,有带图标的bottomtabs,该图标将自动隐藏,在键盘顶部留下空白/空白

我的代码示例:


   
     
   

已经尝试使用KeyboardAvoidingView更改SafeAreaView,但是空格/空白仍然存在。

const MainTabs = createBottomTabNavigator({
  Screen1: {
    screen: Screen1Stack,
    navigationOptions: {
      tabBarIcon: Icon
    }
  },
  Screen2: {
    screen: Screen2Screen,
    navigationOptions: {
      tabBarIcon: Icon
    }
  },
  Screen3: {
    screen: Screen3Screen,
    navigationOptions: {
      tabBarIcon: Icon
    }
  },
  Screen4: {
    screen: Screen4Screen,
    navigationOptions: {
      tabBarIcon: Icon
    }
  },
},
  {
    tabBarOptions: {
      ...
      showLabel: false
    }
  }
)



1> Demmy Demoni..:

我在react navigation tabs github(标题为“ Android#16上的底部标签栏和键盘”)上的评论中得到了答案,如果有人遇到与我相同的问题,我将在这里分享,@ export-回答迈克和@hegelstad详细

import React from 'react';
import { Platform, Keyboard } from 'react-native';
import { BottomTabBar } from 'react-navigation-tabs'; // need version 2.0 react-navigation of course... it comes preinstalled as a dependency of react-navigation.

export default class TabBarComponent extends React.Component {
  state = {
    visible: true
  }

  componentDidMount() {
    if (Platform.OS === 'android') {
      this.keyboardEventListeners = [
        Keyboard.addListener('keyboardDidShow', this.visible(false)),
        Keyboard.addListener('keyboardDidHide', this.visible(true))
      ];
    }
  }

  componentWillUnmount() {
    this.keyboardEventListeners && this.keyboardEventListeners.forEach((eventListener) => eventListener.remove());
  }

  visible = visible => () => this.setState({visible});

  render() {
    if (!this.state.visible) {
      return null;
    } else {
      return (
        
      );
    }
  }
}

用法:

const Tabs = createBottomTabNavigator({
  TabA: {
    screen: TabA,
    path: 'tab-a',
    navigationOptions: ({ navigation }) => ({
      tabBarLabel: 'Tab A',
    })
  },
  TabB: {
    screen: TabB,
    path: 'tab-b',
    navigationOptions: ({ navigation }) => ({
      tabBarLabel: 'Tab B',
    })
  }
},
(Platform.OS === 'android')
? {
    tabBarComponent: props => ,
    tabBarPosition: 'bottom'
   }
: {
    // don't change tabBarComponent here - it works on iOS after all.
  }
);


推荐阅读
author-avatar
益达怡君33
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有