onPress/onLongPress `position` is in device pixels on Android, points on iOS
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 78/100
Hướng nghiên cứu
Bắt đầu trong phần triển khai Android tại MapView.makeClickEventData(), sau đó so sánh cách xử lý projection.toScreenLocation(point) với MapModule.pointForCoordinate(), vốn đã chuẩn hóa kết quả. Xác minh vị trí sự kiện trên một thiết bị Android có mật độ khác 1 và xác nhận rằng onPress, onLongPress, onPanDrag, onPoiClick và thao tác nhấn vào marker sử dụng cùng đơn vị với iOS.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Summary
Map events that carry a position (onPress, onLongPress, onPanDrag, onPoiClick, marker presses) report it in device pixels on Android and in UIKit points on iOS. Anything an app positions from that value — a context menu, a tooltip, a custom callout — therefore lands PixelRatio.get() times too far right and down on Android. On a 420 dpi device that is 2.625x, which is usually far enough to leave the screen.
docs/mapview.md documents these props as { coordinate: LatLng, position: Point } without stating a unit, so there is nothing that says which platform is right — but the two disagree, and the library itself is not consistent either: MapModule.pointForCoordinate() divides by the display density before resolving its promise, so the two ways of getting a frame point out of the same map answer in different units.
Version
react-native-maps 1.27.2, also present on master (1.29.0) and on beta.
Steps to reproduce
- Render a
MapViewwithprovider={PROVIDER_GOOGLE}on an Android device whose density is not 1. - In
onLongPress, storenativeEvent.positionand absolutely position a small view at that{x, y}. - Long-press somewhere near the middle of the map.
Expected: the view appears under the finger, as it does on iOS.
Actual: it appears at position * density — down and to the right, usually clamped at the edge of the screen.
Cause
MapView.makeClickEventData() puts projection.toScreenLocation(point) into the event as is:
Projection projection = map.getProjection();
Point screenPoint = projection.toScreenLocation(point);
WritableMap position = new WritableNativeMap();
position.putDouble("x", screenPoint.x);
position.putDouble("y", screenPoint.y);
toScreenLocation() answers in device pixels. MapModule.pointForCoordinate(), a few files over, divides the very same call by getResources().getDisplayMetrics().density. On iOS the same events carry locationInView: results, which are already points.
Suggested fix
Divide by the display density in makeClickEventData(), the way pointForCoordinate() already does. PR follows.
- Ngôn ngữ chính
- TypeScript
- Star
- 16k
- Fork
- 5k
- Merge trung bình
- 17 giờ 45 phút
- Pull request đã merge (30 ngày)
- 2
Hướng dẫn đóng góp
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.
Issue khác của react-native-maps/react-native-maps
-
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 88/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
react-native-maps/react-native-maps#5987 · 1 bình luận ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
react-native-maps/react-native-maps#5977 · 2 bình luận · 1 reaction ·
Tất cả issue của react-native-maps/react-native-maps
Issue tương tự
-
blocklist removal
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
MetaMask/eth-phishing-detect#296544 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
pastelsky/bundlephobia#1122 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
-
category/development priority/P2 scope/file-operations scope/testing type/enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
-
Enatega Customer and Rider app: Add-ons price is not visible to customer after order is placed. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100