Skip to content

Convert folly::dynamic event dispatch to r-value #50133

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -212,12 +212,11 @@ - (void)finalizeUpdates:(RNComponentViewUpdateMask)updateMask
if (!_adapter) {
_adapter = [[RCTLegacyViewManagerInteropCoordinatorAdapter alloc] initWithCoordinator:[self _coordinator]
reactTag:self.tag];
_adapter.eventInterceptor = ^(std::string eventName, folly::dynamic event) {
_adapter.eventInterceptor = ^(std::string eventName, folly::dynamic &&event) {
if (weakSelf) {
__typeof(self) strongSelf = weakSelf;
const auto &eventEmitter =
static_cast<const LegacyViewManagerInteropViewEventEmitter &>(*strongSelf->_eventEmitter);
eventEmitter.dispatchEvent(eventName, event);
const auto &eventEmitter = static_cast<const ViewEventEmitter &>(*strongSelf->_eventEmitter);
eventEmitter.dispatchEvent(eventName, std::move(event));
}
};
// Set props immediately. This is required to set the initial state of the view.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ NS_ASSUME_NONNULL_BEGIN

@property (strong, nonatomic) UIView *paperView;

@property (nonatomic, copy, nullable) void (^eventInterceptor)(std::string eventName, folly::dynamic event);
@property (nonatomic, copy, nullable) void (^eventInterceptor)(std::string eventName, folly::dynamic &&event);

- (void)setProps:(const folly::dynamic &)props;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ - (UIView *)paperView
_paperView = [_coordinator createPaperViewWithTag:_tag];
__weak __typeof(self) weakSelf = self;
[_coordinator addObserveForTag:_tag
usingBlock:^(std::string eventName, folly::dynamic event) {
usingBlock:^(std::string eventName, folly::dynamic &&event) {
if (weakSelf.eventInterceptor) {
weakSelf.eventInterceptor(eventName, event);
weakSelf.eventInterceptor(eventName, std::move(event));
}
}];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#pragma once

#include <react/renderer/components/legacyviewmanagerinterop/LegacyViewManagerInteropState.h>
#include <react/renderer/components/legacyviewmanagerinterop/LegacyViewManagerInteropViewEventEmitter.h>
#include <react/renderer/components/legacyviewmanagerinterop/LegacyViewManagerInteropViewProps.h>
#include <react/renderer/components/view/ConcreteViewShadowNode.h>

Expand All @@ -19,7 +18,7 @@ extern const char LegacyViewManagerInteropComponentName[];
using LegacyViewManagerInteropShadowNode = ConcreteViewShadowNode<
LegacyViewManagerInteropComponentName,
LegacyViewManagerInteropViewProps,
LegacyViewManagerInteropViewEventEmitter,
ViewEventEmitter,
LegacyViewManagerInteropState>;

} // namespace facebook::react

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ NS_ASSUME_NONNULL_BEGIN
@class RCTBridge;
@class RCTBridgeProxy;

typedef void (^InterceptorBlock)(std::string eventName, folly::dynamic event);
typedef void (^InterceptorBlock)(std::string eventName, folly::dynamic &&event);

@interface RCTLegacyViewManagerInteropCoordinator : NSObject

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

#pragma once

#include <react/renderer/components/legacyviewmanagerinterop/LegacyViewManagerInteropViewEventEmitter.h>
#include <react/renderer/components/legacyviewmanagerinterop/LegacyViewManagerInteropViewProps.h>
#include <react/renderer/components/view/ConcreteViewShadowNode.h>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,20 @@ EventEmitter::EventEmitter(

void EventEmitter::dispatchEvent(
std::string type,
const folly::dynamic& payload,
folly::dynamic&& payload,
RawEvent::Category category) const {
dispatchEvent(
std::move(type),
std::make_shared<DynamicEventPayload>(folly::dynamic(payload)),
std::make_shared<DynamicEventPayload>(std::move(payload)),
category);
}

void EventEmitter::dispatchUniqueEvent(
std::string type,
const folly::dynamic& payload) const {
folly::dynamic&& payload) const {
dispatchUniqueEvent(
std::move(type),
std::make_shared<DynamicEventPayload>(folly::dynamic(payload)));
std::make_shared<DynamicEventPayload>(std::move(payload)));
}

void EventEmitter::dispatchEvent(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,15 @@ class EventEmitter {

void dispatchEvent(
std::string type,
const folly::dynamic& payload,
folly::dynamic&& payload,
RawEvent::Category category = RawEvent::Category::Unspecified) const;

void dispatchEvent(
std::string type,
SharedEventPayload payload,
RawEvent::Category category = RawEvent::Category::Unspecified) const;

void dispatchUniqueEvent(std::string type, const folly::dynamic& payload)
const;
void dispatchUniqueEvent(std::string type, folly::dynamic&& payload) const;

void dispatchUniqueEvent(
std::string type,
Expand Down
Loading