简体   繁体   English

TextInput在本机iOS中做出反应

[英]TextInput in react native iOS

I have a TextInput component in react native 我有一个反应原生的TextInput组件

<TextInput
            style={styles.searchBar}
            value={this.state.searchText}
            onChange={this.setSearchText.bind(this)}
            placeholder='Search State'
         />

This is working perfectly fine in android, but Textbox is not showing in iOS app. 这在android中工作得很好,但Textbox没有在iOS应用中显示。 And, there is no what to find what the issue is. 并且,没有什么可以找到问题所在。

Can anybody help with this issue ? 任何人都可以帮助解决这个问题吗?

Here is a code sample that demonstrates the need to provide a height for the TextInput component on iOS. 下面是一个代码示例,演示了为iOS上的TextInput组件提供高度的必要性。 It's not explicitly stated in the docs but reviewing it closely you'll notice the iOS section of the code samples provides a height while the android samples do not. 它没有在文档中明确说明,但仔细查看它会注意到代码示例的iOS部分提供了一个高度而android示例没有。 Here is a complete code sample that displays a TextInput in the center of the view: 这是一个完整的代码示例,它在视图的中心显示一个TextInput

import React, { Component } from 'react';
import {
  AppRegistry,
  StyleSheet,
  TextInput,
  View
} from 'react-native';

class MyApp extends Component {
  constructor (props) {
    super(props);
    this.state = {
      searchText: ''
    };
  }

  setSearchText (e) {
    this.setState({
      searchText: e.target.value
    });
  }

  render () {
    return (
      <View style={styles.container}>
        <TextInput
              style={styles.searchBar}
              value={this.state.searchText}
              onChange={this.setSearchText.bind(this)}
              placeholder='Search State'
           />
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center'
  },

  searchBar: {
    borderWidth: 1,
    height: 40
  }
});

AppRegistry.registerComponent('MyApp', () => MyApp);

If this doesn't help as a sanity check in debugging your code, please post the style definition ( styles.searchBar ) you have configured for your TextInput so we can give that a better test. 如果这在调试代码时没有帮助作为一个完整性检查,请发布您为TextInput配置的样式定义( styles.searchBar ),这样我们就可以给出更好的测试。

你应该给textinput高度和宽度显示textinput为:

<Textinput style={{height:200, width:300}}/>

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

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