react-navigation / react-navigation/react-navigation.github.io
Update [Custom Android back button behavior] example
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- JavaScript
- Star
- 324
- Fork
- 2k
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Mô tả
Hi! I am currently refactoring code to using hooks. And I found refactoring the custom back button behaviour confusing.
I tried to adapt the example you have here to the code I refactored
import React from "react";
import { BackHandler } from "react-native";
const ScreenWithCustomBackBehavior = ({ navigation }) => {
const onBackButtonPressAndroid = useCallback(() => {
if (isSelectionModeEnabled()) {
disableSelectionMode();
return true;
} else {
return false;
}
}, [isSelectionModeEnabled, disableSelectionMode]);
useEffect(() => {
const _didFocusSubscription = navigation.addListener('didFocus', () => {
BackHandler.addEventListener('hardwareBackPress', onBackButtonPressAndroid);
});
const _willBlurSubscription = navigation.addListener('willBlur', () => {
BackHandler.removeEventListener('hardwareBackPress', onBackButtonPressAndroid);
});
return () => {
if (_didFocusSubscription) {
_didFocusSubscription.remove();
}
if (_willBlurSubscription) {
_willBlurSubscription.remove();
}
};
}, [navigation, onBackButtonPressAndroid]);
}
return (
// ...
)
Do you think it's a proper way to do it? If yes, should I submit a PR?
Thank you
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Xem xét ví dụ được liên kết về hành vi của nút quay lại Android tùy chỉnh và đoạn mã dựa trên hooks được đề xuất. Quyết định xem có nên cập nhật ví dụ theo cách tiếp cận này hay không; hoàn thành nghĩa là ví dụ trong tài liệu phản ánh hành vi đã thống nhất và rõ ràng đối với người đọc.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- react, react-native
- Lĩnh vực
- documentation
- Loại issue
- Tài liệu
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 35/100