android - 来自react-native-vector-icons onpress的图标需要点击两次才能工作

标签 android ios reactjs react-native react-native-vector-icons

我使用react-native-vector-icons。

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

预期结果需要实时聊天,而键盘打开时提交图标将始终触发。

我试图用keyboardshouldpersisttaps将它包裹在 ScrollView 中,但它不起作用。

 <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 上

最佳答案

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

<Content keyboardShouldPersistTaps={'handled'}>
    ...
</Content>

对于 ReactNative <ScrollView/>

<ScrollView keyboardShouldPersistTaps={'handled'}>
    ...
</ScrollView> 

关于android - 来自react-native-vector-icons onpress的图标需要点击两次才能工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55988964/

相关文章:

java - Android - 应用程序崩溃并显示 "java.lang.ClassCastException"

Android 日志与 Titanium INFO

android - 多个联系人选择器列表

ios - SuperpoweredAdvancedAudioPlayer 无法在 iOS13 中打开 "ipod-library"路径

ios - 当我将 minSpace 设置为 0 CollectionView 单元格时仍然有空间

javascript - 强制数字输入有两位小数,并在 React 中始终显示两位小数

java - 从 Java 代码创建 AVD 设备。库或其他解决方案

javascript - React-Rails - 入门问题

reactjs - 如何使用 enableReinitialize 在 formik 中重置表单?

ios - iOS 设备上未显示开发人员菜单