【问题标题】:Open Keyboard on TouchableOpacity onPress在 TouchableOpacity onPress 上打开键盘
【发布时间】:2018-03-01 16:08:14
【问题描述】:

我想在 TouchableOpacity onPress 上打开一个数字键盘。 然后 stockAtStart 和 stockAtEnd 监听键盘输入并在输入时更新。

class MakeInventory extends React.Component {

      state = {
        stockAtStart: 0,
        stockAtEnd: 0,
      }

      render() {
        return (
          <View style={styles.container}>
            <View style={(styles.boxContainerToggle, styles.boxOne)}>
              <Text style={[styles.currentDate]}>27 Feb 2018</Text>
            </View>

            <View style={[styles.boxContainerToggle, styles.boxTwo]}>
                <TouchableOpacity style={[styles.boxContainer]}>
                  <Text style={styles.inventoryParagraph}>start</Text>
                  <Text style={styles.stockNumber}>{this.state.stockAtStart}</Text>
                </TouchableOpacity>
            </View>

             <View style={[styles.boxContainerToggle, styles.boxThree]}> 
                <TouchableOpacity style={[styles.boxContainer]}>
                  <Text style={styles.inventoryParagraph}>end</Text>
                  <Text style={styles.stockNumber}>{this.state.stockAtEnd}</Text>
                </TouchableOpacity>
              </View>

              <View style={[styles.boxContainerToggle, styles.boxFour]}>  
                <TouchableOpacity style={styles.boxContainer}>
                  <Text style={styles.paragraph}>COUNT</Text>
                </TouchableOpacity>
              </View>
            </View>
        );
      }
    }

【问题讨论】:

    标签: react-native


    【解决方案1】:

    https://github.com/amirfl/react-native-num-textinput

    import NumTextInput from 'react-native-num-textinput'
    
    <NumTextInput
        underlineColorAndroid="transparent"
        precision={EXPENSE_AMOUNT_PRECISION}
        maxLength={EXPENSE_AMOUNT_MAX_LENGTH}
        keyboardType={Platform.OS === 'ios' ? 'numeric' : 'phone-pad'}
        style={textInput}
        placeholder= 'what ever...'
        placeholderTextColor={ColorStyles.slateGray}
        onChangeText={
            (value) => {
                this.setState({inputValue: value})
            }
        }
        value={this.state.inputValue}
    />
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-11-23
      • 1970-01-01
      • 2020-12-06
      • 2018-09-24
      • 2021-12-21
      • 2012-03-30
      • 1970-01-01
      • 2020-10-26
      相关资源
      最近更新 更多