feat: 右滑
This commit is contained in:
parent
fab73d196f
commit
6e8113e109
@ -20,6 +20,8 @@ import {
|
|||||||
TouchableOpacity,
|
TouchableOpacity,
|
||||||
View
|
View
|
||||||
} from 'react-native';
|
} from 'react-native';
|
||||||
|
import { Gesture, GestureDetector } from "react-native-gesture-handler";
|
||||||
|
import { runOnJS } from 'react-native-reanimated';
|
||||||
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
||||||
|
|
||||||
export default function AskScreen() {
|
export default function AskScreen() {
|
||||||
@ -46,6 +48,25 @@ export default function AskScreen() {
|
|||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
const updateState = (value: string) => {
|
||||||
|
console.log('Received in JS:', value);
|
||||||
|
// 更新 React 状态或路由
|
||||||
|
router.replace(value);
|
||||||
|
};
|
||||||
|
// 右滑
|
||||||
|
const gesture = Gesture.Pan()
|
||||||
|
.onEnd((event) => {
|
||||||
|
const { translationX } = event;
|
||||||
|
const threshold = 100; // 滑动阈值
|
||||||
|
|
||||||
|
if (translationX > threshold) {
|
||||||
|
// 从左向右滑动,跳转页面
|
||||||
|
runOnJS(router.replace)("memo-list");
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.minPointers(1)
|
||||||
|
.activeOffsetX([-10, 10]); // 在 X 方向触发的范围
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!isHello && userMessages.length > 0) {
|
if (!isHello && userMessages.length > 0) {
|
||||||
scrollToEnd();
|
scrollToEnd();
|
||||||
@ -236,6 +257,7 @@ export default function AskScreen() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
<GestureDetector gesture={gesture}>
|
||||||
<View style={[styles.container, { paddingTop: insets.top }]}>
|
<View style={[styles.container, { paddingTop: insets.top }]}>
|
||||||
{/* 导航栏 */}
|
{/* 导航栏 */}
|
||||||
<View style={[styles.navbar, isHello && styles.hiddenNavbar]}>
|
<View style={[styles.navbar, isHello && styles.hiddenNavbar]}>
|
||||||
@ -316,6 +338,7 @@ export default function AskScreen() {
|
|||||||
</View>
|
</View>
|
||||||
</KeyboardAvoidingView>
|
</KeyboardAvoidingView>
|
||||||
</View >
|
</View >
|
||||||
|
</GestureDetector>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user