RN 三星S7 点击和 滑动事件冲突

版权声明:本文为博主原创文章,转载请注明出处。 https://blog.csdn.net/gongziwushuang/article/details/88315591

RN 三星S7 点击和 滑动事件冲突

目的

PanResponder监听外层View ,并包裹TouchableWithoutFeedback 来实现,当点击其中的TouchableWithoutFeedback 触发开关灯动作 即按钮事件,手指落到TouchableWithoutFeedback 上往外滑动触发上下滑动 用来调节亮度

  <View style={styles.verticalView}  {...this._panResponder.panHandlers}>
              <TouchableWithoutFeedback  style={{position:'absolute', height:120*ratio,width:120*ratio}} onPress={()=>this.setPower()}>
                  <Image style={{
                    opacity:this.calculateCurrentBri(),
                    tintColor:this.gradient(parseInt(this.state.valueCct*100.0/(200*ratio))),height:120*ratio,width:120*ratio,backgroundColor:'transparent'}} 
                      source={picSource} />
              </TouchableWithoutFeedback>
            </View>

现象

滑动事件抢去点击的事件,点击出现不灵敏

解决方法

用另外一种方式监听滑动手势,就可以解决


            <View onStartShouldSetResponder={() => true} onResponderGrant={(e) => { this._onTouchDown(e) }} onResponderMove={(e) => this._onouchMove(e)} onResponderRelease={(e) => { this.onouchUp(e) }}>

            </View>

猜你喜欢

转载自blog.csdn.net/gongziwushuang/article/details/88315591
RN
今日推荐