Skip to content

Commit

Permalink
Allow legalLabelInsets to be changed and animated (#873)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
scarlac authored and gilbox committed Dec 8, 2016
1 parent 8d654fb commit 7869dfd
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 2 deletions.
10 changes: 10 additions & 0 deletions docs/mapview.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
| `loadingIndicatorColor` | `Color` | `#606060` | Sets loading indicator color, default to `#606060`.
| `loadingBackgroundColor` | `Color` | `#FFFFFF` | Sets loading background color, default to `#FFFFFF`.
| `moveOnMarkerPress` | `Boolean` | `true` | `Android only` If `false` the map won't move when a marker is pressed.
| `legalLabelInsets` | `EdgeInsets` | | If set, changes the position of the "Legal" label link from the OS default. **Note:** iOS only.


## Events
Expand Down Expand Up @@ -103,3 +104,12 @@ type EdgePadding {
left: Number
}
```

```
type EdgeInsets {
top: Number,
left: Number,
bottom: Number,
right: Number
}
```
38 changes: 36 additions & 2 deletions example/examples/LegalLabel.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import {
StyleSheet,
View,
Text,
Animated,
Dimensions,
TouchableOpacity,
} from 'react-native';

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

state = {
_legalLabelPositionY: new Animated.Value(10),
legalLabelPositionY: 10,
}

componentDidMount() {
this.state._legalLabelPositionY.addListener(({ value }) => {
this.setState({
legalLabelPositionY: value,
});
});
}

componentWillUnmount() {
this.state._legalLabelPositionY.removeAllListeners();
}

onPressAnimate = () => {
Animated.sequence([
Animated.spring(this.state._legalLabelPositionY, {
toValue: 100,
}),
Animated.spring(this.state._legalLabelPositionY, {
toValue: 10,
}),
]).start();
}

render() {
const latlng = {
latitude: 37.78825,
Expand All @@ -30,7 +60,7 @@ class LegalLabel extends React.Component {
<MapView
provider={this.props.provider}
style={styles.map}
legalLabelInsets={{ bottom: 10, right: 10 }}
legalLabelInsets={{ bottom: this.state.legalLabelPositionY, right: 10 }}
initialRegion={{
...latlng,
latitudeDelta: LATITUDE_DELTA,
Expand All @@ -41,7 +71,9 @@ class LegalLabel extends React.Component {
</MapView>

<View style={styles.username}>
<Text style={styles.usernameText}>Username</Text>
<TouchableOpacity onPress={this.onPressAnimate}>
<Text style={styles.usernameText}>Animate</Text>
</TouchableOpacity>
</View>

<View style={styles.bio}>
Expand Down Expand Up @@ -84,6 +116,8 @@ const styles = StyleSheet.create({
usernameText: {
fontSize: 36,
lineHeight: 36,
color: 'blue',
textDecorationLine: 'underline',
},
photo: {
padding: 2,
Expand Down
6 changes: 6 additions & 0 deletions ios/AirMaps/AIRMap.m
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,12 @@ - (void)updateLegalLabelInsets {
}
}


- (void)setLegalLabelInsets:(UIEdgeInsets)legalLabelInsets {
_legalLabelInsets = legalLabelInsets;
[self updateLegalLabelInsets];
}

- (void)beginLoading {
if ((!self.hasShownInitialLoading && self.loadingEnabled) || (self.cacheEnabled && self.cacheImageView.image == nil)) {
self.loadingView.hidden = NO;
Expand Down

0 comments on commit 7869dfd

Please sign in to comment.