レスキューネイティブで作業を開始しました。問題が発生しました。私はdispatching
アクションで、onLoadStart
の画像コンポーネントの機能でコールバックが発砲しています。そのアクションが呼び出され、表示されます。Loading...
画面上では、しかし、私はdispatching
のonLoadEnd
で何も起こらない(callback loadEnd is not fired, app looks like frozen)
。両方の場所でconsole.logを使用すると、コードは正常に動作しています。誰かが私に何が間違っているのか教えてもらえますか?コールバックでアクションをディスパッチ
class DisplayImage extends Component {
loadStart() {
this.props.iLoadingFunction(true);
}
loadEnd() { // <- this function is not fired
this.props.iLoadingFunction(false);
}
render() {
if (this.props.isLoading) {
return <Text>Loading…</Text>;
}
return (
<View>
<Image
source={{uri: 'https://test.com/image'}}
onLoadStart={this.loadStart.bind(this)}
onLoadEnd={this.loadEnd.bind(this)}
/>
</View>
);
}
}
const mapStateToProps = (state) => {
return {
isLoading: state.isLoading
};
};
const mapDispatchToProps = (dispatch) => {
return bindActionCreators({ iLoadingFunction }, dispatch);
};
export default connect(mapStateToProps, mapDispatchToProps)(DisplayImage);
アクションと減速
export function iLoadingFunction(bool) {
return {
type: 'IS_LOADING',
isLoading: bool
};
}
export function iLoadingFunction(state = false, action) {
switch (action.type) {
case 'IS_LOADING':
return action.isLoading;
default:
return state;
}
}
のように、
this.props.isLoading
に基づいて、あなたがチェックした場合を除外しますか? –あなたの括弧が外れていると思います。 componentDidMountはレンダリング関数全体を囲んでいます。また、これら2つのメソッドをcomponentDidMountの外に定義し、内部で呼び出す必要があります。 –
componentDidMountを削除しましたが、コードを貼り付けたときに何か問題があります。私はiLoadingFunctionアクションをチェックして、それも減速機と呼ばれることがわかりますが、ロードは無限に進みます。私はにconsole.log loadStartでアクションを交換するとき は(){ はconsole.log( '開始') } loadEnd() - ストップ{// <この関数は はconsole.log( '停止') を解雇されていません} – mrc