-
-
Notifications
You must be signed in to change notification settings - Fork 941
Expand file tree
/
Copy pathRNMBXShapeSourceComponentView.mm
More file actions
121 lines (95 loc) · 3.84 KB
/
RNMBXShapeSourceComponentView.mm
File metadata and controls
121 lines (95 loc) · 3.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#import "RNMBXShapeSourceComponentView.h"
#import "RNMBXFabricHelpers.h"
#import "RNMBXFabricPropConvert.h"
#import <React/RCTConversions.h>
#import <React/RCTFabricComponentsPlugins.h>
#import <react/renderer/components/rnmapbox_maps_specs/ComponentDescriptors.h>
#import <react/renderer/components/rnmapbox_maps_specs/EventEmitters.h>
#import <react/renderer/components/rnmapbox_maps_specs/Props.h>
#import <react/renderer/components/rnmapbox_maps_specs/RCTComponentViewHelpers.h>
using namespace facebook::react;
@interface RNMBXShapeSourceComponentView () <RCTRNMBXShapeSourceViewProtocol>
@end
@implementation RNMBXShapeSourceComponentView {
RNMBXShapeSource *_view;
}
// Needed because of this: https://github.com/facebook/react-native/pull/37274
+ (void)load
{
[super load];
}
- (instancetype)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
static const auto defaultProps = std::make_shared<const RNMBXShapeSourceProps>();
_props = defaultProps;
[self prepareView];
}
return self;
}
- (void)prepareView
{
_view = [[RNMBXShapeSource alloc] init];
// capture weak self reference to prevent retain cycle
__weak __typeof__(self) weakSelf = self;
[_view setOnPress:^(NSDictionary* event) {
__typeof__(self) strongSelf = weakSelf;
if (strongSelf != nullptr && strongSelf->_eventEmitter != nullptr) {
const auto [type, json] = RNMBXStringifyEventData(event);
std::dynamic_pointer_cast<const facebook::react::RNMBXShapeSourceEventEmitter>(strongSelf->_eventEmitter)->onMapboxShapeSourcePress({type, json});
}
}];
self.contentView = _view;
}
- (void)prepareForRecycle
{
[super prepareForRecycle];
[self prepareView];
}
- (void)mountChildComponentView:(UIView<RCTComponentViewProtocol> *)childComponentView index:(NSInteger)index
{
if ([childComponentView isKindOfClass:[RCTViewComponentView class]] && ((RCTViewComponentView *)childComponentView).contentView != nil) {
[_view insertReactSubviewInternal:((RCTViewComponentView *)childComponentView).contentView at:index];
} else {
[_view insertReactSubviewInternal:childComponentView at:index];
}
}
- (void)unmountChildComponentView:(UIView<RCTComponentViewProtocol> *)childComponentView index:(NSInteger)index
{
if ([childComponentView isKindOfClass:[RCTViewComponentView class]] && ((RCTViewComponentView *)childComponentView).contentView != nil) {
[_view removeReactSubviewInternal:((RCTViewComponentView *)childComponentView).contentView];
} else {
[_view removeReactSubviewInternal:childComponentView];
}
}
#pragma mark - RCTComponentViewProtocol
+ (ComponentDescriptorProvider)componentDescriptorProvider
{
return concreteComponentDescriptorProvider<RNMBXShapeSourceComponentDescriptor>();
}
- (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &)oldProps
{
const auto &oldViewProps = static_cast<const RNMBXShapeSourceProps &>(*_props);
const auto &newViewProps = static_cast<const RNMBXShapeSourceProps &>(*props);
RNMBX_OPTIONAL_PROP_NSString(id)
RNMBX_OPTIONAL_PROP_BOOL(existing)
RNMBX_OPTIONAL_PROP_NSString(url)
RNMBX_OPTIONAL_PROP_NSString(shape)
RNMBX_OPTIONAL_PROP_NSNumber(cluster)
RNMBX_OPTIONAL_PROP_NSNumber(clusterRadius)
RNMBX_OPTIONAL_PROP_NSNumber(clusterMaxZoomLevel)
RNMBX_OPTIONAL_PROP_NSDictionary(clusterProperties)
RNMBX_OPTIONAL_PROP_NSNumber(maxZoomLevel)
RNMBX_OPTIONAL_PROP_NSNumber(minZoomLevel)
RNMBX_OPTIONAL_PROP_NSNumber(buffer)
RNMBX_OPTIONAL_PROP_NSNumber(tolerance)
RNMBX_OPTIONAL_PROP_BOOL(lineMetrics)
RNMBX_OPTIONAL_PROP_BOOL(hasPressListener)
RNMBX_OPTIONAL_PROP_NSDictionary(hitbox)
[super updateProps:props oldProps:oldProps];
}
@end
Class<RCTComponentViewProtocol> RNMBXShapeSourceCls(void)
{
return RNMBXShapeSourceComponentView.class;
}