gpt4 book ai didi

react-native - react-native-router-flux 中的抽屉菜单不显示任何内容

转载 作者:行者123 更新时间:2023-12-01 23:38:28 25 4
gpt4 key购买 nike

我想在使用 flux 的 react-native 中有一个侧边菜单。但是,它没有显示任何内容。

App.js

const App = () => {
return (
<Router>
<Scene key="root">
<Scene
key="LoginScreen"
component={LoginScreen}
initial
/>
<Scene
key="CodeValidationScreen"
component={CodeValidationScreen}
/>

<Scene
key="ProfileScreen"
component={ProfileScreen}
/>

<Scene
key="RegisterScreen"
component={RegisterScreen}
/>

<Scene
key="CarsListScreen"
component={CarsListScreen}
/>

<Scene
key="CarViewScreen"
component={CarViewScreen}
/>

<Scene contentComponent={NavigationDrawer} drawer key="drawer">
<Scene key="main">
<Scene
key="LogoutScreen"
component={LogoutScreen}
/>
</Scene>
</Scene>
{/*<Scene key="drawer" contentComponent={SideMenu} drawerPosition='right'>*/}
{/*<Scene key="main" >*/}
{/*<Scene*/}
{/*key="home"*/}
{/*component={LoginScreen}*/}
{/*title="Home"*/}
{/*initial*/}
{/*/>*/}
{/*</Scene>*/}
{/*</Scene>*/}
</Scene>

</Router>
)
};

index.js:

AppRegistry.registerComponent('sidemenu', () => App);

抽屉.js

export default class NavigationDrawer extends Component {
constructor(props) {
super(props);
};
render(){
const state = this.props.navigationState;
const children = state.children;
return (
<Drawer
ref="navigation"
open={state.open}
onOpen={()=>Actions.refresh({key:state.key, open: true})}
onClose={()=>Actions.refresh({key:state.key, open: false})}
type="displace"
content={<SideMenu />}
tapToClose={true}
openDrawerOffset={0.2}
panCloseMask={0.2}
negotiatePan={true}
tweenHandler={(ratio) => ({
main: { opacity:Math.max(0.54,1-ratio) }
})}>
{this.props.children[0]}
{/*<DefaultRenderer navigationState={children[0]} onNavigate={this.props.onNavigate} />*/}
</Drawer>
);
}
}

侧边菜单.js

export default class SideMenu extends Component<{}> {
constructor(props) {
super(props);

};

render() {
return (
<View style={styles.container}>
<Text>menu items go here</Text>
</View>
);
}
}

const styles = StyleSheet.create({
container: {
flex: 1,
flexDirection: 'column',
justifyContent: 'flex-start',
alignItems: 'stretch',
backgroundColor: '#F5FCFF',
paddingRight: 20,
paddingLeft: 20,
paddingBottom: 10,
},

});

showDrawer 函数(当我点击一个按钮时,我希望 SideMenu 显示。):

_showDrawer  = () => {
return () => {
Actions.refresh({key: 'drawer', open: true });
};

这是我所有的代码。我可以在屏幕之间导航,但是侧边菜单不起作用。我的错误是什么?

最佳答案

   <Router>
<Scene>
<Scene
key="login"
component={LoginScreen}
initial
type="reset"
/>
<Scene
key="registerScreen"
component={RegisterScreen}
/>

<Scene
key="codeValidationScreen"
component={CodeValidationScreen}
/>

<Drawer
hideNavBar
key="drawerMenu"
contentComponent={SideMenu}
drawerWidth={250}
drawerPosition="right"
>
<Scene
key="profileScreen"
component={ProfileScreen}

/>
<Scene
key="carsListScreen"
component={CarsListScreen}
/>

<Scene
key="carViewScreen"
component={CarViewScreen}
/>

</Drawer>
</Scene>

</Router>);

和:

Actions.drawerMenu(params)

而且不需要Drawer.js

关于react-native - react-native-router-flux 中的抽屉菜单不显示任何内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48238435/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com