Skip to content
Merged
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
4 changes: 2 additions & 2 deletions RNTester/RNTester/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#import <React/RCTBridge.h>
#import <React/RCTBundleURLProvider.h>
#import <React/RCTJavaScriptLoader.h>
#import <React/RCTDevBundlesDownloader.h>
#import <React/RCTLinkingManager.h>
#import <React/RCTRootView.h>

Expand Down Expand Up @@ -72,7 +72,7 @@ - (void)loadSourceForBridge:(RCTBridge *)bridge
onProgress:(RCTSourceLoadProgressBlock)onProgress
onComplete:(RCTSourceLoadBlock)loadCallback
{
[RCTJavaScriptLoader loadBundleAtURL:[self sourceURLForBridge:bridge]
[RCTDevBundlesDownloader loadBundleAtURL:[self sourceURLForBridge:bridge]
onProgress:onProgress
onComplete:loadCallback];
}
Expand Down
13 changes: 6 additions & 7 deletions React/Base/RCTBridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ RCT_EXTERN NSString *const RCTBridgeDidDownloadScriptNotification;
*/
RCT_EXTERN NSString *const RCTBridgeDidDownloadScriptNotificationSourceKey;

/**
* Key for the bundles' RCTSource object in the RCTBridgeDidDownloadScriptNotification
* userInfo dictionary.
*/
RCT_EXTERN NSString *const RCTBridgeDidDownloadScriptNotificationBundlesKey;

/**
* Key for the bridge description (NSString_ in the
* RCTBridgeDidDownloadScriptNotification userInfo dictionary.
Expand Down Expand Up @@ -139,13 +145,6 @@ RCT_EXTERN void RCTEnableTurboModule(BOOL enabled);
- (void)enqueueJSCall:(NSString *)moduleDotMethod args:(NSArray *)args;
- (void)enqueueJSCall:(NSString *)module method:(NSString *)method args:(NSArray *)args completion:(dispatch_block_t)completion;

/**
* This method registers the file path of an additional JS segment by its ID.
*
* @experimental
*/
- (void)registerSegmentWithId:(NSUInteger)segmentId path:(NSString *)path;

/**
* Retrieve a bridge module instance by name or class. Note that modules are
* lazily instantiated, so calling these methods for the first time with a given
Expand Down
6 changes: 1 addition & 5 deletions React/Base/RCTBridge.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
NSString *const RCTBridgeWillDownloadScriptNotification = @"RCTBridgeWillDownloadScriptNotification";
NSString *const RCTBridgeDidDownloadScriptNotification = @"RCTBridgeDidDownloadScriptNotification";
NSString *const RCTBridgeDidDownloadScriptNotificationSourceKey = @"source";
NSString *const RCTBridgeDidDownloadScriptNotificationBundlesKey = @"bundles";
NSString *const RCTBridgeDidDownloadScriptNotificationBridgeDescriptionKey = @"bridgeDescription";

static NSMutableArray<Class> *RCTModuleClasses;
Expand Down Expand Up @@ -398,9 +399,4 @@ - (void)enqueueCallback:(NSNumber *)cbID args:(NSArray *)args
[self.batchedBridge enqueueCallback:cbID args:args];
}

- (void)registerSegmentWithId:(NSUInteger)segmentId path:(NSString *)path
{
[self.batchedBridge registerSegmentWithId:segmentId path:path];
}

@end
8 changes: 4 additions & 4 deletions React/Base/RCTBridgeDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

#import <React/RCTJavaScriptLoader.h>
#import <React/RCTDevBundlesDownloader.h>

@class RCTBridge;
@protocol RCTBridgeModule;
Expand Down Expand Up @@ -62,15 +62,15 @@
* to handle loading the JS yourself, you can do so by implementing this method.
*/
- (void)loadSourceForBridge:(RCTBridge *)bridge
onProgress:(RCTSourceLoadProgressBlock)onProgress
onComplete:(RCTSourceLoadBlock)loadCallback;
onProgress:(RCTDevBundlesProgressBlock)onProgress
onComplete:(RCTDevBundlesLoadBlock)loadCallback;

/**
* Similar to loadSourceForBridge:onProgress:onComplete: but without progress
* reporting.
*/
- (void)loadSourceForBridge:(RCTBridge *)bridge
withBlock:(RCTSourceLoadBlock)loadCallback;
withBlock:(RCTDevBundlesLoadBlock)loadCallback;

/**
* Retrieve the list of lazy-native-modules names for the given bridge.
Expand Down
15 changes: 15 additions & 0 deletions React/Base/RCTBundleLoader.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

#import <Foundation/Foundation.h>


@protocol RCTInvalidating <NSObject>

- (void)invalidate;

@end
28 changes: 28 additions & 0 deletions React/Base/RCTDevBundleLoader.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#pragma once

#import <memory>
#import <cxxreact/Bundle.h>
#import <cxxreact/BundleLoader.h>
#import "RCTDevBundlesDownloader.h"

#import <Foundation/Foundation.h>

namespace facebook {
namespace react {

class RCTDevBundleLoader : public BundleLoader {
public:

RCTDevBundleLoader(NSDictionary<NSString *, RCTDevBundleSource *> *bundles);
~RCTDevBundleLoader() {}

std::unique_ptr<const Bundle> getBundle(std::string bundleURL) const override;
std::string getBundleURLFromName(std::string bundleName) const override;

private:
NSDictionary<NSString *, RCTDevBundleSource *> *_bundles;

};

} // namespace react
} // namespace facebook
33 changes: 33 additions & 0 deletions React/Base/RCTDevBundleLoader.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#import "RCTDevBundleLoader.h"

#import "RCTMultipartDataTask.h"
#import <cxxreact/BasicBundle.h>
#import "NSDataBigString.h"
#import "RCTBundleURLProvider.h"
#import "RCTUtils.h"


namespace facebook {
namespace react {

RCTDevBundleLoader::RCTDevBundleLoader(NSDictionary<NSString *, RCTDevBundleSource *> *bundles) {
_bundles = bundles;
}

std::unique_ptr<const Bundle> RCTDevBundleLoader::getBundle(std::string bundleURL) const {
RCTDevBundleSource *bundleSource = [_bundles objectForKey:[NSString stringWithUTF8String:bundleURL.c_str()]];
if(bundleSource) {
std::unique_ptr<const NSDataBigString> script = std::make_unique<const NSDataBigString>([bundleSource data]);
return std::make_unique<BasicBundle>(std::move(script), std::string([[[bundleSource url] absoluteString] UTF8String]));
}
return nil;
}

std::string RCTDevBundleLoader::getBundleURLFromName(std::string bundleName) const {
return std::string([[[RCTBundleURLProvider sharedSettings]
jsBundleURLForBundleRoot:[NSString stringWithUTF8String:bundleName.c_str()]
fallbackResource:nil].absoluteString UTF8String]);
}

} // namespace react
} // namespace facebook
82 changes: 82 additions & 0 deletions React/Base/RCTDevBundlesDownloader.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* 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/RCTDefines.h>

extern NSString *const RCTDevBundleDownloaderErrorDomain;

NS_ENUM(NSInteger) {
RCTDevBundleDownloaderErrorNoScriptURL = 1,
RCTDevBundleDownloaderErrorURLLoadFailed = 3,
};

NS_ENUM(NSInteger) {
RCTDevSourceFilesChangedCountNotBuiltByBundler = -2,
RCTDevSourceFilesChangedCountRebuiltFromScratch = -1,
};

@interface RCTDevBundleLoadingProgress : NSObject

@property (nonatomic, copy) NSString *status;
@property (strong, nonatomic) NSNumber *done;
@property (strong, nonatomic) NSNumber *total;

@end

@interface RCTDevBundleSource : NSObject

/**
* Name of the bundle.
*/
@property (strong, nonatomic, readonly) NSString *bundleName;

/**
* URL of the source object.
*/
@property (strong, nonatomic, readonly) NSURL *url;

/**
* JS source (or simply the binary header in the case of a RAM bundle).
*/
@property (strong, nonatomic, readonly) NSData *data;

/**
* Length of the entire JS bundle. Note that self.length != self.data.length in the case of certain bundle formats. For
* instance, when using RAM bundles:
*
* - self.data will point to the bundle header
* - self.data.length is the length of the bundle header, i.e. sizeof(facebook::react::BundleHeader)
* - self.length is the length of the entire bundle file (header + contents)
*/
@property (nonatomic, readonly) NSUInteger length;

/**
* Returns number of files changed when building this bundle:
*
* - RCTSourceFilesChangedCountNotBuiltByBundler if the source wasn't built by the bundler (e.g. read from disk)
* - RCTSourceFilesChangedCountRebuiltFromScratch if the source was rebuilt from scratch by the bundler
* - Otherwise, the number of files changed when incrementally rebuilding the source
*/
@property (nonatomic, readonly) NSInteger filesChangedCount;

@end

typedef void (^RCTDevBundlesProgressBlock)(RCTDevBundleLoadingProgress *progressData);
typedef void (^RCTDevBundlesLoadBlock)(NSError *error, NSDictionary<NSString *, RCTDevBundleSource *> *bundles);

typedef void (^RCTDevBundleLoadBlock)(NSError *error, RCTDevBundleSource *bundleSource, NSArray<NSString *> *additionalBundles);
typedef void (^RCTDevBundleProgressBlock)(RCTDevBundleLoadingProgress *progressData);

@interface RCTDevBundlesDownloader : NSObject

@property (nonatomic, readonly) NSMutableDictionary<NSString *, RCTDevBundleSource *> *bundlesContainer;

+ (void)loadBundleAtURL:(NSURL *)scriptURL onProgress:(RCTDevBundlesProgressBlock)onProgress onComplete:(RCTDevBundlesLoadBlock)onComplete;

@end
Loading