【问题标题】:completing scratch in react-native-scratch在 react-native-scratch 中完成从头开始
【发布时间】:2021-08-01 19:54:22
【问题描述】:

我想在 react-native-scratch 中完成暂存后重新加载暂存,但对此没有任何解决方案。当我完成划伤并获得结果后,我想再次划伤它,它不会重置,也无法再次划伤。

【问题讨论】:

    标签: react-native react-native-android react-native-ios react-native-flatlist react-native-navigation


    【解决方案1】:

    在 react-native-scratch 中,

    在 src 文件夹内的 ScratchView.js 中添加以下方法用于重置(重新填充)从头开始

    refresh = () => {
    
        AnimatedScratchView = RNTScratchView && Animated.createAnimatedComponent(RNTScratchView);
        this.setState({
            isScratchDone: false,
            visible: true
        })
        this.scratchOpacity = {
            opacity: this.state.animatedValue.interpolate({
                inputRange: [0, 1],
                outputRange: [1, 0],
            }),
        };
    }
    

    并在顶部将此 const 更改为 var

    var AnimatedScratchView = RNTScratchView && Animated.createAnimatedComponent(RNTScratchView);
    

    之后通过引用父组件中的子组件调用此方法

      <ScratchView
         ref={(ref) => this.scratchRef = ref} />
    

    使用“scratchRef”可以使用刷新方法重新加载暂存器,如下所示:

    this.scratchRef.refresh();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-04-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-24
      • 2018-02-10
      • 2021-02-02
      相关资源
      最近更新 更多