React Native Align button on top of keyboard for all devices

前端 未结 2 1727
深忆病人
深忆病人 2021-01-12 00:58

So I need to align a button Which is not at bottom om screen by design should be at middle of screen but it should align to be on top of the keyboard for all de

2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-12 01:50

    First import this packages

    import {
      Button,
      ScrollView,
      KeyboardAvoidingView,
      TextInput,
    } from 'react-native';
    

    Render method

    
      
        
      
      

    This are the styles

    const styles = StyleSheet.create({
      container: {
        flex: 1,
      },
      scrollView: {
        paddingHorizontal: 20,
      },
      input: {
        marginBottom: 20,
        borderBottomWidth: 2,
        borderColor: '#dbdbdb',
        padding: 10,
      },
    });
    

    Make sure the button is outside the scrollview.

    NOTE: You may need to adjust the offset prop of KeyboardAvoidingView if the keyboard has got autocomplete enabled.

    Stick button at the bottom of the screen demo

提交回复
热议问题