简体   繁体   English

在键盘弹出窗口上扩展屏幕反应原生?

[英]Extend screen on keyboard pop-up react native?

I have a problem with my react-native app.我的 react-native 应用程序有问题。 At the bottom of the page, there are textboxes.在页面底部,有文本框。 After I click on some textbox, keyboard pop-up, so I can't see text boxes.单击某个文本框后,键盘弹出,所以我看不到文本框。 Is there any way to extend screens height when a keyboard is opened, so I can normally see my text boxes?有没有办法在打开键盘时扩展屏幕高度,以便我可以正常看到我的文本框? Pictures with issue:有问题的图片:
Picture without opened keyboard没有打开键盘的图片
Picture with keyboard opened打开键盘的图片

And here is my code:这是我的代码:

render() {
    return (
        <View style={styles.container}>
            <View style={styles.container1}>
                <Text style={styles.headerText}>Pivoznalac</Text>
                <Text style={styles.infoText2}>Dobrodošli u Jelenov kviz</Text>
                <View style={styles.container12}>
                    {/* <View style={styles.sociaContainer}> */}
                    <View style={styles.container12}>
                        <TouchableOpacity style={styles.socialIcon}
                            onPress={() => Linking.openURL('https://www.facebook.com/JelenPivoBiH/?brand_redir=28032575448')}>
                            <Icon name="facebook" size={50} color="#fff" />
                        </TouchableOpacity>
                        <TouchableOpacity style={styles.socialIcon}
                            onPress={() => Linking.openURL('https://www.instagram.com/jelenpivo/')}>
                            <Icon name="instagram" size={50} color="#fff" />
                        </TouchableOpacity>
                    </View>
                    <Image style={styles.headerImage} source={require('../assets/images/Picture-app2.png')} />
                </View>
            </View>
             <View style={styles.container2}>
                 <Text style={styles.infoHeading}>
                    Upiši podatke i započni igru
                  </Text>
                  <Text style={styles.infoText}
                   onPress={this.toggleButtonStyle}>
                    Upišite korisničko ime ili se registrujte da bi ga dobili.
                  </Text>
                  <TextInput style={styles.inputBox}
                    onChangeText={text => this.onChangeUserToken(text)} 
                    placeholder='Unesite korisnički token'
                    placeholderTextColor = "#ccc"
                  />
                  <TextInput style={styles.inputBox}
                    onChangeText={text => this.onChangeGameToken(text)} 
                    placeholder='Unesite token za igru'
                    placeholderTextColor = "#ccc"
                  />
                  <TouchableHighlight style={styles.button}
                            onPress={this._proceedAsync}
                            underlayColor='#FEC424'>
                        <Text style={styles.buttonText}>
                            Započni igru
                        </Text>    
                  </TouchableHighlight>

              </View>
        </View>
      );
  }

And style:和风格:

//ProceedScreen
container1: {
    backgroundColor:'#FEC424',
    height: "45%",
},

socialIcon: { 
    alignItems: 'center',
    flexDirection:'row',
    marginLeft: 50,
},

container12: {
    flex: 1,
    flexDirection: 'row',
    marginTop: 20,
},    

headerImage: {
    flex: 1,
    height: 235,
    resizeMode: 'contain',
    marginRight: -30,
},

infoHeading: {
    fontSize: 25,
    fontFamily: 'robotoBold'
},

container2: {
    backgroundColor: '#fff',
    height: "55%",
    padding: 30,
    borderTopLeftRadius: 25,
    borderTopRightRadius: 25,
    zIndex: -1,
    justifyContent: 'flex-end',
},

button: {
    borderWidth: 2,
    borderRadius: 50,
    borderColor: '#FEC424',
},

buttonText: {
    textAlign: 'center',   
    textTransform: 'uppercase',
    fontSize: 16,
    padding: 10,
    color: '#FEC424',
}

You can use onFocus and onBlur events on TextInput elements to detect when the user wants to write something, and when user stopped writing.您可以在TextInput元素上使用onFocusonBlur事件来检测用户何时想要写东西,以及用户何时停止写作。 Using this you can, for example, hide upper beer photos, for time of writing, so inputs will be positioned higher and visible for user.使用它,例如,您可以在写作时隐藏上部啤酒照片,因此输入将被放置在更高的位置并且对用户可见。 Native mobile keyboards are tricky :)原生移动键盘很棘手:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM