2016-07-05 3 views
1

バックボタンを押すと、前の画面に戻りますが、アプリも閉じます。私はすでにevent.preventDefault()を追加しようとしましたが、私の問題は修正されません。BackAndroid - アプリがまだ閉じています

componentWillMount() { 
 
    BackAndroid.addEventListener('hardwareBackPress',() => { 
 
     this.goBack(); 
 
    }) 
 
} 
 
    
 
goBack() { 
 
    this.props.actions.goBack(); 
 
} 
 

 
//Reducer 
 

 

 
export default function navReducer(state = initialState, action = {}) { 
 
    switch(action.type) { 
 
     case types.OPEN: 
 
      return { 
 
       scenes: [ 
 
        ...state.scenes, 
 
        {key: action.key, name: action.name} 
 
       ] 
 
      }; 
 
     case types.BACK: 
 
      if(state.scenes.length > 1) { 
 
       return { 
 
        scenes: state.scenes.slice(0, state.scenes.length - 1) 
 
       } 
 
      } else { 
 
       console.log('Error') 
 
      }; 
 
     default: 
 
      return state; 
 
    } 
 
}

答えて

2

アップデートとしてあなたGOBACK方法:あなたはGOBACKメソッドからtrueを返す必要はあり

goBack() { 
     this.props.actions.goBack(); 
     return true; 
    } 

は、それ以外の場合は、アプリを閉じます。

関連する問題