Tôi đang sử dụng các thành phần sau đây để tạo ra một Phản ứng Native + Redux ứng dụng:Tại sao React Native Drawer không được kích hoạt bằng React Native Router Flux + Redux?
tôi đã cố gắng sau chính xác example provided on how to implement the drawer, nhưng khi điều hướng đến nơi ngăn kéo nên được hiển thị, sử dụng Actions.drawer
, tôi gặp lỗi:
Nhưng nếu tôi cố điều hướng đến Scene, qua Actions.home
, bên trong Scene Drawer, không có gì xảy ra nhưng hành động REACT_NATIVE_ROUTER_FLUX_RESET
vẫn đang được gọi qua số redux-logger
.
Đã thử theo chính xác ví dụ nhưng không may mắn. Tôi có thể làm gì sai?
Dưới đây là bộ của tôi lên cho cảnh sử dụng Redux:
// @flow
import React, { Component } from 'react'
import {
ActionConst,
Actions,
Router,
Scene,
} from 'react-native-router-flux'
import {
Provider,
connect,
} from 'react-redux'
import configureStore from './store/configureStore'
import Login from './components/Login'
import Home from './components/Home'
import NavDrawer from './components/NavDrawer'
const RouterWithRedux = connect()(Router)
const store = configureStore()
export default class App extends Component {
render() {
return (
<Provider store={store}>
<RouterWithRedux>
<Scene key='root'>
<Scene component={Login} initial={true} key='login' title='Login'/>
<Scene key="drawer" component={NavDrawer}>
<Scene component={Home} key='home' title='Home' type='reset' initial={true}/>
</Scene>
</Scene>
</RouterWithRedux>
</Provider>
)
}
}
Sau đó, tôi nhấn một nút trong Login và nó gây nên Actions.
để điều hướng đến.
Các NavDrawer là:
import React, { PropTypes } from 'react'
import Drawer from 'react-native-drawer'
import { Actions, DefaultRenderer } from 'react-native-router-flux'
import NavDrawerPanel from './NavDrawerPanel'
export default class NavDrawer extends Component {
componentDidMount() {
Actions.refresh({key: 'drawer', ref: this.refs.navigation});
}
render() {
const children = state.children;
return (
<Drawer
ref="navigation"
type="displace"
content={<NavDrawerPanel />}
tapToClose
openDrawerOffset={0.2}
panCloseMask={0.2}
negotiatePan
tweenHandler={(ratio) => ({
main: { opacity: Math.max(0.54, 1 - ratio) },
})}
>
<DefaultRenderer
navigationState={children[0]}
onNavigate={this.props.onNavigate}
/>
</Drawer>
);
}
}
Và NavDrawerPanel là:
import React from 'react';
import {PropTypes} from "react";
import {
StyleSheet,
Text,
View,
} from "react-native";
import { Actions } from 'react-native-router-flux';
const NavDrawerPanel = (props, context) => {
const drawer = context.drawer;
return (
<View style={styles.container}>
<TouchableHighlight onPress={Actions.home}>
<Text>Home Page</Text>
</TouchableHighlight>
<TouchableHighlight onPress={Actions.login}>
<Text>Login Page</Text>
</TouchableHighlight>
</View>
)
}
const styles = StyleSheet.create({
container: {
flex: 1,
padding: 30,
backgroundColor: 'black'
},
})
EDIT Dưới đây là những gì đang được nhập khẩu nơi Scene + Redux được thiết lập:
// @flow
import React, { Component } from 'react'
import {
ActionConst,
Actions,
Router,
Scene,
} from 'react-native-router-flux'
import {
Provider,
connect,
} from 'react-redux'
import configureStore from './store/configureStore'
import Login from './components/Login'
import Home from './components/Home'
import NavDrawer from './components/NavDrawer'
EDIT 2 - console.log (this.props)
Làm console.log (this.props) trong thành phần Login:
Khi Actions.home() từ thành phần Login:
Khi Actions.drawer() từ thành phần Login:
EDIT 3 - console.log (this.props) bên NavDrawer.js
Các NavDrawer không bao giờ được trả lại để console.log (this.props) không thường xuyên bị thoát
Nhưng với console.log (this.props) bên NavDrawer.js và Actions.home, tôi nhận được:
Và với console.log (this.props) bên trong NavDrawer.js và Tác vụ.ngăn kéo, tôi nhận được:
bạn có chắc chắn đang nhập mọi thứ chính xác không? – octohedron
@Gazta Có, chính xác cách hiển thị trong bài đăng gốc. Có thể vấn đề là ngăn kéo cần phải được thực hiện khác nhau vì nó có thiết lập redux không? –
đăng phần còn lại của tệp mà bạn đang thiết lập cảnh – octohedron