-
-
Notifications
You must be signed in to change notification settings - Fork 847
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: inconsistent iconSize between iOS and Android #3009
Comments
note from paul's teammate: we haven't been able to determine yet whether this is a bug in our code which generates the icon image per platform, or a bug in rnmapbox's icon scaling, so if this can't be reproduced it should be safe to close out |
We are having the same problem, please write an update if it was a bug in your code. We run into this issue while updating to v10. |
update: current best guess is that it is due to |
We noticed that this issue happens for us when we import an image like this: import defaultMapLayerIcon from './empty-icon.png';
const images = {
example: defaultMapLayerIcon
} when we are loading images from disk like this is rendered correctly: const images = {
example: { uri: imagePathOnDisk, scale: pixelRatio }
} |
I've done a bit more digging around this issue and I think what is causing the issue is that some Android devices have a pixel ratio with decimal points (on one of my devices is 1.75 for example). For example, when an image is loaded from the disk in our case we default to scale: 1 because is not 2
and this renders correctly. but when the image is loaded from the bundler the source looks like this:
so it loads the scale: 2 images so I think that's what causing the issue. On iOS it works fine because the scale is 2 when calling The solution I found for this issue is to set the Not sure how this case was handled on the old repo, but this workaround was not needed. |
It's really strange for me. Only certain icons are different sizes, some are rendered the same size regardless of platform. Tried resizing the inconsistent one, but didn't seem to resolve it. |
Hey, I think a potential fix could be done here |
I think those are the factors: A dev asset looks like this: 'asset', { __packager_asset: true,
width: 44,
height: 44,
uri: 'http://localhost:8081/assets/src/assets/[email protected]?platform=ios&hash=2557a9ee1ee49ac29dff472336c97a87',
scale: 3 } See also: See also the fixes: |
Thanks, as I understood, in your fixes for old versions the scale is passed directly to sdk methods without modifying. So what scale RN picks depends on what is available in file system (@, @2x, @3x), that image will be created. In release mode, the asset looks like this Hence, in both cases (debug, prod) the scale property is available and the value is the same. And it's correct as on my device pixelRatio is 1.5 and the image was picked @2x. |
So I've tried the example in the bug report, and for me it was the same size. This was in debug build and using the example in the example.png repo: |
So if anyone have issue with icon size, please write a clear description: Screenshots on both platform. Ideally you can also add a circle layer above the icons, to see how it compares with the desired size: With the example.png as it's 44x44 pixel sized, and there is a iconSize=3 in the StyleLayer style I've just added a CircleLayer to verify it's correct size on both platforms: <ShapeSource id={'shape-source-id-0'} shape={features}>
<SymbolLayer id="symbol-id" style={styles.iconLayer} />
<CircleLayer
id="circel-layer"
style={{
circleRadius: 3 * (44.0 / 2),
circleOpacity: 0.4,
circleStrokeColor: 'green',
circleStrokeWidth: 2,
}}
/>
</ShapeSource> FWIW it's the code I've used: import React from 'react';
import {
Images,
MapView,
ShapeSource,
SymbolLayer,
Camera,
CircleLayer,
} from '@rnmapbox/maps';
const styles = {
mapView: { flex: 1 },
iconLayer: {
iconSize: 3.0,
iconImage: 'example',
},
};
const features = {
type: 'FeatureCollection',
features: [
{
type: 'Feature',
id: 'a-feature',
geometry: {
type: 'Point',
coordinates: [-74.00597, 40.71427],
},
},
],
};
class BugReportExample extends React.Component {
render() {
return (
<MapView style={styles.mapView}>
<Camera centerCoordinate={[-74.00597, 40.71427]} zoomLevel={14} />
<Images images={{ example: require('../assets/example.png') }} />
<ShapeSource id={'shape-source-id-0'} shape={features}>
<SymbolLayer id="symbol-id" style={styles.iconLayer} />
<CircleLayer
id="circel-layer"
style={{
circleRadius: 3 * (44.0 / 2),
circleOpacity: 0.4,
circleStrokeColor: 'green',
circleStrokeWidth: 2,
}}
/>
</ShapeSource>
</MapView>
);
}
}
export default BugReportExample; |
@mfazekas thanks for the detailed example, I've managed to reproduce the issue with your code sample.
Shared with you the code on this branch: https://github.com/lineinspector/rnmapbox-react-native-background-geolocation/tree/inconsistent-iconSize |
The issues should have been fixed |
Thank you @mfazekas, the issue was fixed! |
Thanks @mfazekas. It works as expected in debug, but not in prod
Note: The size of image looks the same as with this workaround #3009 (comment) |
@snazarkoo can you test |
@mfazekas Perfect, icons are properly sized. Thanks for your work |
Hello, I'm having this exact issue, but the other way around. |
Hey @JasonSanford , did you find a solution for your issue? I'm still experiencing the issue on version "10.1.3" (magnified HeadingIcon & some SymbolLayers). |
Mapbox Implementation
Mapbox
Mapbox Version
default
Platform
iOS, Android
@rnmapbox/maps
version10.0.11
Standalone component to reproduce
Observed behavior and steps to reproduce
Images on iOS are are ≈2.5x larger than on Android:
Expected behavior
Same size on both device types.
Notes / preliminary analysis
React 18.2.0
React Native 0.72.4
@rnmapbox/maps 10.0.11
Additional links and references
Previous related bug: #68
The text was updated successfully, but these errors were encountered: