Skip to content

Commit 6ae548e

Browse files
scarlacgilbox
authored andcommitted
Allow legalLabelInsets to be changed and animated (react-native-maps#873)
* Allow legalLabelInsets to be changed and animated Updated example to include a button to animate the legal label. * Docs for legalLabelInsets prop While structurally identical to EdgePadding, they serve completely different purposes. Default left empty since it's an OS default (around {left: 10, bottom: 10}) * Spacing / linting
1 parent d841428 commit 6ae548e

File tree

3 files changed

+52
-2
lines changed

3 files changed

+52
-2
lines changed

docs/mapview.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
| `loadingIndicatorColor` | `Color` | `#606060` | Sets loading indicator color, default to `#606060`.
2929
| `loadingBackgroundColor` | `Color` | `#FFFFFF` | Sets loading background color, default to `#FFFFFF`.
3030
| `moveOnMarkerPress` | `Boolean` | `true` | `Android only` If `false` the map won't move when a marker is pressed.
31+
| `legalLabelInsets` | `EdgeInsets` | | If set, changes the position of the "Legal" label link from the OS default. **Note:** iOS only.
3132

3233

3334
## Events
@@ -103,3 +104,12 @@ type EdgePadding {
103104
left: Number
104105
}
105106
```
107+
108+
```
109+
type EdgeInsets {
110+
top: Number,
111+
left: Number,
112+
bottom: Number,
113+
right: Number
114+
}
115+
```

example/examples/LegalLabel.js

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ import {
33
StyleSheet,
44
View,
55
Text,
6+
Animated,
67
Dimensions,
8+
TouchableOpacity,
79
} from 'react-native';
810

911
import MapView from 'react-native-maps';
@@ -15,6 +17,34 @@ class LegalLabel extends React.Component {
1517
provider: MapView.ProviderPropType,
1618
}
1719

20+
state = {
21+
_legalLabelPositionY: new Animated.Value(10),
22+
legalLabelPositionY: 10,
23+
}
24+
25+
componentDidMount() {
26+
this.state._legalLabelPositionY.addListener(({ value }) => {
27+
this.setState({
28+
legalLabelPositionY: value,
29+
});
30+
});
31+
}
32+
33+
componentWillUnmount() {
34+
this.state._legalLabelPositionY.removeAllListeners();
35+
}
36+
37+
onPressAnimate = () => {
38+
Animated.sequence([
39+
Animated.spring(this.state._legalLabelPositionY, {
40+
toValue: 100,
41+
}),
42+
Animated.spring(this.state._legalLabelPositionY, {
43+
toValue: 10,
44+
}),
45+
]).start();
46+
}
47+
1848
render() {
1949
const latlng = {
2050
latitude: 37.78825,
@@ -30,7 +60,7 @@ class LegalLabel extends React.Component {
3060
<MapView
3161
provider={this.props.provider}
3262
style={styles.map}
33-
legalLabelInsets={{ bottom: 10, right: 10 }}
63+
legalLabelInsets={{ bottom: this.state.legalLabelPositionY, right: 10 }}
3464
initialRegion={{
3565
...latlng,
3666
latitudeDelta: LATITUDE_DELTA,
@@ -41,7 +71,9 @@ class LegalLabel extends React.Component {
4171
</MapView>
4272

4373
<View style={styles.username}>
44-
<Text style={styles.usernameText}>Username</Text>
74+
<TouchableOpacity onPress={this.onPressAnimate}>
75+
<Text style={styles.usernameText}>Animate</Text>
76+
</TouchableOpacity>
4577
</View>
4678

4779
<View style={styles.bio}>
@@ -84,6 +116,8 @@ const styles = StyleSheet.create({
84116
usernameText: {
85117
fontSize: 36,
86118
lineHeight: 36,
119+
color: 'blue',
120+
textDecorationLine: 'underline',
87121
},
88122
photo: {
89123
padding: 2,

ios/AirMaps/AIRMap.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,12 @@ - (void)updateLegalLabelInsets {
404404
}
405405
}
406406

407+
408+
- (void)setLegalLabelInsets:(UIEdgeInsets)legalLabelInsets {
409+
_legalLabelInsets = legalLabelInsets;
410+
[self updateLegalLabelInsets];
411+
}
412+
407413
- (void)beginLoading {
408414
if ((!self.hasShownInitialLoading && self.loadingEnabled) || (self.cacheEnabled && self.cacheImageView.image == nil)) {
409415
self.loadingView.hidden = NO;

0 commit comments

Comments
 (0)