0

我有一个onHandlerStateChange活动TapGestureHandler。当 onHandlerStateChange 被触发时,我想改变内部按钮的不透明度TapGestureHandler

<View style={{ height: height / 3, justifyContent: 'center' }}>
  <TapGestureHandler onHandlerStateChange={ this.onStateChange }>
    <Animated.View 
        style={{ ...styles.button, opacity: this.buttonOpacity }}>
      <Text style= {{ fontSize:16, fontWeight: 'bold' }}>GET STARTED</Text>
    </Animated.View>
  </TapGestureHandler>        
</View>

在里面this.onStateChange我有以下代码来改变不透明度。

constructor(props) {
    super(props);
    this.state={
    }
    this.buttonOpacity = new Value(1)
    this.onStateChange = event([{
      nativeEvent: ({ state }) => 
      block([
        cond( eq(state, State.END), set(this.buttonOpacity, 0) )
      ])
    }])
  }

我正在使用 android studio 模拟器并尝试使用react-native run-android并导入运行 android 应用程序

import Animated from 'react-native-reanimated'
import {TapGestureHandler, State} from 'react-native-gesture-handler'

我是反应原生编程的初学者。

4

1 回答 1

5

修复(请按照步骤操作)

使用以下代码更新 MainActivity.java

//不要忘记导入

import com.facebook.react.ReactActivityDelegate;
import com.facebook.react.ReactRootView;
import com.swmansion.gesturehandler.react.RNGestureHandlerEnabledRootView;

// 将以下方法添加到您的主活动类

  protected ReactActivityDelegate createReactActivityDelegate() {
    return new ReactActivityDelegate(this, getMainComponentName()) {
      @Override
      protected ReactRootView createRootView() {
        return new RNGestureHandlerEnabledRootView(MainActivity.this);
      }
    };
  }
于 2019-09-20T11:12:23.717 回答