onValueChange 不适用于现有组件

onValueChange not working on existing component

我正在使用来自 react-native-ui-kitten 的 RkSwitch 组件。该软件包只是一堆我可以使用的 ui 组件。

开发人员不再支持该组件,我的 RkSwitch 组件无法正常工作。

我的问题是 RkSwitch 的 onValueChange 没有做任何事情。

render function for android <- 不起作用。 (问题

render function for iOS <- 尚未测试,但我认为它应该有效。

我给 RkSwitch 打了电话。由于RkSwitch是react native的<Animated.View>的wrapperclass,它不能传递onValueChange。

<RkSwitch
    style={styles.switch}
    value={this.state.onlyMe}
    name="Push"
    onValueChange={
        (onlyMe) => {
            console.log('helloworld'); // it can't print helloworld
        }
    }
/> 

这里是RkSwitch的实际代码。 (这是 android 版本)。 Doc Link

_onPanResponderRelease = (evt, gestureState) => {
    let {toggleable} = this.state;
    let {disabled, onValueChange} = this.props;

    if (toggleable && !disabled) {
      if (onValueChange) { // calls onValueChange and..?
        this.toggleSwitch(onValueChange) // call toggle switch
      }
    }
  };

toggleSwitch = (result, callback = () => null) => {
    let {value, switchAnimation} = this.state;
    let toValue = !value;

    this.animateHandler(this.handlerSize);

    this.animateSwitch(toValue, () => {
      callback(toValue);
      this.setState({
        value: toValue,
        left: toValue ? onLeftValue : offLeftValue
      });
     switchAnimation.setValue(toValue ? -1 : 1)
    })

他们似乎正在处理 onValueChange 道具,但它不起作用。有没有好的Javascript或者React高手???

我还没有尝试过这个,但也许可以进入 RKSwitch 代码并在 Animated.View 周围添加一个 <TouchableOpacity> 并将 onValueChange 道具提供给 TouchableOpacity 的 onPress 函数。