通过询问ChatG-PT,稍作修改,终于找到两种方式,代码如下:
import React, { Component, useEffect, useContext } from 'react';
import { View } from 'react-native';
import { Actions, Scene, Router } from 'react-native-router-flux';
const MyScene = () => {
useEffect(() => {
setTimeout(() => {
Actions.scene2()
}, 1000);
}, [])
return (
<View style={{ flex: 1 }}>
{/* 页面内容 */}
</View>
);
};
const MyScene2 = () => {
useEffect(() => {
setTimeout(() => {
Actions.scene3()
}, 1000);
}, [])
return (
<View style={{ flex: 1 }}>
{/* 页面内容 */}
</View>
);
};
class MyScene3 extends Component {
// 方式一
// static navigationOptions = {
// gesturesEnabled: false, // 禁用左滑返回手势
// };
render() {
return (
<View>
{/* 页面内容 */}
</View>
);
}
};
const App = () => {
return (
<Router>
<Scene key="root" modal={true}>
<Scene key="scene1" component={MyScene} title="Scene 1" />
<Scene
key="scene2"
component={MyScene2}
title="Scene 2"
// gesturesEnabled={false}
/>
<Scene key="scene3" component={MyScene3} title="Scene 3"
// 方式二
gesturesEnabled={false}
/>
</Scene>
</Router>
);
};
export default App;