2019-10-16 20:03:47 +03:00
|
|
|
/*
|
2021-12-31 02:08:43 +03:00
|
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
2019-08-14 23:35:12 +03:00
|
|
|
*
|
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#import <UIKit/UIKit.h>
|
|
|
|
|
|
|
|
#import <React/RCTBridge.h>
|
2019-12-09 21:56:57 +03:00
|
|
|
#import <React/RCTDefines.h>
|
2019-08-14 23:35:12 +03:00
|
|
|
#import <React/RCTResizeMode.h>
|
|
|
|
#import <React/RCTURLRequestHandler.h>
|
|
|
|
#import <React/RCTImageDataDecoder.h>
|
|
|
|
#import <React/RCTImageURLLoader.h>
|
|
|
|
#import <React/RCTImageCache.h>
|
|
|
|
#import <React/RCTImageLoaderProtocol.h>
|
2020-10-30 07:57:46 +03:00
|
|
|
#import <React/RCTImageLoaderLoggable.h>
|
2019-08-14 23:35:12 +03:00
|
|
|
|
2020-10-30 07:57:46 +03:00
|
|
|
@interface RCTImageLoader : NSObject <RCTBridgeModule, RCTImageLoaderProtocol, RCTImageLoaderLoggableProtocol>
|
2019-08-14 23:35:12 +03:00
|
|
|
- (instancetype)init;
|
|
|
|
- (instancetype)initWithRedirectDelegate:(id<RCTImageRedirectProtocol>)redirectDelegate NS_DESIGNATED_INITIALIZER;
|
|
|
|
- (instancetype)initWithRedirectDelegate:(id<RCTImageRedirectProtocol>)redirectDelegate
|
RCTImageLoader: Use RCTModuleRegistry to load loaders/decoders
Summary:
## Context
A React Native application can configure its RCTImageLoader by initializing it with two different sets of objects:
- id<RCTImageURLLoader>
- id<RCTImageDataDecoder>
Therefore, RCTImageLoader supports this initializer:
```
- (instancetype)initWithRedirectDelegate:(id<RCTImageRedirectProtocol>)redirectDelegate
loadersProvider:(NSArray<id<RCTImageURLLoader>> * (^)(void))getLoaders
decodersProvider:(NSArray<id<RCTImageDataDecoder>> * (^)(void))getHandlers
```
Right now, both the id<RCTImageURLLoader>s and id<RCTImageDataDecoder>s are NativeModules. So, they need to be loaded using the Bridge/TurboModuleManager.
## Problem
The method [that constructs RCTImageLoader](https://www.internalfb.com/code/fbsource/[6530647879a5e6d5edcfad029b39879c87e97bb3]/fbobjc/Apps/Wilde/FBReactModule2/FBReactModuleAPI/FBReactModuleAPI/FBReactModule.mm?lines=1462-1469) is shared between bridge mode and bridgeless mode. So, the shared constructor needs to know what infra to use to load the loaders/decoders: the TurboModuleManager, when called from a bridgeless context; the bridge, when called from a bridge context. There's no easy way to let this shared constructor know what context it's being called from. We could fork the constructor, but that's not very clean.
## Changes
In this refactor, RCTImageLoader gives its loadersProvider and decodersProvider its RCTModuleRegistry. If the module was instantiated in bridgeless mode, RCTModuleRegistry will use the TurboModuleManager. If the module was instantiated in bridge mode, RCTModuleRegistry will use the bridge. Using RCTModuleRegistry allows these two blocks to load the RCTImageURLLoaders and RCTImageDataDecoder from correct infra, in both contexts.
Changelog: [iOS][Changed] - Give RCTImageURLLoader's loader/decoder provider blocks RCTModuleRegistry
Reviewed By: PeteTheHeat
Differential Revision: D28012999
fbshipit-source-id: 09c787923b57bbf72aff95b504f88ee1f2f44283
2021-04-28 01:00:51 +03:00
|
|
|
loadersProvider:(NSArray<id<RCTImageURLLoader>> * (^)(RCTModuleRegistry *))getLoaders
|
|
|
|
decodersProvider:(NSArray<id<RCTImageDataDecoder>> * (^)(RCTModuleRegistry *))getDecoders;
|
2019-08-14 23:35:12 +03:00
|
|
|
@end
|
|
|
|
|
|
|
|
/**
|
|
|
|
* DEPRECATED!! DO NOT USE
|
|
|
|
* Instead use `[_bridge moduleForClass:[RCTImageLoader class]]`
|
|
|
|
*/
|
|
|
|
@interface RCTBridge (RCTImageLoader)
|
|
|
|
|
|
|
|
@property (nonatomic, readonly) RCTImageLoader *imageLoader;
|
|
|
|
|
|
|
|
@end
|