React-native-router-flux: Actions.refreshκ°€ μž‘λ™ν•˜μ§€ μ•ŠμŒ

에 λ§Œλ“  2017λ…„ 10μ›” 18일  Β·  24μ½”λ©˜νŠΈ  Β·  좜처: aksonov/react-native-router-flux

버전

μ‚¬μš© 쀑인 버전을 μ•Œλ €μ£Όμ‹­μ‹œμ˜€.

  • react-native-router-flux v4.0.0-beta.12
  • λ°˜μ‘ λ„€μ΄ν‹°λΈŒ v0.46.4

μ˜ˆμƒλ˜λŠ” 행동

Actions.refresh()λŠ” ν˜„μž¬ μž₯면을 μƒˆλ‘œ κ³ μΉ©λ‹ˆλ‹€.
λ‚΄ μ ‘κ·Ό 방식이 잘λͺ»λ˜μ—ˆκ±°λ‚˜ Actions.refresh에 λͺ‡ 가지 μš”κ΅¬ 사항이 μžˆλŠ” 경우 정보λ₯Ό μ œκ³΅ν•΄ μ£Όμ„Έμš”.

μ‹€μ œ 행동

const ConnectRouter = connect()(Router);

const Routes = () => (
  <ConnectRouter>
    <Scene key="root">
      <Scene key="launchScreen" component={LoadingFull} hideNavBar />
      <Scene key="login" component={LoginForm} hideNavBar type={ActionConst.RESET} />
      <Scene key="lostPassword" component={LostPasswordForm} hideNavBar />
      <Scene key="dashboard" component={Dashboard} hideNavBar type={ActionConst.RESET} />
      <Scene key="search" component={SearchResult} hideNavBar />
    </Scene>
  </ConnectRouter>
);

λ‚΄κ°€ 검색 μž₯λ©΄(μƒνƒœκ°€ μžˆλŠ” 일반 ꡬ성 μš”μ†Œ)에 μžˆμ„ λ•Œ Actions.refreshλ₯Ό μ‚¬μš©ν•˜μ—¬ μž₯면을 μƒˆλ‘œ 고치렀고 ν–ˆμŠ΅λ‹ˆλ‹€. κ·ΈλŸ¬λ‚˜ μ–΄λ–»κ²Œ λ“  그것은 μ „ν˜€ μž‘λ™ν•˜μ§€ μ•Šμ•˜μŠ΅λ‹ˆλ‹€.

μž¬ν˜„ 단계

  1. 제곡된 μž₯λ©΄ λͺ©λ‘μ„ μ‚¬μš©ν•˜μ—¬ ꡬ성 μš”μ†Œ κ²€μƒ‰μœΌλ‘œ μ΄λ™ν•©λ‹ˆλ‹€(μƒνƒœκ°€ μžˆλŠ” 일반 ꡬ성 μš”μ†ŒμΌ λΏμž…λ‹ˆλ‹€).
  2. action.refresh λ²„νŠΌμ„ 눌러 μƒˆλ‘œ κ³ μΉ¨/일뢀 이벀트 트리거
needs response from author

κ°€μž₯ μœ μš©ν•œ λŒ“κΈ€

@jaysassyinfotech
Actions.refresh({ ν‚€: Actions.currentScene }); 두 번째둜 μž‘λ™ν•˜μ§€ μ•ŠμŒ
μ΄λ ‡κ²Œ ν•˜λ©΄ 잘 λ©λ‹ˆλ‹€ :)
Actions.refresh({ν‚€: Math.random()})

λͺ¨λ“  24 λŒ“κΈ€

+1
μž₯λ©΄μ—μ„œ renderBackButton을 μ‚¬μš©ν•˜κ³  μ‹ΆμŠ΅λ‹ˆλ‹€. λ‚΄ 예제 μ½”λ“œ,

public componentWillMount (): void {
               Actions.refresh({
            renderBackButton: this.renderBackButton.bind(this),
            onRight: this.onRightButtonPress.bind(this)
        });
}

μž‘λ™ν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€. 같은 문제라고 μƒκ°ν•©λ‹ˆλ‹€.

$#$ renderBackButton leftButton λ₯Ό μ‹œλ„ν•˜κ³  Componentλ₯Ό μ „λ‹¬ν•˜μ‹­μ‹œμ˜€.

@kesha-antonov μž‘λ™ν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€. λ‚˜λŠ” 이것을 μœ„ν•΄ μƒˆλ‘œμš΄ 문제λ₯Ό λ§Œλ“­λ‹ˆλ‹€.

그것은 λ‚˜λ₯Ό μœ„ν•΄ μž‘λ™ν•©λ‹ˆλ‹€. rnrf-4-베타22

leftButton μ™Όμͺ½ μ•„μ΄μ½˜
right 였λ₯Έμͺ½ μ•„μ΄μ½˜

곡개 componentWillMount(): 무효 {
this.props.navigation.setParams({
onRight: () => {this.myOnRight();},
rightTitle: 'newTitle',
});
}
그것은 λ‚˜λ₯Ό μœ„ν•΄ μΌν•©λ‹ˆλ‹€.

λ§™μ†Œμ‚¬, λ‚˜λŠ” μ›λž˜ λ¬Έμ œμ— λŒ€ν•œ 닡을 μ°ΎκΈ° μœ„ν•΄ 여기에 μ™”μŠ΅λ‹ˆλ‹€.
κ΄€λ ¨ μ—†λŠ” λ¬Έμ œμ— νŽΈμŠΉν•˜μ§€ λ§ˆμ‹­μ‹œμ˜€!

λ™μΌν•œ λ¬Έμ œκ°€ μžˆμ§€λ§Œ μŠ€ν† μ–΄(mobx)λ₯Ό μ—…λ°μ΄νŠΈν•  λ•Œ

<strong i="7">@observer</strong>
class Custom extends Component {
  render() {

    // prints every time I update state, this's ok!
    console.log('update', store.session.get('logged'))

    return (
      <Router>
        <Scene key="root">
          <Scene key="login"
            component={login}
            type="replace"
            onEnter={() => {
                // ONLY enter here once
                console.log('onEnter');
                return store.session.get('logged')
            }}
            success="recents"
          />
          <Scene key="recents" component={recents} />
        </Scene>
      </Router>
    )
  }
}

μŠ€ν† μ–΄ μ—…λ°μ΄νŠΈ ν›„ Actions.refresh() λ₯Ό ν˜ΈμΆœν•˜μ—¬ 'λ‹€μ‹œ λ Œλ”λ§'을 μ‹œλ„ν–ˆμ§€λ§Œ onEnter 이(κ°€) μ‘λ‹΅ν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€.

  _onPressButton() {
    store.session.set('logged', !store.session.get('logged')) // invert the value in store
    Actions.refresh() // tested with { key: 'login' } too
  }

issue

@aksonov μ˜¬λ°”λ₯Έ λ°©ν–₯을 μ•Œλ €μ£Όμ‹œκ² μŠ΅λ‹ˆκΉŒ? :κΈ°λ„ν•˜λ‹€:

μ•ˆλ…•

λ‚˜λŠ” 같은 λ¬Έμ œκ°€ μžˆμŠ΅λ‹ˆλ‹€ ... Actions.refresh()둜 μƒˆλ‘œ 고침을 μ‹œλ„ν•˜λ©΄ 아무 일도 μΌμ–΄λ‚˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€

import React, { Component } from 'react';
import {
    View,
    Text,
    Button,
} from 'react-native';

import { Actions } from 'react-native-router-flux';

export default class Types extends Component {

    constructor(props) {
        super(props);
        console.log("Constructor Types")
    }

    componentWillMount() {
        console.log('Will mount Types')
    }

    componentWillUpdate() {
        console.log("Will Update Types")
    }

    componentWillUnmount() {
        console.log("will Unmont Types")
    }
    render() {
        console.log("render Types")
        return (
            <Button title='refresh' onPress={() => Actions.refresh()}/>
        )
    }
}

μ—¬κΈ°μ—μ„œ λ™μΌν•œ λ¬Έμ œκ°€ λ°œμƒν•©λ‹ˆλ‹€. μ €λŠ” reduxλ₯Ό μ‚¬μš©ν•˜κ³  있으며 였λ₯Έμͺ½ λ²„νŠΌμ„ μƒˆλ‘œ 고치렀고 ν•  λ•Œ μ—…λ°μ΄νŠΈλ˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€.

예제 ν”„λ‘œμ νŠΈμ—μ„œ 문제λ₯Ό μž¬ν˜„ν•˜μ‹­μ‹œμ˜€.

Actions.refresh({ key: Actions.currentScene }); 두 번째둜 μž‘λ™ν•˜μ§€ μ•ŠμŒ
https://github.com/aksonov/react-native-router-flux/issues/2862
@aksonov

@jaysassyinfotech
Actions.refresh({ ν‚€: Actions.currentScene }); 두 번째둜 μž‘λ™ν•˜μ§€ μ•ŠμŒ
μ΄λ ‡κ²Œ ν•˜λ©΄ 잘 λ©λ‹ˆλ‹€ :)
Actions.refresh({ν‚€: Math.random()})

@cosinus84 당신은 생λͺ…μ˜ μ€μΈμž…λ‹ˆλ‹€.

@cosinus84 정말 μΌμž…λ‹ˆλ‹€. 와
κ·ΈλŸ¬λ‚˜ Math.random()이 λͺ¨λ“  νŠΈλ¦­μ„ μˆ˜ν–‰ν•˜λŠ” μ΄μœ μ— λŒ€ν•œ μ„€λͺ…이 μžˆμŠ΅λ‹ˆκΉŒ?

@cosinus84 당신은 둝맨 (y)

이제 μ΅œμ‹  λ²„μ „μ—λŠ” λ¬΄μž‘μœ„κ°€ ν•„μš”ν•˜μ§€ μ•ŠκΈ°λ₯Ό λ°”λžλ‹ˆλ‹€.

@aksonov μž₯λ©΄ μ†Œν’ˆμ΄ μ—¬κΈ°μ—μ„œ μž‘λ™ν•˜μ§€ μ•ŠλŠ” 것 κ°™μ•„μ„œ Actions.refresh()μ—μ„œ μ‚¬μš©ν•  수 μžˆλŠ” μ†Œν’ˆ(ν•΄λ‹Ή κΈ°λŠ₯ 포함)을 λ‚˜μ—΄ν•΄ μ£Όμ‹œκ² μŠ΅λ‹ˆκΉŒ?

예제 μ•±κ³Ό μƒˆλ‘œ κ³ μΉ¨ ν˜ΈμΆœμ„ 확인할 수 μžˆμŠ΅λ‹ˆλ‹€. μ΅œμ‹  4.0.5μ—μ„œλŠ” 잘 μž‘λ™ν•©λ‹ˆλ‹€. 문제λ₯Ό μ„€λͺ…ν•˜κΈ° μœ„ν•΄ 자유둭게 예제λ₯Ό λ³΅μ œν•˜κ³  μˆ˜μ •ν•˜μ‹­μ‹œμ˜€.

예, 잘 μž‘λ™ν•˜μ§€λ§Œ μ–Έμ œ μ–΄λ–€ 것을 μ‚¬μš©ν•΄μ•Ό 할지 λͺ¨λ₯Ό 수 μžˆμœΌλ―€λ‘œ μƒˆλ‘œ κ³ μΉ¨ ν˜ΈμΆœμ— μ‚¬μš©ν•  props λͺ©λ‘μ„ λ§Œλ“œλŠ” 것이 μ’‹μŠ΅λ‹ˆλ‹€.
예λ₯Ό λ“€μ–΄ λ’€λ‘œ λ²„νŠΌμ„ λ Œλ”λ§ν•˜λ €λ©΄ leftButton μ†Œν’ˆμ„ μ‚¬μš©ν•΄μ•Ό ν•˜μ§€λ§Œ @kesha-antonov의 λŒ“κΈ€μ„ 읽을 λ•ŒκΉŒμ§€ λͺ°λžμŠ΅λ‹ˆλ‹€.

κ·Έκ²ƒμ˜ μž‘λ™

@preetluv μ–΄λ–»κ²Œ κ³ μ³€λŠ”μ§€ 말씀해 μ£Όμ‹œκ² μŠ΅λ‹ˆκΉŒ?

@preetluv cosinus84 의 λ‹΅λ³€ μ°Έμ‘°

λ‹€μŒμ„ μˆ˜ν–‰ν•  수 μžˆμŠ΅λ‹ˆλ‹€ .

μ•‘μ…˜.팝()
setTimeout(()=> Actions.refresh({"somePropToRefresh":Math.random(),"yourProp":"μƒˆλ‘œ κ³ μΉ¨
λŒμ•„κ°ˆ λ•Œμ˜ 이전 ν™”λ©΄"}),0.5);

back을 ν•œ ν›„ 이전 ν™”λ©΄μ˜ componentWillReceiveProps μ—μ„œ "yourProp"을 확인할 수 μžˆμŠ΅λ‹ˆλ‹€.

react-native-router-flux 4.2.0-beta.2 λ₯Ό μ‚¬μš©ν•˜κ³  setTimeout κ³Ό ν•¨κ»˜ μž‘λ™ν•©λ‹ˆλ‹€.

이 νŽ˜μ΄μ§€κ°€ 도움이 λ˜μ—ˆλ‚˜μš”?
0 / 5 - 0 λ“±κΈ‰