Skip to content
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

Fix React state update warning #968

Merged
merged 1 commit into from
Dec 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/components/interactive-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,10 @@ export default class InteractiveMap extends PureComponent<InteractiveMapProps, S
this._updateInteractiveContext({mapContainer});
}

componentDidUpdate() {
this._setControllerProps(this.props);
}

componentWillUnmount() {
this._eventManager.destroy();
}
Expand Down Expand Up @@ -489,8 +493,6 @@ export default class InteractiveMap extends PureComponent<InteractiveMapProps, S
};

render() {
this._setControllerProps(this.props);

const {width, height, style, getCursor} = this.props;

const eventCanvasStyle = Object.assign({position: 'relative'}, style, {
Expand Down
3 changes: 2 additions & 1 deletion src/mapbox/mapbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ const defaultProps = {
latitude: 0,
zoom: 0,
bearing: 0,
pitch: 0
pitch: 0,
altitude: 1.5
};

type MapboxGL = {
Expand Down
10 changes: 6 additions & 4 deletions src/utils/map-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export default class MapController {
/* Callback util */
// formats map state and invokes callback function
updateViewport(newMapState: MapState, extraProps: any = {}, extraState: any = {}) {
const oldViewport = this.mapState ? this.mapState.getViewportProps() : {};
const oldViewport = this.mapState ? this.mapState.getViewportProps() : this.mapStateProps;
const newViewport = Object.assign({}, newMapState.getViewportProps(), extraProps);

const viewStateChanged = Object.keys(newViewport).some(
Expand Down Expand Up @@ -176,12 +176,14 @@ export default class MapController {
this.onViewportChange = onViewportChange;
this.onStateChange = onStateChange;

if (!this.mapStateProps || this.mapStateProps.height !== options.height) {
const dimensionChanged = !this.mapStateProps || this.mapStateProps.height !== options.height;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't need check whether width changed here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Width does not affect normalization. A map may need to be scaled and shifted vertically to fill the height.


this.mapStateProps = options;

if (dimensionChanged) {
// Dimensions changed, normalize the props
this.updateViewport(new MapState(options));
}

this.mapStateProps = options;
// Update transition
this._transitionManager.processViewportChange(
Object.assign({}, options, {
Expand Down