React Native Make View “Hug” the Top of the Keyboard

后端 未结 5 1976
陌清茗
陌清茗 2021-02-13 03:48

Let\'s say I have a view that is positioned absolute at the bottom of the screen. This view contains a text input. When the text input is focused, I want the bottom of the view

5条回答
  •  花落未央
    2021-02-13 03:54

    You can use flexbox to bottom position the element. Here's simple example -

      render() {
        return (
          
            
            
              
                
              
            
          
        );
      }
    
    const styles = StyleSheet.create({
      container: {
        flex: 1,
        justifyContent: 'center',
        alignItems: 'center',
        backgroundColor: '#F5FCFF',
      },
      top: {
        flex: .8,
      },
      bottom: {
        flex: .2,
      },
      input: {
        width: 200,
      },
    });
    

提交回复
热议问题