์๋
ํ์ธ์,
ํ๋ฅญํ ๋ชจ๋์ ๊ฐ์ฌ๋๋ฆฝ๋๋ค - ์ ๋ชฉ๊ณผ ํ์ ํ์์ค์ ์ํ๋ฅผ ๋์ ์ผ๋ก ๋ณ๊ฒฝํ ์ ์๋ ๋ฐฉ๋ฒ์ด ์์ต๋๊น?
์๋ฅผ ๋ค์ด.
<Route key="UserCredentials" name="UserCredentials" hideNavBar={this.state.UserCredentialsNavBar} component={UserCredentials} initial={ false } title={this.state.title} schema="withoutAnimation" />
๊ทธ๋ฐ ๋ค์ this.state.UserCredentialsNavBar 'true' ๋๋ 'false' ๋ฐ this.state.title 'Some title' ๋๋ 'Some other title' ์ํ๋ฅผ ๋ณ๊ฒฝํ๋ ๋ฆฌ์ค๋๊ฐ ์์ต๋๋ค.
๋๋ ์๋ํ์ง๋ง ์๋ฌด๋ฐ๋ ์ป์ง ๋ชปํ์ต๋๋ค.
๋ฏธ๋ฆฌ ๊ฐ์ฌ๋๋ฆฝ๋๋ค.
:0)
Actions.refresh(props)๋ฅผ ์ฌ์ฉํ์ฌ ๋ด๋น๊ฒ์ดํฐ ์ ํ ์์ด ์์ฑ์ ์ค์ ํ๋ ์ง์์ ์ถ๊ฐํ์ต๋๋ค. ์๋ํด ๋ณด์ธ์(๋ฒ์ 2.3.1).
๊ฐ์ฌํฉ๋๋ค aksonov.
๋ด๊ฐ ๋น์ ์ ์ ๋๋ก ์ดํดํ์ง ๋ชปํ ์๋ ์์ต๋๋ค.
์๋ฅผ ๋ค์ด ์ ๋ชฉ์ ์ํ๋ฅผ ๋ณ๊ฒฝํ๋ ค๋ ๊ฒฝ์ฐ์
๋๋ค. ๋๋ ์ ํ ํ ๊ฒ์ด๋ค
Actions.refresh({title: 'Some other title'})
๋ค์ ์ฐพ์์ฃผ์
์ ๊ฐ์ฌํฉ๋๋ค.
:0)
๋ด ๋์, ๋ชจ๋ ์ ์๋ํฉ๋๋ค. ๋์์ ์ฃผ์ ์ ๋๋จํ ๊ฐ์ฌํฉ๋๋ค aksonov. ๋งค์ฐ ๊ฐ์ฌ. :0)
์ ๋ชฉ์ ๋์ ์ผ๋ก ์ค์ ํ๋ ๋ฒ๊ทธ์ฒ๋ผ ๋ณด์ด๋ ๋ฌธ์ ๊ฐ ๋ฐ์ํ์ต๋๋ค. Actions.refresh๊ฐ ์ ์ ์ ๋ชฉ์ ์ฌ์ ์ํ์ฌ ๋ชจ๋ ๊ฒฝ๋ก์ ๋ํด ์ค์ ํ๋ ๊ฒ ๊ฐ์ต๋๋ค.
์ ๊ฒฝ์ฐ์๋ ๋ง์คํฐ ๊ฒฝ๋ก์ ์ ๋ชฉ ์ํ์ด ์๊ณ ์ธ๋ถ ๊ฒฝ๋ก ์ ๋ชฉ์ด ๋์ ์ผ๋ก๋ง ์ค์ ๋๋ ๋ง์คํฐ-์ธ๋ถ ์ค์ ์ด ์์ต๋๋ค. ๋ด๊ฐ ์ธ๋ถ ๊ฒฝ๋ก์ ์๊ณ ์ ๋ชฉ์ด ๋ณ๊ฒฝ๋๋ฉด ์ ๋ชฉ๊ณผ ๋ค๋ก ๋ฒํผ์ด ๋ชจ๋ ๋์ผํ ํ ์คํธ๋ก ๋ณ๊ฒฝ๋ฉ๋๋ค. ๋ง์คํฐ๋ก ๋์๊ฐ ๋ ๋์ ์ ๋ชฉ์ ๊ทธ๋๋ก ์ ์ง๋ฉ๋๋ค(์คํค๋ง ์ ๋ชฉ์ผ๋ก ๋์๊ฐ์ง ์๊ณ ).
๋๋ React Native๋ฅผ ์ฒ์ ์ฌ์ฉํ๊ธฐ ๋๋ฌธ์ ์ด๊ฒ์ด ์๋ ๋ ๊ฒ์ธ์ง ํ์คํ์ง ์์ต๋๋ค ...?
๊ฐ์ฌ ํด์!
๋ด๊ฐ ํ์ฌ ๊ทธ ์ฅ๋ฉด์ ์์ง ์์๋ ํน์ ์ฅ๋ฉด์ ๋ํด ์ค์ ํ ์ ์๋ ๋ฐฉ๋ฒ์ด ์๋์? ์ฆ
Actions.refresh({key: 'home', title: 'My new title'})
@greatwitenorth ์ ํํ ์ฌ์ฉ ์ฌ๋ก๋ ๋ฌด์์
๋๊น?
์๋ฅผ ๋ค์ด view2
ํค๋ฅผ ์ฌ์ฉํ์ฌ ๋ทฐ๋ฅผ ํ์ํ๋ ๊ฒฝ์ฐ ๋ค์๊ณผ ๊ฐ์ด ์ํ์ผ๋ก ์ ๋ชฉ์ ์ค์ ํ ์ ์์ต๋๋ค.
Actions.view2({ title: 'My New Title' })
๋ด ๋ฌธ์ ๋ ์ ๋ชฉ ์ ๋ฐ์ดํธ๊ฐ ํ์ํ ์ฅ๋ฉด์ผ๋ก ์ด๋ํ์ง ์์๋ค๋ ๊ฒ์ ๋๋ค. ๋ด ํ๋ฉด์ ์ฌ์ฉ์์ ์ฃผ์๋ฅผ ์ ๋ฐ์ดํธํ์ง๋ง ์ฃผ์๋ ์์ ํ ๋ณ๋์ ํ๋ฉด์ ์ ๋ชฉ์ผ๋ก ํ์๋์์ต๋๋ค.
@greatwitenorth ๋๋ ๊ฐ์ ๋ฌธ์ ์
์ข์, ๋๋ ๋ฌธ์๋ฅผ ๋ ์ ์ฝ์์ด์ผ ํ๋ค, ๊ทธ๊ฒ์ ๋จ์ํ
Actions.refresh({title: 'new title'})
@greatwitenorth ๊ด์ฐฎ์ ํด๊ฒฐ์ฑ
์ ์ฐพ์์ต๋๊น?
์ํ์์ ์ ๋ชฉ์ ๊ฐ์ ธ์ค๊ณ ์์ผ๋ฏ๋ก ์ํ๊ฐ ๋ณ๊ฒฝ๋ ๋๋ง๋ค ํน์ ๋ณด๊ธฐ๊ฐ ํด๋น ๊ฐ์ ์ ๋ชฉ์ผ๋ก ๊ฐ์ง๊ธฐ๋ฅผ ์ํฉ๋๋ค. ๋๋๋ก ์ฌ๋๋ค์ ์ ๋ชฉ์ ๋ณ๊ฒฝํ๊ณ ๋ค๋ก ๋ฒํผ์ ํตํด ํ์ํฉ๋๋ค. ์ด ๊ฒฝ์ฐ {title: } ๋งค๊ฐ๋ณ์๋ฅผ ์ ์ํ ์ ์๋ ๊ฒ ๊ฐ์ต๋๋ค(๋ค๋ก ์์
์์ ์ํ ๊ฐ ์ ๋ฌ), ์๋๋ฉด ์ ๊ฐ ๋์น ๊ฒ์ด ์์ต๋๊น?
๊ตฌ์ฑ ์์(๋๋ ๋ ๋๋ง)์ ์๋ช ์ฃผ๊ธฐ ๋ฉ์๋ ์ค ํ๋๋ฅผ ์๋ก ๊ณ ์น๋ฉด ์ํ ์์ฑ ๋ณ๊ฒฝ์ผ๋ก ์ธํด ์ฑ์ด ๋ฌดํ ๋ฃจํ์ ๋น ์ง ์ ์์ผ๋ฏ๋ก ์ฑ์ด ์ถฉ๋ํฉ๋๋ค.
์๋ถ ์ธ์ฌ,
@JeroenNelen ๋น์ทํ ๋ฌธ์ ๊ฐ ์์๊ณ ComponentDidMount์ ์๋ก ๊ณ ์นจ์ ๋ฃ๊ณ Redux ๋ฆฌ๋์์์ ์ํ๋ฅผ ์ค์ ํ์ฌ ํด๊ฒฐํ์ต๋๋ค. ์ ๋ชฉ์ ๋ณ๊ฒฝํ๊ณ ์ฑ ์ํ๋ฅผ ์ ๋ฐ์ดํธํ๊ณ props๊ฐ ์ ๋ฐ์ดํธ๋ฅผ ์ฝ๋ ๋ชจ๋ ์ฌ์ฉ์ ์์ ์ Redux ์์ ์ ์ฐ๊ฒฐํฉ๋๋ค. ๋.
๊ธฐ๋ณธ์ ์ผ๋ก ComponentDidMount์ ๋ค์ ์ค๊ณผ ๊ฐ์ต๋๋ค.
Actions.refresh({title: this.props.state.myapp.myvalue})
@jondbm ์ ์์ ๊ฐ์ฌํ์ง๋ง ์ฐ๋ฆฌ๋ ๋ค๋ฅธ ํ์๊ธฐ๋ก ์ ํํ๊ธฐ๋ก ๊ฒฐ์ ํ์ต๋๋ค.
์๋ถ ์ธ์ฌ,
@JeroenNelen ์ง๊ธ ์ด๋ค ๋ค๋น๊ฒ์ดํฐ๋ฅผ ์ฌ์ฉํ๊ณ ์์ต๋๊น? (๊ณต์ ๊ฐ ์ซ๋ค๋ฉด)
์๋ ์ค์ ์์ ์ค๋ฅธ์ชฝ ๋ฒํผ์ ์๋ก ๊ณ ์นจํ์ง ์๋ ์ด์ ๋ ๋ฌด์์ ๋๊น? console.log๊ฐ ์ ๊ฐ์ ๊ธฐ๋กํ์ง๋ง ์ฌ๋ฐ๋ฅธ ์ ๋ชฉ์ด ์๋ก ๊ณ ์ณ์ง์ง ์์ต๋๊น?
const RouterWithRedux = connect()(Router);
export class App extends Component {
constructor(props) {
super(props);
}
render() {
let title = '(' + this.props.basket.length + ')';
console.log(title);
return (
<RouterWithRedux rightTitle={title} onRight={() => alert('All right')}>
<Scene key="root">
<Scene key="home" component={Main} title="Main"/>
<Scene key="page1" component={SomePage} title="SomePage"/>
</Scene>
</RouterWithRedux>
);
}
}
App.propTypes = {
dispatch: PropTypes.func.isRequired
};
// Wrap the component to inject dispatch and state into it
export default connect(
state => {
return {basket: state.basket.items}
}
)(App);
@jaynakus righttitle ๋๋ ์ค๋ฅธ์ชฝ ๋ฒํผ?
์ ๋ชฉ!
์ํ๋ ๋๋ก ์ฌ์ฉ์ ์ง์ ํ์ ๋ชจ์์ ์ฌ์ฉํ๋ ๊ฒ์ด ์ข์ต๋๋ค.
@jaynakus๋ rightTitle ๋ฐ onRight๋ฅผ ์ต์์ RouterWithRedux ์์ค ๋์ Scene ๊ตฌ์ฑ ์์์
@jondbm ์ ๋ฃจํธ ์ฅ๋ฉด์ ๋ฃ๋ ๊ฒ์ ํด๊ฒฐ๋์ง ์์์ง๋ง
const RouterWithRedux = connect()(Router);
export class App extends Component {
constructor(props) {
super(props);
}
componentWillReceiveProps(nextProps) {
if (this.props.basket.length !== nextProps.basket.length) {
console.log(nextProps.basket.length);
let title = '(' + nextProps.basket.length + ')';
Actions.refresh({rightTitle: title});
}
}
render() {
let title = '(' + this.props.basket.length + ')';
return (
<RouterWithRedux>
<Scene key="root" rightTitle={title} onRight={() => alert('All right')}>
<Scene key="home" component={Main} title="Main"/>
<Scene key="page1" component={SomePage} title="SomePage"/>
</Scene>
</RouterWithRedux>
);
}
}
App.propTypes = {
dispatch: PropTypes.func.isRequired
};
// Wrap the component to inject dispatch and state into it
export default connect(
state => {
return {basket: state.basket.items}
}
)(App);
์ฌ๊ธฐ๋ฅผ ๋ณด์ญ์์ค: https://github.com/aksonov/react-native-router-flux/issues/1922
๊ต์ฅํฉ๋๋ค. ์ ํํ ๋ ์ ๋ชฉ์ ํ์ด๋ ์ธ/์์ํ๋ ๊น๋ํ ๋ฐฉ๋ฒ์ด ์์ต๋๊น? ์ ๊ฒฝ์ฐ์๋ ์ฌ์ฉ์๊ฐ 100px ์ด์ ์คํฌ๋กคํ๋ฉด ์ ๋ชฉ์ด ๋ฐ๋๋๋ค. ์ ํ์ ํ์ด๋ํ๋ ๊ฒ์ด ์ข์ต๋๋ค. ๊ฑด๋ฐฐ.
@greatwitenorth ์ ํํ ์ฌ์ฉ ์ฌ๋ก๋ ๋ฌด์์ ๋๊น?
์๋ฅผ ๋ค์ดview2
ํค๋ฅผ ์ฌ์ฉํ์ฌ ๋ทฐ๋ฅผ ํ์ํ๋ ๊ฒฝ์ฐ ๋ค์๊ณผ ๊ฐ์ด ์ํ์ผ๋ก ์ ๋ชฉ์ ์ค์ ํ ์ ์์ต๋๋ค.```js
Actions.view2({ title: '๋ด ์ ์ ๋ชฉ' })
์ค์ ํ์ผ์์ ์ด๋ป๊ฒ ์ก์ธ์คํ ์ ์์ต๋๊น?
๋ค์๊ณผ ๊ฐ์ ๊ตฌ์ฑ์ด ์๋ ๊ฒฝ์ฐ:
<Router>
<Scene key="root" navBar={NavBar}>
<Scene
hideNavBar
key="login"
component={Login}
initial
/>
<Scene drawer
drawerPosition="right" drawerWidth={300}
key="task"
contentComponent={DrawerView}
drawerIcon={drawerIcon}
rightButtonImage="menu"
onRight={() => {
Actions.drawerOpen()
}} hideNavBar
>
<Scene key="taskInner"
leftButtonImage="arrow-back"
component={TaskView}
onLeft={() => {
Actions.popTo('tasksList')
}}
/>
</Scene>
</Scene>
</Router>
๊ทธ๋ฌ๋ฉด Actions.task({ title: 'My New Title' }) ๋๋ Actions.refresh({title: "My New Title"})๊ฐ ์๋ํ์ง ์์ต๋๋ค. ์๋์ด ์์ ๋ ์ ๋ชฉ์ ์ค์ ํ๊ฑฐ๋ ์ผ๋ถ ์์ฑ์ ๋ณด๋ด๋ ๋ฐฉ๋ฒ์ ๋ฌด์์ ๋๊น?
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
๊ฐ์ฌํฉ๋๋ค aksonov.
๋ด๊ฐ ๋น์ ์ ์ ๋๋ก ์ดํดํ์ง ๋ชปํ ์๋ ์์ต๋๋ค.
์๋ฅผ ๋ค์ด ์ ๋ชฉ์ ์ํ๋ฅผ ๋ณ๊ฒฝํ๋ ค๋ ๊ฒฝ์ฐ์ ๋๋ค. ๋๋ ์ ํ ํ ๊ฒ์ด๋ค
Actions.refresh({title: 'Some other title'})
๋ค์ ์ฐพ์์ฃผ์ ์ ๊ฐ์ฌํฉ๋๋ค.
:0)