728x90
먼저 아래와 같이 BackHandler 를 import 해온다.
import {
BackHandler
} from 'react-native';
다음으로 뒤로가기 버튼을 다루고자 하는 뷰의 Constructor에 아래와 같은 코드 추가.
this.backHandler = BackHandler.addEventListener('hardwareBackPress', this.handleBackPress);
또한 컴포넌트 코드 내에서 위에서 선언한 handleBackPress() 를 구현하고, return false면 기존 뒤로가기 명령을 그대로 보내고, return true를 하면 기존 뒤로가기 명령을 무시하게 된다(뒤로가기 버튼이 작동하지 않게 된다).
handleBackPress(){
console.log("TQW1E");
return true;
}
728x90
'프로그래밍 > React Native(2018)' 카테고리의 다른 글
[React Native] createBottomTabNavigator의 header 없애는 방법 (0) | 2019.09.29 |
---|---|
[React Native] 간단한 팝업창을 띄우는 방법 (0) | 2019.09.29 |
[React Native] 뒤로가기 버튼 두번 눌러서 앱 종료하기 (0) | 2019.09.29 |
[React Native] Navigation의 header사용방법 (0) | 2019.09.29 |
[React Native] array를 alphabetically 배열하는 방법 (0) | 2019.09.29 |
댓글