1 /*
2 * Copyright (c) Meta Platforms, Inc. and 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 <ABI47_0_0React/ABI47_0_0RCTDefines.h>
11
12 extern NSString *const ABI47_0_0RCTJavaScriptLoaderErrorDomain;
13
14 extern const uint32_t ABI47_0_0RCT_BYTECODE_ALIGNMENT;
15
NS_ENUM(NSInteger)16 NS_ENUM(NSInteger){
17 ABI47_0_0RCTJavaScriptLoaderErrorNoScriptURL = 1,
18 ABI47_0_0RCTJavaScriptLoaderErrorFailedOpeningFile = 2,
19 ABI47_0_0RCTJavaScriptLoaderErrorFailedReadingFile = 3,
20 ABI47_0_0RCTJavaScriptLoaderErrorFailedStatingFile = 3,
21 ABI47_0_0RCTJavaScriptLoaderErrorURLLoadFailed = 3,
22 ABI47_0_0RCTJavaScriptLoaderErrorBCVersion = 4,
23 ABI47_0_0RCTJavaScriptLoaderErrorBCNotSupported = 4,
24
25 ABI47_0_0RCTJavaScriptLoaderErrorCannotBeLoadedSynchronously = 1000,
26 };
27
NS_ENUM(NSInteger)28 NS_ENUM(NSInteger){
29 ABI47_0_0RCTSourceFilesChangedCountNotBuiltByBundler = -2,
30 ABI47_0_0RCTSourceFilesChangedCountRebuiltFromScratch = -1,
31 };
32
33 @interface ABI47_0_0RCTLoadingProgress : NSObject
34
35 @property (nonatomic, copy) NSString *status;
36 @property (strong, nonatomic) NSNumber *done;
37 @property (strong, nonatomic) NSNumber *total;
38
39 @end
40
41 @interface ABI47_0_0RCTSource : NSObject
42
43 /**
44 * URL of the source object.
45 */
46 @property (strong, nonatomic, readonly) NSURL *url;
47
48 /**
49 * JS source (or simply the binary header in the case of a RAM bundle).
50 */
51 @property (strong, nonatomic, readonly) NSData *data;
52
53 /**
54 * Length of the entire JS bundle. Note that self.length != self.data.length in the case of certain bundle formats. For
55 * instance, when using RAM bundles:
56 *
57 * - self.data will point to the bundle header
58 * - self.data.length is the length of the bundle header, i.e. sizeof(ABI47_0_0facebook::ABI47_0_0React::BundleHeader)
59 * - self.length is the length of the entire bundle file (header + contents)
60 */
61 @property (nonatomic, readonly) NSUInteger length;
62
63 /**
64 * Returns number of files changed when building this bundle:
65 *
66 * - ABI47_0_0RCTSourceFilesChangedCountNotBuiltByBundler if the source wasn't built by the bundler (e.g. read from disk)
67 * - ABI47_0_0RCTSourceFilesChangedCountRebuiltFromScratch if the source was rebuilt from scratch by the bundler
68 * - Otherwise, the number of files changed when incrementally rebuilding the source
69 */
70 @property (nonatomic, readonly) NSInteger filesChangedCount;
71
72 @end
73
74 typedef void (^ABI47_0_0RCTSourceLoadProgressBlock)(ABI47_0_0RCTLoadingProgress *progressData);
75 typedef void (^ABI47_0_0RCTSourceLoadBlock)(NSError *error, ABI47_0_0RCTSource *source);
76
77 @interface ABI47_0_0RCTJavaScriptLoader : NSObject
78
79 + (void)loadBundleAtURL:(NSURL *)scriptURL
80 onProgress:(ABI47_0_0RCTSourceLoadProgressBlock)onProgress
81 onComplete:(ABI47_0_0RCTSourceLoadBlock)onComplete;
82
83 /**
84 * @experimental
85 * Attempts to synchronously load the script at the given URL. The following two conditions must be met:
86 * 1. It must be a file URL.
87 * 2. It must not point to a text/javascript file.
88 * If the URL does not meet those conditions, this method will return nil and supply an error with the domain
89 * ABI47_0_0RCTJavaScriptLoaderErrorDomain and the code ABI47_0_0RCTJavaScriptLoaderErrorCannotBeLoadedSynchronously.
90 */
91 + (NSData *)attemptSynchronousLoadOfBundleAtURL:(NSURL *)scriptURL
92 sourceLength:(int64_t *)sourceLength
93 error:(NSError **)error;
94
95 @end
96