2015-04-19 19:55:46 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This source code is licensed under the BSD-style license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
*/
|
2015-04-02 14:33:21 +00:00
|
|
|
|
|
|
|
#import <UIKit/UIKit.h>
|
|
|
|
|
2016-11-01 17:14:00 +00:00
|
|
|
#import "RCTDefines.h"
|
|
|
|
|
|
|
|
/**
|
|
|
|
* RCTScriptTag
|
|
|
|
*
|
|
|
|
* Scripts given to the JS Executors to run could be in any of the following
|
|
|
|
* formats. They are tagged so the executor knows how to run them.
|
|
|
|
*/
|
|
|
|
typedef NS_ENUM(NSInteger) {
|
|
|
|
RCTScriptString = 0,
|
|
|
|
RCTScriptRAMBundle,
|
|
|
|
RCTScriptBCBundle,
|
|
|
|
} RCTScriptTag;
|
|
|
|
|
|
|
|
/**
|
2016-11-11 13:21:37 +00:00
|
|
|
* RCTBundleHeader
|
2016-11-01 17:14:00 +00:00
|
|
|
*
|
2016-11-11 13:21:37 +00:00
|
|
|
* RAM bundles and BC bundles begin with headers. For RAM bundles this is
|
|
|
|
* 4 bytes, for BC bundles this is 12 bytes. This structure holds the first 12
|
2016-11-01 17:14:00 +00:00
|
|
|
* bytes from a bundle in a way that gives access to that information.
|
|
|
|
*/
|
|
|
|
typedef union {
|
2016-11-11 13:21:37 +00:00
|
|
|
// `allBytes` is the first field so that zero-initializing the union fills
|
|
|
|
// it completely with zeroes. Without it, only the first field of the union
|
|
|
|
// gets zero-initialized.
|
|
|
|
uint32_t allBytes[3];
|
|
|
|
|
|
|
|
uint32_t RAMMagic;
|
|
|
|
|
|
|
|
struct {
|
|
|
|
uint64_t BCMagic;
|
|
|
|
uint32_t BCVersion;
|
|
|
|
};
|
|
|
|
} RCTBundleHeader;
|
2016-11-01 17:14:00 +00:00
|
|
|
|
|
|
|
/**
|
2016-11-11 13:21:37 +00:00
|
|
|
* RCTParseTypeFromHeader
|
2016-11-01 17:14:00 +00:00
|
|
|
*
|
|
|
|
* Takes the first 8 bytes of a bundle, and returns a tag describing the
|
|
|
|
* bundle's format.
|
|
|
|
*/
|
2016-11-11 13:21:37 +00:00
|
|
|
RCT_EXTERN RCTScriptTag RCTParseTypeFromHeader(RCTBundleHeader header);
|
2016-03-17 17:34:46 +00:00
|
|
|
|
2016-11-14 15:53:31 +00:00
|
|
|
/**
|
|
|
|
* RCTStringForScriptTag
|
|
|
|
*
|
|
|
|
* Convert an `RCTScriptTag` enum into a string, useful for emitting in errors
|
|
|
|
* and diagnostic messages.
|
|
|
|
*/
|
|
|
|
RCT_EXTERN NSString *RCTStringForScriptTag(RCTScriptTag tag);
|
|
|
|
|
2016-07-12 12:13:32 +00:00
|
|
|
extern NSString *const RCTJavaScriptLoaderErrorDomain;
|
|
|
|
|
|
|
|
NS_ENUM(NSInteger) {
|
|
|
|
RCTJavaScriptLoaderErrorNoScriptURL = 1,
|
|
|
|
RCTJavaScriptLoaderErrorFailedOpeningFile = 2,
|
|
|
|
RCTJavaScriptLoaderErrorFailedReadingFile = 3,
|
|
|
|
RCTJavaScriptLoaderErrorFailedStatingFile = 3,
|
|
|
|
RCTJavaScriptLoaderErrorURLLoadFailed = 3,
|
2016-11-11 13:21:37 +00:00
|
|
|
RCTJavaScriptLoaderErrorBCVersion = 4,
|
2016-07-12 12:13:32 +00:00
|
|
|
|
|
|
|
RCTJavaScriptLoaderErrorCannotBeLoadedSynchronously = 1000,
|
|
|
|
};
|
|
|
|
|
2016-10-13 18:42:30 +00:00
|
|
|
@interface RCTLoadingProgress : NSObject
|
|
|
|
|
|
|
|
@property (nonatomic, copy) NSString *status;
|
|
|
|
@property (strong, nonatomic) NSNumber *done;
|
|
|
|
@property (strong, nonatomic) NSNumber *total;
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
typedef void (^RCTSourceLoadProgressBlock)(RCTLoadingProgress *progressData);
|
2016-07-12 12:13:34 +00:00
|
|
|
typedef void (^RCTSourceLoadBlock)(NSError *error, NSData *source, int64_t sourceLength);
|
2015-04-02 14:33:21 +00:00
|
|
|
|
|
|
|
@interface RCTJavaScriptLoader : NSObject
|
|
|
|
|
2016-10-13 18:42:30 +00:00
|
|
|
+ (void)loadBundleAtURL:(NSURL *)scriptURL onProgress:(RCTSourceLoadProgressBlock)onProgress onComplete:(RCTSourceLoadBlock)onComplete;
|
2016-07-12 12:13:32 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @experimental
|
|
|
|
* Attempts to synchronously load the script at the given URL. The following two conditions must be met:
|
2016-07-13 23:39:15 +00:00
|
|
|
* 1. It must be a file URL.
|
2016-11-01 17:14:00 +00:00
|
|
|
* 2. It must not point to a text/javascript file.
|
2016-07-12 12:13:32 +00:00
|
|
|
* If the URL does not meet those conditions, this method will return nil and supply an error with the domain
|
|
|
|
* RCTJavaScriptLoaderErrorDomain and the code RCTJavaScriptLoaderErrorCannotBeLoadedSynchronously.
|
|
|
|
*/
|
|
|
|
+ (NSData *)attemptSynchronousLoadOfBundleAtURL:(NSURL *)scriptURL
|
2016-11-11 13:21:37 +00:00
|
|
|
runtimeBCVersion:(int32_t)runtimeBCVersion
|
2016-07-12 12:13:32 +00:00
|
|
|
sourceLength:(int64_t *)sourceLength
|
|
|
|
error:(NSError **)error;
|
2015-04-02 14:33:21 +00:00
|
|
|
|
|
|
|
@end
|