Shu*_*ood 1 react-native react-native-android touchableopacity react-navigation touchablewithoutfeedback
我创建了一个组合组件来将 TouchableNativeFeedback 组合到 wrapperComponent。
export default function withFeedback2(
WrappedComponent
) {
return class extends BaseComponent {
constructor(props) {
super(props);
}
render() {
return (
<View>
<TouchableNativeFeedback
onPress={() => this.props.onContainerViewPress()}
>
<WrappedComponent {...this.props} />
</TouchableNativeFeedback>
{/* <TouchableOpacity
onPress={this.props.onContainerViewPress ? () => this.props.onContainerViewPress() : null}
>
<WrappedComponent {...this.props} />
</TouchableOpacity> */}
</View>
);
}
};
}
Run Code Online (Sandbox Code Playgroud)
但是TochableNativeFeedback 的 OnPress事件没有触发。而 OnPress 事件被正确触发,并且如果 wrappercomponent 包装在 TouchableOpacity 下,则调用 wrappercomponent 的onContainerViewPress道具。
我正在 Android 平台上对此进行测试。
小智 11
使用 a<View></View>来包装您的WrappedComponentfor TouchableNativeFeedback。
<TouchableNativeFeedback
onPress={() => this.props.onContainerViewPress()}>
<View>
<WrappedComponent {...this.props} />
</View>
</TouchableNativeFeedback>
Run Code Online (Sandbox Code Playgroud)
有两个不同的TouchableNativeFeedback类。确保您导入正确的:
import { TouchableNativeFeedback } from "react-native"
import { TouchableNativeFeedback } from "react-native-gesture-handler"
Run Code Online (Sandbox Code Playgroud)
我遇到了类似的问题,最终从“react-native”库中使用了它。从“react-native-gesture-handler”导入它对我不起作用。
| 归档时间: |
|
| 查看次数: |
3825 次 |
| 最近记录: |