GT2/Ejectable/node_modules/@react-navigation/native/lib/module/useBackButton.js

22 lines
551 B
JavaScript
Raw Normal View History

2021-08-16 00:14:59 +00:00
import * as React from 'react';
import { BackHandler } from 'react-native';
export default function useBackButton(ref) {
React.useEffect(() => {
const subscription = BackHandler.addEventListener('hardwareBackPress', () => {
const navigation = ref.current;
if (navigation == null) {
return false;
}
if (navigation.canGoBack()) {
navigation.goBack();
return true;
}
return false;
});
return () => subscription.remove();
}, [ref]);
}
//# sourceMappingURL=useBackButton.js.map