Skip to content

Commit

Permalink
Rotate only when rotationThreshold reached
Browse files Browse the repository at this point in the history
  • Loading branch information
maRci002 committed Aug 6, 2020
1 parent 95e9afa commit 08e22d5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
16 changes: 9 additions & 7 deletions lib/src/gestures/gestures.dart
Expand Up @@ -169,7 +169,7 @@ abstract class MapGestureMixin extends State<FlutterMap>

if (hasRotate) {
if (!_rotationStarted &&
_rotationAccumlator >= options.rotationThreshold) {
_rotationAccumlator.abs() >= options.rotationThreshold) {
_rotationStarted = true;
map.emitMapEvent(
MapEventRotateStart(
Expand All @@ -180,12 +180,14 @@ abstract class MapGestureMixin extends State<FlutterMap>
);
}

map.rotate(
map.rotation + rotationDiff,
hasGesture: true,
simulateMove: !mapMoved,
source: MapEventSource.onDrag,
);
if (_rotationStarted) {
map.rotate(
map.rotation + rotationDiff,
hasGesture: true,
simulateMove: !mapMoved,
source: MapEventSource.onDrag,
);
}
}
}

Expand Down
9 changes: 5 additions & 4 deletions lib/src/map/map_state_widget.dart
@@ -1,4 +1,5 @@
import 'package:flutter/widgets.dart';

import 'map.dart';

class MapStateInheritedWidget extends InheritedWidget {
Expand All @@ -12,10 +13,10 @@ class MapStateInheritedWidget extends InheritedWidget {

@override
bool updateShouldNotify(MapStateInheritedWidget oldWidget) {
return oldWidget.mapState.zoom == mapState.zoom &&
oldWidget.mapState.center == mapState.center &&
oldWidget.mapState.bounds == mapState.bounds &&
oldWidget.mapState.rotation == mapState.rotation;
// mapState will be the same because FlutterMapState create MapState object just once
// and pass the same instance to the old / new MapStateInheritedWidget
// Moreover MapStateInheritedWidget isn't cached so all of it's child will be updated no matter if we return here with false
return true;
}

static MapStateInheritedWidget of(BuildContext context) {
Expand Down

0 comments on commit 08e22d5

Please sign in to comment.