Frontend/React
[React Native] Android Backkey 종료 처리
romeoh
2022. 12. 18. 19:39
반응형
App.tsx
...
import {BackHandler, Alert} from 'react-native';
const App = () => {
useEffect(() => {
const backAction = () => {
Alert.alert('', '앱을 종료하시겠습니까?', [
{text: '취소', onPress: () => null},
{text: '확인', onPress: () => BackHandler.exitApp()},
]);
return true;
};
const backHandler = BackHandler.addEventListener(
'hardwareBackPress',
backAction,
);
return () => backHandler.remove();
}, []);
return (
<View>
...
</View>
);
};
export default App;
반응형