UNPKG

3.25 kBtext/x-cView Raw
1/*
2 * Copyright (c) Facebook, Inc. and its affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8#import <UIKit/UIKit.h>
9
10#import <React/RCTDefines.h>
11
12extern NSString *const RCTJavaScriptLoaderErrorDomain;
13
14NS_ENUM(NSInteger) {
15 RCTJavaScriptLoaderErrorNoScriptURL = 1,
16 RCTJavaScriptLoaderErrorFailedOpeningFile = 2,
17 RCTJavaScriptLoaderErrorFailedReadingFile = 3,
18 RCTJavaScriptLoaderErrorFailedStatingFile = 3,
19 RCTJavaScriptLoaderErrorURLLoadFailed = 3,
20 RCTJavaScriptLoaderErrorBCVersion = 4,
21 RCTJavaScriptLoaderErrorBCNotSupported = 4,
22
23 RCTJavaScriptLoaderErrorCannotBeLoadedSynchronously = 1000,
24};
25
26NS_ENUM(NSInteger) {
27 RCTSourceFilesChangedCountNotBuiltByBundler = -2,
28 RCTSourceFilesChangedCountRebuiltFromScratch = -1,
29};
30
31@interface RCTLoadingProgress : NSObject
32
33@property (nonatomic, copy) NSString *status;
34@property (strong, nonatomic) NSNumber *done;
35@property (strong, nonatomic) NSNumber *total;
36
37@end
38
39@interface RCTSource : NSObject
40
41/**
42 * URL of the source object.
43 */
44@property (strong, nonatomic, readonly) NSURL *url;
45
46/**
47 * JS source (or simply the binary header in the case of a RAM bundle).
48 */
49@property (strong, nonatomic, readonly) NSData *data;
50
51/**
52 * Length of the entire JS bundle. Note that self.length != self.data.length in the case of certain bundle formats. For
53 * instance, when using RAM bundles:
54 *
55 * - self.data will point to the bundle header
56 * - self.data.length is the length of the bundle header, i.e. sizeof(facebook::react::BundleHeader)
57 * - self.length is the length of the entire bundle file (header + contents)
58 */
59@property (nonatomic, readonly) NSUInteger length;
60
61/**
62 * Returns number of files changed when building this bundle:
63 *
64 * - RCTSourceFilesChangedCountNotBuiltByBundler if the source wasn't built by the bundler (e.g. read from disk)
65 * - RCTSourceFilesChangedCountRebuiltFromScratch if the source was rebuilt from scratch by the bundler
66 * - Otherwise, the number of files changed when incrementally rebuilding the source
67 */
68@property (nonatomic, readonly) NSInteger filesChangedCount;
69
70@end
71
72typedef void (^RCTSourceLoadProgressBlock)(RCTLoadingProgress *progressData);
73typedef void (^RCTSourceLoadBlock)(NSError *error, RCTSource *source);
74
75@interface RCTJavaScriptLoader : NSObject
76
77+ (void)loadBundleAtURL:(NSURL *)scriptURL
78 onProgress:(RCTSourceLoadProgressBlock)onProgress
79 onComplete:(RCTSourceLoadBlock)onComplete;
80
81/**
82 * @experimental
83 * Attempts to synchronously load the script at the given URL. The following two conditions must be met:
84 * 1. It must be a file URL.
85 * 2. It must not point to a text/javascript file.
86 * If the URL does not meet those conditions, this method will return nil and supply an error with the domain
87 * RCTJavaScriptLoaderErrorDomain and the code RCTJavaScriptLoaderErrorCannotBeLoadedSynchronously.
88 */
89+ (NSData *)attemptSynchronousLoadOfBundleAtURL:(NSURL *)scriptURL
90 runtimeBCVersion:(int32_t)runtimeBCVersion
91 sourceLength:(int64_t *)sourceLength
92 error:(NSError **)error;
93
94@end