@wanderlogapp/react-native 0.86.3-wanderlog.3 → 0.86.3-wanderlog.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/React/Fabric/Mounting/ComponentViews/LegacyViewManagerInterop/RCTLegacyViewManagerInteropComponentView.mm +35 -1
- package/React/Fabric/Mounting/ComponentViews/LegacyViewManagerInterop/RCTLegacyViewManagerInteropCoordinatorAdapter.h +14 -1
- package/React/Fabric/Mounting/ComponentViews/LegacyViewManagerInterop/RCTLegacyViewManagerInteropCoordinatorAdapter.mm +32 -89
- package/React/Fabric/Mounting/RCTComponentViewDescriptor.h +8 -0
- package/React/Fabric/Mounting/RCTComponentViewFactory.mm +1 -0
- package/React/Fabric/Mounting/RCTComponentViewRegistry.h +8 -0
- package/React/Fabric/Mounting/RCTComponentViewRegistry.mm +10 -0
- package/React/Fabric/RCTSurfacePresenter.mm +6 -5
- package/React/Tests/Mounting/RCTComponentViewRegistryTests.mm +14 -0
- package/package.json +1 -1
|
@@ -21,12 +21,36 @@ using namespace facebook::react;
|
|
|
21
21
|
static NSString *const kRCTLegacyInteropChildComponentKey = @"childComponentView";
|
|
22
22
|
static NSString *const kRCTLegacyInteropChildIndexKey = @"index";
|
|
23
23
|
|
|
24
|
+
/**
|
|
25
|
+
* How native-driver Animated frames reach a legacy (Paper) view
|
|
26
|
+
*
|
|
27
|
+
* Every legacy view manager (e.g. react-native-maps' AIRGoogleMapPolyline) renders through this one view class, but
|
|
28
|
+
* each manager registers its own component descriptor under its own handle. Animated frames used to look up the
|
|
29
|
+
* descriptor by this class's shared handle, find nothing, and get dropped without a warning.
|
|
30
|
+
*
|
|
31
|
+
* Now, for each frame:
|
|
32
|
+
*
|
|
33
|
+
* 1. Animated works out the frame's props, like a polyline's new stroke color, and hands them to RCTSurfacePresenter.
|
|
34
|
+
* 2. RCTSurfacePresenter finds this manager's descriptor using the handle the view registry created this view for.
|
|
35
|
+
* 3. RCTMountingManager merges the frame's props into this view's props. It calls updateProps:oldProps: with
|
|
36
|
+
* Animated's keys cleared, so we don't skip any of them.
|
|
37
|
+
* 4. In finalizeUpdates:, the adapter sends the paper view only the props that changed, and the paper view's setter
|
|
38
|
+
* runs (e.g. -[AIRGoogleMapPolyline setStrokeColor:]).
|
|
39
|
+
*
|
|
40
|
+
* When JS re-renders the view later, Animated's keys are still set during updateProps:oldProps:. So we skip them,
|
|
41
|
+
* and the paper view keeps its animated value instead of the stale JS one.
|
|
42
|
+
*/
|
|
24
43
|
@implementation RCTLegacyViewManagerInteropComponentView {
|
|
25
44
|
NSMutableArray<NSDictionary *> *_viewsToBeMounted;
|
|
26
45
|
NSMutableArray<UIView *> *_viewsToBeUnmounted;
|
|
27
46
|
RCTLegacyViewManagerInteropCoordinatorAdapter *_adapter;
|
|
28
47
|
LegacyViewManagerInteropShadowNode::ConcreteState::Shared _state;
|
|
29
48
|
BOOL _hasInvokedForwardingWarning;
|
|
49
|
+
/**
|
|
50
|
+
* Keys that native-driver Animated owns, for the props update in progress. We skip them on a JS commit so the paper
|
|
51
|
+
* view keeps its animated value instead of the stale JS one.
|
|
52
|
+
*/
|
|
53
|
+
NSSet<NSString *> *_Nullable _propKeysToSkip;
|
|
30
54
|
}
|
|
31
55
|
|
|
32
56
|
- (instancetype)initWithFrame:(CGRect)frame
|
|
@@ -165,6 +189,7 @@ static NSString *const kRCTLegacyInteropChildIndexKey = @"index";
|
|
|
165
189
|
_state.reset();
|
|
166
190
|
self.contentView = nil;
|
|
167
191
|
_hasInvokedForwardingWarning = NO;
|
|
192
|
+
_propKeysToSkip = nil;
|
|
168
193
|
[super prepareForRecycle];
|
|
169
194
|
}
|
|
170
195
|
|
|
@@ -204,6 +229,15 @@ static NSString *const kRCTLegacyInteropChildIndexKey = @"index";
|
|
|
204
229
|
return concreteComponentDescriptorProvider<LegacyViewManagerInteropComponentDescriptor>();
|
|
205
230
|
}
|
|
206
231
|
|
|
232
|
+
- (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &)oldProps
|
|
233
|
+
{
|
|
234
|
+
// This is named "broken" because once Animated touches a key, JS can't set that key again until the view is
|
|
235
|
+
// recycled. That's what we want here: Animated owns those keys, like opacity and transform in RCTViewComponentView.
|
|
236
|
+
// It's nil only while RCTMountingManager applies an Animated frame, so it tells a frame apart from a JS commit.
|
|
237
|
+
_propKeysToSkip = self.propKeysManagedByAnimated_DO_NOT_USE_THIS_IS_BROKEN;
|
|
238
|
+
[super updateProps:props oldProps:oldProps];
|
|
239
|
+
}
|
|
240
|
+
|
|
207
241
|
- (void)updateState:(const State::Shared &)state oldState:(const State::Shared &)oldState
|
|
208
242
|
{
|
|
209
243
|
_state = std::static_pointer_cast<const LegacyViewManagerInteropShadowNode::ConcreteState>(state);
|
|
@@ -271,7 +305,7 @@ static NSString *const kRCTLegacyInteropChildIndexKey = @"index";
|
|
|
271
305
|
{
|
|
272
306
|
if (updateMask & RNComponentViewUpdateMaskProps) {
|
|
273
307
|
const auto &newProps = static_cast<const LegacyViewManagerInteropViewProps &>(*_props);
|
|
274
|
-
[_adapter setProps:newProps.otherProps];
|
|
308
|
+
[_adapter setProps:newProps.otherProps propKeysToSkip:_propKeysToSkip];
|
|
275
309
|
}
|
|
276
310
|
}
|
|
277
311
|
|
|
@@ -18,10 +18,23 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
18
18
|
|
|
19
19
|
@property (nonatomic, copy, nullable) void (^eventInterceptor)(std::string eventName, folly::dynamic &&event);
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
/**
|
|
22
|
+
* Sends the paper view only the props that changed since the last call, leaving out `propKeysToSkip`, which
|
|
23
|
+
* native-driver Animated owns.
|
|
24
|
+
*/
|
|
25
|
+
- (void)setProps:(const folly::dynamic &)props propKeysToSkip:(nullable NSSet<NSString *> *)propKeysToSkip;
|
|
22
26
|
|
|
23
27
|
- (void)handleCommand:(NSString *)commandName args:(NSArray *)args;
|
|
24
28
|
|
|
25
29
|
@end
|
|
26
30
|
|
|
31
|
+
/**
|
|
32
|
+
* Returns the props that differ from `sentProps`, and records them in `sentProps`. Leaves out `propKeysToSkip`, which
|
|
33
|
+
* native-driver Animated owns.
|
|
34
|
+
*/
|
|
35
|
+
folly::dynamic RCTLegacyViewManagerInteropDiffProps(
|
|
36
|
+
const folly::dynamic &props,
|
|
37
|
+
folly::dynamic &sentProps,
|
|
38
|
+
NSSet<NSString *> *_Nullable propKeysToSkip);
|
|
39
|
+
|
|
27
40
|
NS_ASSUME_NONNULL_END
|
|
@@ -6,13 +6,18 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
#import "RCTLegacyViewManagerInteropCoordinatorAdapter.h"
|
|
9
|
+
#import <React/RCTConversions.h>
|
|
9
10
|
#import <React/UIView+React.h>
|
|
10
11
|
#import <react/utils/FollyConvert.h>
|
|
11
12
|
|
|
12
13
|
@implementation RCTLegacyViewManagerInteropCoordinatorAdapter {
|
|
13
14
|
RCTLegacyViewManagerInteropCoordinator *_coordinator;
|
|
14
15
|
NSInteger _tag;
|
|
15
|
-
|
|
16
|
+
/**
|
|
17
|
+
* The props we last sent to the paper view. We diff against these so a frame of a native-driver animation only
|
|
18
|
+
* converts and sends the keys it changed, not every prop (e.g. a polyline's whole coordinates array).
|
|
19
|
+
*/
|
|
20
|
+
folly::dynamic _sentProps;
|
|
16
21
|
}
|
|
17
22
|
|
|
18
23
|
- (instancetype)initWithCoordinator:(RCTLegacyViewManagerInteropCoordinator *)coordinator reactTag:(NSInteger)tag
|
|
@@ -20,6 +25,7 @@
|
|
|
20
25
|
if (self = [super init]) {
|
|
21
26
|
_coordinator = coordinator;
|
|
22
27
|
_tag = tag;
|
|
28
|
+
_sentProps = folly::dynamic::object();
|
|
23
29
|
}
|
|
24
30
|
return self;
|
|
25
31
|
}
|
|
@@ -45,16 +51,16 @@
|
|
|
45
51
|
return _paperView;
|
|
46
52
|
}
|
|
47
53
|
|
|
48
|
-
- (void)setProps:(const folly::dynamic &)props
|
|
54
|
+
- (void)setProps:(const folly::dynamic &)props propKeysToSkip:(nullable NSSet<NSString *> *)propKeysToSkip
|
|
49
55
|
{
|
|
50
|
-
if (props.isObject()) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
_oldProps = convertedProps;
|
|
56
|
+
if (!props.isObject()) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
folly::dynamic changedProps = RCTLegacyViewManagerInteropDiffProps(props, _sentProps, propKeysToSkip);
|
|
60
|
+
if (changedProps.empty()) {
|
|
61
|
+
return;
|
|
57
62
|
}
|
|
63
|
+
[_coordinator setProps:facebook::react::convertFollyDynamicToId(changedProps) forView:self.paperView];
|
|
58
64
|
}
|
|
59
65
|
|
|
60
66
|
- (void)handleCommand:(NSString *)commandName args:(NSArray *)args
|
|
@@ -62,87 +68,24 @@
|
|
|
62
68
|
[_coordinator handleCommand:commandName args:args reactTag:_tag paperView:self.paperView];
|
|
63
69
|
}
|
|
64
70
|
|
|
65
|
-
|
|
66
|
-
{
|
|
67
|
-
NSMutableDictionary<NSString *, id> *diffedProps = [NSMutableDictionary new];
|
|
68
|
-
|
|
69
|
-
[newProps enumerateKeysAndObjectsUsingBlock:^(NSString *key, id newProp, __unused BOOL *stop) {
|
|
70
|
-
id oldProp = _oldProps[key];
|
|
71
|
-
if ([self _prop:newProp isDifferentFrom:oldProp]) {
|
|
72
|
-
diffedProps[key] = newProp;
|
|
73
|
-
}
|
|
74
|
-
}];
|
|
75
|
-
|
|
76
|
-
return diffedProps;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
#pragma mark - Private
|
|
71
|
+
@end
|
|
80
72
|
|
|
81
|
-
|
|
73
|
+
folly::dynamic RCTLegacyViewManagerInteropDiffProps(
|
|
74
|
+
const folly::dynamic &props,
|
|
75
|
+
folly::dynamic &sentProps,
|
|
76
|
+
NSSet<NSString *> *_Nullable propKeysToSkip)
|
|
82
77
|
{
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
if (bothNil) {
|
|
95
|
-
return NO;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
BOOL onlyOneNil = (oldProp && !newProp) || (!oldProp && newProp);
|
|
99
|
-
if (onlyOneNil) {
|
|
100
|
-
return YES;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
if ([self _propIsSameNumber:oldProp second:newProp]) {
|
|
104
|
-
// Boolean should be captured by NSNumber
|
|
105
|
-
return NO;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
if ([self _propIsSameString:oldProp second:newProp]) {
|
|
109
|
-
return NO;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
if ([self _propIsSameArray:oldProp second:newProp]) {
|
|
113
|
-
return NO;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
if ([self _propIsSameObject:oldProp second:newProp]) {
|
|
117
|
-
return NO;
|
|
78
|
+
folly::dynamic changedProps = folly::dynamic::object();
|
|
79
|
+
for (const auto &[key, value] : props.items()) {
|
|
80
|
+
if (propKeysToSkip != nil && [propKeysToSkip containsObject:RCTNSStringFromString(key.asString())]) {
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
auto sentProp = sentProps.find(key);
|
|
84
|
+
if (sentProp != sentProps.items().end() && sentProp->second == value) {
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
changedProps[key] = value;
|
|
88
|
+
sentProps[key] = value;
|
|
118
89
|
}
|
|
119
|
-
|
|
120
|
-
// Previous behavior, fallback to YES
|
|
121
|
-
return YES;
|
|
90
|
+
return changedProps;
|
|
122
91
|
}
|
|
123
|
-
|
|
124
|
-
- (BOOL)_propIsSameNumber:(id)first second:(id)second
|
|
125
|
-
{
|
|
126
|
-
return [first isKindOfClass:[NSNumber class]] && [second isKindOfClass:[NSNumber class]] &&
|
|
127
|
-
[(NSNumber *)first isEqualToNumber:(NSNumber *)second];
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
- (BOOL)_propIsSameString:(id)first second:(id)second
|
|
131
|
-
{
|
|
132
|
-
return [first isKindOfClass:[NSString class]] && [second isKindOfClass:[NSString class]] &&
|
|
133
|
-
[(NSString *)first isEqualToString:(NSString *)second];
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
- (BOOL)_propIsSameArray:(id)first second:(id)second
|
|
137
|
-
{
|
|
138
|
-
return [first isKindOfClass:[NSArray class]] && [second isKindOfClass:[NSArray class]] &&
|
|
139
|
-
[(NSArray *)first isEqualToArray:(NSArray *)second];
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
- (BOOL)_propIsSameObject:(id)first second:(id)second
|
|
143
|
-
{
|
|
144
|
-
return [first isKindOfClass:[NSDictionary class]] && [second isKindOfClass:[NSDictionary class]] &&
|
|
145
|
-
[(NSDictionary *)first isEqualToDictionary:(NSDictionary *)second];
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
@end
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
#import <UIKit/UIKit.h>
|
|
9
9
|
|
|
10
10
|
#import <React/RCTComponentViewProtocol.h>
|
|
11
|
+
#import <react/renderer/core/ReactPrimitives.h>
|
|
11
12
|
|
|
12
13
|
NS_ASSUME_NONNULL_BEGIN
|
|
13
14
|
|
|
@@ -23,6 +24,13 @@ class RCTComponentViewDescriptor final {
|
|
|
23
24
|
*/
|
|
24
25
|
__strong UIView<RCTComponentViewProtocol> *const view = nil;
|
|
25
26
|
|
|
27
|
+
/*
|
|
28
|
+
* The handle of the component descriptor this view was created for. Use this instead of the view class's
|
|
29
|
+
* `componentDescriptorProvider` handle: one class can serve several handles. For example, every legacy (Paper) view
|
|
30
|
+
* manager renders through RCTLegacyViewManagerInteropComponentView, but each one has its own handle.
|
|
31
|
+
*/
|
|
32
|
+
const facebook::react::ComponentHandle componentHandle{};
|
|
33
|
+
|
|
26
34
|
/*
|
|
27
35
|
* Indicates a requirement to call on the view methods from
|
|
28
36
|
* `RCTMountingTransactionObserving` protocol.
|
|
@@ -214,6 +214,7 @@ static Class<RCTComponentViewProtocol> RCTComponentViewClassWithName(const char
|
|
|
214
214
|
|
|
215
215
|
return RCTComponentViewDescriptor{
|
|
216
216
|
.view = [viewClass new],
|
|
217
|
+
.componentHandle = componentHandle,
|
|
217
218
|
.observesMountingTransactionWillMount = componentViewClassDescriptor.observesMountingTransactionWillMount,
|
|
218
219
|
.observesMountingTransactionDidMount = componentViewClassDescriptor.observesMountingTransactionDidMount,
|
|
219
220
|
.shouldBeRecycled = componentViewClassDescriptor.shouldBeRecycled,
|
|
@@ -7,6 +7,8 @@
|
|
|
7
7
|
|
|
8
8
|
#import <UIKit/UIKit.h>
|
|
9
9
|
|
|
10
|
+
#import <optional>
|
|
11
|
+
|
|
10
12
|
#import <React/RCTComponentViewDescriptor.h>
|
|
11
13
|
#import <React/RCTComponentViewFactory.h>
|
|
12
14
|
#import <React/RCTComponentViewProtocol.h>
|
|
@@ -50,6 +52,12 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
50
52
|
*/
|
|
51
53
|
- (nullable UIView<RCTComponentViewProtocol> *)findComponentViewWithTag:(facebook::react::Tag)tag;
|
|
52
54
|
|
|
55
|
+
/**
|
|
56
|
+
* Finds the handle of the component descriptor that the view with given `tag` was created for.
|
|
57
|
+
* Returns `std::nullopt` if there is no registered component with the `tag`.
|
|
58
|
+
*/
|
|
59
|
+
- (std::optional<facebook::react::ComponentHandle>)findComponentHandleWithTag:(facebook::react::Tag)tag;
|
|
60
|
+
|
|
53
61
|
@end
|
|
54
62
|
|
|
55
63
|
NS_ASSUME_NONNULL_END
|
|
@@ -87,6 +87,16 @@ const NSInteger RCTComponentViewRegistryRecyclePoolMaxSize = 1024;
|
|
|
87
87
|
return iterator->second.view;
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
+
- (std::optional<ComponentHandle>)findComponentHandleWithTag:(Tag)tag
|
|
91
|
+
{
|
|
92
|
+
RCTAssertMainQueue();
|
|
93
|
+
auto iterator = _registry.find(tag);
|
|
94
|
+
if (iterator == _registry.end()) {
|
|
95
|
+
return std::nullopt;
|
|
96
|
+
}
|
|
97
|
+
return iterator->second.componentHandle;
|
|
98
|
+
}
|
|
99
|
+
|
|
90
100
|
- (RCTComponentViewDescriptor)_dequeueComponentViewWithComponentHandle:(ComponentHandle)componentHandle
|
|
91
101
|
{
|
|
92
102
|
RCTAssertMainQueue();
|
|
@@ -161,13 +161,14 @@ using namespace facebook::react;
|
|
|
161
161
|
return;
|
|
162
162
|
}
|
|
163
163
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
if (componentView == nil) {
|
|
164
|
+
std::optional<ComponentHandle> handle = [_mountingManager.componentViewRegistry findComponentHandleWithTag:tag];
|
|
165
|
+
if (!handle) {
|
|
167
166
|
return; // This view probably isn't managed by Fabric
|
|
168
167
|
}
|
|
169
|
-
|
|
170
|
-
|
|
168
|
+
// Use the handle the view was created for, not its class's handle. They differ for legacy interop views, like
|
|
169
|
+
// react-native-maps' iOS Google polylines: they share one class, but each legacy view manager has its own handle.
|
|
170
|
+
// The class's handle would find no descriptor, and we'd drop their native-driver Animated updates.
|
|
171
|
+
auto *componentDescriptor = [scheduler findComponentDescriptorByHandle_DO_NOT_USE_THIS_IS_BROKEN:*handle];
|
|
171
172
|
|
|
172
173
|
if (!componentDescriptor) {
|
|
173
174
|
return;
|
|
@@ -58,6 +58,20 @@ using namespace facebook::react;
|
|
|
58
58
|
XCTAssertEqual(newViewDescriptor.view, [_componentViewRegistry findComponentViewWithTag:existingTag]);
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
+
- (void)testFindComponentHandleWithTag
|
|
62
|
+
{
|
|
63
|
+
Tag nonExistingTag = 12;
|
|
64
|
+
XCTAssertFalse([_componentViewRegistry findComponentHandleWithTag:nonExistingTag].has_value());
|
|
65
|
+
|
|
66
|
+
Tag existingTag = 2;
|
|
67
|
+
auto handle = [RCTViewComponentView componentDescriptorProvider].handle;
|
|
68
|
+
[_componentViewRegistry dequeueComponentViewWithComponentHandle:handle tag:existingTag];
|
|
69
|
+
|
|
70
|
+
auto foundHandle = [_componentViewRegistry findComponentHandleWithTag:existingTag];
|
|
71
|
+
XCTAssertTrue(foundHandle.has_value());
|
|
72
|
+
XCTAssertEqual(foundHandle.value_or(0), handle);
|
|
73
|
+
}
|
|
74
|
+
|
|
61
75
|
- (void)testDequeueAndEnqueue
|
|
62
76
|
{
|
|
63
77
|
Tag existingTag = 2;
|