我正在使用博览会 ^40.0.0。
我正在尝试让 react-native-gesture-handler 组件<Modal>
在 Android 中的 react-native 中工作。我在这里关注了文档 - https://docs.swmansion.com/react-native-gesture-handler/docs/#for-library-authors
它保持包裹<GestureHandlerRootView>
,我这样做了,但它不能解决问题。
我创建了一个问题的小吃演示 - https://snack.expo.io/@noitidart/frisky-carrot
在这里,您会看到“点击此处计数:0”。请尝试点击它,您会看到它不会增加计数器。
您将看到一个“RN BUTTON”,它有效,但它不是来自 react-native-gesture-handler。
这是我的小吃代码:
import * as React from 'react';
import { Text, View, Modal, Button as RNButton } from 'react-native';
import {
BaseButton,
GestureHandlerRootView
} from 'react-native-gesture-handler';
export default function App() {
return (
<Modal animationType="slide" transparent={false}>
<Example />
</Modal>
);
}
const Example = function () {
const [cnt, setCnt] = React.useState(0);
return (
<View style={{ justifyContent: 'center', flex: 1 }}>
<RNButton title="rn button" onPress={() => alert('hi')} />
<GestureHandlerRootView>
<BaseButton
onPress={() => {
// alert('pressed');
setCnt(cnt + 1);
}}
>
<View style={{ backgroundColor: 'steelblue', height: 100 }}>
<Text>Tapped here count: {cnt}</Text>
</View>
</BaseButton>
</GestureHandlerRootView>
</View>
);
};