mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Introducing RCTWeakViewHolder [4/n]
Summary: Problem: In paper, there is a handy API called `[uiManager viewForReactTag:]`. Fabric does not have this mapping. The Fabric interop layer still relies on this Paper mapping. Solution: As a workaround, re-create this mapping in the Fabric interop layer. Therefore, whenever Fabric interop layer asks a paper view manager to create a view, store a weak reference to the view in a `NSMapTable`. NSMapTable allows us to customize the strong/weak relationship. I've added a comment explaining that `RCTWeakViewHolder` only needs to be used for this special circumstance. Changelog: [Internal] Reviewed By: sammy-SC Differential Revision: D27438899 fbshipit-source-id: 94663ef06479a8c863ce58b0f36d42109fa1c4f3
This commit is contained in:
committed by
Facebook GitHub Bot
parent
10acccc86d
commit
4efdf264d1
+1
-1
@@ -20,7 +20,7 @@ typedef void (^InterceptorBlock)(std::string eventName, folly::dynamic event);
|
||||
|
||||
- (instancetype)initWithComponentData:(RCTComponentData *)componentData bridge:(RCTBridge *)bridge;
|
||||
|
||||
- (UIView *)paperView;
|
||||
- (UIView *)createPaperViewWithTag:(NSInteger)tag;
|
||||
|
||||
- (void)addObserveForTag:(NSInteger)tag usingBlock:(InterceptorBlock)block;
|
||||
|
||||
|
||||
+11
-3
@@ -16,6 +16,7 @@
|
||||
#include <React/RCTUIManager.h>
|
||||
#include <React/RCTUIManagerUtils.h>
|
||||
#include <React/RCTUtils.h>
|
||||
#include <React/RCTWeakViewHolder.h>
|
||||
#include <folly/json.h>
|
||||
#include <objc/runtime.h>
|
||||
|
||||
@@ -70,10 +71,17 @@ using namespace facebook::react;
|
||||
[_eventInterceptors removeObjectForKey:[NSNumber numberWithInteger:tag]];
|
||||
}
|
||||
|
||||
- (UIView *)paperView
|
||||
- (UIView *)createPaperViewWithTag:(NSInteger)tag;
|
||||
{
|
||||
// TODO: pass in the right tags?
|
||||
return [_componentData createViewWithTag:NULL rootTag:NULL];
|
||||
UIView *view = [_componentData createViewWithTag:[NSNumber numberWithInteger:tag] rootTag:NULL];
|
||||
if ([_componentData.bridgelessViewManager conformsToProtocol:@protocol(RCTWeakViewHolder)]) {
|
||||
id<RCTWeakViewHolder> weakViewHolder = (id<RCTWeakViewHolder>)_componentData.bridgelessViewManager;
|
||||
if (!weakViewHolder.weakViews) {
|
||||
weakViewHolder.weakViews = [NSMapTable strongToWeakObjectsMapTable];
|
||||
}
|
||||
[weakViewHolder.weakViews setObject:view forKey:[NSNumber numberWithInteger:tag]];
|
||||
}
|
||||
return view;
|
||||
}
|
||||
|
||||
- (void)setProps:(folly::dynamic const &)props forView:(UIView *)view
|
||||
|
||||
Reference in New Issue
Block a user