Skip to content

Commit

Permalink
Expose scheduler through RCTSurfacePresenter
Browse files Browse the repository at this point in the history
Summary:
Exposes event listener through iOS scheduler wrapper (`RCTScheduler`) and exposes scheduler itself through `RCTSurfacePresenter`.

Changelog: [Changed] Exposed `RCTScheduler` to allow setting event listeners.

Reviewed By: philIip

Differential Revision: D35313398

fbshipit-source-id: 794179d47f407fee5692a98b13ac08f92e85a61c
  • Loading branch information
cortinico authored and facebook-github-bot committed Apr 26, 2022
1 parent 1730949 commit 614aa86
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
5 changes: 5 additions & 0 deletions React/Fabric/RCTScheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#import <react/renderer/componentregistry/ComponentDescriptorFactory.h>
#import <react/renderer/core/ComponentDescriptor.h>
#import <react/renderer/core/EventListener.h>
#import <react/renderer/core/LayoutConstraints.h>
#import <react/renderer/core/LayoutContext.h>
#import <react/renderer/mounting/MountingCoordinator.h>
Expand Down Expand Up @@ -64,6 +65,10 @@ NS_ASSUME_NONNULL_BEGIN

- (void)animationTick;

- (void)addEventListener:(std::shared_ptr<facebook::react::EventListener> const &)listener;

- (void)removeEventListener:(std::shared_ptr<facebook::react::EventListener> const &)listener;

@end

NS_ASSUME_NONNULL_END
10 changes: 10 additions & 0 deletions React/Fabric/RCTScheduler.mm
Original file line number Diff line number Diff line change
Expand Up @@ -193,4 +193,14 @@ - (void)onAllAnimationsComplete
}
}

- (void)addEventListener:(std::shared_ptr<EventListener> const &)listener
{
return _scheduler->addEventListener(listener);
}

- (void)removeEventListener:(std::shared_ptr<EventListener> const &)listener
{
return _scheduler->removeEventListener(listener);
}

@end
2 changes: 2 additions & 0 deletions React/Fabric/RCTSurfacePresenter.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ NS_ASSUME_NONNULL_BEGIN
@class RCTFabricSurface;
@class RCTImageLoader;
@class RCTMountingManager;
@class RCTScheduler;

/**
* Coordinates presenting of React Native Surfaces and represents application
Expand Down Expand Up @@ -53,6 +54,7 @@ NS_ASSUME_NONNULL_BEGIN
- (void)unregisterSurface:(RCTFabricSurface *)surface;

@property (readonly) RCTMountingManager *mountingManager;
@property (readonly, nullable) RCTScheduler *scheduler;

/*
* Allow callers to initialize a new fabric surface without adding Fabric as a Buck dependency.
Expand Down
10 changes: 5 additions & 5 deletions React/Fabric/RCTSurfacePresenter.mm
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ - (RCTMountingManager *)mountingManager
return _mountingManager;
}

- (RCTScheduler *_Nullable)_scheduler
- (RCTScheduler *_Nullable)scheduler
{
std::lock_guard<std::mutex> lock(_schedulerAccessMutex);
return _scheduler;
Expand Down Expand Up @@ -151,15 +151,15 @@ - (void)setRuntimeExecutor:(RuntimeExecutor)runtimeExecutor
- (void)registerSurface:(RCTFabricSurface *)surface
{
[_surfaceRegistry registerSurface:surface];
RCTScheduler *scheduler = [self _scheduler];
RCTScheduler *scheduler = [self scheduler];
if (scheduler) {
[scheduler registerSurface:surface.surfaceHandler];
}
}

- (void)unregisterSurface:(RCTFabricSurface *)surface
{
RCTScheduler *scheduler = [self _scheduler];
RCTScheduler *scheduler = [self scheduler];
if (scheduler) {
[scheduler unregisterSurface:surface.surfaceHandler];
}
Expand Down Expand Up @@ -188,7 +188,7 @@ - (UIView *)findComponentViewWithTag_DO_NOT_USE_DEPRECATED:(NSInteger)tag

- (BOOL)synchronouslyUpdateViewOnUIThread:(NSNumber *)reactTag props:(NSDictionary *)props
{
RCTScheduler *scheduler = [self _scheduler];
RCTScheduler *scheduler = [self scheduler];
if (!scheduler) {
return NO;
}
Expand All @@ -212,7 +212,7 @@ - (BOOL)synchronouslyUpdateViewOnUIThread:(NSNumber *)reactTag props:(NSDictiona

- (void)setupAnimationDriverWithSurfaceHandler:(facebook::react::SurfaceHandler const &)surfaceHandler
{
[[self _scheduler] setupAnimationDriver:surfaceHandler];
[[self scheduler] setupAnimationDriver:surfaceHandler];
}

- (BOOL)suspend
Expand Down

0 comments on commit 614aa86

Please sign in to comment.