Skip to content

Commit 15375dc

Browse files
authored
Fix/elements handling (#302)
* fix: android map elements tap event propagation * fix: ios map elements tap event propagation * fix: add handled param * build: update README * build: version 4.8.1
1 parent 866a402 commit 15375dc

35 files changed

+130
-16
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ import { Marker } from 'react-native-yamap';
304304
| anchor | { x: number, y: number } | Якорь иконки маркера. Координаты принимают значения от 0 до 1 |
305305
| zIndex | number | Отображение элемента по оси Z |
306306
| visible | boolean | Отображение маркера на карте |
307+
| handled | boolean | Включение(**false**)/отключение(**true**) всплытия события нажатия для родителя `default:true` |
307308

308309
#### Доступные методы для примитива **Marker**:
309310

@@ -331,6 +332,7 @@ import { Circle } from 'react-native-yamap';
331332
| strokeWidth | number | Толщина границы |
332333
| onPress | function | Действие при нажатии/клике |
333334
| zIndex | number | Отображение элемента по оси Z |
335+
| handled | boolean | Включение(**false**)/отключение(**true**) всплытия события нажатия для родителя `default:true` |
334336

335337
### Polyline
336338

@@ -362,6 +364,7 @@ import { Polyline } from 'react-native-yamap';
362364
| gapLength | number | Длина разрыва между штрихами |
363365
| onPress | function | Действие при нажатии/клике |
364366
| zIndex | number | Отображение элемента по оси Z |
367+
| handled | boolean | Включение(**false**)/отключение(**true**) всплытия события нажатия для родителя `default:true` |
365368

366369
### Polygon
367370

@@ -390,6 +393,7 @@ import { Polygon } from 'react-native-yamap';
390393
| innerRings | (Point[])[] | Массив полилиний, которые образуют отверстия в полигоне |
391394
| onPress | function | Действие при нажатии/клике |
392395
| zIndex | number | Отображение элемента по оси Z |
396+
| handled | boolean | Включение(**false**)/отключение(**true**) всплытия события нажатия для родителя `default:true` |
393397

394398
## Запрос маршрутов
395399

android/src/main/java/ru/vvdev/yamap/YamapCircleManager.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ class YamapCircleManager internal constructor() : ViewGroupManager<YamapCircle>(
6666
view.setZIndex(zIndex)
6767
}
6868

69+
@ReactProp(name = "handled")
70+
fun setHandled(view: YamapCircle, handled: Boolean?) {
71+
view.setHandled(handled ?: true)
72+
}
73+
6974
companion object {
7075
const val REACT_CLASS: String = "YamapCircle"
7176
}

android/src/main/java/ru/vvdev/yamap/YamapMarkerManager.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ class YamapMarkerManager internal constructor() : ViewGroupManager<YamapMarker>(
5858
castToMarkerView(view).setScale(scale)
5959
}
6060

61+
@ReactProp(name = "handled")
62+
fun setHandled(view: View, handled: Boolean?) {
63+
castToMarkerView(view).setHandled(handled ?: true)
64+
}
65+
6166
@ReactProp(name = "rotated")
6267
fun setRotated(view: View, rotated: Boolean?) {
6368
castToMarkerView(view).setRotated(rotated ?: true)

android/src/main/java/ru/vvdev/yamap/YamapPolygonManager.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@ class YamapPolygonManager internal constructor() : ViewGroupManager<YamapPolygon
9797
castToPolygonView(view).setZIndex(zIndex)
9898
}
9999

100+
@ReactProp(name = "handled")
101+
fun setHandled(view: View, handled: Boolean?) {
102+
castToPolygonView(view).setHandled(handled ?: true)
103+
}
104+
100105
companion object {
101106
const val REACT_CLASS: String = "YamapPolygon"
102107
}

android/src/main/java/ru/vvdev/yamap/YamapPolylineManager.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ class YamapPolylineManager internal constructor() : ViewGroupManager<YamapPolyli
9393
castToPolylineView(view).setOutlineColor(color)
9494
}
9595

96+
@ReactProp(name = "handled")
97+
fun setHandled(view: View, handled: Boolean?) {
98+
castToPolylineView(view).setHandled(handled ?: true)
99+
}
100+
96101
companion object {
97102
const val REACT_CLASS: String = "YamapPolyline"
98103
}

android/src/main/java/ru/vvdev/yamap/view/YamapCircle.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class YamapCircle(context: Context?) : ViewGroup(context), MapObjectTapListener,
1818
var circle: Circle
1919

2020
override var rnMapObject: MapObject? = null
21+
private var handled = true
2122
private var fillColor = Color.BLACK
2223
private var strokeColor = Color.BLACK
2324
private var zIndex = 1
@@ -54,6 +55,10 @@ class YamapCircle(context: Context?) : ViewGroup(context), MapObjectTapListener,
5455
updateCircle()
5556
}
5657

58+
fun setHandled(_handled: Boolean) {
59+
handled = _handled
60+
}
61+
5762
fun setStrokeColor(_color: Int) {
5863
strokeColor = _color
5964
updateCircle()
@@ -97,6 +102,6 @@ class YamapCircle(context: Context?) : ViewGroup(context), MapObjectTapListener,
97102
id, "onPress", e
98103
)
99104

100-
return false
105+
return handled
101106
}
102107
}

android/src/main/java/ru/vvdev/yamap/view/YamapMarker.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class YamapMarker(context: Context?) : ReactViewGroup(context), MapObjectTapList
3030
private var zIndex = 1
3131
private var scale = 1f
3232
private var visible = true
33+
private var handled = true
3334
private var rotated = false
3435
private val YAMAP_FRAMES_PER_SECOND = 25
3536
private var markerAnchor: PointF? = null
@@ -60,6 +61,10 @@ class YamapMarker(context: Context?) : ReactViewGroup(context), MapObjectTapList
6061
updateMarker()
6162
}
6263

64+
fun setHandled(_handled: Boolean) {
65+
handled = _handled
66+
}
67+
6368
fun setRotated(_rotated: Boolean) {
6469
rotated = _rotated
6570
updateMarker()
@@ -205,6 +210,6 @@ class YamapMarker(context: Context?) : ReactViewGroup(context), MapObjectTapList
205210
id, "onPress", e
206211
)
207212

208-
return true
213+
return handled
209214
}
210215
}

android/src/main/java/ru/vvdev/yamap/view/YamapPolygon.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class YamapPolygon(context: Context?) : ViewGroup(context), MapObjectTapListener
2424
private var strokeColor = Color.BLACK
2525
private var zIndex = 1
2626
private var strokeWidth = 1f
27+
private var handled = true
2728

2829
init {
2930
polygon = Polygon(LinearRing(ArrayList()), ArrayList())
@@ -97,6 +98,10 @@ class YamapPolygon(context: Context?) : ViewGroup(context), MapObjectTapListener
9798
updatePolygon()
9899
}
99100

101+
fun setHandled(_handled: Boolean) {
102+
handled = _handled
103+
}
104+
100105
// fun setRnMapObject(obj: MapObject?) {
101106
// rnMapObject = obj as PolygonMapObject?
102107
// rnMapObject!!.addTapListener(this)
@@ -109,6 +114,6 @@ class YamapPolygon(context: Context?) : ViewGroup(context), MapObjectTapListener
109114
id, "onPress", e
110115
)
111116

112-
return false
117+
return handled
113118
}
114119
}

android/src/main/java/ru/vvdev/yamap/view/YamapPolyline.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class YamapPolyline(context: Context?) : ViewGroup(context), MapObjectTapListene
2626
private var gapLength = 0
2727
private var dashOffset = 0f
2828
private var outlineWidth = 0
29+
private var handled = true
2930

3031
init {
3132
polyline = Polyline(ArrayList())
@@ -100,6 +101,10 @@ class YamapPolyline(context: Context?) : ViewGroup(context), MapObjectTapListene
100101
rnMapObject!!.addTapListener(this)
101102
updatePolyline()
102103
}
104+
105+
fun setHandled(_handled: Boolean) {
106+
handled = _handled
107+
}
103108
// fun setRnMapObject(obj: MapObject?) {
104109
// rnMapObject = obj as PolylineMapObject?
105110
// rnMapObject!!.addTapListener(this)
@@ -112,6 +117,6 @@ class YamapPolyline(context: Context?) : ViewGroup(context), MapObjectTapListene
112117
id, "onPress", e
113118
)
114119

115-
return false
120+
return handled
116121
}
117122
}

build/components/Circle.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export interface CircleProps {
99
center: Point;
1010
radius: number;
1111
children?: undefined;
12+
handled?: boolean;
1213
}
1314
export declare class Circle extends React.Component<CircleProps> {
1415
static defaultProps: {};

build/components/Circle.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/components/Marker.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export interface MarkerProps {
1414
y: number;
1515
};
1616
visible?: boolean;
17+
handled?: boolean;
1718
}
1819
interface State {
1920
recreateKey: boolean;

build/components/Marker.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/components/Polygon.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export interface PolygonProps {
99
points: Point[];
1010
innerRings?: (Point[])[];
1111
children?: undefined;
12+
handled?: boolean;
1213
}
1314
export declare class Polygon extends React.Component<PolygonProps> {
1415
static defaultProps: {

build/components/Polygon.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/components/Polyline.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export interface PolylineProps {
1212
onPress?: () => void;
1313
points: Point[];
1414
children?: undefined;
15+
handled?: boolean;
1516
}
1617
export declare class Polyline extends React.Component<PolylineProps> {
1718
render(): React.JSX.Element;

build/components/Polyline.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ios/View/YamapCircleView.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
- (YMKCircle*)getCircle;
1818
- (YMKPolygonMapObject*)getMapObject;
1919
- (void)setMapObject:(YMKCircleMapObject*)mapObject;
20+
- (void)setHandled:(BOOL)_handled;
2021

2122
@end
2223

ios/View/YamapCircleView.m

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ @implementation YamapCircleView {
2323
UIColor* strokeColor;
2424
NSNumber* strokeWidth;
2525
NSNumber* zIndex;
26+
BOOL handled;
2627
}
2728

2829
- (instancetype)init {
@@ -31,6 +32,7 @@ - (instancetype)init {
3132
strokeColor = UIColor.blackColor;
3233
zIndex = [[NSNumber alloc] initWithInt:1];
3334
strokeWidth = [[NSNumber alloc] initWithInt:1];
35+
handled = YES;
3436
center = [YMKPoint pointWithLatitude:0 longitude:0];
3537
radius = 0.f;
3638
circle = [YMKCircle circleWithCenter:center radius:radius];
@@ -58,6 +60,11 @@ - (void)setStrokeColor:(UIColor*)color {
5860
[self updateCircle];
5961
}
6062

63+
- (void)setHandled:(BOOL)_handled {
64+
handled = _handled;
65+
}
66+
67+
6168
- (void)setStrokeWidth:(NSNumber*)width {
6269
strokeWidth = width;
6370
[self updateCircle];
@@ -100,7 +107,7 @@ - (BOOL)onMapObjectTapWithMapObject:(nonnull YMKMapObject*)mapObject point:(nonn
100107
if (self.onPress)
101108
self.onPress(@{});
102109

103-
return YES;
110+
return handled;
104111
}
105112

106113
- (YMKCircleMapObject*)getMapObject {

ios/View/YamapMarkerView.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
- (void)setPoint:(YMKPoint*)_points;
1818
- (void)setAnchor:(NSValue*)_anchor;
1919
- (void)setVisible:(NSNumber*)_visible;
20+
- (void)setHandled:(BOOL)_visible;
2021

2122
// REF
2223
- (void)animatedMoveTo:(YMKPoint*)point withDuration:(float)duration;

ios/View/YamapMarkerView.m

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ @implementation YamapMarkerView {
2626
NSString* lastSource;
2727
NSValue* anchor;
2828
NSNumber* visible;
29+
BOOL handled;
2930
NSMutableArray<UIView*>* _reactSubviews;
3031
UIView* _childView;
3132
}
@@ -36,6 +37,7 @@ - (instancetype)init {
3637
scale = [[NSNumber alloc] initWithInt:1];
3738
rotated = [[NSNumber alloc] initWithInt:0];
3839
visible = [[NSNumber alloc] initWithInt:1];
40+
handled = YES;
3941
_reactSubviews = [[NSMutableArray alloc] init];
4042
source = @"";
4143
lastSource = @"";
@@ -110,6 +112,10 @@ - (void)setVisible:(NSNumber*)_visible {
110112
[self updateMarker];
111113
}
112114

115+
- (void)setHandled:(BOOL)_handled {
116+
handled = _handled;
117+
}
118+
113119
- (void)setPoint:(YMKPoint*)point {
114120
_point = point;
115121
[self updateMarker];
@@ -166,7 +172,7 @@ - (BOOL)onMapObjectTapWithMapObject:(nonnull YMKMapObject*)_mapObject point:(non
166172
if (self.onPress)
167173
self.onPress(@{});
168174

169-
return YES;
175+
return handled;
170176
}
171177

172178
- (YMKPoint*)getPoint {

ios/View/YamapPolygonView.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
- (YMKPolygon*)getPolygon;
1919
- (YMKPolygonMapObject*)getMapObject;
2020
- (void)setMapObject:(YMKPolygonMapObject*)mapObject;
21+
- (void)setHandled:(BOOL)_handled;
2122

2223
@end
2324

ios/View/YamapPolygonView.m

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,15 @@ @implementation YamapPolygonView {
2323
UIColor* strokeColor;
2424
NSNumber* strokeWidth;
2525
NSNumber* zIndex;
26+
BOOL handled;
2627
}
2728

2829
- (instancetype)init {
2930
self = [super init];
3031
fillColor = UIColor.blackColor;
3132
strokeColor = UIColor.blackColor;
3233
zIndex = [[NSNumber alloc] initWithInt:1];
34+
handled = YES;
3335
strokeWidth = [[NSNumber alloc] initWithInt:1];
3436
_points = [[NSMutableArray alloc] init];
3537
innerRings = [[NSMutableArray alloc] init];
@@ -91,6 +93,10 @@ - (void)setInnerRings:(NSArray<NSArray<YMKPoint*>*>*)_innerRings {
9193
[self updatePolygon];
9294
}
9395

96+
- (void)setHandled:(BOOL)_handled {
97+
handled = _handled;
98+
}
99+
94100
- (void)setMapObject:(YMKPolygonMapObject *)_mapObject {
95101
mapObject = _mapObject;
96102
[mapObject addTapListenerWithTapListener:self];
@@ -101,7 +107,7 @@ - (BOOL)onMapObjectTapWithMapObject:(nonnull YMKMapObject*)mapObject point:(nonn
101107
if (self.onPress)
102108
self.onPress(@{});
103109

104-
return YES;
110+
return handled;
105111
}
106112

107113
- (NSMutableArray<YMKPoint*>*)getPoints {

ios/View/YamapPolylineView.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
- (YMKPolyline*)getPolyline;
2222
- (YMKPolylineMapObject*)getMapObject;
2323
- (void)setMapObject:(YMKPolylineMapObject*)mapObject;
24+
- (void)setHandled:(BOOL)_handled;
2425

2526
@end
2627

0 commit comments

Comments
 (0)