TapGestureHandler 未触发 onHandlerStateChange
TapGestureHandler not triggering onHandlerStateChange
我在 TapGestureHandler
有一个 onHandlerStateChange
事件。当触发 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 模拟器并尝试 运行 android 应用程序使用 react-native run-android
并且还导入了
import Animated from 'react-native-reanimated'
import {TapGestureHandler, State} from 'react-native-gesture-handler'
我是 React 原生编程的初学者。
修复(请按步骤操作)
使用以下代码
更新MainActivity.java
//不要忘记导入
import com.facebook.react.ReactActivityDelegate;
import com.facebook.react.ReactRootView;
import com.swmansion.gesturehandler.react.RNGestureHandlerEnabledRootView;
// 将以下方法添加到您的 main activity class
protected ReactActivityDelegate createReactActivityDelegate() {
return new ReactActivityDelegate(this, getMainComponentName()) {
@Override
protected ReactRootView createRootView() {
return new RNGestureHandlerEnabledRootView(MainActivity.this);
}
};
}
我在 TapGestureHandler
有一个 onHandlerStateChange
事件。当触发 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 模拟器并尝试 运行 android 应用程序使用 react-native run-android
并且还导入了
import Animated from 'react-native-reanimated'
import {TapGestureHandler, State} from 'react-native-gesture-handler'
我是 React 原生编程的初学者。
修复(请按步骤操作)
使用以下代码
更新MainActivity.java//不要忘记导入
import com.facebook.react.ReactActivityDelegate;
import com.facebook.react.ReactRootView;
import com.swmansion.gesturehandler.react.RNGestureHandlerEnabledRootView;
// 将以下方法添加到您的 main activity class
protected ReactActivityDelegate createReactActivityDelegate() {
return new ReactActivityDelegate(this, getMainComponentName()) {
@Override
protected ReactRootView createRootView() {
return new RNGestureHandlerEnabledRootView(MainActivity.this);
}
};
}