告诉我们您正在使用哪些版本:
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
我想从场景中使用 renderBackButton。 我的示例代码,
public componentWillMount (): void {
Actions.refresh({
renderBackButton: this.renderBackButton.bind(this),
onRight: this.onRightButtonPress.bind(this)
});
}
它不工作。 我认为这是同一个问题。
尝试使用leftButton
而不是renderBackButton
并将 Component 传递给它。
@kesha-antonov 它不起作用。 我为此创建了新问题。
这个对我有用。 rnrf-4-beta22
leftButton
用于左侧图标
right
用于右图标
公共组件WillMount():无效{
this.props.navigation.setParams({
onRight: () => {this.myOnRight();},
rightTitle:'新标题',
});
}
它为我工作。
耶稣,我来这里是为了寻找原始问题的答案。
请尽量不要背负无关的问题!
我在更新商店( 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
}
@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({ key: Actions.currentScene }); 第二次不工作
如果你这样做,它会起作用:)
Actions.refresh({key: Math.random()})
@cosinus84您先生是救生员。
@cosinus84这真的很有效。 哇
但是有什么解释为什么 Math.random() 会做所有的把戏吗?
@cosinus84你摇滚男(y)
希望现在最新版本不需要随机
@aksonov请您列出我们可以在 Actions.refresh() 中使用的道具(及其功能),因为场景道具似乎在这里不起作用。
您可以检查示例应用程序及其刷新调用 - 它适用于最新的 4.0.5。 随意克隆和修改示例以演示该问题。
是的,它工作正常,但我建议您制作一个用于刷新调用的道具列表,因为我们可能不知道何时使用哪个道具。
例如,要渲染后退按钮,我们需要使用leftButton
道具,但直到我阅读了@kesha-antonov 的评论后我才知道
它的工作
@preetluv介意告诉我你是如何解决的吗?
@preetluv见cosinus84的回答
您可以执行以下操作:-
Actions.pop()
setTimeout(()=> Actions.refresh({"somePropToRefresh":Math.random(),"yourProp":"刷新
返回上一个屏幕"}),0.5);
您可以在返回后在前一个屏幕中检查componentWillReceiveProps中的“yourProp”。
我使用react-native-router-flux 4.2.0-beta.2
它适用于setTimeout
最有用的评论
@jaysassyinfotech
Actions.refresh({ key: Actions.currentScene }); 第二次不工作
如果你这样做,它会起作用:)
Actions.refresh({key: Math.random()})