onpress上的“ react-native-vector-icons”图标需要点击两次才能工作

时间:2019-05-05 04:56:11

标签: android ios reactjs react-native mobile

我使用react-native-vector-icons

  1. 点击输入
  2. 键盘升起
  3. 按下图标时,图标不会触发,键盘会先下降,而不是在打开键盘时触发onpress方法图标

期望的结果希望进行实时聊天,而当键盘向上时,提交图标将始终触发。

我试图用键盘将其包裹在滚动视图中,但它不起作用。

 <KeyboardAvoidingView
        behavior={Platform.OS === 'ios' ? 'padding' : null}
        style={{ flex: 1 }}
        keyboardVerticalOffset={64}
      >
        <View style={styles.slide} key={i}>
          <TouchableHighlight
            style={styles.video}
            onPress={this.handleDoubleTap}
            onLongPress={this.handlePlayAndPause}
          >
            <ViewportAwareVideo
              key={i}
              source={{ uri: firstVideoUri }}
              shouldPlay={this.state.shouldPlay}
              isLooping
              preTriggerRatio={-0.4} // default is 0
              retainOnceInViewport={false} // default is false
              style={styles.video}
              onPlaybackStatusUpdate={this._onPlaybackStatusUpdate}
              progressUpdateIntervalMillis={1000}
              resizeMode='contain'
              innerRef={ref => (this._videoRef = ref)}
              onViewportEnter={() => {
                this.setState({ shouldPlay: true });
              }}
              onViewportLeave={() => {
                this.setState({ shouldPlay: false });
              }}
            />
          </TouchableHighlight>

          {this.state.shouldPlay ? null : (
            <TouchableHighlight
              onPress={this.handlePlayAndPause}
              style={styles.pauseBtn}
            >
              <IconComponent name='play-circle' size={50} color='black' />
            </TouchableHighlight>
          )}

          <CopilotStep
            name='swipeUp'
            text='Swipe up to view next video'
            order={5}
          >
            <WalkthroughableView style={styles.topSection}>
              <Text style={styles.imageHeadingText}>{product.name}</Text>
              {product.short_description === '' ? null : (
                <HTML
                  html={product.short_description}
                  imagesMaxWidth={Dimensions.get('window').width}
                  containerStyle={styles.imageDescText}
                  baseFontStyle={styles.htmlStyle}
                />
              )}
              <CopilotStep
                name='swipeRight'
                text='Swipe right to view product details'
                order={6}
              >
                <WalkthroughableView
                  style={{
                    flexDirection: 'row',
                    flexWrap: 'wrap',
                    paddingHorizontal: 20,
                    paddingVertical: 5
                  }}
                >
                  {product.tags.map((value, index) => {
                    return (
                      <Text key={index} style={styles.tagText}>
                        {value.name.charAt(0) === '#'
                          ? value.name
                          : '#' + value.name}
                      </Text>
                    );
                  })}
                </WalkthroughableView>
              </CopilotStep>
              {product.total_sales > 0 ? (
                <View
                  style={{
                    flexDirection: 'row',
                    flexWrap: 'wrap',
                    paddingHorizontal: 20,
                    paddingVertical: 5
                  }}
                >
                  <Text style={styles.totalSales}>
                    {product.total_sales +
                      (product.total_sales > 100
                        ? '+ bought'
                        : ' bought in the last 24 hours')}
                  </Text>
                </View>
              ) : null}
            </WalkthroughableView>
          </CopilotStep>

          <View style={styles.bottomSection}>
            <View style={{ flex: 1, justifyContent: 'flex-end', height: 30 }}>
              {this.state.messages.map((message, index) => (
                <React.Fragment key={index}>
                  <View
                    key={index}
                    style={{
                      flexDirection: 'row',
                      alignItems: 'center',
                      marginHorizontal: 5,
                      marginVertical: 5,
                      paddingLeft: 10,
                      height: 20
                    }}
                  >
                    <Image
                      style={{ width: 20, height: 20, borderRadius: 20 / 2 }}
                      source={{ uri: 'https://picsum.photos/20/20' }}
                    />
                    <Text
                      style={{
                        fontFamily: Constants.fontHeader,
                        marginHorizontal: 5,
                        color: '#007AFF'
                      }}
                    >
                      {message.user.name}
                    </Text>
                    <Text
                      style={{
                        fontFamily: Constants.fontHeader,
                        marginHorizontal: 5,
                        color: 'white'
                      }}
                    >
                      {message.text}
                    </Text>
                  </View>
                </React.Fragment>
              ))}
            </View>
            <CopilotStep
              name='chatOnFeed'
              text='Click here to chat on video feed'
              order={7}
            >
              <WalkthroughableTextInput
                style={{
                  // position: 'absolute',
                  // bottom: 0,
                  // left: 0,
                  fontFamily: Constants.fontFamily,
                  marginBottom: 110,
                  marginHorizontal: 5,
                  marginVertical: 5,
                  paddingRight: 35,
                  paddingLeft: 20,
                  height: 35,
                  width: width - 60,
                  backgroundColor: 'white',
                  borderRadius: 25
                }}
                onChangeText={messageText => this.setState({ messageText })}
                value={this.state.messageText}
                placeholder='Share your thoughts'
                placeholderTextColor='#9B9B9B'
              />
            </CopilotStep>

            <IconComponent
              style={{ position: 'absolute', bottom: 115, right: 10 }}
              name='arrow-right'
              size={25}
              color='black'
              onPress={product => this.sendMessage(product)}
            />
          </View>

          <View style={styles.iconBar}>
            <CopilotStep
              name='productDetail'
              text='Click here to got to product details'
              order={8}
            >
              <WalkthroughableText>
                <IconComponent
                  style={styles.iconBarIcon}
                  name='shopping-cart'
                  size={iconSize}
                  color='white'
                  onPress={() => {
                    this.props.onViewProductScreen({ product });
                    this.setState({ shouldPlay: false });
                  }}
                />
              </WalkthroughableText>
            </CopilotStep>
            <Text style={styles.iconBarText}>Shop</Text>
            <CopilotStep
              name='like'
              text='Click here to like this product'
              order={9}
            >
              <WalkthroughableText>
                <Entypo
                  style={styles.iconBarIcon}
                  name='heart'
                  size={30}
                  color={this.state.isInWishList ? 'red' : 'white'}
                  onPress={() => {
                    this.state.isInWishList
                      ? this.props.removeWishListItem(product)
                      : this.props.addWishListItem(product);

                    this.setState(prevState => ({
                      isInWishList: !prevState.isInWishList
                    }));
                  }}
                />
              </WalkthroughableText>
            </CopilotStep>
            <Text style={styles.iconBarText}>Like</Text>
            <CopilotStep
              name='share'
              text='Click here to share this product'
              order={10}
            >
              <WalkthroughableText>
                <IconComponent
                  style={styles.iconBarIcon}
                  name='share'
                  size={iconSize}
                  color='white'
                  onPress={this.onShare}
                />
              </WalkthroughableText>
            </CopilotStep>
            <Text style={styles.iconBarText}>Share</Text>
            <CopilotStep
              name='fullChat'
              text='Click here to view full chat'
              order={11}
            >
              <WalkthroughableText>
                <IconComponent
                  style={[styles.iconBarIcon, { paddingTop: 4 }]}
                  name='message-circle'
                  size={iconSize}
                  color='white'
                  onPress={product => this.sendChat(product)}
                />
              </WalkthroughableText>
            </CopilotStep>
          </View>
        </View>
      </KeyboardAvoidingView>
    );

在WalkthroughableTextInput之后,您可以看到我的问题出在IconComponent上

1 个答案:

答案 0 :(得分:0)

如果您使用的是NativeBase组件,请像这样使用它

state

对于ReactNative <Content keyboardShouldPersistTaps={'handled'}> ... </Content>

<ScrollView/>