Skip to content

Commit ddeafcd

Browse files
scarlacgilbox
authored andcommitted
Fixes react-native-maps#470. Support legalLabelInsets on Apple Maps (react-native-maps#840)
* Fixes react-native-maps#470 for iOS and Apple Maps This will add support for `legalLabelInsets` prop on iOS with Apple Maps. Code is adapted from RN core. * Pluralize updateLegalLabelInset(s) for consistency * Removed arrow notation * Added legalLabelInsets example
1 parent b1f5a4b commit ddeafcd

File tree

3 files changed

+135
-0
lines changed

3 files changed

+135
-0
lines changed

example/App.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import CustomTiles from './examples/CustomTiles';
3232
import ZIndexMarkers from './examples/ZIndexMarkers';
3333
import StaticMap from './examples/StaticMap';
3434
import MapStyle from './examples/MapStyle';
35+
import LegalLabel from './examples/LegalLabel';
3536

3637
const IOS = Platform.OS === 'ios';
3738
const ANDROID = Platform.OS === 'android';
@@ -142,6 +143,7 @@ class App extends React.Component {
142143
[CustomTiles, 'Custom Tiles', true],
143144
[ZIndexMarkers, 'Position Markers with Z-index', true],
144145
[MapStyle, 'Customize the style of the map', true],
146+
[LegalLabel, 'Reposition the legal label', true],
145147
]
146148
// Filter out examples that are not yet supported for Google Maps on iOS.
147149
.filter(example => ANDROID || (IOS && (example[2] || !this.state.useGoogleMaps)))

example/examples/LegalLabel.js

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
import React from 'react';
2+
import {
3+
StyleSheet,
4+
View,
5+
Text,
6+
Dimensions,
7+
} from 'react-native';
8+
9+
import MapView from 'react-native-maps';
10+
11+
const screen = Dimensions.get('window');
12+
13+
class LegalLabel extends React.Component {
14+
static propTypes = {
15+
provider: MapView.ProviderPropType,
16+
}
17+
18+
render() {
19+
const latlng = {
20+
latitude: 37.78825,
21+
longitude: -122.4324,
22+
};
23+
24+
const ASPECT_RATIO = screen.width / screen.height;
25+
const LATITUDE_DELTA = 0.0922;
26+
const LONGITUDE_DELTA = LATITUDE_DELTA * ASPECT_RATIO;
27+
28+
return (
29+
<View style={{ ...StyleSheet.absoluteFillObject }}>
30+
<MapView
31+
provider={this.props.provider}
32+
style={styles.map}
33+
legalLabelInsets={{ bottom: 10, right: 10 }}
34+
initialRegion={{
35+
...latlng,
36+
latitudeDelta: LATITUDE_DELTA,
37+
longitudeDelta: LONGITUDE_DELTA,
38+
}}
39+
>
40+
<MapView.Marker coordinate={latlng} />
41+
</MapView>
42+
43+
<View style={styles.username}>
44+
<Text style={styles.usernameText}>Username</Text>
45+
</View>
46+
47+
<View style={styles.bio}>
48+
<Text style={styles.bioText}>
49+
Bio description lorem ipsum Ullamco exercitation
50+
aliqua ullamco nostrud dolor et aliquip fugiat do
51+
aute fugiat velit in aliqua sit.
52+
</Text>
53+
</View>
54+
55+
<View style={styles.photo}>
56+
<View style={styles.photoInner}>
57+
<Text style={styles.photoText}>
58+
Profile Photo
59+
</Text>
60+
</View>
61+
</View>
62+
</View>
63+
);
64+
}
65+
}
66+
67+
const padding = 10;
68+
const photoSize = 80;
69+
const mapHeight = screen.height - 130;
70+
const styles = StyleSheet.create({
71+
bio: {
72+
marginHorizontal: padding,
73+
marginBottom: 0,
74+
paddingVertical: padding / 2,
75+
},
76+
bioText: {
77+
fontSize: 16,
78+
lineHeight: 16 * 1.5,
79+
},
80+
username: {
81+
paddingLeft: photoSize + padding + padding,
82+
paddingTop: padding,
83+
},
84+
usernameText: {
85+
fontSize: 36,
86+
lineHeight: 36,
87+
},
88+
photo: {
89+
padding: 2,
90+
position: 'absolute',
91+
top: mapHeight - (photoSize / 2),
92+
left: padding,
93+
borderRadius: 5,
94+
borderWidth: StyleSheet.hairlineWidth,
95+
backgroundColor: '#ccc',
96+
width: photoSize,
97+
height: photoSize,
98+
},
99+
photoInner: {
100+
alignItems: 'center',
101+
justifyContent: 'center',
102+
flex: 1,
103+
},
104+
photoText: {
105+
fontSize: 9,
106+
textAlign: 'center',
107+
},
108+
map: {
109+
height: mapHeight,
110+
},
111+
});
112+
113+
module.exports = LegalLabel;

ios/AirMaps/AIRMap.m

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,26 @@ - (void)cacheViewIfNeeded {
381381

382382
[self updateScrollEnabled];
383383
[self updateZoomEnabled];
384+
[self updateLegalLabelInsets];
385+
}
386+
}
387+
388+
- (void)updateLegalLabelInsets {
389+
if (_legalLabel) {
390+
dispatch_async(dispatch_get_main_queue(), ^{
391+
CGRect frame = _legalLabel.frame;
392+
if (_legalLabelInsets.left) {
393+
frame.origin.x = _legalLabelInsets.left;
394+
} else if (_legalLabelInsets.right) {
395+
frame.origin.x = self.frame.size.width - _legalLabelInsets.right - frame.size.width;
396+
}
397+
if (_legalLabelInsets.top) {
398+
frame.origin.y = _legalLabelInsets.top;
399+
} else if (_legalLabelInsets.bottom) {
400+
frame.origin.y = self.frame.size.height - _legalLabelInsets.bottom - frame.size.height;
401+
}
402+
_legalLabel.frame = frame;
403+
});
384404
}
385405
}
386406

0 commit comments

Comments
 (0)